about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_codegen_cranelift/src/constant.rs5
-rw-r--r--compiler/rustc_codegen_gcc/src/consts.rs5
-rw-r--r--compiler/rustc_codegen_llvm/src/consts.rs6
-rw-r--r--tests/codegen-llvm/sanitizer/cfi/external_weak_symbols.rs2
-rw-r--r--tests/ui/linkage-attr/linkage-detect-extern-generated-name-collision.rs26
-rw-r--r--tests/ui/linkage-attr/linkage-detect-extern-generated-name-collision.stderr8
-rw-r--r--tests/ui/linkage-attr/linkage-detect-local-generated-name-collision.rs26
-rw-r--r--tests/ui/linkage-attr/linkage-detect-local-generated-name-collision.stderr8
8 files changed, 11 insertions, 75 deletions
diff --git a/compiler/rustc_codegen_cranelift/src/constant.rs b/compiler/rustc_codegen_cranelift/src/constant.rs
index a04cfa27237..bec546badc9 100644
--- a/compiler/rustc_codegen_cranelift/src/constant.rs
+++ b/compiler/rustc_codegen_cranelift/src/constant.rs
@@ -310,7 +310,10 @@ fn data_id_for_static(
         // `extern_with_linkage_foo` will instead be initialized to
         // zero.
 
-        let ref_name = format!("_rust_extern_with_linkage_{}", symbol_name);
+        let ref_name = format!(
+            "_rust_extern_with_linkage_{:016x}_{symbol_name}",
+            tcx.stable_crate_id(LOCAL_CRATE)
+        );
         let ref_data_id = module.declare_data(&ref_name, Linkage::Local, false, false).unwrap();
         let mut data = DataDescription::new();
         data.set_align(align);
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);
diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs
index 0b96b63bc85..6b06daf3477 100644
--- a/compiler/rustc_codegen_llvm/src/consts.rs
+++ b/compiler/rustc_codegen_llvm/src/consts.rs
@@ -5,7 +5,7 @@ use rustc_codegen_ssa::common;
 use rustc_codegen_ssa::traits::*;
 use rustc_hir::LangItem;
 use rustc_hir::def::DefKind;
-use rustc_hir::def_id::DefId;
+use rustc_hir::def_id::{DefId, LOCAL_CRATE};
 use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
 use rustc_middle::mir::interpret::{
     Allocation, ConstAllocation, ErrorHandled, InitChunk, Pointer, Scalar as InterpScalar,
@@ -191,8 +191,8 @@ fn check_and_apply_linkage<'ll, '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 g2 = cx.define_global(&real_name, llty).unwrap_or_else(|| {
             cx.sess().dcx().emit_fatal(SymbolAlreadyDefined {
                 span: cx.tcx.def_span(def_id),
diff --git a/tests/codegen-llvm/sanitizer/cfi/external_weak_symbols.rs b/tests/codegen-llvm/sanitizer/cfi/external_weak_symbols.rs
index 00e9b5029af..b3cb6dfdd37 100644
--- a/tests/codegen-llvm/sanitizer/cfi/external_weak_symbols.rs
+++ b/tests/codegen-llvm/sanitizer/cfi/external_weak_symbols.rs
@@ -10,7 +10,7 @@ unsafe extern "C" {
     #[linkage = "extern_weak"]
     static FOO: Option<unsafe extern "C" fn(f64) -> ()>;
 }
-// CHECK: @_rust_extern_with_linkage_FOO = internal global ptr @FOO
+// CHECK: @_rust_extern_with_linkage_{{.*}}_FOO = internal global ptr @FOO
 
 fn main() {
     unsafe {
diff --git a/tests/ui/linkage-attr/linkage-detect-extern-generated-name-collision.rs b/tests/ui/linkage-attr/linkage-detect-extern-generated-name-collision.rs
deleted file mode 100644
index 23848056ee1..00000000000
--- a/tests/ui/linkage-attr/linkage-detect-extern-generated-name-collision.rs
+++ /dev/null
@@ -1,26 +0,0 @@
-// rust-lang/rust#61232: We used to ICE when trying to detect a
-// collision on the symbol generated for the external linkage item in
-// an extern crate.
-
-//@ build-fail
-//@ aux-build:def_colliding_external.rs
-// FIXME(#83838) codegen-units=1 triggers llvm asserts
-//@ compile-flags: -Ccodegen-units=16
-
-extern crate def_colliding_external as dep1;
-
-#[no_mangle]
-pub static _rust_extern_with_linkage_collision: i32 = 0;
-
-mod dep2 {
-    #[no_mangle]
-    pub static collision: usize = 0;
-}
-
-fn main() {
-    unsafe {
-       println!("{:p}", &dep1::collision);
-    }
-}
-
-//~? ERROR symbol `collision` is already defined
diff --git a/tests/ui/linkage-attr/linkage-detect-extern-generated-name-collision.stderr b/tests/ui/linkage-attr/linkage-detect-extern-generated-name-collision.stderr
deleted file mode 100644
index 2448c160c5c..00000000000
--- a/tests/ui/linkage-attr/linkage-detect-extern-generated-name-collision.stderr
+++ /dev/null
@@ -1,8 +0,0 @@
-error: symbol `collision` is already defined
-  --> $DIR/auxiliary/def_colliding_external.rs:6:5
-   |
-LL |     pub static collision: *const i32;
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: aborting due to 1 previous error
-
diff --git a/tests/ui/linkage-attr/linkage-detect-local-generated-name-collision.rs b/tests/ui/linkage-attr/linkage-detect-local-generated-name-collision.rs
deleted file mode 100644
index df952504eef..00000000000
--- a/tests/ui/linkage-attr/linkage-detect-local-generated-name-collision.rs
+++ /dev/null
@@ -1,26 +0,0 @@
-//@ build-fail
-// FIXME(#83838) codegen-units=1 triggers llvm asserts
-//@ compile-flags: -Ccodegen-units=16
-#![feature(linkage)]
-
-mod dep1 {
-    extern "C" {
-        #[linkage = "external"]
-        #[no_mangle]
-        pub static collision: *const i32; //~ ERROR symbol `collision` is already defined
-    }
-}
-
-#[no_mangle]
-pub static _rust_extern_with_linkage_collision: i32 = 0;
-
-mod dep2 {
-    #[no_mangle]
-    pub static collision: usize = 0;
-}
-
-fn main() {
-    unsafe {
-        println!("{:p}", &dep1::collision);
-    }
-}
diff --git a/tests/ui/linkage-attr/linkage-detect-local-generated-name-collision.stderr b/tests/ui/linkage-attr/linkage-detect-local-generated-name-collision.stderr
deleted file mode 100644
index fcaaa39b674..00000000000
--- a/tests/ui/linkage-attr/linkage-detect-local-generated-name-collision.stderr
+++ /dev/null
@@ -1,8 +0,0 @@
-error: symbol `collision` is already defined
-  --> $DIR/linkage-detect-local-generated-name-collision.rs:10:9
-   |
-LL |         pub static collision: *const i32;
-   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: aborting due to 1 previous error
-