Skip to content

Commit

Permalink
Merge pull request gimli-rs#601 from philipc/elf-def
Browse files Browse the repository at this point in the history
read/elf: exclude zero sized STT_NOTYPE symbols from is_definitions
  • Loading branch information
philipc authored Nov 29, 2023
2 parents 859e910 + 9f0620e commit b3dbfab
Show file tree
Hide file tree
Showing 35 changed files with 3,893 additions and 4 deletions.
6 changes: 6 additions & 0 deletions crates/examples/src/objdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ fn dump_parsed_object<W: Write, E: Write>(w: &mut W, e: &mut E, file: &object::F
Err(err) => writeln!(e, "Failed to parse exports: {}", err)?,
}

writeln!(w)?;
writeln!(w, "Symbol map")?;
for symbol in file.symbol_map().symbols() {
writeln!(w, "0x{:x} \"{}\"", symbol.address(), symbol.name())?;
}

Ok(())
}

Expand Down
39 changes: 39 additions & 0 deletions crates/examples/testfiles/coff/import_msvc.lib.objdump
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ Symbols

Dynamic symbols

Symbol map
0x0 "@comp.id"
0x0 "test_x64_NULL_THUNK_DATA"

test_x64.dll:
Format: Coff Little-endian 32-bit
Kind: Relocatable
Expand All @@ -70,6 +74,10 @@ Symbols

Dynamic symbols

Symbol map
0x0 "@comp.id"
0x0 "__NULL_IMPORT_DESCRIPTOR"

test_x64.dll:
Format: Coff Little-endian 32-bit
Kind: Relocatable
Expand Down Expand Up @@ -101,6 +109,11 @@ Symbols

Dynamic symbols

Symbol map
0x0 "@comp.id"
0x0 "__IMPORT_DESCRIPTOR_test_x64"
0x0 ".idata$6"

test_x86.dll:
Format: Short Import File
Architecture: I386
Expand Down Expand Up @@ -129,6 +142,10 @@ Symbols

Dynamic symbols

Symbol map
0x0 "@comp.id"
0x0 "test_x86_NULL_THUNK_DATA"

test_x86.dll:
Format: Coff Little-endian 32-bit
Kind: Relocatable
Expand All @@ -147,6 +164,10 @@ Symbols

Dynamic symbols

Symbol map
0x0 "@comp.id"
0x0 "__NULL_IMPORT_DESCRIPTOR"

test_x86.dll:
Format: Coff Little-endian 32-bit
Kind: Relocatable
Expand Down Expand Up @@ -178,6 +199,11 @@ Symbols

Dynamic symbols

Symbol map
0x0 "@comp.id"
0x0 "__IMPORT_DESCRIPTOR_test_x86"
0x0 ".idata$6"

test_arm64ec.dll:
Format: Short Import File
Architecture: Unknown
Expand Down Expand Up @@ -206,6 +232,10 @@ Symbols

Dynamic symbols

Symbol map
0x0 "@comp.id"
0x0 "test_arm64ec_NULL_THUNK_DATA"

test_arm64ec.dll:
Format: Coff Little-endian 32-bit
Kind: Relocatable
Expand All @@ -224,6 +254,10 @@ Symbols

Dynamic symbols

Symbol map
0x0 "@comp.id"
0x0 "__NULL_IMPORT_DESCRIPTOR"

test_arm64ec.dll:
Format: Coff Little-endian 32-bit
Kind: Relocatable
Expand Down Expand Up @@ -254,3 +288,8 @@ Symbols
(10, Relocation { kind: ImageOffset, encoding: Generic, size: 20, target: Symbol(SymbolIndex(5)), addend: 0, implicit_addend: true })

Dynamic symbols

Symbol map
0x0 "@comp.id"
0x0 "__IMPORT_DESCRIPTOR_test_arm64ec"
0x0 ".idata$6"
43 changes: 43 additions & 0 deletions crates/examples/testfiles/elf/base-aarch64.o.objdump
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Format: Elf Little-endian 64-bit
Kind: Relocatable
Architecture: Aarch64
Flags: Elf { os_abi: 0, abi_version: 0, e_flags: 0 }
Relative Address Base: 0
Entry Address: 0
0: Section { name: "", address: 0, size: 0, align: 0, kind: Metadata, flags: Elf { sh_flags: 0 } }
1: Section { name: ".text", address: 0, size: 20, align: 4, kind: Text, flags: Elf { sh_flags: 6 } }
2: Section { name: ".rela.text", address: 0, size: 48, align: 8, kind: Metadata, flags: Elf { sh_flags: 40 } }
3: Section { name: ".data", address: 0, size: 0, align: 1, kind: Data, flags: Elf { sh_flags: 3 } }
4: Section { name: ".bss", address: 0, size: 0, align: 1, kind: UninitializedData, flags: Elf { sh_flags: 3 } }
5: Section { name: ".rodata", address: 0, size: d, align: 8, kind: ReadOnlyData, flags: Elf { sh_flags: 2 } }
6: Section { name: ".comment", address: 0, size: 31, align: 1, kind: OtherString, flags: Elf { sh_flags: 30 } }
7: Section { name: ".note.GNU-stack", address: 0, size: 0, align: 1, kind: Other, flags: Elf { sh_flags: 0 } }
8: Section { name: ".symtab", address: 0, size: 120, align: 8, kind: Metadata, flags: Elf { sh_flags: 0 } }
9: Section { name: ".strtab", address: 0, size: 1a, align: 1, kind: Metadata, flags: Elf { sh_flags: 0 } }
10: Section { name: ".shstrtab", address: 0, size: 52, align: 1, kind: Metadata, flags: Elf { sh_flags: 0 } }

Symbols
0: Symbol { name: "", address: 0, size: 0, kind: Null, section: Undefined, scope: Unknown, weak: false, flags: Elf { st_info: 0, st_other: 0 } }
1: Symbol { name: "base.c", address: 0, size: 0, kind: File, section: None, scope: Compilation, weak: false, flags: Elf { st_info: 4, st_other: 0 } }
2: Symbol { name: "", address: 0, size: 0, kind: Section, section: Section(SectionIndex(1)), scope: Compilation, weak: false, flags: Elf { st_info: 3, st_other: 0 } }
3: Symbol { name: "", address: 0, size: 0, kind: Section, section: Section(SectionIndex(3)), scope: Compilation, weak: false, flags: Elf { st_info: 3, st_other: 0 } }
4: Symbol { name: "", address: 0, size: 0, kind: Section, section: Section(SectionIndex(4)), scope: Compilation, weak: false, flags: Elf { st_info: 3, st_other: 0 } }
5: Symbol { name: "", address: 0, size: 0, kind: Section, section: Section(SectionIndex(5)), scope: Compilation, weak: false, flags: Elf { st_info: 3, st_other: 0 } }
6: Symbol { name: "$d", address: 0, size: 0, kind: Label, section: Section(SectionIndex(5)), scope: Compilation, weak: false, flags: Elf { st_info: 0, st_other: 0 } }
7: Symbol { name: "$x", address: 0, size: 0, kind: Label, section: Section(SectionIndex(1)), scope: Compilation, weak: false, flags: Elf { st_info: 0, st_other: 0 } }
8: Symbol { name: "", address: 0, size: 0, kind: Section, section: Section(SectionIndex(7)), scope: Compilation, weak: false, flags: Elf { st_info: 3, st_other: 0 } }
9: Symbol { name: "", address: 0, size: 0, kind: Section, section: Section(SectionIndex(6)), scope: Compilation, weak: false, flags: Elf { st_info: 3, st_other: 0 } }
10: Symbol { name: "main", address: 0, size: 20, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: Elf { st_info: 12, st_other: 0 } }
11: Symbol { name: "printf", address: 0, size: 0, kind: Label, section: Undefined, scope: Unknown, weak: false, flags: Elf { st_info: 10, st_other: 0 } }

.text relocations
(8, Relocation { kind: Elf(113), encoding: Generic, size: 0, target: Symbol(SymbolIndex(5)), addend: 0, implicit_addend: false })
(c, Relocation { kind: Elf(115), encoding: Generic, size: 0, target: Symbol(SymbolIndex(5)), addend: 0, implicit_addend: false })
(10, Relocation { kind: PltRelative, encoding: AArch64Call, size: 1a, target: Symbol(SymbolIndex(b)), addend: 0, implicit_addend: false })

Dynamic symbols

Dynamic relocations

Symbol map
0x0 "main"
Loading

0 comments on commit b3dbfab

Please sign in to comment.