Skip to content

Commit

Permalink
Add simple C test and fix gnu_hash verifier
Browse files Browse the repository at this point in the history
  • Loading branch information
marxin authored and davidlattimore committed Aug 19, 2024
1 parent 4d5bc66 commit 478e012
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions linker-diff/src/gnu_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ pub(crate) fn check_object(obj: &Object) -> Result {
dynamic symbols ({num_symbols})"
)
})?;

// For a simple binary, both LLD and BFD create .gnu.hash section that does not contain any chain:
// Contents of section .gnu.hash:
// objdump -s -j .gnu.hash
// 4003e8 01000000 01000000 01000000 00000000
// 4003f8 00000000 00000000 00000000
if buckets == [0] && rest.is_empty() {
return Ok(());
}

let (chains, _) = object::slice_from_bytes::<u32>(rest, chain_count).map_err(|_| {
anyhow!(
"Insufficient data for .gnu.hash chains. \
Expand Down
1 change: 1 addition & 0 deletions wild/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,7 @@ fn setup_symlink() {
fn integration_test(
#[values(
"trivial.c",
"trivial-main.c",
"link_args.c",
"global_definitions.c",
"data.c",
Expand Down
10 changes: 10 additions & 0 deletions wild/tests/sources/trivial-main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//#AbstractConfig:default
//#LinkArgs:--cc=gcc -Wl,-z,now
//#DiffIgnore:.dynamic.DT_NEEDED
//#DiffIgnore:section.rodata
//#DiffIgnore:section.data

int main()
{
return 42;
}

0 comments on commit 478e012

Please sign in to comment.