{"id":"9a0edf041e94d629","repo":"rust-lang/rust","slug":"corrupt-rlib","errorCode":null,"errorMessage":"corrupt rlib","messagePattern":"corrupt rlib","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_codegen_llvm/src/back/lto.rs","lineNumber":112,"sourceCode":"    for path in each_linked_rlib_for_lto {\n        let archive_data = unsafe {\n            Mmap::map(std::fs::File::open(&path).expect(\"couldn't open rlib\"))\n                .expect(\"couldn't map rlib\")\n        };\n        let archive = ArchiveFile::parse(&*archive_data).expect(\"wanted an rlib\");\n        let metadata_link = rmeta_link::read(&archive, &archive_data, &path).unwrap();\n        let obj_files = archive\n            .members()\n            .filter_map(|child| {\n                child\n                    .ok()\n                    .and_then(|c| std::str::from_utf8(c.name()).ok().map(|name| (name.trim(), c)))\n            })\n            .filter(|&(name, _)| metadata_link.rust_object_files.iter().any(|f| f == name));\n        for (name, child) in obj_files {\n            info!(\"adding bitcode from {}\", name);\n            match get_bitcode_slice_from_object_data(\n                child.data(&*archive_data).expect(\"corrupt rlib\"),\n                cgcx,\n            ) {\n                Ok(data) => {\n                    let module = SerializedModule::FromRlib(data.to_vec());\n                    upstream_modules.push((module, CString::new(name).unwrap()));\n                }\n                Err(e) => dcx.emit_fatal(e),\n            }\n        }\n    }\n\n    (symbols_below_threshold, upstream_modules)\n}\n\nfn get_bitcode_slice_from_object_data<'a>(\n    obj: &'a [u8],\n    cgcx: &CodegenContext,\n) -> Result<&'a [u8], LtoBitcodeFromRlib> {","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_codegen_llvm/src/back/lto.rs#L94-L130","documentation":"Thrown by `child.data(&*archive_data).expect(\"corrupt rlib\")` in lto.rs:112 while iterating the archive's rust object members during LTO. The archive parsed fine, but reading the raw bytes of an individual archive member failed — meaning the archive is structurally a valid `ar` container but one of its object members is truncated, has an invalid offset/size, or the backing data is shorter than the member header claims.","triggerScenarios":"Triggered during LTO when `child.data()` returns `Err` for a member whose name matches `metadata_link.rust_object_files`: partial write truncated the archive tail, an object member size field is larger than the file, or the archive was assembled incorrectly by a buggy/old rustc. Only members identified as Rust object files reach this call.","commonSituations":"Interrupted/killed build left a `.rlib` with a complete header but truncated member data; disk filled mid-write; concurrent writers to the same rlib path; copying `target/` over a channel that truncated large files; using a hand-built toolchain whose archive writer mis-encodes member sizes; antivirus/quarantine modifying the rlib after write.","solutions":["Delete the offending rlib and rebuild: `cargo clean` (or remove the specific `*.rlib`) then `cargo build`.","Check free disk space and that no other process is writing to `target/` concurrently.","Re-run on local disk (avoid NFS/SMB that may truncate or cache-incoherently write large files).","Disable any antivirus/scan-on-close for the `target/` directory.","If reproducible across clean builds, file a rustc issue with the rlib and the `-C lto` invocation, since a structurally malformed member is a compiler bug."],"exampleFix":"# before: archive header OK but member data truncated\nlto.rs:112  panic: corrupt rlib\n\n# after: ensure atomic, complete rlib writes\ncargo clean\n# avoid concurrent builds sharing one target dir\ncargo build --release","handlingStrategy":"fallback","validationCode":"fn archive_members_ok(data: &[u8]) -> bool {\n    object::read::archive::ArchiveFile::parse(data)\n        .map(|a| a.members().all(|m| m.is_ok()))\n        .unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match std::panic::catch_unwind(|| invoke_lto()) {\n    Ok(v) => v,\n    Err(_) => { /* one archive member is corrupt -> cargo clean + full rebuild */ }\n}","preventionTips":["Never SIGKILL a build mid-write; interrupted writes truncate rlib members.","Ensure the disk is not full or suffering hardware errors during codegen.","Run `cargo clean` after a crash or power loss before rebuilding.","Keep Cargo.lock stable so the same dependency tree is regenerated deterministically."],"tags":["rustc","lto","codegen","archive","corruption"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}