Skip to content

rustc_symbol_mangling: use core's disambiguator for internal symbols - #164693

Open
Darksonn wants to merge 3 commits into
rust-lang:mainfrom
Darksonn:internal-symbol-core
Open

Darksonn wants to merge 3 commits into
rust-lang:mainfrom
Darksonn:internal-symbol-core

Conversation

@Darksonn

@Darksonn Darksonn commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Internal symbols incorporate the rustc version in the disambiguator to avoid linker errors when linking together multiple staticlibs containing rustc code built separately.

// We are mangling all #[rustc_std_internal_symbol] items as a
// combination of the rustc version and the unmangled linkage name.
// This is to ensure that if we link against a staticlib compiled by a
// different rustc version, we don't get symbol conflicts or even UB
// due to a different implementation/ABI. Rust staticlibs currently
// export all symbols, including those that are hidden in cdylibs.

However, the current logic doesn't properly avoid linker errors if you link together multiple staticlibs with the same rustc version but using -Zbuild-std and -Cmetadata to give the two copies of core different symbol names.

To fix this, have internal symbols use the same disambiguator as the core crate, which will avoid this linker error.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 21, 2026
@rustbot

rustbot commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator

r? @fee1-dead

rustbot has assigned @fee1-dead.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 77 candidates
  • Random selection from 19 candidates

@Darksonn

Copy link
Copy Markdown
Member Author

cc @bjorn3

@Darksonn
Darksonn force-pushed the internal-symbol-core branch from fbff534 to de147c9 Compare October 21, 2026 14:30
});
// Use the same disambiguator as 'core' to ensure #[rustc_std_internal_symbol] functions
// get a different symbol name depending on the rustc version and -Cmetadata flags.
if let Some(sized) = tcx.lang_items().sized_trait() {

@bjorn3 bjorn3 Oct 21, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Sized trait is guaranteed to exist at this point. If you try to define any function or static without defining the Sized trait you will get an error during type checking.

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I just unwrap, then?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like that's not quite true. CI fails with unwrap.

@Darksonn
Darksonn force-pushed the internal-symbol-core branch 2 times, most recently from 8b77646 to ca9ccce Compare October 21, 2026 15:20
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job test-x86_64-gnu-gcc-core-tests failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

thread 'rustc' (12795) panicked at compiler/rustc_symbol_mangling/src/v0.rs:160:22:
#[rustc_std_internal_symbol] requires the Sized trait to be defined
stack backtrace:
   0:     0x7f6224768751 - <<std[617be2ca0a6fd877]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[a373ad73a504971]::fmt::Display>::fmt
   1:     0x7f62247af0aa - core[a373ad73a504971]::fmt::write
   2:     0x7f622477a2ec - <std[617be2ca0a6fd877]::sys::stdio::unix::Stderr as core[a373ad73a504971]::io::write::Write>::write_fmt
   3:     0x7f6224731cb6 - std[617be2ca0a6fd877]::panicking::default_hook::{closure#0}
   4:     0x7f62247596c1 - std[617be2ca0a6fd877]::panicking::default_hook
   5:     0x7f6220d53fa4 - <alloc[2e1b2a31b91974c5]::boxed::Box<rustc_driver_impl[1ffecc3148cf2547]::install_ice_hook::{closure#1}> as core[a373ad73a504971]::ops::function::Fn<(&dyn for<'a, 'b> core[a373ad73a504971]::ops::function::Fn<(&'a std[617be2ca0a6fd877]::panic::PanicHookInfo<'b>,), Output = ()> + core[a373ad73a504971]::marker::Sync + core[a373ad73a504971]::marker::Send, &std[617be2ca0a6fd877]::panic::PanicHookInfo)>>::call
   6:     0x7f6224759a22 - std[617be2ca0a6fd877]::panicking::panic_with_hook
   7:     0x7f6224731d62 - std[617be2ca0a6fd877]::panicking::panic_handler::{closure#0}
   8:     0x7f6224729329 - std[617be2ca0a6fd877]::sys::backtrace::__rust_end_short_backtrace::<std[617be2ca0a6fd877]::panicking::panic_handler::{closure#0}, !>
   9:     0x7f622473384d - __rustc[ea4f61d10b84890b]::rust_begin_unwind
  10:     0x7f62247afb3c - core[a373ad73a504971]::panicking::panic_fmt
  11:     0x7f62247af784 - core[a373ad73a504971]::option::expect_failed
  12:     0x7f622385d727 - rustc_symbol_mangling[eff94014b6d3cdd8]::v0::mangle_internal_symbol
  13:     0x7f621e05a3f1 - <rustc_codegen_gcc[aba235c9c9c51efc]::GccCodegenBackend as rustc_codegen_ssa[1c153239a267f10]::traits::backend::CodegenBackend>::codegen_crate
  14:     0x7f6220f1b0d1 - <rustc_session[7fc9010920fe7054]::session::Session>::time::<alloc[2e1b2a31b91974c5]::boxed::Box<dyn core[a373ad73a504971]::any::Any>, rustc_interface[e2be339984192575]::passes::start_codegen::{closure#1}>
  15:     0x7f6220ed80c2 - rustc_interface[e2be339984192575]::passes::start_codegen
  16:     0x7f6220f34c4a - <rustc_interface[e2be339984192575]::queries::Linker>::codegen_and_build_linker
  17:     0x7f6220d27001 - <std[617be2ca0a6fd877]::thread::local::LocalKey<core[a373ad73a504971]::cell::Cell<*const ()>>>::with::<rustc_middle[718ae9a37f5aca00]::ty::context::tls::enter_context<<rustc_middle[718ae9a37f5aca00]::ty::context::GlobalCtxt>::enter<rustc_interface[e2be339984192575]::passes::create_and_enter_global_ctxt<core[a373ad73a504971]::option::Option<rustc_interface[e2be339984192575]::queries::Linker>, rustc_driver_impl[1ffecc3148cf2547]::compiler_entrypoint::{closure#0}::{closure#1}>::{closure#2}, core[a373ad73a504971]::option::Option<rustc_interface[e2be339984192575]::queries::Linker>>::{closure#1}, core[a373ad73a504971]::option::Option<rustc_interface[e2be339984192575]::queries::Linker>>::{closure#0}, core[a373ad73a504971]::option::Option<rustc_interface[e2be339984192575]::queries::Linker>>
  18:     0x7f6220cd80ae - <rustc_middle[718ae9a37f5aca00]::ty::context::TyCtxt>::create_global_ctxt::<core[a373ad73a504971]::option::Option<rustc_interface[e2be339984192575]::queries::Linker>, rustc_interface[e2be339984192575]::passes::create_and_enter_global_ctxt<core[a373ad73a504971]::option::Option<rustc_interface[e2be339984192575]::queries::Linker>, rustc_driver_impl[1ffecc3148cf2547]::compiler_entrypoint::{closure#0}::{closure#1}>::{closure#2}>
  19:     0x7f6220cd69c8 - rustc_interface[e2be339984192575]::passes::create_and_enter_global_ctxt::<core[a373ad73a504971]::option::Option<rustc_interface[e2be339984192575]::queries::Linker>, rustc_driver_impl[1ffecc3148cf2547]::compiler_entrypoint::{closure#0}::{closure#1}>
  20:     0x7f6220c23323 - <scoped_tls[c37948c3ace7b1b7]::ScopedKey<rustc_span[1dc4d9806baf01bb]::SessionGlobals>>::set::<rustc_interface[e2be339984192575]::util::run_in_thread_with_globals<rustc_interface[e2be339984192575]::util::run_in_thread_pool_with_globals<rustc_interface[e2be339984192575]::interface::run_compiler<(), rustc_driver_impl[1ffecc3148cf2547]::compiler_entrypoint::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}, ()>
  21:     0x7f6220d6d13e - std[617be2ca0a6fd877]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[e2be339984192575]::util::run_in_thread_with_globals<rustc_interface[e2be339984192575]::util::run_in_thread_pool_with_globals<rustc_interface[e2be339984192575]::interface::run_compiler<(), rustc_driver_impl[1ffecc3148cf2547]::compiler_entrypoint::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  22:     0x7f6220c2822b - <std[617be2ca0a6fd877]::thread::lifecycle::spawn_unchecked<rustc_interface[e2be339984192575]::util::run_in_thread_with_globals<rustc_interface[e2be339984192575]::util::run_in_thread_pool_with_globals<rustc_interface[e2be339984192575]::interface::run_compiler<(), rustc_driver_impl[1ffecc3148cf2547]::compiler_entrypoint::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[a373ad73a504971]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  23:     0x7f6224764c8f - <std[617be2ca0a6fd877]::sys::thread::unix::Thread>::new::thread_start
  24:     0x7f621f66ba83 - <unknown>
  25:     0x7f621f6fd8e0 - <unknown>
  26:                0x0 - <unknown>

error: the compiler unexpectedly panicked. This is a bug

note: using internal features is not supported and expected to cause internal compiler errors when used incorrectly

warning: the ICE couldn't be written to `/checkout/rustc-ice-2026-10-21T15_28_51-12793.txt`: Read-only file system (os error 30)

note: rustc 1.101.0-nightly (f2f1aecb6 2026-10-21) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -Z embed-metadata=no -C opt-level=3 -C embed-bitcode=no -C codegen-units=1 -C embed-bitcode=yes -Z unstable-options -C force-frame-pointers=non-leaf -C overflow-checks=on -Z annotate-moves -Z unstable-options -Z macro-backtrace -C split-debuginfo=off -C prefer-dynamic -Z inline-mir -Z inline-mir-preserve-debug -Z mir_strip_debuginfo=locals-in-tiny-functions -C link-args=-Wl,-z,origin -C link-args=-Wl,-rpath,$ORIGIN/../lib -Z crate-attr=doc(html_root_url="https://doc.rust-lang.org/nightly/") -C panic=abort -Z panic-abort-tests -Z binary-dep-depinfo -Z force-unstable-if-unmarked

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
[RUSTC-TIMING] profiler_builtins test:false 0.248
rustc exited with signal: 6 (SIGABRT) (core dumped)
error: could not compile `profiler_builtins` (lib)

Caused by:
  process didn't exit successfully: `/checkout/obj/build/bootstrap/debug/rustc /checkout/obj/build/bootstrap/debug/rustc --crate-name profiler_builtins --edition=2024 library/profiler_builtins/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat,unused-externs-silent --crate-type lib --emit=dep-info,metadata,link -Z embed-metadata=no -C opt-level=3 -C embed-bitcode=no -C codegen-units=1 -Cembed-bitcode=yes -Zunstable-options -Cforce-frame-pointers=non-leaf -C overflow-checks=on --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=01d5a0a45a66a5b9 -C extra-filename=-c1b53e1736b26881 --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/dist/build/profiler_builtins/c1b53e1736b26881/out --target x86_64-unknown-linux-gnu -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/dist/build/profiler_builtins/c1b53e1736b26881/out -Zannotate-moves '--check-cfg=cfg(feature,values(any()))' -Zunstable-options -Zmacro-backtrace -Csplit-debuginfo=off -Cprefer-dynamic -Zinline-mir -Zinline-mir-preserve-debug -Zmir_strip_debuginfo=locals-in-tiny-functions -Clink-args=-Wl,-z,origin '-Clink-args=-Wl,-rpath,$ORIGIN/../lib' -Alinker-messages '-Zcrate-attr=doc(html_root_url="https://doc.rust-lang.org/nightly/")' -Cpanic=abort -Zpanic-abort-tests -Z binary-dep-depinfo --force-warn=unused_crate_dependencies -L native=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/dist/build/profiler_builtins/380a9bbad8ab27cb/out -l static=profiler-rt` (exit status: 254)
warning: build failed, waiting for other jobs to finish...
[RUSTC-TIMING] core test:false 29.034
Bootstrap failed while executing `--stage 1 test library/coretests`
Currently active steps:
test::Crate { build_compiler: Compiler { stage: 1, host: x86_64-unknown-linux-gnu, forced_compiler: false }, target: x86_64-unknown-linux-gnu, mode: Std, crates: ["coretests"] } at src/bootstrap/src/core/build_steps/test.rs:3622

Important

For more information how to resolve CI failures of this job, visit this link.

@fee1-dead

Copy link
Copy Markdown
Member

r? @bjorn3

@bjorn3

bjorn3 commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

profiler_builtins is #![no_core] #![profiler_runtime]. I suspect it is trying to get the symbol name of the personality function. Maybe extern crate core as _; in profiler_builtins would work? You did also need to add a dependency on libcore to profiler_builtins then. Not entirely sure about the consequences of that though.

@rustbot rustbot assigned bjorn3 and unassigned fee1-dead Oct 21, 2026
@Darksonn

Copy link
Copy Markdown
Member Author

Looks like rust_eh_personality may also be a problem

@bjorn3

bjorn3 commented Oct 22, 2026

Copy link
Copy Markdown
Member

Yeah, that is what I'm saying. It likely tries to compute the symbol name of the personality function (_R*rust_eh_personality) when building profiler_builtins, but profiler_builtins currently doesn't depend on anything, so it fails due to a lack of a definition for Sized.

@rust-bors

rust-bors Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #165234) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants