rust-lang / rust-lang/rust

ICE in link_staticlib: called Result::unwrap() on an Err value: Os { code: 2, kind: NotFound, message: No such file or directory }

Open
#156,464 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs-triage
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Summary

Incremental compilation of a crate with crate-type = ["lib", "cdylib", "staticlib"] panics in link_staticlibeach_linked_rlibadd_archive() with ENOENT. The stale rlib path persists from a prior compilation cycle.

Steps to Reproduce

  1. cargo new ice-repro && cd ice-repro
  2. Add crc-fast = "=1.8.0" to [dependencies] in Cargo.toml
  3. cargo check (creates incremental metadata)
  4. cargo clean -p ice-repro (cleans only the top crate, not deps)
  5. cargo build (triggers incremental rebuild of crc-fast which has crate-type = ["lib", "cdylib", "staticlib"])

Alternatively, use this Cargo.toml:

[package]
name = "ice-repro"
version = "0.1.0"
edition = "2024"

[dependencies]
crc-fast = "=1.8.0"

The ICE is intermittent (~50% occurrence in the observed workspace).

Meta

rustc --version --verbose:

rustc 1.95.0 (59807616e 2026-04-14)
binary: rustc
commit-hash: 59807616e1fa2540724bfbac14d7976d7e4a3860
commit-date: 2026-04-14
host: x86_64-unknown-linux-gnu
release: 1.95.0
LLVM version: 20.1.4

Error Output

thread 'rustc' (1111947) panicked at /rustc-dev/59807616e1fa2540724bfbac14d7976d7e4a3860/compiler/rustc_codegen_ssa/src/back/link.rs:509:14:
called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }

Full backtrace:

   0:     0x7fc469f9314b - <<std[e28293b1aa0f68bd]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[c1f1a4ba060b9bfa]::fmt::Display>::fmt
   1:     0x7fc46a61f408 - core[c1f1a4ba060b9bfa]::fmt::write
   2:     0x7fc46bb683b6 - <std[e28293b1aa0f68bd]::sys::stdio::unix::Stderr as std[e28293b1aa0f68bd]::io::Write>::write_fmt
   3:     0x7fc469f69238 - std[e28293b1aa0f68bd]::panicking::default_hook::{closure#0}
   4:     0x7fc469f865b3 - std[e28293b1aa0f68bd]::panicking::default_hook
   5:     0x7fc468f5cc30 - std[e28293b1aa0f68bd]::panicking::update_hook::<alloc[fdfd2bd8633a6659]::boxed::Box<rustc_driver_impl[e4ca9dd5dd6cf2a8]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7fc469f86892 - std[e28293b1aa0f68bd]::panicking::panic_with_hook
   7:     0x7fc469f692f8 - std[e28293b1aa0f68bd]::panicking::panic_handler::{closure#0}
   8:     0x7fc469f60029 - std[e28293b1aa0f68bd]::sys::backtrace::__rust_end_short_backtrace::<std[e28293b1aa0f68bd]::panicking::panic_handler::{closure#0}, !>
   9:     0x7fc469f6ad5d - __rustc[b7974e8690430dd9]::rust_begin_unwind
  10:     0x7fc466cde82c - core[c1f1a4ba060b9bfa]::panicking::panic_fmt
  11:     0x7fc4667076f2 - core[c1f1a4ba060b9bfa]::result::unwrap_failed
  12:     0x7fc468dc368a - rustc_codegen_ssa[fd5ecd340cdb7a09]::back::link::link_staticlib::{closure#0}
  13:     0x7fc46b96e27b - rustc_codegen_ssa[fd5ecd340cdb7a09]::back::link::each_linked_rlib
  14:     0x7fc46b5c1024 - rustc_codegen_ssa[fd5ecd340cdb7a09]::back::link::link_binary
  15:     0x7fc46b5bf8a9 - <rustc_codegen_llvm[3c18e353d9a32df8]::LlvmCodegenBackend as rustc_codegen_ssa[fd5ecd340cdb7a09]::traits::backend::CodegenBackend>::link
  16:     0x7fc46b97807b - <rustc_interface[c8170c4b7b680ee8]::queries::Linker>::link
  17:     0x7fc46b85651a - rustc_interface[c8170c4b7b680ee8]::interface::run_compiler::<(), rustc_driver_impl[e4ca9dd5dd6cf2a8]::run_compiler::{closure#0}>::{closure#1}
  18:     0x7fc46b82663e - std[e28293b1aa0f68bd]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[c8170c4b7b680ee8]::util::run_in_thread_with_globals<rustc_interface[c8170c4b7b680ee8]::util::run_in_thread_pool_with_globals<rustc_interface[c8170c4b7b680ee8]::interface::run_compiler<(), rustc_driver_impl[e4ca9dd5dd6cf2a8]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  19:     0x7fc46b826ca0 - <std[e28293b1aa0f68bd]::thread::lifecycle::spawn_unchecked<rustc_interface[c8170c4b7b680ee8]::util::run_in_thread_with_globals<rustc_interface[c8170c4b7b680ee8]::util::run_in_thread_pool_with_globals<rustc_interface[c8170c4b7b680ee8]::interface::run_compiler<(), rustc_driver_impl[e4ca9dd5dd6cf2a8]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[c1f1a4ba060b9bfa]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  20:     0x7fc46b827b2c - <std[e28293b1aa0f68bd]::sys::thread::unix::Thread>::new::thread_start
  21:     0x7fc4650981b9 - <unknown>
  22:     0x7fc46511d21c - <unknown>
  23:                0x0 - <unknown>

Compiler Flags

--crate-type lib --crate-type cdylib --crate-type staticlib -C embed-bitcode=no -C debuginfo=2

Notes

  • The crc-fast crate declares crate-type = ["lib", "cdylib", "staticlib"] to produce a C-compatible shared library alongside the Rust lib.
  • The panic occurs at link.rs:509 in link_staticlib when each_linked_rlib returns a path to an rlib that no longer exists on disk (stale incremental-cache reference).
  • The same thread ID (1111947) appeared consistently across runs, suggesting deterministic behavior based on the incremental cache state.
  • Does NOT trigger on rustc 1.94.0.
  • The add_archive(path).unwrap() at link.rs:509 should handle this gracefully (e.g. expect with a descriptive message, or skip missing rlibs).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the ICE with the provided cargo new, cargo check, cargo clean -p, and cargo build sequence. Read compiler/rustc_codegen_ssa/src/back/link.rs around link_staticlib, each_linked_rlib, and add_archive(), where the stale rlib path is reported. Done means the reproduction no longer panics when that rlib is missing and the failure is handled gracefully.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.