diff --git a/crates/examples/src/readobj/mod.rs b/crates/examples/src/readobj/mod.rs index c0002464..cffecb02 100644 --- a/crates/examples/src/readobj/mod.rs +++ b/crates/examples/src/readobj/mod.rs @@ -323,7 +323,7 @@ fn print_archive(p: &mut Printer<'_>, data: &[u8]) { for member in archive.members() { if let Some(member) = member.print_err(p) { p.blank(); - p.field("Member", String::from_utf8_lossy(member.name())); + p.field_inline_string("Member", member.name()); if member.is_thin() { p.field("Size", member.size()); } else if let Some(data) = member.data(data).print_err(p) { @@ -331,6 +331,20 @@ fn print_archive(p: &mut Printer<'_>, data: &[u8]) { } } } + if let Some(symbols) = archive.symbols().print_err(p).flatten() { + p.blank(); + for symbol in symbols { + if let Some(symbol) = symbol.print_err(p) { + p.group("Symbol", |p| { + p.field_inline_string("Name", symbol.name()); + let offset = symbol.offset(); + if let Some(member) = archive.member(offset).print_err(p) { + p.field_inline_string("Member", member.name()); + } + }); + } + } + } } } diff --git a/crates/examples/testfiles/archive/bsd.a.readobj b/crates/examples/testfiles/archive/bsd.a.readobj new file mode 100644 index 00000000..a95de267 --- /dev/null +++ b/crates/examples/testfiles/archive/bsd.a.readobj @@ -0,0 +1,1646 @@ +Format: Archive (Bsd) + +Member: "one.o" +Format: ELF 64-bit +FileHeader { + Ident { + Magic: [7F, 45, 4C, 46] + Class: ELFCLASS64 (0x2) + Data: ELFDATA2LSB (0x1) + Version: EV_CURRENT (0x1) + OsAbi: ELFOSABI_SYSV (0x0) + AbiVersion: 0x0 + Unused: [0, 0, 0, 0, 0, 0, 0] + } + Type: ET_REL (0x1) + Machine: EM_X86_64 (0x3E) + Version: EV_CURRENT (0x1) + Type: ET_REL (0x1) + Entry: 0x0 + ProgramHeaderOffset: 0x0 + SectionHeaderOffset: 0x228 + Flags: 0x0 + HeaderSize: 0x40 + ProgramHeaderEntrySize: 0x0 + ProgramHeaderCount: 0 + SectionHeaderEntrySize: 0x40 + SectionHeaderCount: 12 + SectionHeaderStringTableIndex: 11 +} +SectionHeader { + Index: 0 + Name: "" (0x0) + Type: SHT_NULL (0x0) + Flags: 0x0 + Address: 0x0 + Offset: 0x0 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x0 + EntrySize: 0x0 +} +SectionHeader { + Index: 1 + Name: ".text" (0x1B) + Type: SHT_PROGBITS (0x1) + Flags: 0x6 + SHF_ALLOC (0x2) + SHF_EXECINSTR (0x4) + Address: 0x0 + Offset: 0x40 + Size: 0x16 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 2 + Name: ".data" (0x21) + Type: SHT_PROGBITS (0x1) + Flags: 0x3 + SHF_WRITE (0x1) + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x56 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 3 + Name: ".bss" (0x27) + Type: SHT_NOBITS (0x8) + Flags: 0x3 + SHF_WRITE (0x1) + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x56 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 4 + Name: ".comment" (0x2C) + Type: SHT_PROGBITS (0x1) + Flags: 0x30 + SHF_MERGE (0x10) + SHF_STRINGS (0x20) + Address: 0x0 + Offset: 0x56 + Size: 0x2C + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x1 +} +SectionHeader { + Index: 5 + Name: ".note.GNU-stack" (0x35) + Type: SHT_PROGBITS (0x1) + Flags: 0x0 + Address: 0x0 + Offset: 0x82 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 6 + Name: ".note.gnu.property" (0x45) + Type: SHT_NOTE (0x7) + Flags: 0x2 + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x88 + Size: 0x20 + Link: 0 + Info: 0 + AddressAlign: 0x8 + EntrySize: 0x0 + Note { + Name: "GNU" (0x4) + Type: NT_GNU_PROPERTY_TYPE_0 (0x5) + Property { + Type: GNU_PROPERTY_X86_FEATURE_1_AND (0xC0000002) + Value: 0x3 + GNU_PROPERTY_X86_FEATURE_1_IBT (0x1) + GNU_PROPERTY_X86_FEATURE_1_SHSTK (0x2) + } + } +} +SectionHeader { + Index: 7 + Name: ".eh_frame" (0x5D) + Type: SHT_PROGBITS (0x1) + Flags: 0x2 + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0xA8 + Size: 0x58 + Link: 0 + Info: 0 + AddressAlign: 0x8 + EntrySize: 0x0 +} +SectionHeader { + Index: 8 + Name: ".rela.eh_frame" (0x58) + Type: SHT_RELA (0x4) + Flags: 0x40 + SHF_INFO_LINK (0x40) + Address: 0x0 + Offset: 0x190 + Size: 0x30 + Link: 9 + Info: 7 + AddressAlign: 0x8 + EntrySize: 0x18 + Relocation { + Offset: 0x20 + Type: R_X86_64_PC32 (0x2) + Symbol: "" (0x2) + } + Relocation { + Offset: 0x40 + Type: R_X86_64_PC32 (0x2) + Symbol: "" (0x2) + Addend: 0xB + } +} +SectionHeader { + Index: 9 + Name: ".symtab" (0x1) + Type: SHT_SYMTAB (0x2) + Flags: 0x0 + Address: 0x0 + Offset: 0x100 + Size: 0x78 + Link: 10 + Info: 3 + AddressAlign: 0x8 + EntrySize: 0x18 + Symbol { + Index: 0 + Name: 0x0 + Value: 0x0 + Size: 0x0 + Type: STT_NOTYPE (0x0) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: SHN_UNDEF (0x0) + } + Symbol { + Index: 1 + Name: "" (0x1) + Value: 0x0 + Size: 0x0 + Type: STT_FILE (0x4) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: SHN_ABS (0xFFF1) + } + Symbol { + Index: 2 + Name: "" (0x0) + Value: 0x0 + Size: 0x0 + Type: STT_SECTION (0x3) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } + Symbol { + Index: 3 + Name: "one_a" (0x9) + Value: 0x0 + Size: 0xB + Type: STT_FUNC (0x2) + Bind: STB_GLOBAL (0x1) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } + Symbol { + Index: 4 + Name: "one_b" (0xF) + Value: 0xB + Size: 0xB + Type: STT_FUNC (0x2) + Bind: STB_GLOBAL (0x1) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } +} +SectionHeader { + Index: 10 + Name: ".strtab" (0x9) + Type: SHT_STRTAB (0x3) + Flags: 0x0 + Address: 0x0 + Offset: 0x178 + Size: 0x15 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 11 + Name: ".shstrtab" (0x11) + Type: SHT_STRTAB (0x3) + Flags: 0x0 + Address: 0x0 + Offset: 0x1C0 + Size: 0x67 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} + +Member: "two.o" +Format: ELF 64-bit +FileHeader { + Ident { + Magic: [7F, 45, 4C, 46] + Class: ELFCLASS64 (0x2) + Data: ELFDATA2LSB (0x1) + Version: EV_CURRENT (0x1) + OsAbi: ELFOSABI_SYSV (0x0) + AbiVersion: 0x0 + Unused: [0, 0, 0, 0, 0, 0, 0] + } + Type: ET_REL (0x1) + Machine: EM_X86_64 (0x3E) + Version: EV_CURRENT (0x1) + Type: ET_REL (0x1) + Entry: 0x0 + ProgramHeaderOffset: 0x0 + SectionHeaderOffset: 0x228 + Flags: 0x0 + HeaderSize: 0x40 + ProgramHeaderEntrySize: 0x0 + ProgramHeaderCount: 0 + SectionHeaderEntrySize: 0x40 + SectionHeaderCount: 12 + SectionHeaderStringTableIndex: 11 +} +SectionHeader { + Index: 0 + Name: "" (0x0) + Type: SHT_NULL (0x0) + Flags: 0x0 + Address: 0x0 + Offset: 0x0 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x0 + EntrySize: 0x0 +} +SectionHeader { + Index: 1 + Name: ".text" (0x1B) + Type: SHT_PROGBITS (0x1) + Flags: 0x6 + SHF_ALLOC (0x2) + SHF_EXECINSTR (0x4) + Address: 0x0 + Offset: 0x40 + Size: 0x16 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 2 + Name: ".data" (0x21) + Type: SHT_PROGBITS (0x1) + Flags: 0x3 + SHF_WRITE (0x1) + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x56 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 3 + Name: ".bss" (0x27) + Type: SHT_NOBITS (0x8) + Flags: 0x3 + SHF_WRITE (0x1) + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x56 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 4 + Name: ".comment" (0x2C) + Type: SHT_PROGBITS (0x1) + Flags: 0x30 + SHF_MERGE (0x10) + SHF_STRINGS (0x20) + Address: 0x0 + Offset: 0x56 + Size: 0x2C + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x1 +} +SectionHeader { + Index: 5 + Name: ".note.GNU-stack" (0x35) + Type: SHT_PROGBITS (0x1) + Flags: 0x0 + Address: 0x0 + Offset: 0x82 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 6 + Name: ".note.gnu.property" (0x45) + Type: SHT_NOTE (0x7) + Flags: 0x2 + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x88 + Size: 0x20 + Link: 0 + Info: 0 + AddressAlign: 0x8 + EntrySize: 0x0 + Note { + Name: "GNU" (0x4) + Type: NT_GNU_PROPERTY_TYPE_0 (0x5) + Property { + Type: GNU_PROPERTY_X86_FEATURE_1_AND (0xC0000002) + Value: 0x3 + GNU_PROPERTY_X86_FEATURE_1_IBT (0x1) + GNU_PROPERTY_X86_FEATURE_1_SHSTK (0x2) + } + } +} +SectionHeader { + Index: 7 + Name: ".eh_frame" (0x5D) + Type: SHT_PROGBITS (0x1) + Flags: 0x2 + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0xA8 + Size: 0x58 + Link: 0 + Info: 0 + AddressAlign: 0x8 + EntrySize: 0x0 +} +SectionHeader { + Index: 8 + Name: ".rela.eh_frame" (0x58) + Type: SHT_RELA (0x4) + Flags: 0x40 + SHF_INFO_LINK (0x40) + Address: 0x0 + Offset: 0x190 + Size: 0x30 + Link: 9 + Info: 7 + AddressAlign: 0x8 + EntrySize: 0x18 + Relocation { + Offset: 0x20 + Type: R_X86_64_PC32 (0x2) + Symbol: "" (0x2) + } + Relocation { + Offset: 0x40 + Type: R_X86_64_PC32 (0x2) + Symbol: "" (0x2) + Addend: 0xB + } +} +SectionHeader { + Index: 9 + Name: ".symtab" (0x1) + Type: SHT_SYMTAB (0x2) + Flags: 0x0 + Address: 0x0 + Offset: 0x100 + Size: 0x78 + Link: 10 + Info: 3 + AddressAlign: 0x8 + EntrySize: 0x18 + Symbol { + Index: 0 + Name: 0x0 + Value: 0x0 + Size: 0x0 + Type: STT_NOTYPE (0x0) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: SHN_UNDEF (0x0) + } + Symbol { + Index: 1 + Name: "" (0x1) + Value: 0x0 + Size: 0x0 + Type: STT_FILE (0x4) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: SHN_ABS (0xFFF1) + } + Symbol { + Index: 2 + Name: "" (0x0) + Value: 0x0 + Size: 0x0 + Type: STT_SECTION (0x3) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } + Symbol { + Index: 3 + Name: "two_a" (0x9) + Value: 0x0 + Size: 0xB + Type: STT_FUNC (0x2) + Bind: STB_GLOBAL (0x1) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } + Symbol { + Index: 4 + Name: "two_b" (0xF) + Value: 0xB + Size: 0xB + Type: STT_FUNC (0x2) + Bind: STB_GLOBAL (0x1) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } +} +SectionHeader { + Index: 10 + Name: ".strtab" (0x9) + Type: SHT_STRTAB (0x3) + Flags: 0x0 + Address: 0x0 + Offset: 0x178 + Size: 0x15 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 11 + Name: ".shstrtab" (0x11) + Type: SHT_STRTAB (0x3) + Flags: 0x0 + Address: 0x0 + Offset: 0x1C0 + Size: 0x67 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} + +Member: "three.o" +Format: ELF 64-bit +FileHeader { + Ident { + Magic: [7F, 45, 4C, 46] + Class: ELFCLASS64 (0x2) + Data: ELFDATA2LSB (0x1) + Version: EV_CURRENT (0x1) + OsAbi: ELFOSABI_SYSV (0x0) + AbiVersion: 0x0 + Unused: [0, 0, 0, 0, 0, 0, 0] + } + Type: ET_REL (0x1) + Machine: EM_X86_64 (0x3E) + Version: EV_CURRENT (0x1) + Type: ET_REL (0x1) + Entry: 0x0 + ProgramHeaderOffset: 0x0 + SectionHeaderOffset: 0x230 + Flags: 0x0 + HeaderSize: 0x40 + ProgramHeaderEntrySize: 0x0 + ProgramHeaderCount: 0 + SectionHeaderEntrySize: 0x40 + SectionHeaderCount: 12 + SectionHeaderStringTableIndex: 11 +} +SectionHeader { + Index: 0 + Name: "" (0x0) + Type: SHT_NULL (0x0) + Flags: 0x0 + Address: 0x0 + Offset: 0x0 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x0 + EntrySize: 0x0 +} +SectionHeader { + Index: 1 + Name: ".text" (0x1B) + Type: SHT_PROGBITS (0x1) + Flags: 0x6 + SHF_ALLOC (0x2) + SHF_EXECINSTR (0x4) + Address: 0x0 + Offset: 0x40 + Size: 0x16 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 2 + Name: ".data" (0x21) + Type: SHT_PROGBITS (0x1) + Flags: 0x3 + SHF_WRITE (0x1) + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x56 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 3 + Name: ".bss" (0x27) + Type: SHT_NOBITS (0x8) + Flags: 0x3 + SHF_WRITE (0x1) + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x56 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 4 + Name: ".comment" (0x2C) + Type: SHT_PROGBITS (0x1) + Flags: 0x30 + SHF_MERGE (0x10) + SHF_STRINGS (0x20) + Address: 0x0 + Offset: 0x56 + Size: 0x2C + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x1 +} +SectionHeader { + Index: 5 + Name: ".note.GNU-stack" (0x35) + Type: SHT_PROGBITS (0x1) + Flags: 0x0 + Address: 0x0 + Offset: 0x82 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 6 + Name: ".note.gnu.property" (0x45) + Type: SHT_NOTE (0x7) + Flags: 0x2 + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x88 + Size: 0x20 + Link: 0 + Info: 0 + AddressAlign: 0x8 + EntrySize: 0x0 + Note { + Name: "GNU" (0x4) + Type: NT_GNU_PROPERTY_TYPE_0 (0x5) + Property { + Type: GNU_PROPERTY_X86_FEATURE_1_AND (0xC0000002) + Value: 0x3 + GNU_PROPERTY_X86_FEATURE_1_IBT (0x1) + GNU_PROPERTY_X86_FEATURE_1_SHSTK (0x2) + } + } +} +SectionHeader { + Index: 7 + Name: ".eh_frame" (0x5D) + Type: SHT_PROGBITS (0x1) + Flags: 0x2 + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0xA8 + Size: 0x58 + Link: 0 + Info: 0 + AddressAlign: 0x8 + EntrySize: 0x0 +} +SectionHeader { + Index: 8 + Name: ".rela.eh_frame" (0x58) + Type: SHT_RELA (0x4) + Flags: 0x40 + SHF_INFO_LINK (0x40) + Address: 0x0 + Offset: 0x198 + Size: 0x30 + Link: 9 + Info: 7 + AddressAlign: 0x8 + EntrySize: 0x18 + Relocation { + Offset: 0x20 + Type: R_X86_64_PC32 (0x2) + Symbol: "" (0x2) + } + Relocation { + Offset: 0x40 + Type: R_X86_64_PC32 (0x2) + Symbol: "" (0x2) + Addend: 0xB + } +} +SectionHeader { + Index: 9 + Name: ".symtab" (0x1) + Type: SHT_SYMTAB (0x2) + Flags: 0x0 + Address: 0x0 + Offset: 0x100 + Size: 0x78 + Link: 10 + Info: 3 + AddressAlign: 0x8 + EntrySize: 0x18 + Symbol { + Index: 0 + Name: 0x0 + Value: 0x0 + Size: 0x0 + Type: STT_NOTYPE (0x0) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: SHN_UNDEF (0x0) + } + Symbol { + Index: 1 + Name: "" (0x1) + Value: 0x0 + Size: 0x0 + Type: STT_FILE (0x4) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: SHN_ABS (0xFFF1) + } + Symbol { + Index: 2 + Name: "" (0x0) + Value: 0x0 + Size: 0x0 + Type: STT_SECTION (0x3) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } + Symbol { + Index: 3 + Name: "three_a" (0x9) + Value: 0x0 + Size: 0xB + Type: STT_FUNC (0x2) + Bind: STB_GLOBAL (0x1) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } + Symbol { + Index: 4 + Name: "three_b" (0x11) + Value: 0xB + Size: 0xB + Type: STT_FUNC (0x2) + Bind: STB_GLOBAL (0x1) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } +} +SectionHeader { + Index: 10 + Name: ".strtab" (0x9) + Type: SHT_STRTAB (0x3) + Flags: 0x0 + Address: 0x0 + Offset: 0x178 + Size: 0x19 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 11 + Name: ".shstrtab" (0x11) + Type: SHT_STRTAB (0x3) + Flags: 0x0 + Address: 0x0 + Offset: 0x1C8 + Size: 0x67 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} + +Member: "a.o" +Format: ELF 64-bit +FileHeader { + Ident { + Magic: [7F, 45, 4C, 46] + Class: ELFCLASS64 (0x2) + Data: ELFDATA2LSB (0x1) + Version: EV_CURRENT (0x1) + OsAbi: ELFOSABI_SYSV (0x0) + AbiVersion: 0x0 + Unused: [0, 0, 0, 0, 0, 0, 0] + } + Type: ET_REL (0x1) + Machine: EM_X86_64 (0x3E) + Version: EV_CURRENT (0x1) + Type: ET_REL (0x1) + Entry: 0x0 + ProgramHeaderOffset: 0x0 + SectionHeaderOffset: 0x228 + Flags: 0x0 + HeaderSize: 0x40 + ProgramHeaderEntrySize: 0x0 + ProgramHeaderCount: 0 + SectionHeaderEntrySize: 0x40 + SectionHeaderCount: 12 + SectionHeaderStringTableIndex: 11 +} +SectionHeader { + Index: 0 + Name: "" (0x0) + Type: SHT_NULL (0x0) + Flags: 0x0 + Address: 0x0 + Offset: 0x0 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x0 + EntrySize: 0x0 +} +SectionHeader { + Index: 1 + Name: ".text" (0x1B) + Type: SHT_PROGBITS (0x1) + Flags: 0x6 + SHF_ALLOC (0x2) + SHF_EXECINSTR (0x4) + Address: 0x0 + Offset: 0x40 + Size: 0x16 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 2 + Name: ".data" (0x21) + Type: SHT_PROGBITS (0x1) + Flags: 0x3 + SHF_WRITE (0x1) + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x56 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 3 + Name: ".bss" (0x27) + Type: SHT_NOBITS (0x8) + Flags: 0x3 + SHF_WRITE (0x1) + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x56 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 4 + Name: ".comment" (0x2C) + Type: SHT_PROGBITS (0x1) + Flags: 0x30 + SHF_MERGE (0x10) + SHF_STRINGS (0x20) + Address: 0x0 + Offset: 0x56 + Size: 0x2C + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x1 +} +SectionHeader { + Index: 5 + Name: ".note.GNU-stack" (0x35) + Type: SHT_PROGBITS (0x1) + Flags: 0x0 + Address: 0x0 + Offset: 0x82 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 6 + Name: ".note.gnu.property" (0x45) + Type: SHT_NOTE (0x7) + Flags: 0x2 + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x88 + Size: 0x20 + Link: 0 + Info: 0 + AddressAlign: 0x8 + EntrySize: 0x0 + Note { + Name: "GNU" (0x4) + Type: NT_GNU_PROPERTY_TYPE_0 (0x5) + Property { + Type: GNU_PROPERTY_X86_FEATURE_1_AND (0xC0000002) + Value: 0x3 + GNU_PROPERTY_X86_FEATURE_1_IBT (0x1) + GNU_PROPERTY_X86_FEATURE_1_SHSTK (0x2) + } + } +} +SectionHeader { + Index: 7 + Name: ".eh_frame" (0x5D) + Type: SHT_PROGBITS (0x1) + Flags: 0x2 + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0xA8 + Size: 0x58 + Link: 0 + Info: 0 + AddressAlign: 0x8 + EntrySize: 0x0 +} +SectionHeader { + Index: 8 + Name: ".rela.eh_frame" (0x58) + Type: SHT_RELA (0x4) + Flags: 0x40 + SHF_INFO_LINK (0x40) + Address: 0x0 + Offset: 0x190 + Size: 0x30 + Link: 9 + Info: 7 + AddressAlign: 0x8 + EntrySize: 0x18 + Relocation { + Offset: 0x20 + Type: R_X86_64_PC32 (0x2) + Symbol: "" (0x2) + } + Relocation { + Offset: 0x40 + Type: R_X86_64_PC32 (0x2) + Symbol: "" (0x2) + Addend: 0xB + } +} +SectionHeader { + Index: 9 + Name: ".symtab" (0x1) + Type: SHT_SYMTAB (0x2) + Flags: 0x0 + Address: 0x0 + Offset: 0x100 + Size: 0x78 + Link: 10 + Info: 3 + AddressAlign: 0x8 + EntrySize: 0x18 + Symbol { + Index: 0 + Name: 0x0 + Value: 0x0 + Size: 0x0 + Type: STT_NOTYPE (0x0) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: SHN_UNDEF (0x0) + } + Symbol { + Index: 1 + Name: "" (0x1) + Value: 0x0 + Size: 0x0 + Type: STT_FILE (0x4) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: SHN_ABS (0xFFF1) + } + Symbol { + Index: 2 + Name: "" (0x0) + Value: 0x0 + Size: 0x0 + Type: STT_SECTION (0x3) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } + Symbol { + Index: 3 + Name: "a_one" (0x9) + Value: 0x0 + Size: 0xB + Type: STT_FUNC (0x2) + Bind: STB_GLOBAL (0x1) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } + Symbol { + Index: 4 + Name: "a_two" (0xF) + Value: 0xB + Size: 0xB + Type: STT_FUNC (0x2) + Bind: STB_GLOBAL (0x1) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } +} +SectionHeader { + Index: 10 + Name: ".strtab" (0x9) + Type: SHT_STRTAB (0x3) + Flags: 0x0 + Address: 0x0 + Offset: 0x178 + Size: 0x15 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 11 + Name: ".shstrtab" (0x11) + Type: SHT_STRTAB (0x3) + Flags: 0x0 + Address: 0x0 + Offset: 0x1C0 + Size: 0x67 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} + +Member: "b.o" +Format: ELF 64-bit +FileHeader { + Ident { + Magic: [7F, 45, 4C, 46] + Class: ELFCLASS64 (0x2) + Data: ELFDATA2LSB (0x1) + Version: EV_CURRENT (0x1) + OsAbi: ELFOSABI_SYSV (0x0) + AbiVersion: 0x0 + Unused: [0, 0, 0, 0, 0, 0, 0] + } + Type: ET_REL (0x1) + Machine: EM_X86_64 (0x3E) + Version: EV_CURRENT (0x1) + Type: ET_REL (0x1) + Entry: 0x0 + ProgramHeaderOffset: 0x0 + SectionHeaderOffset: 0x228 + Flags: 0x0 + HeaderSize: 0x40 + ProgramHeaderEntrySize: 0x0 + ProgramHeaderCount: 0 + SectionHeaderEntrySize: 0x40 + SectionHeaderCount: 12 + SectionHeaderStringTableIndex: 11 +} +SectionHeader { + Index: 0 + Name: "" (0x0) + Type: SHT_NULL (0x0) + Flags: 0x0 + Address: 0x0 + Offset: 0x0 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x0 + EntrySize: 0x0 +} +SectionHeader { + Index: 1 + Name: ".text" (0x1B) + Type: SHT_PROGBITS (0x1) + Flags: 0x6 + SHF_ALLOC (0x2) + SHF_EXECINSTR (0x4) + Address: 0x0 + Offset: 0x40 + Size: 0x16 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 2 + Name: ".data" (0x21) + Type: SHT_PROGBITS (0x1) + Flags: 0x3 + SHF_WRITE (0x1) + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x56 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 3 + Name: ".bss" (0x27) + Type: SHT_NOBITS (0x8) + Flags: 0x3 + SHF_WRITE (0x1) + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x56 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 4 + Name: ".comment" (0x2C) + Type: SHT_PROGBITS (0x1) + Flags: 0x30 + SHF_MERGE (0x10) + SHF_STRINGS (0x20) + Address: 0x0 + Offset: 0x56 + Size: 0x2C + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x1 +} +SectionHeader { + Index: 5 + Name: ".note.GNU-stack" (0x35) + Type: SHT_PROGBITS (0x1) + Flags: 0x0 + Address: 0x0 + Offset: 0x82 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 6 + Name: ".note.gnu.property" (0x45) + Type: SHT_NOTE (0x7) + Flags: 0x2 + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x88 + Size: 0x20 + Link: 0 + Info: 0 + AddressAlign: 0x8 + EntrySize: 0x0 + Note { + Name: "GNU" (0x4) + Type: NT_GNU_PROPERTY_TYPE_0 (0x5) + Property { + Type: GNU_PROPERTY_X86_FEATURE_1_AND (0xC0000002) + Value: 0x3 + GNU_PROPERTY_X86_FEATURE_1_IBT (0x1) + GNU_PROPERTY_X86_FEATURE_1_SHSTK (0x2) + } + } +} +SectionHeader { + Index: 7 + Name: ".eh_frame" (0x5D) + Type: SHT_PROGBITS (0x1) + Flags: 0x2 + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0xA8 + Size: 0x58 + Link: 0 + Info: 0 + AddressAlign: 0x8 + EntrySize: 0x0 +} +SectionHeader { + Index: 8 + Name: ".rela.eh_frame" (0x58) + Type: SHT_RELA (0x4) + Flags: 0x40 + SHF_INFO_LINK (0x40) + Address: 0x0 + Offset: 0x190 + Size: 0x30 + Link: 9 + Info: 7 + AddressAlign: 0x8 + EntrySize: 0x18 + Relocation { + Offset: 0x20 + Type: R_X86_64_PC32 (0x2) + Symbol: "" (0x2) + } + Relocation { + Offset: 0x40 + Type: R_X86_64_PC32 (0x2) + Symbol: "" (0x2) + Addend: 0xB + } +} +SectionHeader { + Index: 9 + Name: ".symtab" (0x1) + Type: SHT_SYMTAB (0x2) + Flags: 0x0 + Address: 0x0 + Offset: 0x100 + Size: 0x78 + Link: 10 + Info: 3 + AddressAlign: 0x8 + EntrySize: 0x18 + Symbol { + Index: 0 + Name: 0x0 + Value: 0x0 + Size: 0x0 + Type: STT_NOTYPE (0x0) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: SHN_UNDEF (0x0) + } + Symbol { + Index: 1 + Name: "" (0x1) + Value: 0x0 + Size: 0x0 + Type: STT_FILE (0x4) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: SHN_ABS (0xFFF1) + } + Symbol { + Index: 2 + Name: "" (0x0) + Value: 0x0 + Size: 0x0 + Type: STT_SECTION (0x3) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } + Symbol { + Index: 3 + Name: "b_one" (0x9) + Value: 0x0 + Size: 0xB + Type: STT_FUNC (0x2) + Bind: STB_GLOBAL (0x1) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } + Symbol { + Index: 4 + Name: "b_two" (0xF) + Value: 0xB + Size: 0xB + Type: STT_FUNC (0x2) + Bind: STB_GLOBAL (0x1) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } +} +SectionHeader { + Index: 10 + Name: ".strtab" (0x9) + Type: SHT_STRTAB (0x3) + Flags: 0x0 + Address: 0x0 + Offset: 0x178 + Size: 0x15 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 11 + Name: ".shstrtab" (0x11) + Type: SHT_STRTAB (0x3) + Flags: 0x0 + Address: 0x0 + Offset: 0x1C0 + Size: 0x67 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} + +Member: "c.o" +Format: ELF 64-bit +FileHeader { + Ident { + Magic: [7F, 45, 4C, 46] + Class: ELFCLASS64 (0x2) + Data: ELFDATA2LSB (0x1) + Version: EV_CURRENT (0x1) + OsAbi: ELFOSABI_SYSV (0x0) + AbiVersion: 0x0 + Unused: [0, 0, 0, 0, 0, 0, 0] + } + Type: ET_REL (0x1) + Machine: EM_X86_64 (0x3E) + Version: EV_CURRENT (0x1) + Type: ET_REL (0x1) + Entry: 0x0 + ProgramHeaderOffset: 0x0 + SectionHeaderOffset: 0x228 + Flags: 0x0 + HeaderSize: 0x40 + ProgramHeaderEntrySize: 0x0 + ProgramHeaderCount: 0 + SectionHeaderEntrySize: 0x40 + SectionHeaderCount: 12 + SectionHeaderStringTableIndex: 11 +} +SectionHeader { + Index: 0 + Name: "" (0x0) + Type: SHT_NULL (0x0) + Flags: 0x0 + Address: 0x0 + Offset: 0x0 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x0 + EntrySize: 0x0 +} +SectionHeader { + Index: 1 + Name: ".text" (0x1B) + Type: SHT_PROGBITS (0x1) + Flags: 0x6 + SHF_ALLOC (0x2) + SHF_EXECINSTR (0x4) + Address: 0x0 + Offset: 0x40 + Size: 0x16 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 2 + Name: ".data" (0x21) + Type: SHT_PROGBITS (0x1) + Flags: 0x3 + SHF_WRITE (0x1) + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x56 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 3 + Name: ".bss" (0x27) + Type: SHT_NOBITS (0x8) + Flags: 0x3 + SHF_WRITE (0x1) + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x56 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 4 + Name: ".comment" (0x2C) + Type: SHT_PROGBITS (0x1) + Flags: 0x30 + SHF_MERGE (0x10) + SHF_STRINGS (0x20) + Address: 0x0 + Offset: 0x56 + Size: 0x2C + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x1 +} +SectionHeader { + Index: 5 + Name: ".note.GNU-stack" (0x35) + Type: SHT_PROGBITS (0x1) + Flags: 0x0 + Address: 0x0 + Offset: 0x82 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 6 + Name: ".note.gnu.property" (0x45) + Type: SHT_NOTE (0x7) + Flags: 0x2 + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x88 + Size: 0x20 + Link: 0 + Info: 0 + AddressAlign: 0x8 + EntrySize: 0x0 + Note { + Name: "GNU" (0x4) + Type: NT_GNU_PROPERTY_TYPE_0 (0x5) + Property { + Type: GNU_PROPERTY_X86_FEATURE_1_AND (0xC0000002) + Value: 0x3 + GNU_PROPERTY_X86_FEATURE_1_IBT (0x1) + GNU_PROPERTY_X86_FEATURE_1_SHSTK (0x2) + } + } +} +SectionHeader { + Index: 7 + Name: ".eh_frame" (0x5D) + Type: SHT_PROGBITS (0x1) + Flags: 0x2 + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0xA8 + Size: 0x58 + Link: 0 + Info: 0 + AddressAlign: 0x8 + EntrySize: 0x0 +} +SectionHeader { + Index: 8 + Name: ".rela.eh_frame" (0x58) + Type: SHT_RELA (0x4) + Flags: 0x40 + SHF_INFO_LINK (0x40) + Address: 0x0 + Offset: 0x190 + Size: 0x30 + Link: 9 + Info: 7 + AddressAlign: 0x8 + EntrySize: 0x18 + Relocation { + Offset: 0x20 + Type: R_X86_64_PC32 (0x2) + Symbol: "" (0x2) + } + Relocation { + Offset: 0x40 + Type: R_X86_64_PC32 (0x2) + Symbol: "" (0x2) + Addend: 0xB + } +} +SectionHeader { + Index: 9 + Name: ".symtab" (0x1) + Type: SHT_SYMTAB (0x2) + Flags: 0x0 + Address: 0x0 + Offset: 0x100 + Size: 0x78 + Link: 10 + Info: 3 + AddressAlign: 0x8 + EntrySize: 0x18 + Symbol { + Index: 0 + Name: 0x0 + Value: 0x0 + Size: 0x0 + Type: STT_NOTYPE (0x0) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: SHN_UNDEF (0x0) + } + Symbol { + Index: 1 + Name: "" (0x1) + Value: 0x0 + Size: 0x0 + Type: STT_FILE (0x4) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: SHN_ABS (0xFFF1) + } + Symbol { + Index: 2 + Name: "" (0x0) + Value: 0x0 + Size: 0x0 + Type: STT_SECTION (0x3) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } + Symbol { + Index: 3 + Name: "c_one" (0x9) + Value: 0x0 + Size: 0xB + Type: STT_FUNC (0x2) + Bind: STB_GLOBAL (0x1) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } + Symbol { + Index: 4 + Name: "c_two" (0xF) + Value: 0xB + Size: 0xB + Type: STT_FUNC (0x2) + Bind: STB_GLOBAL (0x1) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } +} +SectionHeader { + Index: 10 + Name: ".strtab" (0x9) + Type: SHT_STRTAB (0x3) + Flags: 0x0 + Address: 0x0 + Offset: 0x178 + Size: 0x15 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 11 + Name: ".shstrtab" (0x11) + Type: SHT_STRTAB (0x3) + Flags: 0x0 + Address: 0x0 + Offset: 0x1C0 + Size: 0x67 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} + +Symbol { + Name: "one_a" + Member: "one.o" +} +Symbol { + Name: "one_b" + Member: "one.o" +} +Symbol { + Name: "two_a" + Member: "two.o" +} +Symbol { + Name: "two_b" + Member: "two.o" +} +Symbol { + Name: "three_a" + Member: "three.o" +} +Symbol { + Name: "three_b" + Member: "three.o" +} +Symbol { + Name: "a_one" + Member: "a.o" +} +Symbol { + Name: "a_two" + Member: "a.o" +} +Symbol { + Name: "b_one" + Member: "b.o" +} +Symbol { + Name: "b_two" + Member: "b.o" +} +Symbol { + Name: "c_one" + Member: "c.o" +} +Symbol { + Name: "c_two" + Member: "c.o" +} diff --git a/crates/examples/testfiles/archive/gnu.a.readobj b/crates/examples/testfiles/archive/gnu.a.readobj new file mode 100644 index 00000000..6e742b33 --- /dev/null +++ b/crates/examples/testfiles/archive/gnu.a.readobj @@ -0,0 +1,1646 @@ +Format: Archive (Gnu) + +Member: "one.o" +Format: ELF 64-bit +FileHeader { + Ident { + Magic: [7F, 45, 4C, 46] + Class: ELFCLASS64 (0x2) + Data: ELFDATA2LSB (0x1) + Version: EV_CURRENT (0x1) + OsAbi: ELFOSABI_SYSV (0x0) + AbiVersion: 0x0 + Unused: [0, 0, 0, 0, 0, 0, 0] + } + Type: ET_REL (0x1) + Machine: EM_X86_64 (0x3E) + Version: EV_CURRENT (0x1) + Type: ET_REL (0x1) + Entry: 0x0 + ProgramHeaderOffset: 0x0 + SectionHeaderOffset: 0x228 + Flags: 0x0 + HeaderSize: 0x40 + ProgramHeaderEntrySize: 0x0 + ProgramHeaderCount: 0 + SectionHeaderEntrySize: 0x40 + SectionHeaderCount: 12 + SectionHeaderStringTableIndex: 11 +} +SectionHeader { + Index: 0 + Name: "" (0x0) + Type: SHT_NULL (0x0) + Flags: 0x0 + Address: 0x0 + Offset: 0x0 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x0 + EntrySize: 0x0 +} +SectionHeader { + Index: 1 + Name: ".text" (0x1B) + Type: SHT_PROGBITS (0x1) + Flags: 0x6 + SHF_ALLOC (0x2) + SHF_EXECINSTR (0x4) + Address: 0x0 + Offset: 0x40 + Size: 0x16 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 2 + Name: ".data" (0x21) + Type: SHT_PROGBITS (0x1) + Flags: 0x3 + SHF_WRITE (0x1) + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x56 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 3 + Name: ".bss" (0x27) + Type: SHT_NOBITS (0x8) + Flags: 0x3 + SHF_WRITE (0x1) + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x56 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 4 + Name: ".comment" (0x2C) + Type: SHT_PROGBITS (0x1) + Flags: 0x30 + SHF_MERGE (0x10) + SHF_STRINGS (0x20) + Address: 0x0 + Offset: 0x56 + Size: 0x2C + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x1 +} +SectionHeader { + Index: 5 + Name: ".note.GNU-stack" (0x35) + Type: SHT_PROGBITS (0x1) + Flags: 0x0 + Address: 0x0 + Offset: 0x82 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 6 + Name: ".note.gnu.property" (0x45) + Type: SHT_NOTE (0x7) + Flags: 0x2 + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x88 + Size: 0x20 + Link: 0 + Info: 0 + AddressAlign: 0x8 + EntrySize: 0x0 + Note { + Name: "GNU" (0x4) + Type: NT_GNU_PROPERTY_TYPE_0 (0x5) + Property { + Type: GNU_PROPERTY_X86_FEATURE_1_AND (0xC0000002) + Value: 0x3 + GNU_PROPERTY_X86_FEATURE_1_IBT (0x1) + GNU_PROPERTY_X86_FEATURE_1_SHSTK (0x2) + } + } +} +SectionHeader { + Index: 7 + Name: ".eh_frame" (0x5D) + Type: SHT_PROGBITS (0x1) + Flags: 0x2 + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0xA8 + Size: 0x58 + Link: 0 + Info: 0 + AddressAlign: 0x8 + EntrySize: 0x0 +} +SectionHeader { + Index: 8 + Name: ".rela.eh_frame" (0x58) + Type: SHT_RELA (0x4) + Flags: 0x40 + SHF_INFO_LINK (0x40) + Address: 0x0 + Offset: 0x190 + Size: 0x30 + Link: 9 + Info: 7 + AddressAlign: 0x8 + EntrySize: 0x18 + Relocation { + Offset: 0x20 + Type: R_X86_64_PC32 (0x2) + Symbol: "" (0x2) + } + Relocation { + Offset: 0x40 + Type: R_X86_64_PC32 (0x2) + Symbol: "" (0x2) + Addend: 0xB + } +} +SectionHeader { + Index: 9 + Name: ".symtab" (0x1) + Type: SHT_SYMTAB (0x2) + Flags: 0x0 + Address: 0x0 + Offset: 0x100 + Size: 0x78 + Link: 10 + Info: 3 + AddressAlign: 0x8 + EntrySize: 0x18 + Symbol { + Index: 0 + Name: 0x0 + Value: 0x0 + Size: 0x0 + Type: STT_NOTYPE (0x0) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: SHN_UNDEF (0x0) + } + Symbol { + Index: 1 + Name: "" (0x1) + Value: 0x0 + Size: 0x0 + Type: STT_FILE (0x4) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: SHN_ABS (0xFFF1) + } + Symbol { + Index: 2 + Name: "" (0x0) + Value: 0x0 + Size: 0x0 + Type: STT_SECTION (0x3) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } + Symbol { + Index: 3 + Name: "one_a" (0x9) + Value: 0x0 + Size: 0xB + Type: STT_FUNC (0x2) + Bind: STB_GLOBAL (0x1) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } + Symbol { + Index: 4 + Name: "one_b" (0xF) + Value: 0xB + Size: 0xB + Type: STT_FUNC (0x2) + Bind: STB_GLOBAL (0x1) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } +} +SectionHeader { + Index: 10 + Name: ".strtab" (0x9) + Type: SHT_STRTAB (0x3) + Flags: 0x0 + Address: 0x0 + Offset: 0x178 + Size: 0x15 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 11 + Name: ".shstrtab" (0x11) + Type: SHT_STRTAB (0x3) + Flags: 0x0 + Address: 0x0 + Offset: 0x1C0 + Size: 0x67 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} + +Member: "two.o" +Format: ELF 64-bit +FileHeader { + Ident { + Magic: [7F, 45, 4C, 46] + Class: ELFCLASS64 (0x2) + Data: ELFDATA2LSB (0x1) + Version: EV_CURRENT (0x1) + OsAbi: ELFOSABI_SYSV (0x0) + AbiVersion: 0x0 + Unused: [0, 0, 0, 0, 0, 0, 0] + } + Type: ET_REL (0x1) + Machine: EM_X86_64 (0x3E) + Version: EV_CURRENT (0x1) + Type: ET_REL (0x1) + Entry: 0x0 + ProgramHeaderOffset: 0x0 + SectionHeaderOffset: 0x228 + Flags: 0x0 + HeaderSize: 0x40 + ProgramHeaderEntrySize: 0x0 + ProgramHeaderCount: 0 + SectionHeaderEntrySize: 0x40 + SectionHeaderCount: 12 + SectionHeaderStringTableIndex: 11 +} +SectionHeader { + Index: 0 + Name: "" (0x0) + Type: SHT_NULL (0x0) + Flags: 0x0 + Address: 0x0 + Offset: 0x0 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x0 + EntrySize: 0x0 +} +SectionHeader { + Index: 1 + Name: ".text" (0x1B) + Type: SHT_PROGBITS (0x1) + Flags: 0x6 + SHF_ALLOC (0x2) + SHF_EXECINSTR (0x4) + Address: 0x0 + Offset: 0x40 + Size: 0x16 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 2 + Name: ".data" (0x21) + Type: SHT_PROGBITS (0x1) + Flags: 0x3 + SHF_WRITE (0x1) + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x56 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 3 + Name: ".bss" (0x27) + Type: SHT_NOBITS (0x8) + Flags: 0x3 + SHF_WRITE (0x1) + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x56 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 4 + Name: ".comment" (0x2C) + Type: SHT_PROGBITS (0x1) + Flags: 0x30 + SHF_MERGE (0x10) + SHF_STRINGS (0x20) + Address: 0x0 + Offset: 0x56 + Size: 0x2C + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x1 +} +SectionHeader { + Index: 5 + Name: ".note.GNU-stack" (0x35) + Type: SHT_PROGBITS (0x1) + Flags: 0x0 + Address: 0x0 + Offset: 0x82 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 6 + Name: ".note.gnu.property" (0x45) + Type: SHT_NOTE (0x7) + Flags: 0x2 + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x88 + Size: 0x20 + Link: 0 + Info: 0 + AddressAlign: 0x8 + EntrySize: 0x0 + Note { + Name: "GNU" (0x4) + Type: NT_GNU_PROPERTY_TYPE_0 (0x5) + Property { + Type: GNU_PROPERTY_X86_FEATURE_1_AND (0xC0000002) + Value: 0x3 + GNU_PROPERTY_X86_FEATURE_1_IBT (0x1) + GNU_PROPERTY_X86_FEATURE_1_SHSTK (0x2) + } + } +} +SectionHeader { + Index: 7 + Name: ".eh_frame" (0x5D) + Type: SHT_PROGBITS (0x1) + Flags: 0x2 + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0xA8 + Size: 0x58 + Link: 0 + Info: 0 + AddressAlign: 0x8 + EntrySize: 0x0 +} +SectionHeader { + Index: 8 + Name: ".rela.eh_frame" (0x58) + Type: SHT_RELA (0x4) + Flags: 0x40 + SHF_INFO_LINK (0x40) + Address: 0x0 + Offset: 0x190 + Size: 0x30 + Link: 9 + Info: 7 + AddressAlign: 0x8 + EntrySize: 0x18 + Relocation { + Offset: 0x20 + Type: R_X86_64_PC32 (0x2) + Symbol: "" (0x2) + } + Relocation { + Offset: 0x40 + Type: R_X86_64_PC32 (0x2) + Symbol: "" (0x2) + Addend: 0xB + } +} +SectionHeader { + Index: 9 + Name: ".symtab" (0x1) + Type: SHT_SYMTAB (0x2) + Flags: 0x0 + Address: 0x0 + Offset: 0x100 + Size: 0x78 + Link: 10 + Info: 3 + AddressAlign: 0x8 + EntrySize: 0x18 + Symbol { + Index: 0 + Name: 0x0 + Value: 0x0 + Size: 0x0 + Type: STT_NOTYPE (0x0) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: SHN_UNDEF (0x0) + } + Symbol { + Index: 1 + Name: "" (0x1) + Value: 0x0 + Size: 0x0 + Type: STT_FILE (0x4) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: SHN_ABS (0xFFF1) + } + Symbol { + Index: 2 + Name: "" (0x0) + Value: 0x0 + Size: 0x0 + Type: STT_SECTION (0x3) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } + Symbol { + Index: 3 + Name: "two_a" (0x9) + Value: 0x0 + Size: 0xB + Type: STT_FUNC (0x2) + Bind: STB_GLOBAL (0x1) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } + Symbol { + Index: 4 + Name: "two_b" (0xF) + Value: 0xB + Size: 0xB + Type: STT_FUNC (0x2) + Bind: STB_GLOBAL (0x1) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } +} +SectionHeader { + Index: 10 + Name: ".strtab" (0x9) + Type: SHT_STRTAB (0x3) + Flags: 0x0 + Address: 0x0 + Offset: 0x178 + Size: 0x15 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 11 + Name: ".shstrtab" (0x11) + Type: SHT_STRTAB (0x3) + Flags: 0x0 + Address: 0x0 + Offset: 0x1C0 + Size: 0x67 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} + +Member: "three.o" +Format: ELF 64-bit +FileHeader { + Ident { + Magic: [7F, 45, 4C, 46] + Class: ELFCLASS64 (0x2) + Data: ELFDATA2LSB (0x1) + Version: EV_CURRENT (0x1) + OsAbi: ELFOSABI_SYSV (0x0) + AbiVersion: 0x0 + Unused: [0, 0, 0, 0, 0, 0, 0] + } + Type: ET_REL (0x1) + Machine: EM_X86_64 (0x3E) + Version: EV_CURRENT (0x1) + Type: ET_REL (0x1) + Entry: 0x0 + ProgramHeaderOffset: 0x0 + SectionHeaderOffset: 0x230 + Flags: 0x0 + HeaderSize: 0x40 + ProgramHeaderEntrySize: 0x0 + ProgramHeaderCount: 0 + SectionHeaderEntrySize: 0x40 + SectionHeaderCount: 12 + SectionHeaderStringTableIndex: 11 +} +SectionHeader { + Index: 0 + Name: "" (0x0) + Type: SHT_NULL (0x0) + Flags: 0x0 + Address: 0x0 + Offset: 0x0 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x0 + EntrySize: 0x0 +} +SectionHeader { + Index: 1 + Name: ".text" (0x1B) + Type: SHT_PROGBITS (0x1) + Flags: 0x6 + SHF_ALLOC (0x2) + SHF_EXECINSTR (0x4) + Address: 0x0 + Offset: 0x40 + Size: 0x16 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 2 + Name: ".data" (0x21) + Type: SHT_PROGBITS (0x1) + Flags: 0x3 + SHF_WRITE (0x1) + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x56 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 3 + Name: ".bss" (0x27) + Type: SHT_NOBITS (0x8) + Flags: 0x3 + SHF_WRITE (0x1) + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x56 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 4 + Name: ".comment" (0x2C) + Type: SHT_PROGBITS (0x1) + Flags: 0x30 + SHF_MERGE (0x10) + SHF_STRINGS (0x20) + Address: 0x0 + Offset: 0x56 + Size: 0x2C + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x1 +} +SectionHeader { + Index: 5 + Name: ".note.GNU-stack" (0x35) + Type: SHT_PROGBITS (0x1) + Flags: 0x0 + Address: 0x0 + Offset: 0x82 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 6 + Name: ".note.gnu.property" (0x45) + Type: SHT_NOTE (0x7) + Flags: 0x2 + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x88 + Size: 0x20 + Link: 0 + Info: 0 + AddressAlign: 0x8 + EntrySize: 0x0 + Note { + Name: "GNU" (0x4) + Type: NT_GNU_PROPERTY_TYPE_0 (0x5) + Property { + Type: GNU_PROPERTY_X86_FEATURE_1_AND (0xC0000002) + Value: 0x3 + GNU_PROPERTY_X86_FEATURE_1_IBT (0x1) + GNU_PROPERTY_X86_FEATURE_1_SHSTK (0x2) + } + } +} +SectionHeader { + Index: 7 + Name: ".eh_frame" (0x5D) + Type: SHT_PROGBITS (0x1) + Flags: 0x2 + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0xA8 + Size: 0x58 + Link: 0 + Info: 0 + AddressAlign: 0x8 + EntrySize: 0x0 +} +SectionHeader { + Index: 8 + Name: ".rela.eh_frame" (0x58) + Type: SHT_RELA (0x4) + Flags: 0x40 + SHF_INFO_LINK (0x40) + Address: 0x0 + Offset: 0x198 + Size: 0x30 + Link: 9 + Info: 7 + AddressAlign: 0x8 + EntrySize: 0x18 + Relocation { + Offset: 0x20 + Type: R_X86_64_PC32 (0x2) + Symbol: "" (0x2) + } + Relocation { + Offset: 0x40 + Type: R_X86_64_PC32 (0x2) + Symbol: "" (0x2) + Addend: 0xB + } +} +SectionHeader { + Index: 9 + Name: ".symtab" (0x1) + Type: SHT_SYMTAB (0x2) + Flags: 0x0 + Address: 0x0 + Offset: 0x100 + Size: 0x78 + Link: 10 + Info: 3 + AddressAlign: 0x8 + EntrySize: 0x18 + Symbol { + Index: 0 + Name: 0x0 + Value: 0x0 + Size: 0x0 + Type: STT_NOTYPE (0x0) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: SHN_UNDEF (0x0) + } + Symbol { + Index: 1 + Name: "" (0x1) + Value: 0x0 + Size: 0x0 + Type: STT_FILE (0x4) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: SHN_ABS (0xFFF1) + } + Symbol { + Index: 2 + Name: "" (0x0) + Value: 0x0 + Size: 0x0 + Type: STT_SECTION (0x3) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } + Symbol { + Index: 3 + Name: "three_a" (0x9) + Value: 0x0 + Size: 0xB + Type: STT_FUNC (0x2) + Bind: STB_GLOBAL (0x1) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } + Symbol { + Index: 4 + Name: "three_b" (0x11) + Value: 0xB + Size: 0xB + Type: STT_FUNC (0x2) + Bind: STB_GLOBAL (0x1) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } +} +SectionHeader { + Index: 10 + Name: ".strtab" (0x9) + Type: SHT_STRTAB (0x3) + Flags: 0x0 + Address: 0x0 + Offset: 0x178 + Size: 0x19 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 11 + Name: ".shstrtab" (0x11) + Type: SHT_STRTAB (0x3) + Flags: 0x0 + Address: 0x0 + Offset: 0x1C8 + Size: 0x67 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} + +Member: "a.o" +Format: ELF 64-bit +FileHeader { + Ident { + Magic: [7F, 45, 4C, 46] + Class: ELFCLASS64 (0x2) + Data: ELFDATA2LSB (0x1) + Version: EV_CURRENT (0x1) + OsAbi: ELFOSABI_SYSV (0x0) + AbiVersion: 0x0 + Unused: [0, 0, 0, 0, 0, 0, 0] + } + Type: ET_REL (0x1) + Machine: EM_X86_64 (0x3E) + Version: EV_CURRENT (0x1) + Type: ET_REL (0x1) + Entry: 0x0 + ProgramHeaderOffset: 0x0 + SectionHeaderOffset: 0x228 + Flags: 0x0 + HeaderSize: 0x40 + ProgramHeaderEntrySize: 0x0 + ProgramHeaderCount: 0 + SectionHeaderEntrySize: 0x40 + SectionHeaderCount: 12 + SectionHeaderStringTableIndex: 11 +} +SectionHeader { + Index: 0 + Name: "" (0x0) + Type: SHT_NULL (0x0) + Flags: 0x0 + Address: 0x0 + Offset: 0x0 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x0 + EntrySize: 0x0 +} +SectionHeader { + Index: 1 + Name: ".text" (0x1B) + Type: SHT_PROGBITS (0x1) + Flags: 0x6 + SHF_ALLOC (0x2) + SHF_EXECINSTR (0x4) + Address: 0x0 + Offset: 0x40 + Size: 0x16 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 2 + Name: ".data" (0x21) + Type: SHT_PROGBITS (0x1) + Flags: 0x3 + SHF_WRITE (0x1) + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x56 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 3 + Name: ".bss" (0x27) + Type: SHT_NOBITS (0x8) + Flags: 0x3 + SHF_WRITE (0x1) + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x56 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 4 + Name: ".comment" (0x2C) + Type: SHT_PROGBITS (0x1) + Flags: 0x30 + SHF_MERGE (0x10) + SHF_STRINGS (0x20) + Address: 0x0 + Offset: 0x56 + Size: 0x2C + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x1 +} +SectionHeader { + Index: 5 + Name: ".note.GNU-stack" (0x35) + Type: SHT_PROGBITS (0x1) + Flags: 0x0 + Address: 0x0 + Offset: 0x82 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 6 + Name: ".note.gnu.property" (0x45) + Type: SHT_NOTE (0x7) + Flags: 0x2 + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x88 + Size: 0x20 + Link: 0 + Info: 0 + AddressAlign: 0x8 + EntrySize: 0x0 + Note { + Name: "GNU" (0x4) + Type: NT_GNU_PROPERTY_TYPE_0 (0x5) + Property { + Type: GNU_PROPERTY_X86_FEATURE_1_AND (0xC0000002) + Value: 0x3 + GNU_PROPERTY_X86_FEATURE_1_IBT (0x1) + GNU_PROPERTY_X86_FEATURE_1_SHSTK (0x2) + } + } +} +SectionHeader { + Index: 7 + Name: ".eh_frame" (0x5D) + Type: SHT_PROGBITS (0x1) + Flags: 0x2 + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0xA8 + Size: 0x58 + Link: 0 + Info: 0 + AddressAlign: 0x8 + EntrySize: 0x0 +} +SectionHeader { + Index: 8 + Name: ".rela.eh_frame" (0x58) + Type: SHT_RELA (0x4) + Flags: 0x40 + SHF_INFO_LINK (0x40) + Address: 0x0 + Offset: 0x190 + Size: 0x30 + Link: 9 + Info: 7 + AddressAlign: 0x8 + EntrySize: 0x18 + Relocation { + Offset: 0x20 + Type: R_X86_64_PC32 (0x2) + Symbol: "" (0x2) + } + Relocation { + Offset: 0x40 + Type: R_X86_64_PC32 (0x2) + Symbol: "" (0x2) + Addend: 0xB + } +} +SectionHeader { + Index: 9 + Name: ".symtab" (0x1) + Type: SHT_SYMTAB (0x2) + Flags: 0x0 + Address: 0x0 + Offset: 0x100 + Size: 0x78 + Link: 10 + Info: 3 + AddressAlign: 0x8 + EntrySize: 0x18 + Symbol { + Index: 0 + Name: 0x0 + Value: 0x0 + Size: 0x0 + Type: STT_NOTYPE (0x0) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: SHN_UNDEF (0x0) + } + Symbol { + Index: 1 + Name: "" (0x1) + Value: 0x0 + Size: 0x0 + Type: STT_FILE (0x4) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: SHN_ABS (0xFFF1) + } + Symbol { + Index: 2 + Name: "" (0x0) + Value: 0x0 + Size: 0x0 + Type: STT_SECTION (0x3) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } + Symbol { + Index: 3 + Name: "a_one" (0x9) + Value: 0x0 + Size: 0xB + Type: STT_FUNC (0x2) + Bind: STB_GLOBAL (0x1) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } + Symbol { + Index: 4 + Name: "a_two" (0xF) + Value: 0xB + Size: 0xB + Type: STT_FUNC (0x2) + Bind: STB_GLOBAL (0x1) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } +} +SectionHeader { + Index: 10 + Name: ".strtab" (0x9) + Type: SHT_STRTAB (0x3) + Flags: 0x0 + Address: 0x0 + Offset: 0x178 + Size: 0x15 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 11 + Name: ".shstrtab" (0x11) + Type: SHT_STRTAB (0x3) + Flags: 0x0 + Address: 0x0 + Offset: 0x1C0 + Size: 0x67 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} + +Member: "b.o" +Format: ELF 64-bit +FileHeader { + Ident { + Magic: [7F, 45, 4C, 46] + Class: ELFCLASS64 (0x2) + Data: ELFDATA2LSB (0x1) + Version: EV_CURRENT (0x1) + OsAbi: ELFOSABI_SYSV (0x0) + AbiVersion: 0x0 + Unused: [0, 0, 0, 0, 0, 0, 0] + } + Type: ET_REL (0x1) + Machine: EM_X86_64 (0x3E) + Version: EV_CURRENT (0x1) + Type: ET_REL (0x1) + Entry: 0x0 + ProgramHeaderOffset: 0x0 + SectionHeaderOffset: 0x228 + Flags: 0x0 + HeaderSize: 0x40 + ProgramHeaderEntrySize: 0x0 + ProgramHeaderCount: 0 + SectionHeaderEntrySize: 0x40 + SectionHeaderCount: 12 + SectionHeaderStringTableIndex: 11 +} +SectionHeader { + Index: 0 + Name: "" (0x0) + Type: SHT_NULL (0x0) + Flags: 0x0 + Address: 0x0 + Offset: 0x0 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x0 + EntrySize: 0x0 +} +SectionHeader { + Index: 1 + Name: ".text" (0x1B) + Type: SHT_PROGBITS (0x1) + Flags: 0x6 + SHF_ALLOC (0x2) + SHF_EXECINSTR (0x4) + Address: 0x0 + Offset: 0x40 + Size: 0x16 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 2 + Name: ".data" (0x21) + Type: SHT_PROGBITS (0x1) + Flags: 0x3 + SHF_WRITE (0x1) + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x56 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 3 + Name: ".bss" (0x27) + Type: SHT_NOBITS (0x8) + Flags: 0x3 + SHF_WRITE (0x1) + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x56 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 4 + Name: ".comment" (0x2C) + Type: SHT_PROGBITS (0x1) + Flags: 0x30 + SHF_MERGE (0x10) + SHF_STRINGS (0x20) + Address: 0x0 + Offset: 0x56 + Size: 0x2C + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x1 +} +SectionHeader { + Index: 5 + Name: ".note.GNU-stack" (0x35) + Type: SHT_PROGBITS (0x1) + Flags: 0x0 + Address: 0x0 + Offset: 0x82 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 6 + Name: ".note.gnu.property" (0x45) + Type: SHT_NOTE (0x7) + Flags: 0x2 + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x88 + Size: 0x20 + Link: 0 + Info: 0 + AddressAlign: 0x8 + EntrySize: 0x0 + Note { + Name: "GNU" (0x4) + Type: NT_GNU_PROPERTY_TYPE_0 (0x5) + Property { + Type: GNU_PROPERTY_X86_FEATURE_1_AND (0xC0000002) + Value: 0x3 + GNU_PROPERTY_X86_FEATURE_1_IBT (0x1) + GNU_PROPERTY_X86_FEATURE_1_SHSTK (0x2) + } + } +} +SectionHeader { + Index: 7 + Name: ".eh_frame" (0x5D) + Type: SHT_PROGBITS (0x1) + Flags: 0x2 + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0xA8 + Size: 0x58 + Link: 0 + Info: 0 + AddressAlign: 0x8 + EntrySize: 0x0 +} +SectionHeader { + Index: 8 + Name: ".rela.eh_frame" (0x58) + Type: SHT_RELA (0x4) + Flags: 0x40 + SHF_INFO_LINK (0x40) + Address: 0x0 + Offset: 0x190 + Size: 0x30 + Link: 9 + Info: 7 + AddressAlign: 0x8 + EntrySize: 0x18 + Relocation { + Offset: 0x20 + Type: R_X86_64_PC32 (0x2) + Symbol: "" (0x2) + } + Relocation { + Offset: 0x40 + Type: R_X86_64_PC32 (0x2) + Symbol: "" (0x2) + Addend: 0xB + } +} +SectionHeader { + Index: 9 + Name: ".symtab" (0x1) + Type: SHT_SYMTAB (0x2) + Flags: 0x0 + Address: 0x0 + Offset: 0x100 + Size: 0x78 + Link: 10 + Info: 3 + AddressAlign: 0x8 + EntrySize: 0x18 + Symbol { + Index: 0 + Name: 0x0 + Value: 0x0 + Size: 0x0 + Type: STT_NOTYPE (0x0) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: SHN_UNDEF (0x0) + } + Symbol { + Index: 1 + Name: "" (0x1) + Value: 0x0 + Size: 0x0 + Type: STT_FILE (0x4) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: SHN_ABS (0xFFF1) + } + Symbol { + Index: 2 + Name: "" (0x0) + Value: 0x0 + Size: 0x0 + Type: STT_SECTION (0x3) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } + Symbol { + Index: 3 + Name: "b_one" (0x9) + Value: 0x0 + Size: 0xB + Type: STT_FUNC (0x2) + Bind: STB_GLOBAL (0x1) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } + Symbol { + Index: 4 + Name: "b_two" (0xF) + Value: 0xB + Size: 0xB + Type: STT_FUNC (0x2) + Bind: STB_GLOBAL (0x1) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } +} +SectionHeader { + Index: 10 + Name: ".strtab" (0x9) + Type: SHT_STRTAB (0x3) + Flags: 0x0 + Address: 0x0 + Offset: 0x178 + Size: 0x15 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 11 + Name: ".shstrtab" (0x11) + Type: SHT_STRTAB (0x3) + Flags: 0x0 + Address: 0x0 + Offset: 0x1C0 + Size: 0x67 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} + +Member: "c.o" +Format: ELF 64-bit +FileHeader { + Ident { + Magic: [7F, 45, 4C, 46] + Class: ELFCLASS64 (0x2) + Data: ELFDATA2LSB (0x1) + Version: EV_CURRENT (0x1) + OsAbi: ELFOSABI_SYSV (0x0) + AbiVersion: 0x0 + Unused: [0, 0, 0, 0, 0, 0, 0] + } + Type: ET_REL (0x1) + Machine: EM_X86_64 (0x3E) + Version: EV_CURRENT (0x1) + Type: ET_REL (0x1) + Entry: 0x0 + ProgramHeaderOffset: 0x0 + SectionHeaderOffset: 0x228 + Flags: 0x0 + HeaderSize: 0x40 + ProgramHeaderEntrySize: 0x0 + ProgramHeaderCount: 0 + SectionHeaderEntrySize: 0x40 + SectionHeaderCount: 12 + SectionHeaderStringTableIndex: 11 +} +SectionHeader { + Index: 0 + Name: "" (0x0) + Type: SHT_NULL (0x0) + Flags: 0x0 + Address: 0x0 + Offset: 0x0 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x0 + EntrySize: 0x0 +} +SectionHeader { + Index: 1 + Name: ".text" (0x1B) + Type: SHT_PROGBITS (0x1) + Flags: 0x6 + SHF_ALLOC (0x2) + SHF_EXECINSTR (0x4) + Address: 0x0 + Offset: 0x40 + Size: 0x16 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 2 + Name: ".data" (0x21) + Type: SHT_PROGBITS (0x1) + Flags: 0x3 + SHF_WRITE (0x1) + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x56 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 3 + Name: ".bss" (0x27) + Type: SHT_NOBITS (0x8) + Flags: 0x3 + SHF_WRITE (0x1) + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x56 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 4 + Name: ".comment" (0x2C) + Type: SHT_PROGBITS (0x1) + Flags: 0x30 + SHF_MERGE (0x10) + SHF_STRINGS (0x20) + Address: 0x0 + Offset: 0x56 + Size: 0x2C + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x1 +} +SectionHeader { + Index: 5 + Name: ".note.GNU-stack" (0x35) + Type: SHT_PROGBITS (0x1) + Flags: 0x0 + Address: 0x0 + Offset: 0x82 + Size: 0x0 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 6 + Name: ".note.gnu.property" (0x45) + Type: SHT_NOTE (0x7) + Flags: 0x2 + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0x88 + Size: 0x20 + Link: 0 + Info: 0 + AddressAlign: 0x8 + EntrySize: 0x0 + Note { + Name: "GNU" (0x4) + Type: NT_GNU_PROPERTY_TYPE_0 (0x5) + Property { + Type: GNU_PROPERTY_X86_FEATURE_1_AND (0xC0000002) + Value: 0x3 + GNU_PROPERTY_X86_FEATURE_1_IBT (0x1) + GNU_PROPERTY_X86_FEATURE_1_SHSTK (0x2) + } + } +} +SectionHeader { + Index: 7 + Name: ".eh_frame" (0x5D) + Type: SHT_PROGBITS (0x1) + Flags: 0x2 + SHF_ALLOC (0x2) + Address: 0x0 + Offset: 0xA8 + Size: 0x58 + Link: 0 + Info: 0 + AddressAlign: 0x8 + EntrySize: 0x0 +} +SectionHeader { + Index: 8 + Name: ".rela.eh_frame" (0x58) + Type: SHT_RELA (0x4) + Flags: 0x40 + SHF_INFO_LINK (0x40) + Address: 0x0 + Offset: 0x190 + Size: 0x30 + Link: 9 + Info: 7 + AddressAlign: 0x8 + EntrySize: 0x18 + Relocation { + Offset: 0x20 + Type: R_X86_64_PC32 (0x2) + Symbol: "" (0x2) + } + Relocation { + Offset: 0x40 + Type: R_X86_64_PC32 (0x2) + Symbol: "" (0x2) + Addend: 0xB + } +} +SectionHeader { + Index: 9 + Name: ".symtab" (0x1) + Type: SHT_SYMTAB (0x2) + Flags: 0x0 + Address: 0x0 + Offset: 0x100 + Size: 0x78 + Link: 10 + Info: 3 + AddressAlign: 0x8 + EntrySize: 0x18 + Symbol { + Index: 0 + Name: 0x0 + Value: 0x0 + Size: 0x0 + Type: STT_NOTYPE (0x0) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: SHN_UNDEF (0x0) + } + Symbol { + Index: 1 + Name: "" (0x1) + Value: 0x0 + Size: 0x0 + Type: STT_FILE (0x4) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: SHN_ABS (0xFFF1) + } + Symbol { + Index: 2 + Name: "" (0x0) + Value: 0x0 + Size: 0x0 + Type: STT_SECTION (0x3) + Bind: STB_LOCAL (0x0) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } + Symbol { + Index: 3 + Name: "c_one" (0x9) + Value: 0x0 + Size: 0xB + Type: STT_FUNC (0x2) + Bind: STB_GLOBAL (0x1) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } + Symbol { + Index: 4 + Name: "c_two" (0xF) + Value: 0xB + Size: 0xB + Type: STT_FUNC (0x2) + Bind: STB_GLOBAL (0x1) + Other: STV_DEFAULT (0x0) + SectionIndex: 1 + } +} +SectionHeader { + Index: 10 + Name: ".strtab" (0x9) + Type: SHT_STRTAB (0x3) + Flags: 0x0 + Address: 0x0 + Offset: 0x178 + Size: 0x15 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} +SectionHeader { + Index: 11 + Name: ".shstrtab" (0x11) + Type: SHT_STRTAB (0x3) + Flags: 0x0 + Address: 0x0 + Offset: 0x1C0 + Size: 0x67 + Link: 0 + Info: 0 + AddressAlign: 0x1 + EntrySize: 0x0 +} + +Symbol { + Name: "one_a" + Member: "one.o" +} +Symbol { + Name: "one_b" + Member: "one.o" +} +Symbol { + Name: "two_a" + Member: "two.o" +} +Symbol { + Name: "two_b" + Member: "two.o" +} +Symbol { + Name: "three_a" + Member: "three.o" +} +Symbol { + Name: "three_b" + Member: "three.o" +} +Symbol { + Name: "a_one" + Member: "a.o" +} +Symbol { + Name: "a_two" + Member: "a.o" +} +Symbol { + Name: "b_one" + Member: "b.o" +} +Symbol { + Name: "b_two" + Member: "b.o" +} +Symbol { + Name: "c_one" + Member: "c.o" +} +Symbol { + Name: "c_two" + Member: "c.o" +} diff --git a/crates/examples/testfiles/archive/thin.a.readobj b/crates/examples/testfiles/archive/thin.a.readobj new file mode 100644 index 00000000..d42a4bb9 --- /dev/null +++ b/crates/examples/testfiles/archive/thin.a.readobj @@ -0,0 +1,35 @@ +Format: Archive (Gnu) (thin) + +Member: "a.o" +Size: 1320 + +Member: "b.o" +Size: 1320 + +Member: "c.o" +Size: 1320 + +Symbol { + Name: "a_one" + Member: "a.o" +} +Symbol { + Name: "a_two" + Member: "a.o" +} +Symbol { + Name: "b_one" + Member: "b.o" +} +Symbol { + Name: "b_two" + Member: "b.o" +} +Symbol { + Name: "c_one" + Member: "c.o" +} +Symbol { + Name: "c_two" + Member: "c.o" +} diff --git a/crates/examples/testfiles/coff/import_msvc.lib.readobj b/crates/examples/testfiles/coff/import_msvc.lib.readobj index 81593ed8..e8a547e3 100644 --- a/crates/examples/testfiles/coff/import_msvc.lib.readobj +++ b/crates/examples/testfiles/coff/import_msvc.lib.readobj @@ -1,6 +1,6 @@ Format: Archive (Coff) -Member: test_x64.dll +Member: "test_x64.dll" Format: COFF import ImportObjectHeader { Signature1: 0x0 @@ -16,7 +16,7 @@ ImportObjectHeader { Dll: "test_x64.dll" } -Member: test_x64.dll +Member: "test_x64.dll" Format: COFF import ImportObjectHeader { Signature1: 0x0 @@ -32,7 +32,7 @@ ImportObjectHeader { Dll: "test_x64.dll" } -Member: test_x64.dll +Member: "test_x64.dll" Format: COFF import ImportObjectHeader { Signature1: 0x0 @@ -48,7 +48,7 @@ ImportObjectHeader { Dll: "test_x64.dll" } -Member: test_x64.dll +Member: "test_x64.dll" Format: COFF import ImportObjectHeader { Signature1: 0x0 @@ -64,7 +64,7 @@ ImportObjectHeader { Dll: "test_x64.dll" } -Member: test_x64.dll +Member: "test_x64.dll" Format: COFF ImageFileHeader { Machine: IMAGE_FILE_MACHINE_AMD64 (0x8664) @@ -149,7 +149,7 @@ ImageSymbol { NumberOfAuxSymbols: 0x0 } -Member: test_x64.dll +Member: "test_x64.dll" Format: COFF ImageFileHeader { Machine: IMAGE_FILE_MACHINE_AMD64 (0x8664) @@ -217,7 +217,7 @@ ImageSymbol { NumberOfAuxSymbols: 0x0 } -Member: test_x64.dll +Member: "test_x64.dll" Format: COFF ImageFileHeader { Machine: IMAGE_FILE_MACHINE_AMD64 (0x8664) @@ -383,7 +383,7 @@ ImageSymbol { NumberOfAuxSymbols: 0x0 } -Member: test_x86.dll +Member: "test_x86.dll" Format: COFF import ImportObjectHeader { Signature1: 0x0 @@ -399,7 +399,7 @@ ImportObjectHeader { Dll: "test_x86.dll" } -Member: test_x86.dll +Member: "test_x86.dll" Format: COFF ImageFileHeader { Machine: IMAGE_FILE_MACHINE_I386 (0x14C) @@ -485,7 +485,7 @@ ImageSymbol { NumberOfAuxSymbols: 0x0 } -Member: test_x86.dll +Member: "test_x86.dll" Format: COFF ImageFileHeader { Machine: IMAGE_FILE_MACHINE_I386 (0x14C) @@ -554,7 +554,7 @@ ImageSymbol { NumberOfAuxSymbols: 0x0 } -Member: test_x86.dll +Member: "test_x86.dll" Format: COFF ImageFileHeader { Machine: IMAGE_FILE_MACHINE_I386 (0x14C) @@ -721,7 +721,7 @@ ImageSymbol { NumberOfAuxSymbols: 0x0 } -Member: test_arm64ec.dll +Member: "test_arm64ec.dll" Format: COFF import ImportObjectHeader { Signature1: 0x0 @@ -738,7 +738,7 @@ ImportObjectHeader { Export: "foo_arm64ec" } -Member: test_arm64ec.dll +Member: "test_arm64ec.dll" Format: COFF ImageFileHeader { Machine: IMAGE_FILE_MACHINE_ARM64 (0xAA64) @@ -823,7 +823,7 @@ ImageSymbol { NumberOfAuxSymbols: 0x0 } -Member: test_arm64ec.dll +Member: "test_arm64ec.dll" Format: COFF ImageFileHeader { Machine: IMAGE_FILE_MACHINE_ARM64 (0xAA64) @@ -891,7 +891,7 @@ ImageSymbol { NumberOfAuxSymbols: 0x0 } -Member: test_arm64ec.dll +Member: "test_arm64ec.dll" Format: COFF ImageFileHeader { Machine: IMAGE_FILE_MACHINE_ARM64 (0xAA64) @@ -1056,3 +1056,76 @@ ImageSymbol { StorageClass: IMAGE_SYM_CLASS_EXTERNAL (0x2) NumberOfAuxSymbols: 0x0 } + +Symbol { + Name: "BAR_x64" + Member: "test_x64.dll" +} +Symbol { + Name: "__IMPORT_DESCRIPTOR_test_arm64ec" + Member: "test_arm64ec.dll" +} +Symbol { + Name: "__IMPORT_DESCRIPTOR_test_x64" + Member: "test_x64.dll" +} +Symbol { + Name: "__IMPORT_DESCRIPTOR_test_x86" + Member: "test_x86.dll" +} +Symbol { + Name: "__NULL_IMPORT_DESCRIPTOR" + Member: "test_x64.dll" +} +Symbol { + Name: "__imp_BAR_x64" + Member: "test_x64.dll" +} +Symbol { + Name: "__imp_FOO_x64" + Member: "test_x64.dll" +} +Symbol { + Name: "__imp__foo_x86" + Member: "test_x86.dll" +} +Symbol { + Name: "__imp_bar_x64" + Member: "test_x64.dll" +} +Symbol { + Name: "__imp_foo_arm64ec" + Member: "test_arm64ec.dll" +} +Symbol { + Name: "__imp_foo_x64" + Member: "test_x64.dll" +} +Symbol { + Name: "_foo_x86" + Member: "test_x86.dll" +} +Symbol { + Name: "bar_x64" + Member: "test_x64.dll" +} +Symbol { + Name: "foo_arm64ec" + Member: "test_arm64ec.dll" +} +Symbol { + Name: "foo_x64" + Member: "test_x64.dll" +} +Symbol { + Name: "test_arm64ec_NULL_THUNK_DATA" + Member: "test_arm64ec.dll" +} +Symbol { + Name: "test_x64_NULL_THUNK_DATA" + Member: "test_x64.dll" +} +Symbol { + Name: "test_x86_NULL_THUNK_DATA" + Member: "test_x86.dll" +} diff --git a/src/pod.rs b/src/pod.rs index 25ba1ecd..8a25b98e 100644 --- a/src/pod.rs +++ b/src/pod.rs @@ -156,6 +156,8 @@ macro_rules! unsafe_impl_pod { unsafe_impl_pod!(u8, u16, u32, u64); +unsafe impl Pod for [T; N] {} + #[cfg(test)] mod tests { use super::*; diff --git a/src/read/archive.rs b/src/read/archive.rs index 81f2d04e..45d56095 100644 --- a/src/read/archive.rs +++ b/src/read/archive.rs @@ -21,8 +21,10 @@ //! ``` use core::convert::TryInto; +use core::slice; use crate::archive; +use crate::endian::{BigEndian as BE, LittleEndian as LE, U16Bytes, U32Bytes, U64Bytes}; use crate::read::{self, Bytes, Error, ReadError, ReadRef}; /// The kind of archive format. @@ -207,6 +209,7 @@ impl<'data, R: ReadRef<'data>> ArchiveFile<'data, R> { }; // Read the span of symbol table. + // TODO: an archive may have both 32-bit and 64-bit symbol tables. let symtbl64 = parse_u64_digits(&file_header.gst64off, 10) .read_error("Invalid offset to 64-bit symbol table in AIX big archive")?; if symtbl64 > 0 { @@ -278,6 +281,34 @@ impl<'data, R: ReadRef<'data>> ArchiveFile<'data, R> { thin: self.thin, } } + + /// Return the member at the given offset. + pub fn member(&self, member: ArchiveOffset) -> read::Result> { + match self.members { + Members::Common { offset, end_offset } => { + if member.0 < offset || member.0 >= end_offset { + return Err(Error("Invalid archive member offset")); + } + let mut offset = member.0; + ArchiveMember::parse(self.data, &mut offset, self.names, self.thin) + } + Members::AixBig { .. } => { + let offset = member.0; + ArchiveMember::parse_aixbig(self.data, offset) + } + } + } + + /// Iterate over the symbols in the archive. + pub fn symbols(&self) -> read::Result>> { + if self.symbols == (0, 0) { + return Ok(None); + } + let (offset, size) = self.symbols; + ArchiveSymbolIterator::new(self.kind, self.data, offset, size) + .read_error("Invalid archive symbol table") + .map(Some) + } } /// An iterator over the members of an archive. @@ -552,6 +583,240 @@ impl<'data> ArchiveMember<'data> { } } +/// An offset of a member in an archive. +#[derive(Debug, Clone, Copy)] +pub struct ArchiveOffset(pub u64); + +/// An iterator over the symbols in the archive symbol table. +#[derive(Debug, Clone)] +pub struct ArchiveSymbolIterator<'data>(SymbolIteratorInternal<'data>); + +#[derive(Debug, Clone)] +enum SymbolIteratorInternal<'data> { + /// There is no symbol table. + None, + /// A GNU symbol table. + /// + /// Contains: + /// - the number of symbols as a 32-bit big-endian integer + /// - the offsets of the member headers as 32-bit big-endian integers + /// - the symbol names as null-terminated strings + Gnu { + offsets: slice::Iter<'data, U32Bytes>, + names: Bytes<'data>, + }, + /// A GNU 64-bit symbol table + /// + /// Contains: + /// - the number of symbols as a 64-bit big-endian integer + /// - the offsets of the member headers as 64-bit big-endian integers + /// - the symbol names as null-terminated strings + Gnu64 { + offsets: slice::Iter<'data, U64Bytes>, + names: Bytes<'data>, + }, + /// A BSD symbol table. + /// + /// Contains: + /// - the size in bytes of the offsets array as a 32-bit little-endian integer + /// - the offsets array, for which each entry is a pair of 32-bit little-endian integers + /// for the offset of the member header and the offset of the symbol name + /// - the size in bytes of the symbol names as a 32-bit little-endian integer + /// - the symbol names as null-terminated strings + Bsd { + offsets: slice::Iter<'data, [U32Bytes; 2]>, + names: Bytes<'data>, + }, + /// A BSD 64-bit symbol table. + /// + /// Contains: + /// - the size in bytes of the offsets array as a 64-bit little-endian integer + /// - the offsets array, for which each entry is a pair of 64-bit little-endian integers + /// for the offset of the member header and the offset of the symbol name + /// - the size in bytes of the symbol names as a 64-bit little-endian integer + /// - the symbol names as null-terminated strings + Bsd64 { + offsets: slice::Iter<'data, [U64Bytes; 2]>, + names: Bytes<'data>, + }, + /// A Windows COFF symbol table. + /// + /// Contains: + /// - the number of members as a 32-bit little-endian integer + /// - the offsets of the member headers as 32-bit little-endian integers + /// - the number of symbols as a 32-bit little-endian integer + /// - the member index for each symbol as a 16-bit little-endian integer + /// - the symbol names as null-terminated strings in lexical order + Coff { + members: &'data [U32Bytes], + indices: slice::Iter<'data, U16Bytes>, + names: Bytes<'data>, + }, +} + +impl<'data> ArchiveSymbolIterator<'data> { + fn new>( + kind: ArchiveKind, + data: R, + offset: u64, + size: u64, + ) -> Result { + let mut data = data.read_bytes_at(offset, size).map(Bytes)?; + match kind { + ArchiveKind::Unknown => Ok(ArchiveSymbolIterator(SymbolIteratorInternal::None)), + ArchiveKind::Gnu => { + let offsets_count = data.read::>()?.get(BE); + let offsets = data.read_slice::>(offsets_count as usize)?; + Ok(ArchiveSymbolIterator(SymbolIteratorInternal::Gnu { + offsets: offsets.iter(), + names: data, + })) + } + ArchiveKind::Gnu64 => { + let offsets_count = data.read::>()?.get(BE); + let offsets = data.read_slice::>(offsets_count as usize)?; + Ok(ArchiveSymbolIterator(SymbolIteratorInternal::Gnu64 { + offsets: offsets.iter(), + names: data, + })) + } + ArchiveKind::Bsd => { + let offsets_size = data.read::>()?.get(LE); + let offsets = data.read_slice::<[U32Bytes; 2]>(offsets_size as usize / 8)?; + let names_size = data.read::>()?.get(LE); + let names = data.read_bytes(names_size as usize)?; + Ok(ArchiveSymbolIterator(SymbolIteratorInternal::Bsd { + offsets: offsets.iter(), + names, + })) + } + ArchiveKind::Bsd64 => { + let offsets_size = data.read::>()?.get(LE); + let offsets = data.read_slice::<[U64Bytes; 2]>(offsets_size as usize / 16)?; + let names_size = data.read::>()?.get(LE); + let names = data.read_bytes(names_size as usize)?; + Ok(ArchiveSymbolIterator(SymbolIteratorInternal::Bsd64 { + offsets: offsets.iter(), + names, + })) + } + ArchiveKind::Coff => { + let members_count = data.read::>()?.get(LE); + let members = data.read_slice::>(members_count as usize)?; + let indices_count = data.read::>()?.get(LE); + let indices = data.read_slice::>(indices_count as usize)?; + Ok(ArchiveSymbolIterator(SymbolIteratorInternal::Coff { + members, + indices: indices.iter(), + names: data, + })) + } + // TODO: Implement AIX big archive symbol table. + ArchiveKind::AixBig => Ok(ArchiveSymbolIterator(SymbolIteratorInternal::None)), + } + } +} + +impl<'data> Iterator for ArchiveSymbolIterator<'data> { + type Item = read::Result>; + + fn next(&mut self) -> Option { + match &mut self.0 { + SymbolIteratorInternal::None => None, + SymbolIteratorInternal::Gnu { offsets, names } => { + let offset = offsets.next()?.get(BE); + Some( + names + .read_string() + .read_error("Missing archive symbol name") + .map(|name| ArchiveSymbol { + name, + offset: ArchiveOffset(offset.into()), + }), + ) + } + SymbolIteratorInternal::Gnu64 { offsets, names } => { + let offset = offsets.next()?.get(BE); + Some( + names + .read_string() + .read_error("Missing archive symbol name") + .map(|name| ArchiveSymbol { + name, + offset: ArchiveOffset(offset), + }), + ) + } + SymbolIteratorInternal::Bsd { offsets, names } => { + let entry = offsets.next()?; + Some( + names + .read_string_at(entry[0].get(LE) as usize) + .read_error("Invalid archive symbol name offset") + .map(|name| ArchiveSymbol { + name, + offset: ArchiveOffset(entry[1].get(LE).into()), + }), + ) + } + SymbolIteratorInternal::Bsd64 { offsets, names } => { + let entry = offsets.next()?; + Some( + names + .read_string_at(entry[0].get(LE) as usize) + .read_error("Invalid archive symbol name offset") + .map(|name| ArchiveSymbol { + name, + offset: ArchiveOffset(entry[1].get(LE)), + }), + ) + } + SymbolIteratorInternal::Coff { + members, + indices, + names, + } => { + let index = indices.next()?.get(LE).wrapping_sub(1); + let member = members + .get(index as usize) + .read_error("Invalid archive symbol member index"); + let name = names + .read_string() + .read_error("Missing archive symbol name"); + Some(member.and_then(|member| { + name.map(|name| ArchiveSymbol { + name, + offset: ArchiveOffset(member.get(LE).into()), + }) + })) + } + } + } +} + +/// A symbol in the archive symbol table. +/// +/// This is used to find the member containing the symbol. +#[derive(Debug, Clone, Copy)] +pub struct ArchiveSymbol<'data> { + name: &'data [u8], + offset: ArchiveOffset, +} + +impl<'data> ArchiveSymbol<'data> { + /// Return the symbol name. + #[inline] + pub fn name(&self) -> &'data [u8] { + self.name + } + + /// Return the offset of the header for the member containing the symbol. + #[inline] + pub fn offset(&self) -> ArchiveOffset { + self.offset + } +} + // Ignores bytes starting from the first space. fn parse_u64_digits(digits: &[u8], radix: u32) -> Option { if let [b' ', ..] = digits { diff --git a/testfiles b/testfiles index 0949c201..14d80667 160000 --- a/testfiles +++ b/testfiles @@ -1 +1 @@ -Subproject commit 0949c201333ac4aa74c78163bd6754cb733a91c9 +Subproject commit 14d806678c02be9b6571d9af402eea0da1bde802