@@ -8,6 +8,7 @@ use crate::llvm_util;
88use crate :: type_:: Type ;
99use crate :: value:: Value ;
1010
11+ use cstr:: cstr;
1112use rustc_codegen_ssa:: base:: { wants_msvc_seh, wants_wasm_eh} ;
1213use rustc_codegen_ssa:: traits:: * ;
1314use rustc_data_structures:: base_n;
@@ -223,42 +224,36 @@ pub unsafe fn create_module<'ll>(
223224 // If skipping the PLT is enabled, we need to add some module metadata
224225 // to ensure intrinsic calls don't use it.
225226 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 ) ;
232229 }
233230
234231 // Enable canonical jump tables if CFI is enabled. (See https://reviews.llvm.org/D65629.)
235232 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 ( ) ;
236234 llvm:: LLVMRustAddModuleFlag (
237235 llmod,
238236 llvm:: LLVMModFlagBehavior :: Override ,
239- c"CFI Canonical Jump Tables" . as_ptr ( ) . cast ( ) ,
237+ canonical_jump_tables ,
240238 1 ,
241239 ) ;
242240 }
243241
244242 // Enable LTO unit splitting if specified or if CFI is enabled. (See https://reviews.llvm.org/D53891.)
245243 if sess. is_split_lto_unit_enabled ( ) || sess. is_sanitizer_cfi_enabled ( ) {
244+ let enable_split_lto_unit = "EnableSplitLTOUnit\0 " . as_ptr ( ) . cast ( ) ;
246245 llvm:: LLVMRustAddModuleFlag (
247246 llmod,
248247 llvm:: LLVMModFlagBehavior :: Override ,
249- c"EnableSplitLTOUnit" . as_ptr ( ) . cast ( ) ,
248+ enable_split_lto_unit ,
250249 1 ,
251250 ) ;
252251 }
253252
254253 // Add "kcfi" module flag if KCFI is enabled. (See https://reviews.llvm.org/D119296.)
255254 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 ) ;
262257 }
263258
264259 // Control Flow Guard is currently only supported by the MSVC linker on Windows.
@@ -270,7 +265,7 @@ pub unsafe fn create_module<'ll>(
270265 llvm:: LLVMRustAddModuleFlag (
271266 llmod,
272267 llvm:: LLVMModFlagBehavior :: Warning ,
273- c "cfguard". as_ptr ( ) as * const _ ,
268+ "cfguard\0 " . as_ptr ( ) as * const _ ,
274269 1 ,
275270 )
276271 }
@@ -279,7 +274,7 @@ pub unsafe fn create_module<'ll>(
279274 llvm:: LLVMRustAddModuleFlag (
280275 llmod,
281276 llvm:: LLVMModFlagBehavior :: Warning ,
282- c "cfguard". as_ptr ( ) as * const _ ,
277+ "cfguard\0 " . as_ptr ( ) as * const _ ,
283278 2 ,
284279 )
285280 }
@@ -297,26 +292,26 @@ pub unsafe fn create_module<'ll>(
297292 llvm:: LLVMRustAddModuleFlag (
298293 llmod,
299294 behavior,
300- c "branch-target-enforcement". as_ptr ( ) . cast ( ) ,
295+ "branch-target-enforcement\0 " . as_ptr ( ) . cast ( ) ,
301296 bti. into ( ) ,
302297 ) ;
303298 llvm:: LLVMRustAddModuleFlag (
304299 llmod,
305300 behavior,
306- c "sign-return-address". as_ptr ( ) . cast ( ) ,
301+ "sign-return-address\0 " . as_ptr ( ) . cast ( ) ,
307302 pac_ret. is_some ( ) . into ( ) ,
308303 ) ;
309304 let pac_opts = pac_ret. unwrap_or ( PacRet { leaf : false , key : PAuthKey :: A } ) ;
310305 llvm:: LLVMRustAddModuleFlag (
311306 llmod,
312307 behavior,
313- c "sign-return-address-all". as_ptr ( ) . cast ( ) ,
308+ "sign-return-address-all\0 " . as_ptr ( ) . cast ( ) ,
314309 pac_opts. leaf . into ( ) ,
315310 ) ;
316311 llvm:: LLVMRustAddModuleFlag (
317312 llmod,
318313 behavior,
319- c "sign-return-address-with-bkey". as_ptr ( ) . cast ( ) ,
314+ "sign-return-address-with-bkey\0 " . as_ptr ( ) . cast ( ) ,
320315 u32:: from ( pac_opts. key == PAuthKey :: B ) ,
321316 ) ;
322317 } else {
@@ -332,15 +327,15 @@ pub unsafe fn create_module<'ll>(
332327 llvm:: LLVMRustAddModuleFlag (
333328 llmod,
334329 llvm:: LLVMModFlagBehavior :: Override ,
335- c "cf-protection-branch". as_ptr ( ) . cast ( ) ,
330+ "cf-protection-branch\0 " . as_ptr ( ) . cast ( ) ,
336331 1 ,
337332 )
338333 }
339334 if let CFProtection :: Return | CFProtection :: Full = sess. opts . unstable_opts . cf_protection {
340335 llvm:: LLVMRustAddModuleFlag (
341336 llmod,
342337 llvm:: LLVMModFlagBehavior :: Override ,
343- c "cf-protection-return". as_ptr ( ) . cast ( ) ,
338+ "cf-protection-return\0 " . as_ptr ( ) . cast ( ) ,
344339 1 ,
345340 )
346341 }
@@ -349,7 +344,7 @@ pub unsafe fn create_module<'ll>(
349344 llvm:: LLVMRustAddModuleFlag (
350345 llmod,
351346 llvm:: LLVMModFlagBehavior :: Error ,
352- c "Virtual Function Elim". as_ptr ( ) . cast ( ) ,
347+ "Virtual Function Elim\0 " . as_ptr ( ) . cast ( ) ,
353348 1 ,
354349 ) ;
355350 }
@@ -481,13 +476,14 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
481476 }
482477
483478 pub ( crate ) fn create_used_variable_impl ( & self , name : & ' static CStr , values : & [ & ' ll Value ] ) {
479+ let section = cstr ! ( "llvm.metadata" ) ;
484480 let array = self . const_array ( self . type_ptr_to ( self . type_i8 ( ) ) , values) ;
485481
486482 unsafe {
487483 let g = llvm:: LLVMAddGlobal ( self . llmod , self . val_ty ( array) , name. as_ptr ( ) ) ;
488484 llvm:: LLVMSetInitializer ( g, array) ;
489485 llvm:: LLVMRustSetLinkage ( g, llvm:: Linkage :: AppendingLinkage ) ;
490- llvm:: LLVMSetSection ( g, c"llvm.metadata" . as_ptr ( ) ) ;
486+ llvm:: LLVMSetSection ( g, section . as_ptr ( ) ) ;
491487 }
492488 }
493489}
0 commit comments