{"id":"93243beb8065f002","repo":"rust-lang/rust","slug":"couldn-t-map-rlib","errorCode":null,"errorMessage":"couldn't map rlib","messagePattern":"couldn't map rlib","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_codegen_llvm/src/back/lto.rs","lineNumber":97,"sourceCode":"    // __llvm_profile_counter_bias is pulled in at link time by an undefined reference to\n    // __llvm_profile_runtime, therefore we won't know until link time if this symbol\n    // should have default visibility.\n    symbols_below_threshold.push(c\"__llvm_profile_counter_bias\".to_owned());\n\n    // LTO seems to discard this otherwise under certain circumstances.\n    symbols_below_threshold.push(c\"rust_eh_personality\".to_owned());\n\n    // If we're performing LTO for the entire crate graph, then for each of our\n    // upstream dependencies, find the corresponding rlib and load the bitcode\n    // from the archive.\n    //\n    // We save off all the bytecode and LLVM module ids for later processing\n    // with either fat or thin LTO\n    let mut upstream_modules = Vec::new();\n    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) => {","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_codegen_llvm/src/back/lto.rs#L79-L115","documentation":"Thrown by `.expect(\"couldn't map rlib\")` on `Mmap::map(file)` in lto.rs:97 during LTO upstream rlib loading. The rlib file opened successfully but memory-mapping it failed, aborting the compiler. `Mmap::map` fails on I/O errors, empty files, files on filesystems that forbid mmap (e.g. some FUSE/network mounts), or when virtual address space is exhausted.","triggerScenarios":"Triggered when `-C lto` is enabled and the compiler successfully `open()`s an upstream rlib but `Mmap::map` returns `Err`: the rlib is 0 bytes (truncated), lives on a filesystem without mmap support, exceeds address-space limits on 32-bit hosts, or the OS denies the mapping for I/O reasons.","commonSituations":"Empty/truncated rlib from a prior interrupted `cargo build` (e.g. killed during codegen); building on a tmpfs/FUSE/SMB mount that rejects mmap; running a 32-bit toolchain against very large dependency graphs; disk-full / write-corrupted artifacts in `target/`; SELinux/AppArmor denying mmap of build artifacts.","solutions":["Delete the truncated rlib and rebuild: `cargo clean` (or remove the specific `target/release/deps/*.rlib`) then rebuild.","Move the project off network/FUSE mounts onto a local filesystem that supports mmap.","Free disk space and rebuild (a full disk can leave zero-byte artifacts).","If on a 32-bit target/host, switch to a 64-bit toolchain to avoid address-space exhaustion during mmap.","Verify the rlib size is non-zero (`ls -l`) and check `dmesg`/audit logs for mmap denials (SELinux/AppArmor)."],"exampleFix":"# before: mmap fails on a truncated/zero-byte rlib\ncargo build --release  # panic: couldn't map rlib\n\n# after: ensure non-corrupt artifacts on a mmap-capable filesystem\ncargo clean\nls -l target/release/deps/   # confirm rlibs are non-zero after rebuild\ncargo build --release","handlingStrategy":"retry","validationCode":"fn ensure_mappable(path: &std::path::Path) -> std::io::Result<()> {\n    let len = std::fs::metadata(path)?.len();\n    if len == 0 {\n        return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, \"empty rlib\"));\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"for attempt in 0..3 {\n    match std::panic::catch_unwind(|| invoke_lto()) {\n        Ok(v) => break v,\n        Err(_) if attempt < 2 => { std::thread::sleep(std::time::Duration::from_millis(200 * (attempt+1) as u64)); continue; }\n        Err(_) => { /* report mmap exhaustion / resource issue */ }\n    }\n}","preventionTips":["Raise vm.max_map_count (Linux) if many rlibs exhaust the process address space.","Do not run two concurrent builds against the same target directory.","Close any external process holding an exclusive lock on rlibs (antivirus, indexer).","Keep total dependency count reasonable; mmap failure is often address-space exhaustion."],"tags":["rustc","lto","codegen","mmap","filesystem"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}