diff options
| author | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2025-08-07 13:13:04 +0000 |
|---|---|---|
| committer | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2025-08-07 13:41:17 +0000 |
| commit | 6c02653c4a564a2a1509dc55bdec2e5b8f02bdd9 (patch) | |
| tree | fa08ac49fc21a4bd38b1888c564bfc98b48e50ee /compiler/rustc_codegen_gcc/src | |
| parent | 9b1a30e5e69e1537ef6eb6eb829eb47075206dea (diff) | |
| download | rust-6c02653c4a564a2a1509dc55bdec2e5b8f02bdd9.tar.gz rust-6c02653c4a564a2a1509dc55bdec2e5b8f02bdd9.zip | |
Prevent name collisions with internal implementation details
The implementation of the linkage attribute inside extern blocks defines symbols starting with _rust_extern_with_linkage_. If someone tries to also define this symbol you will get a symbol conflict or even an ICE. By adding an unpredictable component to the symbol name, this becomes less of an issue.
Diffstat (limited to 'compiler/rustc_codegen_gcc/src')
| -rw-r--r-- | compiler/rustc_codegen_gcc/src/consts.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/compiler/rustc_codegen_gcc/src/consts.rs b/compiler/rustc_codegen_gcc/src/consts.rs index c04c75e1b11..873f1f1951c 100644 --- a/compiler/rustc_codegen_gcc/src/consts.rs +++ b/compiler/rustc_codegen_gcc/src/consts.rs @@ -6,6 +6,7 @@ use rustc_codegen_ssa::traits::{ BaseTypeCodegenMethods, ConstCodegenMethods, StaticCodegenMethods, }; use rustc_hir::def::DefKind; +use rustc_hir::def_id::LOCAL_CRATE; use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; use rustc_middle::mir::interpret::{ self, ConstAllocation, ErrorHandled, Scalar as InterpScalar, read_target_uint, @@ -384,8 +385,8 @@ fn check_and_apply_linkage<'gcc, 'tcx>( // linkage and there are no definitions), then // `extern_with_linkage_foo` will instead be initialized to // zero. - let mut real_name = "_rust_extern_with_linkage_".to_string(); - real_name.push_str(sym); + let real_name = + format!("_rust_extern_with_linkage_{:016x}_{sym}", cx.tcx.stable_crate_id(LOCAL_CRATE)); let global2 = cx.define_global(&real_name, gcc_type, is_tls, attrs.link_section); // TODO(antoyo): set linkage. let value = cx.const_ptrcast(global1.get_address(None), gcc_type); |
