Skip to content

Add test case for COFF auxiliary weak externals #771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions tests/read/coff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,35 @@ fn coff_extended_relocations() {
let relocations = code_section.relocations().collect::<Vec<_>>();
assert_eq!(relocations.len(), 65536);
}

#[cfg(feature = "coff")]
#[test]
fn coff_weak_external() {
use object::{coff::ImageSymbol, ObjectSymbol};

let path_to_obj: PathBuf = ["testfiles", "pe", "weak-extern.o"].iter().collect();
let contents = fs::read(path_to_obj).expect("Could not read weak-extern.o");
let file =
read::coff::CoffFile::<_>::parse(&contents[..]).expect("Could not parse weak-extern.o");
let weak_symbol = file
.symbol_by_name("weak_symbol")
.expect("Could not find 'weak_symbol' symbol in weak-extern.o");

assert!(
weak_symbol.coff_symbol().has_aux_weak_external(),
"'weak_symbol' should have an auxiliary weak external symbol."
);

let weak_external = file
.coff_symbol_table()
.aux_weak_external(weak_symbol.index())
.expect("Could not parse auxiliary weak external symbol.");

let default_symbol_index = weak_external
.weak_default_sym_index
.get(object::LittleEndian);

let _ = file
.symbol_by_index(read::SymbolIndex(default_symbol_index as usize))
.expect("Could not find default symbol for weak external symbol.");
}
Loading