@@ -8,7 +8,6 @@ use crate::llvm_util;
88use crate :: type_:: Type ;
99use crate :: value:: Value ;
1010
11- use cstr:: cstr;
1211use rustc_codegen_ssa:: base:: wants_msvc_seh;
1312use rustc_codegen_ssa:: traits:: * ;
1413use rustc_data_structures:: base_n;
@@ -224,36 +223,42 @@ pub unsafe fn create_module<'ll>(
224223 // If skipping the PLT is enabled, we need to add some module metadata
225224 // to ensure intrinsic calls don't use it.
226225 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+ ) ;
229232 }
230233
231234 // Enable canonical jump tables if CFI is enabled. (See https://reviews.llvm.org/D65629.)
232235 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 ( ) ;
234236 llvm:: LLVMRustAddModuleFlag (
235237 llmod,
236238 llvm:: LLVMModFlagBehavior :: Override ,
237- canonical_jump_tables ,
239+ c"CFI Canonical Jump Tables" . as_ptr ( ) . cast ( ) ,
238240 1 ,
239241 ) ;
240242 }
241243
242244 // Enable LTO unit splitting if specified or if CFI is enabled. (See https://reviews.llvm.org/D53891.)
243245 if sess. is_split_lto_unit_enabled ( ) || sess. is_sanitizer_cfi_enabled ( ) {
244- let enable_split_lto_unit = "EnableSplitLTOUnit\0 " . as_ptr ( ) . cast ( ) ;
245246 llvm:: LLVMRustAddModuleFlag (
246247 llmod,
247248 llvm:: LLVMModFlagBehavior :: Override ,
248- enable_split_lto_unit ,
249+ c"EnableSplitLTOUnit" . as_ptr ( ) . cast ( ) ,
249250 1 ,
250251 ) ;
251252 }
252253
253254 // Add "kcfi" module flag if KCFI is enabled. (See https://reviews.llvm.org/D119296.)
254255 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+ ) ;
257262 }
258263
259264 // Control Flow Guard is currently only supported by the MSVC linker on Windows.
@@ -265,7 +270,7 @@ pub unsafe fn create_module<'ll>(
265270 llvm:: LLVMRustAddModuleFlag (
266271 llmod,
267272 llvm:: LLVMModFlagBehavior :: Warning ,
268- "cfguard\0 " . as_ptr ( ) as * const _ ,
273+ c "cfguard". as_ptr ( ) as * const _ ,
269274 1 ,
270275 )
271276 }
@@ -274,7 +279,7 @@ pub unsafe fn create_module<'ll>(
274279 llvm:: LLVMRustAddModuleFlag (
275280 llmod,
276281 llvm:: LLVMModFlagBehavior :: Warning ,
277- "cfguard\0 " . as_ptr ( ) as * const _ ,
282+ c "cfguard". as_ptr ( ) as * const _ ,
278283 2 ,
279284 )
280285 }
@@ -292,26 +297,26 @@ pub unsafe fn create_module<'ll>(
292297 llvm:: LLVMRustAddModuleFlag (
293298 llmod,
294299 behavior,
295- "branch-target-enforcement\0 " . as_ptr ( ) . cast ( ) ,
300+ c "branch-target-enforcement". as_ptr ( ) . cast ( ) ,
296301 bti. into ( ) ,
297302 ) ;
298303 llvm:: LLVMRustAddModuleFlag (
299304 llmod,
300305 behavior,
301- "sign-return-address\0 " . as_ptr ( ) . cast ( ) ,
306+ c "sign-return-address". as_ptr ( ) . cast ( ) ,
302307 pac_ret. is_some ( ) . into ( ) ,
303308 ) ;
304309 let pac_opts = pac_ret. unwrap_or ( PacRet { leaf : false , key : PAuthKey :: A } ) ;
305310 llvm:: LLVMRustAddModuleFlag (
306311 llmod,
307312 behavior,
308- "sign-return-address-all\0 " . as_ptr ( ) . cast ( ) ,
313+ c "sign-return-address-all". as_ptr ( ) . cast ( ) ,
309314 pac_opts. leaf . into ( ) ,
310315 ) ;
311316 llvm:: LLVMRustAddModuleFlag (
312317 llmod,
313318 behavior,
314- "sign-return-address-with-bkey\0 " . as_ptr ( ) . cast ( ) ,
319+ c "sign-return-address-with-bkey". as_ptr ( ) . cast ( ) ,
315320 u32:: from ( pac_opts. key == PAuthKey :: B ) ,
316321 ) ;
317322 } else {
@@ -327,15 +332,15 @@ pub unsafe fn create_module<'ll>(
327332 llvm:: LLVMRustAddModuleFlag (
328333 llmod,
329334 llvm:: LLVMModFlagBehavior :: Override ,
330- "cf-protection-branch\0 " . as_ptr ( ) . cast ( ) ,
335+ c "cf-protection-branch". as_ptr ( ) . cast ( ) ,
331336 1 ,
332337 )
333338 }
334339 if let CFProtection :: Return | CFProtection :: Full = sess. opts . unstable_opts . cf_protection {
335340 llvm:: LLVMRustAddModuleFlag (
336341 llmod,
337342 llvm:: LLVMModFlagBehavior :: Override ,
338- "cf-protection-return\0 " . as_ptr ( ) . cast ( ) ,
343+ c "cf-protection-return". as_ptr ( ) . cast ( ) ,
339344 1 ,
340345 )
341346 }
@@ -344,7 +349,7 @@ pub unsafe fn create_module<'ll>(
344349 llvm:: LLVMRustAddModuleFlag (
345350 llmod,
346351 llvm:: LLVMModFlagBehavior :: Error ,
347- "Virtual Function Elim\0 " . as_ptr ( ) . cast ( ) ,
352+ c "Virtual Function Elim". as_ptr ( ) . cast ( ) ,
348353 1 ,
349354 ) ;
350355 }
@@ -476,14 +481,13 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
476481 }
477482
478483 pub ( crate ) fn create_used_variable_impl ( & self , name : & ' static CStr , values : & [ & ' ll Value ] ) {
479- let section = cstr ! ( "llvm.metadata" ) ;
480484 let array = self . const_array ( self . type_ptr_to ( self . type_i8 ( ) ) , values) ;
481485
482486 unsafe {
483487 let g = llvm:: LLVMAddGlobal ( self . llmod , self . val_ty ( array) , name. as_ptr ( ) ) ;
484488 llvm:: LLVMSetInitializer ( g, array) ;
485489 llvm:: LLVMRustSetLinkage ( g, llvm:: Linkage :: AppendingLinkage ) ;
486- llvm:: LLVMSetSection ( g, section . as_ptr ( ) ) ;
490+ llvm:: LLVMSetSection ( g, c"llvm.metadata" . as_ptr ( ) ) ;
487491 }
488492 }
489493}
0 commit comments