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