@@ -8,6 +8,7 @@ use crate::llvm_util;
8
8
use crate :: type_:: Type ;
9
9
use crate :: value:: Value ;
10
10
11
+ use cstr:: cstr;
11
12
use rustc_codegen_ssa:: base:: { wants_msvc_seh, wants_wasm_eh} ;
12
13
use rustc_codegen_ssa:: traits:: * ;
13
14
use rustc_data_structures:: base_n;
@@ -223,42 +224,36 @@ pub unsafe fn create_module<'ll>(
223
224
// If skipping the PLT is enabled, we need to add some module metadata
224
225
// to ensure intrinsic calls don't use it.
225
226
if !sess. needs_plt ( ) {
226
- llvm:: LLVMRustAddModuleFlag (
227
- llmod,
228
- llvm:: LLVMModFlagBehavior :: Warning ,
229
- c"RtLibUseGOT" . as_ptr ( ) . cast ( ) ,
230
- 1 ,
231
- ) ;
227
+ let avoid_plt = "RtLibUseGOT\0 " . as_ptr ( ) . cast ( ) ;
228
+ llvm:: LLVMRustAddModuleFlag ( llmod, llvm:: LLVMModFlagBehavior :: Warning , avoid_plt, 1 ) ;
232
229
}
233
230
234
231
// Enable canonical jump tables if CFI is enabled. (See https://reviews.llvm.org/D65629.)
235
232
if sess. is_sanitizer_cfi_canonical_jump_tables_enabled ( ) && sess. is_sanitizer_cfi_enabled ( ) {
233
+ let canonical_jump_tables = "CFI Canonical Jump Tables\0 " . as_ptr ( ) . cast ( ) ;
236
234
llvm:: LLVMRustAddModuleFlag (
237
235
llmod,
238
236
llvm:: LLVMModFlagBehavior :: Override ,
239
- c"CFI Canonical Jump Tables" . as_ptr ( ) . cast ( ) ,
237
+ canonical_jump_tables ,
240
238
1 ,
241
239
) ;
242
240
}
243
241
244
242
// Enable LTO unit splitting if specified or if CFI is enabled. (See https://reviews.llvm.org/D53891.)
245
243
if sess. is_split_lto_unit_enabled ( ) || sess. is_sanitizer_cfi_enabled ( ) {
244
+ let enable_split_lto_unit = "EnableSplitLTOUnit\0 " . as_ptr ( ) . cast ( ) ;
246
245
llvm:: LLVMRustAddModuleFlag (
247
246
llmod,
248
247
llvm:: LLVMModFlagBehavior :: Override ,
249
- c"EnableSplitLTOUnit" . as_ptr ( ) . cast ( ) ,
248
+ enable_split_lto_unit ,
250
249
1 ,
251
250
) ;
252
251
}
253
252
254
253
// Add "kcfi" module flag if KCFI is enabled. (See https://reviews.llvm.org/D119296.)
255
254
if sess. is_sanitizer_kcfi_enabled ( ) {
256
- llvm:: LLVMRustAddModuleFlag (
257
- llmod,
258
- llvm:: LLVMModFlagBehavior :: Override ,
259
- c"kcfi" . as_ptr ( ) . cast ( ) ,
260
- 1 ,
261
- ) ;
255
+ let kcfi = "kcfi\0 " . as_ptr ( ) . cast ( ) ;
256
+ llvm:: LLVMRustAddModuleFlag ( llmod, llvm:: LLVMModFlagBehavior :: Override , kcfi, 1 ) ;
262
257
}
263
258
264
259
// Control Flow Guard is currently only supported by the MSVC linker on Windows.
@@ -270,7 +265,7 @@ pub unsafe fn create_module<'ll>(
270
265
llvm:: LLVMRustAddModuleFlag (
271
266
llmod,
272
267
llvm:: LLVMModFlagBehavior :: Warning ,
273
- c "cfguard". as_ptr ( ) as * const _ ,
268
+ "cfguard\0 " . as_ptr ( ) as * const _ ,
274
269
1 ,
275
270
)
276
271
}
@@ -279,7 +274,7 @@ pub unsafe fn create_module<'ll>(
279
274
llvm:: LLVMRustAddModuleFlag (
280
275
llmod,
281
276
llvm:: LLVMModFlagBehavior :: Warning ,
282
- c "cfguard". as_ptr ( ) as * const _ ,
277
+ "cfguard\0 " . as_ptr ( ) as * const _ ,
283
278
2 ,
284
279
)
285
280
}
@@ -297,26 +292,26 @@ pub unsafe fn create_module<'ll>(
297
292
llvm:: LLVMRustAddModuleFlag (
298
293
llmod,
299
294
behavior,
300
- c "branch-target-enforcement". as_ptr ( ) . cast ( ) ,
295
+ "branch-target-enforcement\0 " . as_ptr ( ) . cast ( ) ,
301
296
bti. into ( ) ,
302
297
) ;
303
298
llvm:: LLVMRustAddModuleFlag (
304
299
llmod,
305
300
behavior,
306
- c "sign-return-address". as_ptr ( ) . cast ( ) ,
301
+ "sign-return-address\0 " . as_ptr ( ) . cast ( ) ,
307
302
pac_ret. is_some ( ) . into ( ) ,
308
303
) ;
309
304
let pac_opts = pac_ret. unwrap_or ( PacRet { leaf : false , key : PAuthKey :: A } ) ;
310
305
llvm:: LLVMRustAddModuleFlag (
311
306
llmod,
312
307
behavior,
313
- c "sign-return-address-all". as_ptr ( ) . cast ( ) ,
308
+ "sign-return-address-all\0 " . as_ptr ( ) . cast ( ) ,
314
309
pac_opts. leaf . into ( ) ,
315
310
) ;
316
311
llvm:: LLVMRustAddModuleFlag (
317
312
llmod,
318
313
behavior,
319
- c "sign-return-address-with-bkey". as_ptr ( ) . cast ( ) ,
314
+ "sign-return-address-with-bkey\0 " . as_ptr ( ) . cast ( ) ,
320
315
u32:: from ( pac_opts. key == PAuthKey :: B ) ,
321
316
) ;
322
317
} else {
@@ -332,15 +327,15 @@ pub unsafe fn create_module<'ll>(
332
327
llvm:: LLVMRustAddModuleFlag (
333
328
llmod,
334
329
llvm:: LLVMModFlagBehavior :: Override ,
335
- c "cf-protection-branch". as_ptr ( ) . cast ( ) ,
330
+ "cf-protection-branch\0 " . as_ptr ( ) . cast ( ) ,
336
331
1 ,
337
332
)
338
333
}
339
334
if let CFProtection :: Return | CFProtection :: Full = sess. opts . unstable_opts . cf_protection {
340
335
llvm:: LLVMRustAddModuleFlag (
341
336
llmod,
342
337
llvm:: LLVMModFlagBehavior :: Override ,
343
- c "cf-protection-return". as_ptr ( ) . cast ( ) ,
338
+ "cf-protection-return\0 " . as_ptr ( ) . cast ( ) ,
344
339
1 ,
345
340
)
346
341
}
@@ -349,7 +344,7 @@ pub unsafe fn create_module<'ll>(
349
344
llvm:: LLVMRustAddModuleFlag (
350
345
llmod,
351
346
llvm:: LLVMModFlagBehavior :: Error ,
352
- c "Virtual Function Elim". as_ptr ( ) . cast ( ) ,
347
+ "Virtual Function Elim\0 " . as_ptr ( ) . cast ( ) ,
353
348
1 ,
354
349
) ;
355
350
}
@@ -481,13 +476,14 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
481
476
}
482
477
483
478
pub ( crate ) fn create_used_variable_impl ( & self , name : & ' static CStr , values : & [ & ' ll Value ] ) {
479
+ let section = cstr ! ( "llvm.metadata" ) ;
484
480
let array = self . const_array ( self . type_ptr_to ( self . type_i8 ( ) ) , values) ;
485
481
486
482
unsafe {
487
483
let g = llvm:: LLVMAddGlobal ( self . llmod , self . val_ty ( array) , name. as_ptr ( ) ) ;
488
484
llvm:: LLVMSetInitializer ( g, array) ;
489
485
llvm:: LLVMRustSetLinkage ( g, llvm:: Linkage :: AppendingLinkage ) ;
490
- llvm:: LLVMSetSection ( g, c"llvm.metadata" . as_ptr ( ) ) ;
486
+ llvm:: LLVMSetSection ( g, section . as_ptr ( ) ) ;
491
487
}
492
488
}
493
489
}
0 commit comments