1
- use crate :: back:: write:: { self , save_temp_bitcode, CodegenDiagnosticsStage , DiagnosticHandlers } ;
1
+ use crate :: back:: write:: {
2
+ self , bitcode_section_name, save_temp_bitcode, target_is_aix, target_is_apple,
3
+ CodegenDiagnosticsStage , DiagnosticHandlers ,
4
+ } ;
2
5
use crate :: errors:: {
3
6
DynamicLinkingWithLTO , LlvmError , LtoBitcodeFromRlib , LtoDisallowed , LtoDylib ,
4
7
} ;
@@ -121,8 +124,12 @@ fn prepare_lto(
121
124
. filter ( |& ( name, _) | looks_like_rust_object_file ( name) ) ;
122
125
for ( name, child) in obj_files {
123
126
info ! ( "adding bitcode from {}" , name) ;
127
+ let is_apple = target_is_apple ( cgcx) ;
128
+ let is_aix = target_is_aix ( cgcx) ;
124
129
match get_bitcode_slice_from_object_data (
125
130
child. data ( & * archive_data) . expect ( "corrupt rlib" ) ,
131
+ is_apple,
132
+ is_aix,
126
133
) {
127
134
Ok ( data) => {
128
135
let module = SerializedModule :: FromRlib ( data. to_vec ( ) ) ;
@@ -144,19 +151,19 @@ fn prepare_lto(
144
151
Ok ( ( symbols_below_threshold, upstream_modules) )
145
152
}
146
153
147
- fn get_bitcode_slice_from_object_data ( obj : & [ u8 ] ) -> Result < & [ u8 ] , LtoBitcodeFromRlib > {
154
+ fn get_bitcode_slice_from_object_data (
155
+ obj : & [ u8 ] ,
156
+ is_apple : bool ,
157
+ is_aix : bool ,
158
+ ) -> Result < & [ u8 ] , LtoBitcodeFromRlib > {
148
159
// The object crate doesn't understand bitcode files, but we can just sniff for the possible
149
160
// magic strings here and return the whole slice directly.
150
161
if obj. starts_with ( b"\xDE \xC0 \x17 \x0B " ) || obj. starts_with ( b"BC\xC0 \xDE " ) {
151
162
return Ok ( obj) ;
152
163
}
164
+ let section = bitcode_section_name ( is_apple, is_aix) . trim_end_matches ( '\0' ) ;
153
165
match object:: read:: File :: parse ( obj) {
154
- Ok ( f) => match f
155
- . section_by_name ( ".llvmbc" )
156
- . or_else ( || f. section_by_name ( ".llvm.lto" ) )
157
- . or_else ( || f. section_by_name ( "__LLVM,__bitcode" ) )
158
- . or_else ( || f. section_by_name ( ".ipa" ) )
159
- {
166
+ Ok ( f) => match f. section_by_name ( section) {
160
167
Some ( d) => Ok ( d. data ( ) . unwrap ( ) ) ,
161
168
None => Err ( LtoBitcodeFromRlib {
162
169
llvm_err : "Bitcode section not found in object file" . to_string ( ) ,
0 commit comments