{"record":{"id":"15ca21a45ce8f58b","repo":"rust-lang/rust","slug":"failed-to-wait-for-as","errorCode":null,"errorMessage":"Failed to wait for `as`.","messagePattern":"Failed to wait for `as`\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_codegen_cranelift/src/global_asm.rs","lineNumber":235,"sourceCode":"\n    // Remove all LLVM style comments\n    let mut global_asm = global_asm\n        .lines()\n        .map(|line| if let Some(index) = line.find(\"//\") { &line[0..index] } else { line })\n        .collect::<Vec<_>>()\n        .join(\"\\n\");\n    global_asm.push('\\n');\n\n    // Assemble `global_asm`\n    if option_env!(\"CG_CLIF_FORCE_GNU_AS\").is_some() {\n        let mut child = Command::new(&config.assembler)\n            .arg(\"-o\")\n            .arg(&global_asm_object_file)\n            .stdin(Stdio::piped())\n            .spawn()\n            .expect(\"Failed to spawn `as`.\");\n        child.stdin.take().unwrap().write_all(global_asm.as_bytes()).unwrap();\n        let status = child.wait().expect(\"Failed to wait for `as`.\");\n        if !status.success() {\n            return Err(format!(\"Failed to assemble `{}`\", global_asm));\n        }\n    } else {\n        // Escape { and }\n        let global_asm = global_asm.replace('{', \"{{\").replace('}', \"}}\");\n\n        let mut child = Command::new(std::env::current_exe().unwrap())\n            // Avoid a warning about the jobserver fd not being passed\n            .env_remove(\"CARGO_MAKEFLAGS\")\n            .arg(\"--target\")\n            .arg(&config.target)\n            .arg(\"--crate-type\")\n            .arg(\"staticlib\")\n            .arg(\"--emit\")\n            .arg(\"obj\")\n            .arg(\"-o\")\n            .arg(&global_asm_object_file)","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/compiler/rustc_codegen_cranelift/src/global_asm.rs#L217-L253","documentation":"This fires in Cranelift codegen's `compile_global_asm` after spawning the system assembler (`as`) with `CG_CLIF_FORCE_GNU_AS` set. The code calls `child.wait().expect(\"Failed to wait for `as`.\")`. This panics if `wait()` fails — which happens when the child process was already reaped (e.g., by a SIGCHLD handler), killed by the OS (OOM killer), or if the system call itself errors (e.g., EINTR without retry, or the PID is invalid).","triggerScenarios":"The assembler (`as`) was spawned successfully but `wait()` on the child handle fails. This can happen if another part of the process reaps the child (signal handler, threaded runtime), if the OOM killer terminates `as`, or if the process receives a signal that interrupts the wait.","commonSituations":"Systems under memory pressure where `as` gets OOM-killed during assembly of large `global_asm!` blocks. Process managers or threaded runtimes that install SIGCHLD handlers that race with `wait()`. Rare on normal systems; more common in CI under resource constraints or in containers with strict memory limits.","solutions":["Check system memory — `as` may have been OOM-killed. Increase container/host memory limits.","Retry the build — transient signal/OOM issues are often non-reproducible.","Remove `CG_CLIF_FORCE_GNU_AS` to use the LLVM-based asm path which doesn't spawn a subprocess.","If running under a process supervisor that reaps children, disable it or configure it to not reap cg_clif's children.","Check dmesg/syslog for OOM killer activity: `dmesg | grep -i 'killed process'`."],"exampleFix":"# before (large global_asm + memory pressure → as killed → wait fails)\nCG_CLIF_FORCE_GNU_AS=1 cargo build\n\n# after (remove the flag to avoid spawning `as`)\nunset CG_CLIF_FORCE_GNU_AS\ncargo build","handlingStrategy":"retry","validationCode":"// Check available memory before building large global_asm blocks:\n// In a CI script:\n// free -m | awk '/Mem:/ { if ($4 < 512) { echo \"Low memory; as may be OOM-killed\"; exit 1; } }'\n// Or simply avoid CG_CLIF_FORCE_GNU_AS to use the in-process LLVM path.","typeGuard":null,"tryCatchPattern":"// In a build script, retry on assembler wait failure:\nfn assemble_with_retry(asm: &str, n: u32) -> bool {\n    for _ in 0..n {\n        let mut child = match Command::new(\"as\").stdin(Stdio::piped()).spawn() {\n            Ok(c) => c,\n            Err(_) => return false,\n        };\n        if child.wait().is_ok() { return true; }\n    }\n    false\n}","preventionTips":["Ensure sufficient memory for assembling large global_asm! blocks.","Unset CG_CLIF_FORCE_GNU_AS to avoid spawning external 'as'.","Monitor for OOM kills with 'dmesg' during builds.","Retry builds that fail transiently due to resource limits."],"tags":["rustc","cranelift","codegen","global-asm","subprocess","oom","signal","environment","cg-clif"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}