@@ -75,6 +75,10 @@ pub struct CodegenCx<'ll, 'tcx> {
75
75
/// See <https://llvm.org/docs/LangRef.html#the-llvm-used-global-variable> for details
76
76
pub used_statics : RefCell < Vec < & ' ll Value > > ,
77
77
78
+ /// Statics that will be placed in the llvm.compiler.used variable
79
+ /// See <https://llvm.org/docs/LangRef.html#the-llvm-compiler-used-global-variable> for details
80
+ pub compiler_used_statics : RefCell < Vec < & ' ll Value > > ,
81
+
78
82
/// Mapping of non-scalar types to llvm types and field remapping if needed.
79
83
pub type_lowering : RefCell < FxHashMap < ( Ty < ' tcx > , Option < VariantIdx > ) , TypeLowering < ' ll > > > ,
80
84
@@ -115,10 +119,6 @@ fn to_llvm_tls_model(tls_model: TlsModel) -> llvm::ThreadLocalMode {
115
119
}
116
120
}
117
121
118
- fn strip_powerpc64_vectors ( data_layout : String ) -> String {
119
- data_layout. replace ( "-v256:256:256-v512:512:512" , "" )
120
- }
121
-
122
122
pub unsafe fn create_module (
123
123
tcx : TyCtxt < ' _ > ,
124
124
llcx : & ' ll llvm:: Context ,
@@ -130,7 +130,18 @@ pub unsafe fn create_module(
130
130
131
131
let mut target_data_layout = sess. target . data_layout . clone ( ) ;
132
132
if llvm_util:: get_version ( ) < ( 12 , 0 , 0 ) && sess. target . arch == "powerpc64" {
133
- target_data_layout = strip_powerpc64_vectors ( target_data_layout) ;
133
+ target_data_layout = target_data_layout. replace ( "-v256:256:256-v512:512:512" , "" ) ;
134
+ }
135
+ if llvm_util:: get_version ( ) < ( 13 , 0 , 0 ) {
136
+ if sess. target . arch == "powerpc64" {
137
+ target_data_layout = target_data_layout. replace ( "-S128" , "" ) ;
138
+ }
139
+ if sess. target . arch == "wasm32" {
140
+ target_data_layout = "e-m:e-p:32:32-i64:64-n32:64-S128" . to_string ( ) ;
141
+ }
142
+ if sess. target . arch == "wasm64" {
143
+ target_data_layout = "e-m:e-p:64:64-i64:64-n32:64-S128" . to_string ( ) ;
144
+ }
134
145
}
135
146
136
147
// Ensure the data-layout values hardcoded remain the defaults.
@@ -318,6 +329,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
318
329
const_globals : Default :: default ( ) ,
319
330
statics_to_rauw : RefCell :: new ( Vec :: new ( ) ) ,
320
331
used_statics : RefCell :: new ( Vec :: new ( ) ) ,
332
+ compiler_used_statics : RefCell :: new ( Vec :: new ( ) ) ,
321
333
type_lowering : Default :: default ( ) ,
322
334
scalar_lltypes : Default :: default ( ) ,
323
335
pointee_infos : Default :: default ( ) ,
@@ -340,6 +352,18 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
340
352
pub fn coverage_context ( & ' a self ) -> Option < & ' a coverageinfo:: CrateCoverageContext < ' ll , ' tcx > > {
341
353
self . coverage_cx . as_ref ( )
342
354
}
355
+
356
+ fn create_used_variable_impl ( & self , name : & ' static CStr , values : & [ & ' ll Value ] ) {
357
+ let section = cstr ! ( "llvm.metadata" ) ;
358
+ let array = self . const_array ( & self . type_ptr_to ( self . type_i8 ( ) ) , values) ;
359
+
360
+ unsafe {
361
+ let g = llvm:: LLVMAddGlobal ( self . llmod , self . val_ty ( array) , name. as_ptr ( ) ) ;
362
+ llvm:: LLVMSetInitializer ( g, array) ;
363
+ llvm:: LLVMRustSetLinkage ( g, llvm:: Linkage :: AppendingLinkage ) ;
364
+ llvm:: LLVMSetSection ( g, section. as_ptr ( ) ) ;
365
+ }
366
+ }
343
367
}
344
368
345
369
impl MiscMethods < ' tcx > for CodegenCx < ' ll , ' tcx > {
@@ -430,6 +454,10 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
430
454
& self . used_statics
431
455
}
432
456
457
+ fn compiler_used_statics ( & self ) -> & RefCell < Vec < & ' ll Value > > {
458
+ & self . compiler_used_statics
459
+ }
460
+
433
461
fn set_frame_pointer_type ( & self , llfn : & ' ll Value ) {
434
462
attributes:: set_frame_pointer_type ( self , llfn)
435
463
}
@@ -440,17 +468,14 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
440
468
}
441
469
442
470
fn create_used_variable ( & self ) {
443
- let name = cstr ! ( "llvm.used" ) ;
444
- let section = cstr ! ( "llvm.metadata" ) ;
445
- let array =
446
- self . const_array ( & self . type_ptr_to ( self . type_i8 ( ) ) , & * self . used_statics . borrow ( ) ) ;
471
+ self . create_used_variable_impl ( cstr ! ( "llvm.used" ) , & * self . used_statics . borrow ( ) ) ;
472
+ }
447
473
448
- unsafe {
449
- let g = llvm:: LLVMAddGlobal ( self . llmod , self . val_ty ( array) , name. as_ptr ( ) ) ;
450
- llvm:: LLVMSetInitializer ( g, array) ;
451
- llvm:: LLVMRustSetLinkage ( g, llvm:: Linkage :: AppendingLinkage ) ;
452
- llvm:: LLVMSetSection ( g, section. as_ptr ( ) ) ;
453
- }
474
+ fn create_compiler_used_variable ( & self ) {
475
+ self . create_used_variable_impl (
476
+ cstr ! ( "llvm.compiler.used" ) ,
477
+ & * self . compiler_used_statics . borrow ( ) ,
478
+ ) ;
454
479
}
455
480
456
481
fn declare_c_main ( & self , fn_type : Self :: Type ) -> Option < Self :: Function > {
0 commit comments