Unconditionally use the LLVM symbol reader

This may fix a linker error on MSVC
This commit is contained in:
bjorn3 2024-08-14 16:50:48 +00:00
parent 2217014210
commit 9de0d147f4

View File

@ -200,25 +200,11 @@ static LLVM_OBJECT_READER: ObjectReader = ObjectReader {
get_xcoff_member_alignment: DEFAULT_OBJECT_READER.get_xcoff_member_alignment, get_xcoff_member_alignment: DEFAULT_OBJECT_READER.get_xcoff_member_alignment,
}; };
fn should_use_llvm_reader(buf: &[u8]) -> bool {
let is_bitcode = unsafe { llvm::LLVMRustIsBitcode(buf.as_ptr(), buf.len()) };
// COFF bigobj file, msvc LTO file or import library. See
// https://github.com/llvm/llvm-project/blob/453f27bc9/llvm/lib/BinaryFormat/Magic.cpp#L38-L51
let is_unsupported_windows_obj_file = buf.get(0..4) == Some(b"\0\0\xFF\xFF");
is_bitcode || is_unsupported_windows_obj_file
}
#[deny(unsafe_op_in_unsafe_fn)] #[deny(unsafe_op_in_unsafe_fn)]
fn get_llvm_object_symbols( fn get_llvm_object_symbols(
buf: &[u8], buf: &[u8],
f: &mut dyn FnMut(&[u8]) -> io::Result<()>, f: &mut dyn FnMut(&[u8]) -> io::Result<()>,
) -> io::Result<bool> { ) -> io::Result<bool> {
if !should_use_llvm_reader(buf) {
return (DEFAULT_OBJECT_READER.get_symbols)(buf, f);
}
let mut state = Box::new(f); let mut state = Box::new(f);
let err = unsafe { let err = unsafe {
@ -255,18 +241,10 @@ fn get_llvm_object_symbols(
} }
fn llvm_is_64_bit_object_file(buf: &[u8]) -> bool { fn llvm_is_64_bit_object_file(buf: &[u8]) -> bool {
if !should_use_llvm_reader(buf) {
return (DEFAULT_OBJECT_READER.is_64_bit_object_file)(buf);
}
unsafe { llvm::LLVMRustIs64BitSymbolicFile(buf.as_ptr(), buf.len()) } unsafe { llvm::LLVMRustIs64BitSymbolicFile(buf.as_ptr(), buf.len()) }
} }
fn llvm_is_ec_object_file(buf: &[u8]) -> bool { fn llvm_is_ec_object_file(buf: &[u8]) -> bool {
if !should_use_llvm_reader(buf) {
return (DEFAULT_OBJECT_READER.is_ec_object_file)(buf);
}
unsafe { llvm::LLVMRustIsECObject(buf.as_ptr(), buf.len()) } unsafe { llvm::LLVMRustIsECObject(buf.as_ptr(), buf.len()) }
} }