Skip to content

Commit e596f7b

Browse files
authored
Rollup merge of #145051 - bjorn3:prevent_linkage_symbol_name_collision, r=petrochenkov
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. Spawned from the discussion at [#t-compiler > About static variables &rust-lang#96;_rust_extern_with_linkage_&rust-lang#42;&rust-lang#96;](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/About.20static.20variables.20.60_rust_extern_with_linkage_*.60) cc `@ywxt` Fixes rust-lang/rust#144940
2 parents bf44c58 + 60c4da7 commit e596f7b

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/constant.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,10 @@ fn data_id_for_static(
310310
// `extern_with_linkage_foo` will instead be initialized to
311311
// zero.
312312

313-
let ref_name = format!("_rust_extern_with_linkage_{}", symbol_name);
313+
let ref_name = format!(
314+
"_rust_extern_with_linkage_{:016x}_{symbol_name}",
315+
tcx.stable_crate_id(LOCAL_CRATE)
316+
);
314317
let ref_data_id = module.declare_data(&ref_name, Linkage::Local, false, false).unwrap();
315318
let mut data = DataDescription::new();
316319
data.set_align(align);

0 commit comments

Comments
 (0)