@@ -132,7 +132,23 @@ fn get_llvm_object_symbols(
132132 if err. is_null ( ) {
133133 return Ok ( true ) ;
134134 } else {
135- return Err ( unsafe { * Box :: from_raw ( err as * mut io:: Error ) } ) ;
135+ let error = unsafe { * Box :: from_raw ( err as * mut String ) } ;
136+ if buf. starts_with ( & [ 0xDE , 0xCE , 0x17 , 0x0B ] ) || buf. starts_with ( b"BC\xC0 \xDE " ) {
137+ // For LLVM bitcode, failure to read the symbols is not fatal. The bitcode may have been
138+ // produced by a newer LLVM version that the one linked to rustc. This is fine provided
139+ // that the linker does use said newer LLVM version. We skip writing the symbols for the
140+ // bitcode to the symbol table of the archive. Traditional linkers don't like this, but
141+ // newer linkers like lld, mold and wild ignore the symbol table anyway, so if they link
142+ // against a new enough LLVM it will work out in the end.
143+ // LLVM's archive writer also has this same behavior of only warning about invalid
144+ // bitcode since https://github.com/llvm/llvm-project/pull/96848
145+
146+ // We don't have access to the DiagCtxt here to produce a nice warning in the correct format.
147+ eprintln ! ( "warning: Failed to read symbol table from LLVM bitcode: {}" , error) ;
148+ return Ok ( true ) ;
149+ } else {
150+ return Err ( io:: Error :: new ( io:: ErrorKind :: Other , format ! ( "LLVM error: {}" , error) ) ) ;
151+ }
136152 }
137153
138154 unsafe extern "C" fn callback ( state : * mut c_void , symbol_name : * const c_char ) -> * mut c_void {
@@ -145,10 +161,7 @@ fn get_llvm_object_symbols(
145161
146162 unsafe extern "C" fn error_callback ( error : * const c_char ) -> * mut c_void {
147163 let error = unsafe { CStr :: from_ptr ( error) } ;
148- Box :: into_raw ( Box :: new ( io:: Error :: new (
149- io:: ErrorKind :: Other ,
150- format ! ( "LLVM error: {}" , error. to_string_lossy( ) ) ,
151- ) ) ) as * mut c_void
164+ Box :: into_raw ( Box :: new ( error. to_string_lossy ( ) ) ) as * mut c_void
152165 }
153166}
154167
0 commit comments