@@ -879,9 +879,7 @@ pub(crate) fn codegen(
879
879
. generic_activity_with_arg ( "LLVM_module_codegen_embed_bitcode" , & * module. name ) ;
880
880
let thin_bc =
881
881
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) ;
885
883
}
886
884
}
887
885
@@ -945,7 +943,7 @@ pub(crate) fn codegen(
945
943
// binaries. So we must clone the module to produce the asm output
946
944
// if we are also producing object code.
947
945
let llmod = if let EmitObj :: ObjectCode ( _) = config. emit_obj {
948
- unsafe { llvm:: LLVMCloneModule ( llmod) }
946
+ llvm:: LLVMCloneModule ( llmod)
949
947
} else {
950
948
llmod
951
949
} ;
@@ -1073,7 +1071,7 @@ pub(crate) fn bitcode_section_name(cgcx: &CodegenContext<LlvmCodegenBackend>) ->
1073
1071
}
1074
1072
1075
1073
/// Embed the bitcode of an LLVM module for LTO in the LLVM module itself.
1076
- unsafe fn embed_bitcode (
1074
+ fn embed_bitcode (
1077
1075
cgcx : & CodegenContext < LlvmCodegenBackend > ,
1078
1076
llcx : & llvm:: Context ,
1079
1077
llmod : & llvm:: Module ,
@@ -1115,43 +1113,40 @@ unsafe fn embed_bitcode(
1115
1113
// Unfortunately, LLVM provides no way to set custom section flags. For ELF
1116
1114
// and COFF we emit the sections using module level inline assembly for that
1117
1115
// 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"
1147
1138
} 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) ;
1155
1150
}
1156
1151
}
1157
1152
0 commit comments