@@ -17,6 +17,7 @@ use rustc_middle::mir::mono::MonoItem;
1717use rustc_middle:: ty:: { self , Instance , Ty } ;
1818use rustc_middle:: { bug, span_bug} ;
1919use rustc_target:: abi:: { AddressSpace , Align , HasDataLayout , LayoutOf , Primitive , Scalar , Size } ;
20+ use rustc_target:: spec:: RelocModel ;
2021use tracing:: debug;
2122
2223pub fn const_alloc_to_llvm ( cx : & CodegenCx < ' ll , ' _ > , alloc : & Allocation ) -> & ' ll Value {
@@ -282,6 +283,12 @@ impl CodegenCx<'ll, 'tcx> {
282283 }
283284 }
284285
286+ if self . tcx . sess . relocation_model ( ) == RelocModel :: Static {
287+ unsafe {
288+ llvm:: LLVMRustSetDSOLocal ( g, true ) ;
289+ }
290+ }
291+
285292 self . instances . borrow_mut ( ) . insert ( instance, g) ;
286293 g
287294 }
@@ -363,6 +370,12 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> {
363370 set_global_alignment ( & self , g, self . align_of ( ty) ) ;
364371 llvm:: LLVMSetInitializer ( g, v) ;
365372
373+ let linkage = base:: linkage_from_llvm ( llvm:: LLVMRustGetLinkage ( g) ) ;
374+ let visibility = base:: visibility_from_llvm ( llvm:: LLVMRustGetVisibility ( g) ) ;
375+ if self . should_assume_dso_local ( linkage, visibility) {
376+ llvm:: LLVMRustSetDSOLocal ( g, true ) ;
377+ }
378+
366379 // As an optimization, all shared statics which do not have interior
367380 // mutability are placed into read-only memory.
368381 if !is_mutable && self . type_is_freeze ( ty) {
0 commit comments