Skip to content

Commit

Permalink
Unconditionally use the LLVM symbol reader
Browse files Browse the repository at this point in the history
This may fix a linker error on MSVC
  • Loading branch information
bjorn3 committed Aug 14, 2024
1 parent 2217014 commit 9de0d14
Showing 1 changed file with 0 additions and 22 deletions.
22 changes: 0 additions & 22 deletions compiler/rustc_codegen_llvm/src/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,25 +200,11 @@ static LLVM_OBJECT_READER: ObjectReader = ObjectReader {
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)]
fn get_llvm_object_symbols(
buf: &[u8],
f: &mut dyn FnMut(&[u8]) -> io::Result<()>,
) -> io::Result<bool> {
if !should_use_llvm_reader(buf) {
return (DEFAULT_OBJECT_READER.get_symbols)(buf, f);
}

let mut state = Box::new(f);

let err = unsafe {
Expand Down Expand Up @@ -255,18 +241,10 @@ fn get_llvm_object_symbols(
}

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()) }
}

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()) }
}

Expand Down

0 comments on commit 9de0d14

Please sign in to comment.