Skip to content

Commit f4fde20

Browse files
committed
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.
1 parent b56c50f commit f4fde20

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

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)