Skip to content

[ICE]: crash after E0080 when taking a reference to an extern static in a static initializer #153806

@VulnHunter008

Description

@VulnHunter008

Code

extern "C" {
    pub static __ImageBase: u8;
}
pub static FOO: &'static u8 = unsafe { &unsafe { __ImageBase } };
fn main() {}

Meta

rustc --version --verbose:

rustc 1.91.0-nightly (7aef4bec4 2025-09-01)
binary: rustc
commit-hash: 7aef4bec4bec16cb6204d51eb633873e23b18771
commit-date: 2025-09-01
host: x86_64-unknown-linux-gnu
release: 1.91.0-nightly
LLVM version: 21.1.0

Error output

error[E0080]: cannot access extern static `__ImageBase`
 --> equiv-rust-Rule364.rs:4:50
  |
4 | pub static FOO: &'static u8 = unsafe { &unsafe { __ImageBase } };
  |                                                  ^^^^^^^^^^^ evaluation of `FOO` failed here

error: internal compiler error: compiler/rustc_const_eval/src/interpret/eval_context.rs:597:33: interpret const eval failure of Unevaluated(UnevaluatedConst { def: DefId(0:5 ~ equiv_rust_Rule364[7bc5]::FOO), args: [], promoted: Some(promoted[0]) }, &'{erased} u8) which is not in required_consts
 --> equiv-rust-Rule364.rs:4:40
  |
4 | pub static FOO: &'static u8 = unsafe { &unsafe { __ImageBase } };
  |                                        ^^^^^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/eval_context.rs:597:33:
Box<dyn Any>

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
note: please make sure that you have updated to the latest nightly
Backtrace

thread 'rustc' (2015879) panicked at compiler/rustc_const_eval/src/interpret/eval_context.rs:597:33:
Box<dyn Any>
stack backtrace:
   0:     0x7f690179b3f3 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::haa9e21b9f7728e9d
   1:     0x7f6901e01a58 - core::fmt::write::h47c537b314f2b42f
   2:     0x7f6901750281 - std::io::Write::write_fmt::h5da305e456c839dd
   3:     0x7f69017612d2 - std::sys::backtrace::BacktraceLock::print::hcf670bc61597714e
   4:     0x7f6901767259 - std::panicking::default_hook::{{closure}}::hd30aa8fb7428f34c
   5:     0x7f6901766d83 - std::panicking::default_hook::h6f511f2c07c5c455
   6:     0x7f69007c8ee5 - std[5da760f60d7714ca]::panicking::update_hook::<alloc[1522900af3ecc125]::boxed::Box<rustc_driver_impl[16ac858b76c31f9c]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7f690176770e - std::panicking::panic_with_hook::heb0ec0de58fd0d2e
   8:     0x7f69008058c1 - std[5da760f60d7714ca]::panicking::begin_panic::<rustc_errors[ec897967084f5882]::ExplicitBug>::{closure#0}
   9:     0x7f69007f9146 - std[5da760f60d7714ca]::sys::backtrace::__rust_end_short_backtrace::<std[5da760f60d7714ca]::panicking::begin_panic<rustc_errors[ec897967084f5882]::ExplicitBug>::{closure#0}, !>
  10:     0x7f69007f6e4b - std[5da760f60d7714ca]::panicking::begin_panic::<rustc_errors[ec897967084f5882]::ExplicitBug>
  11:     0x7f6900810fd1 - <rustc_errors[ec897967084f5882]::diagnostic::BugAbort as rustc_errors[ec897967084f5882]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x7f6900d80dfc - <rustc_errors[ec897967084f5882]::DiagCtxtHandle>::span_bug::<rustc_span[7570dc1d93289a01]::span_encoding::Span, alloc[1522900af3ecc125]::string::String>
  13:     0x7f6900da6df7 - rustc_middle[7207d213a2a562b6]::util::bug::opt_span_bug_fmt::<rustc_span[7570dc1d93289a01]::span_encoding::Span>::{closure#0}
  14:     0x7f6900da6e7a - rustc_middle[7207d213a2a562b6]::ty::context::tls::with_opt::<rustc_middle[7207d213a2a562b6]::util::bug::opt_span_bug_fmt<rustc_span[7570dc1d93289a01]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  15:     0x7f6900d955cb - rustc_middle[7207d213a2a562b6]::ty::context::tls::with_context_opt::<rustc_middle[7207d213a2a562b6]::ty::context::tls::with_opt<rustc_middle[7207d213a2a562b6]::util::bug::opt_span_bug_fmt<rustc_span[7570dc1d93289a01]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  16:     0x7f68ff0313d7 - rustc_middle[7207d213a2a562b6]::util::bug::span_bug_fmt::<rustc_span[7570dc1d93289a01]::span_encoding::Span>
  17:     0x7f690209d099 - <rustc_const_eval[ddd0185d600a9d90]::interpret::eval_context::InterpCx<rustc_const_eval[ddd0185d600a9d90]::const_eval::machine::CompileTimeMachine>>::eval_rvalue_into_place
  18:     0x7f6902074518 - rustc_const_eval[ddd0185d600a9d90]::const_eval::eval_queries::eval_body_using_ecx::<rustc_middle[7207d213a2a562b6]::mir::interpret::allocation::ConstAllocation>
  19:     0x7f6902b89b90 - rustc_const_eval[ddd0185d600a9d90]::const_eval::eval_queries::eval_static_initializer_provider
  20:     0x7f6902b89755 - rustc_query_impl[684ab2f7647ada3b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[684ab2f7647ada3b]::query_impl::eval_static_initializer::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7207d213a2a562b6]::query::erase::Erased<[u8; 16usize]>>
  21:     0x7f6902b89733 - <rustc_query_impl[684ab2f7647ada3b]::query_impl::eval_static_initializer::dynamic_query::{closure#2} as core[7ac50f046ab9c0d]::ops::function::FnOnce<(rustc_middle[7207d213a2a562b6]::ty::context::TyCtxt, rustc_span[7570dc1d93289a01]::def_id::DefId)>>::call_once
  22:     0x7f6901fa37f2 - rustc_query_system[d8ada103bf964d49]::query::plumbing::try_execute_query::<rustc_query_impl[684ab2f7647ada3b]::DynamicConfig<rustc_query_system[d8ada103bf964d49]::query::caches::DefIdCache<rustc_middle[7207d213a2a562b6]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[684ab2f7647ada3b]::plumbing::QueryCtxt, false>
  23:     0x7f69028bdb62 - rustc_query_impl[684ab2f7647ada3b]::query_impl::eval_static_initializer::get_query_non_incr::__rust_end_short_backtrace
  24:     0x7f69028be619 - rustc_hir_analysis[56a3e766e76011e]::check_crate
  25:     0x7f6901fdf67e - rustc_interface[c500fa999646e344]::passes::analysis
  26:     0x7f6901fdf34b - rustc_query_impl[684ab2f7647ada3b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[684ab2f7647ada3b]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7207d213a2a562b6]::query::erase::Erased<[u8; 0usize]>>
  27:     0x7f6902db97d4 - rustc_query_system[d8ada103bf964d49]::query::plumbing::try_execute_query::<rustc_query_impl[684ab2f7647ada3b]::DynamicConfig<rustc_query_system[d8ada103bf964d49]::query::caches::SingleCache<rustc_middle[7207d213a2a562b6]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[684ab2f7647ada3b]::plumbing::QueryCtxt, false>
  28:     0x7f6902db940c - rustc_query_impl[684ab2f7647ada3b]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  29:     0x7f69030816e4 - rustc_interface[c500fa999646e344]::passes::create_and_enter_global_ctxt::<core[7ac50f046ab9c0d]::option::Option<rustc_interface[c500fa999646e344]::queries::Linker>, rustc_driver_impl[16ac858b76c31f9c]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  30:     0x7f69030724e2 - rustc_interface[c500fa999646e344]::interface::run_compiler::<(), rustc_driver_impl[16ac858b76c31f9c]::run_compiler::{closure#0}>::{closure#1}
  31:     0x7f6902efacf8 - std[5da760f60d7714ca]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[c500fa999646e344]::util::run_in_thread_with_globals<rustc_interface[c500fa999646e344]::util::run_in_thread_pool_with_globals<rustc_interface[c500fa999646e344]::interface::run_compiler<(), rustc_driver_impl[16ac858b76c31f9c]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  32:     0x7f6902efa9dc - <<std[5da760f60d7714ca]::thread::Builder>::spawn_unchecked_<rustc_interface[c500fa999646e344]::util::run_in_thread_with_globals<rustc_interface[c500fa999646e344]::util::run_in_thread_pool_with_globals<rustc_interface[c500fa999646e344]::interface::run_compiler<(), rustc_driver_impl[16ac858b76c31f9c]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[7ac50f046ab9c0d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  33:     0x7f6902f008cd - std::sys::pal::unix::thread::Thread::new::thread_start::h427fd483c5aaf6bf
  34:     0x7f68fca6cac3 - start_thread
                               at ./nptl/pthread_create.c:442:8
  35:     0x7f68fcafea40 - __clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81:0
  36:                0x0 - <unknown>

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions