@@ -879,9 +879,7 @@ pub(crate) fn codegen(
879879 . generic_activity_with_arg ( "LLVM_module_codegen_embed_bitcode" , & * module. name ) ;
880880 let thin_bc =
881881 module. thin_lto_buffer . as_deref ( ) . expect ( "cannot find embedded bitcode" ) ;
882- unsafe {
883- embed_bitcode ( cgcx, llcx, llmod, & config. bc_cmdline , & thin_bc) ;
884- }
882+ embed_bitcode ( cgcx, llcx, llmod, & config. bc_cmdline , & thin_bc) ;
885883 }
886884 }
887885
@@ -945,7 +943,7 @@ pub(crate) fn codegen(
945943 // binaries. So we must clone the module to produce the asm output
946944 // if we are also producing object code.
947945 let llmod = if let EmitObj :: ObjectCode ( _) = config. emit_obj {
948- unsafe { llvm:: LLVMCloneModule ( llmod) }
946+ llvm:: LLVMCloneModule ( llmod)
949947 } else {
950948 llmod
951949 } ;
@@ -1073,7 +1071,7 @@ pub(crate) fn bitcode_section_name(cgcx: &CodegenContext<LlvmCodegenBackend>) ->
10731071}
10741072
10751073/// Embed the bitcode of an LLVM module for LTO in the LLVM module itself.
1076- unsafe fn embed_bitcode (
1074+ fn embed_bitcode (
10771075 cgcx : & CodegenContext < LlvmCodegenBackend > ,
10781076 llcx : & llvm:: Context ,
10791077 llmod : & llvm:: Module ,
@@ -1115,43 +1113,40 @@ unsafe fn embed_bitcode(
11151113 // Unfortunately, LLVM provides no way to set custom section flags. For ELF
11161114 // and COFF we emit the sections using module level inline assembly for that
11171115 // reason (see issue #90326 for historical background).
1118- unsafe {
1119- if cgcx. target_is_like_darwin
1120- || cgcx. target_is_like_aix
1121- || cgcx. target_arch == "wasm32"
1122- || cgcx. target_arch == "wasm64"
1123- {
1124- // We don't need custom section flags, create LLVM globals.
1125- let llconst = common:: bytes_in_context ( llcx, bitcode) ;
1126- let llglobal =
1127- llvm:: add_global ( llmod, common:: val_ty ( llconst) , c"rustc.embedded.module" ) ;
1128- llvm:: set_initializer ( llglobal, llconst) ;
1129-
1130- llvm:: set_section ( llglobal, bitcode_section_name ( cgcx) ) ;
1131- llvm:: set_linkage ( llglobal, llvm:: Linkage :: PrivateLinkage ) ;
1132- llvm:: LLVMSetGlobalConstant ( llglobal, llvm:: True ) ;
1133-
1134- let llconst = common:: bytes_in_context ( llcx, cmdline. as_bytes ( ) ) ;
1135- let llglobal =
1136- llvm:: add_global ( llmod, common:: val_ty ( llconst) , c"rustc.embedded.cmdline" ) ;
1137- llvm:: set_initializer ( llglobal, llconst) ;
1138- let section = if cgcx. target_is_like_darwin {
1139- c"__LLVM,__cmdline"
1140- } else if cgcx. target_is_like_aix {
1141- c".info"
1142- } else {
1143- c".llvmcmd"
1144- } ;
1145- llvm:: set_section ( llglobal, section) ;
1146- llvm:: set_linkage ( llglobal, llvm:: Linkage :: PrivateLinkage ) ;
1116+
1117+ if cgcx. target_is_like_darwin
1118+ || cgcx. target_is_like_aix
1119+ || cgcx. target_arch == "wasm32"
1120+ || cgcx. target_arch == "wasm64"
1121+ {
1122+ // We don't need custom section flags, create LLVM globals.
1123+ let llconst = common:: bytes_in_context ( llcx, bitcode) ;
1124+ let llglobal = llvm:: add_global ( llmod, common:: val_ty ( llconst) , c"rustc.embedded.module" ) ;
1125+ llvm:: set_initializer ( llglobal, llconst) ;
1126+
1127+ llvm:: set_section ( llglobal, bitcode_section_name ( cgcx) ) ;
1128+ llvm:: set_linkage ( llglobal, llvm:: Linkage :: PrivateLinkage ) ;
1129+ llvm:: LLVMSetGlobalConstant ( llglobal, llvm:: True ) ;
1130+
1131+ let llconst = common:: bytes_in_context ( llcx, cmdline. as_bytes ( ) ) ;
1132+ let llglobal = llvm:: add_global ( llmod, common:: val_ty ( llconst) , c"rustc.embedded.cmdline" ) ;
1133+ llvm:: set_initializer ( llglobal, llconst) ;
1134+ let section = if cgcx. target_is_like_darwin {
1135+ c"__LLVM,__cmdline"
1136+ } else if cgcx. target_is_like_aix {
1137+ c".info"
11471138 } else {
1148- // We need custom section flags, so emit module-level inline assembly.
1149- let section_flags = if cgcx. is_pe_coff { "n" } else { "e" } ;
1150- let asm = create_section_with_flags_asm ( ".llvmbc" , section_flags, bitcode) ;
1151- llvm:: append_module_inline_asm ( llmod, & asm) ;
1152- let asm = create_section_with_flags_asm ( ".llvmcmd" , section_flags, cmdline. as_bytes ( ) ) ;
1153- llvm:: append_module_inline_asm ( llmod, & asm) ;
1154- }
1139+ c".llvmcmd"
1140+ } ;
1141+ llvm:: set_section ( llglobal, section) ;
1142+ llvm:: set_linkage ( llglobal, llvm:: Linkage :: PrivateLinkage ) ;
1143+ } else {
1144+ // We need custom section flags, so emit module-level inline assembly.
1145+ let section_flags = if cgcx. is_pe_coff { "n" } else { "e" } ;
1146+ let asm = create_section_with_flags_asm ( ".llvmbc" , section_flags, bitcode) ;
1147+ llvm:: append_module_inline_asm ( llmod, & asm) ;
1148+ let asm = create_section_with_flags_asm ( ".llvmcmd" , section_flags, cmdline. as_bytes ( ) ) ;
1149+ llvm:: append_module_inline_asm ( llmod, & asm) ;
11551150 }
11561151}
11571152
0 commit comments