8000 [pull] master from gimli-rs:master by pull[bot] · Pull Request #101 · exoosh/gimli-object · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[pull] master from gimli-rs:master #101

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

Merged
merged 1 commit into from
Jul 2, 2025
Merged
Show file tree
Hide file tree
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
11 changes: 3 additions & 8 deletions crates/examples/src/readobj/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ fn print_section_rela<Elf: FileHeader>(
);
let sym = relocation.symbol(endian, elf.is_mips64el(endian));
print_rel_symbol(p, endian, symbols, sym);
let addend = relocation.r_addend(endian).into() as u64;
let addend = relocation.r_addend(endian).into();
if addend != 0 {
p.field_hex("Addend", addend);
}
Expand Down Expand Up @@ -604,13 +604,8 @@ fn print_section_crel<Elf: FileHeader>(

p.group("Relocation", |p| {
p.field_hex("Offset", relocation.r_offset);
p.field_enum("Type", relocation.r_type as u32, proc);
print_rel_symbol(
p,
endian,
symbols,
Some(SymbolIndex(relocation.r_sym as usize)),
);
p.field_enum("Type", relocation.r_type, proc);
print_rel_symbol(p, endian, symbols, relocation.symbol());
let addend = relocation.r_addend;
if addend != 0 {
p.field_hex("Addend", addend);
Expand Down
37 changes: 37 additions & 0 deletions crates/examples/testfiles/elf/base-crel.o.objdump
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Format: Elf Little-endian 64-bit
Kind: Relocatable
Architecture: X86_64
Flags: Elf { os_abi: 0, abi_version: 0, e_flags: 0 }
Relative Address Base: 0
Entry Address: 0
1: Section { name: ".strtab", address: 0, size: 7b, align: 1, kind: Metadata, flags: Elf { sh_flags: 0 } }
2: Section { name: ".text", address: 0, size: 25, align: 10, kind: Text, flags: Elf { sh_flags: 6 } }
3: Section { name: ".crel.text", address: 0, size: 9, align: 1, kind: Metadata, flags: Elf { sh_flags: 40 } }
4: Section { name: ".rodata.str1.1", address: 0, size: d, align: 1, kind: ReadOnlyString, flags: Elf { sh_flags: 32 } }
5: Section { name: ".comment", address: 0, size: 57, align: 1, kind: OtherString, flags: Elf { sh_flags: 30 } }
6: Section { name: ".note.GNU-stack", address: 0, size: 0, align: 1, kind: Other, flags: Elf { sh_flags: 0 } }
7: Section { name: ".eh_frame", address: 0, size: 38, align: 8, kind: Elf(70000001), flags: Elf { sh_flags: 2 } }
8: Section { name: ".crel.eh_frame", address: 0, size: 4, align: 1, kind: Metadata, flags: Elf { sh_flags: 40 } }
9: Section { name: ".llvm_addrsig", address: 0, size: 1, align: 1, kind: Elf(6fff4c03), flags: Elf { sh_flags: 80000000 } }
10: Section { name: ".symtab", address: 0, size: 90, align: 8, kind: Metadata, flags: Elf { sh_flags: 0 } }

Symbols
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(2)), scope: Compilation, weak: false, flags: Elf { st_info: 3, st_other: 0 } }
3: Symbol { name: ".L.str", address: 0, size: d, kind: Data, section: Section(SectionIndex(4)), scope: Compilation, weak: false, flags: Elf { st_info: 1, st_other: 0 } }
4: Symbol { name: "main", address: 0, size: 25, kind: Text, section: Section(SectionIndex(2)), scope: Dynamic, weak: false, flags: Elf { st_info: 12, st_other: 0 } }
5: Symbol { name: "printf", address: 0, size: 0, kind: Unknown, section: Undefined, scope: Unknown, weak: false, flags: Elf { st_info: 10, st_other: 0 } }

.text relocations
(12, Relocation { kind: Relative, encoding: Generic, size: 20, target: Symbol(SymbolIndex(3)), addend: fffffffffffffffc, implicit_addend: false, flags: Elf { r_type: 2 } })
(19, Relocation { kind: PltRelative, encoding: Generic, size: 20, target: Symbol(SymbolIndex(5)), addend: fffffffffffffffc, implicit_addend: false, flags: Elf { r_type: 4 } })

.eh_frame relocations
(20, Relocation { kind: Relative, encoding: Generic, size: 20, target: Symbol(SymbolIndex(2)), addend: 0, implicit_addend: false, flags: Elf { r_type: 2 } })

Dynamic symbols

Dynamic relocations

Symbol map
0x0 "main"
256 changes: 256 additions & 0 deletions crates/examples/testfiles/elf/base-crel.o.readobj
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
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)
Entry: 0x0
ProgramHeaderOffset: 0x0
SectionHeaderOffset: 0x228
Flags: 0x0
HeaderSize: 0x40
ProgramHeaderEntrySize: 0x0
ProgramHeaderCount: 0
SectionHeaderEntrySize: 0x40
SectionHeaderCount: 11
SectionHeaderStringTableIndex: 1
}
SectionHeader {
Index: 0
Name: "" (0x0)
Type: SHT_NULL (0x0)
< 10000 span class='blob-code-inner blob-code-marker ' data-code-marker="+"> Flags: 0x0
Address: 0x0
Offset: 0x0
Size: 0x0
Link: 0
Info: 0
AddressAlign: 0x0
EntrySize: 0x0
}
SectionHeader {
Index: 1
Name: ".strtab" (0x5C)
Type: SHT_STRTAB (0x3)
Flags: 0x0
Address: 0x0
Offset: 0x1A6
Size: 0x7B
Link: 0
Info: 0
AddressAlign: 0x1
EntrySize: 0x0
}
SectionHeader {
Index: 2
Name: ".text" (0x6)
Type: SHT_PROGBITS (0x1)
Flags: 0x6
SHF_ALLOC (0x2)
SHF_EXECINSTR (0x4)
Address: 0x0
Offset: 0x40
Size: 0x25
Link: 0
Info: 0
AddressAlign: 0x10
EntrySize: 0x0
}
SectionHeader {
Index: 3
Name: ".crel.text" (0x1)
Type: 0x40000014
Flags: 0x40
SHF_INFO_LINK (0x40)
Address: 0x0
Offset: 0x198
Size: 0x9
Link: 10
Info: 2
AddressAlign: 0x1
EntrySize: 0x1
Relocation {
Offset: 0x12
Type: R_X86_64_PC32 (0x2)
Symbol: ".L.str" (0x3)
Addend: 0xFFFFFFFFFFFFFFFC
}
Relocation {
Offset: 0x19
Type: R_X86_64_PLT32 (0x4)
Symbol: "printf" (0x5)
Addend: 0xFFFFFFFFFFFFFFFC
}
}
SectionHeader {
Index: 4
Name: ".rodata.str1.1" (0x6C)
Type: SHT_PROGBITS (0x1)
Flags: 0x32
SHF_ALLOC (0x2)
SHF_MERGE (0x10)
SHF_STRINGS (0x20)
Address: 0x0
Offset: 0x65
Size: 0xD
Link: 0
Info: 0
AddressAlign: 0x1
EntrySize: 0x1
}
SectionHeader {
Index: 5
Name: ".comment" (0xC)
Type: SHT_PROGBITS (0x1)
Flags: 0x30
SHF_MERGE (0x10)
SHF_STRINGS (0x20)
Address: 0x0
Offset: 0x72
Size: 0x57
Link: 0
Info: 0
AddressAlign: 0x1
EntrySize: 0x1
}
SectionHeader {
Index: 6
Name: ".note.GNU-stack" (0x21)
Type: SHT_PROGBITS (0x1)
Flags: 0x0
Address: 0x0
Offset: 0xC9
Size: 0x0
Link: 0
Info: 0
AddressAlign: 0x1
EntrySize: 0x0
}
SectionHeader {
Index: 7
Name: ".eh_frame" (0x4B)
Type: SHT_X86_64_UNWIND (0x70000001)
Flags: 0x2
SHF_ALLOC (0x2)
Address: 0x0
Offset: 0xD0
Size: 0x38
Link: 0
Info: 0
AddressAlign: 0x8
EntrySize: 0x0
}
SectionHeader {
Index: 8
Name: ".crel.eh_frame" (0x46)
Type: 0x40000014
Flags: 0x40
SHF_INFO_LINK (0x40)
Address: 0x0
Offset: 0x1A1
Size: 0x4
Link: 10
Info: 7
AddressAlign: 0x1
EntrySize: 0x1
Relocation {
Offset: 0x20
Type: R_X86_64_PC32 (0x2)
Symbol: "" (0x2)
}
}
SectionHeader {
Index: 9
Name: ".llvm_addrsig" (0x31)
Type: 0x6FFF4C03
Flags: 0x80000000
SHF_EXCLUDE (0x80000000)
Address: 0x0
Offset: 0x1A5
Size: 0x1
Link: 10
Info: 0
AddressAlign: 0x1
EntrySize: 0x0
}
SectionHeader {
Index: 10
Name: ".symtab" (0x64)
Type: SHT_SYMTAB (0x2)
Flags: 0x0
Address: 0x0
Offset: 0x108
Size: 0x90
Link: 1
Info: 4
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: "base.c" (0x55)
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: 2
}
Symbol {
Index: 3
Name: ".L.str" (0x15)
Value: 0x0
Size: 0xD
Type: STT_OBJECT (0x1)
Bind: STB_LOCAL (0x0)
Other: STV_DEFAULT (0x0)
SectionIndex: 4
}
Symbol {
Index: 4
Name: "main" (0x1C)
Value: 0x0
Size: 0x25
Type: STT_FUNC (0x2)
Bind: STB_GLOBAL (0x1)
Other: STV_DEFAULT (0x0)
SectionIndex: 2
}
Symbol {
Index: 5
Name: "printf" (0x3F)
Value: 0x0
Size: 0x0
Type: STT_NOTYPE (0x0)
Bind: STB_GLOBAL (0x1)
Other: STV_DEFAULT (0x0)
SectionIndex: SHN_UNDEF (0x0)
}
}
6 changes: 3 additions & 3 deletions src/read/elf/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use crate::read::{
};

use super::{
CompressionHeader, Crel, Dyn, ElfComdat, ElfComdatIterator, ElfDynamicRelocationIterator,
ElfSection, ElfSectionIterator, ElfSegment, ElfSegmentIterator, ElfSymbol, ElfSymbolIterator,
CompressionHeader, Dyn, ElfComdat, ElfComdatIterator, ElfDynamicRelocationIterator, ElfSection,
ElfSectionIterator, ElfSegment, ElfSegmentIterator, ElfSymbol, ElfSymbolIterator,
ElfSymbolTable, NoteHeader, ProgramHeader, Rel, Rela, RelocationSections, Relr, SectionHeader,
SectionTable, Sym, SymbolTable,
};
Expand Down Expand Up @@ -537,7 +537,7 @@ pub trait FileHeader: Debug + Pod {
type Dyn: Dyn<Endian = Self::Endian, Word = Self::Word>;
type Sym: Sym<Endian = Self::Endian, Word = Self::Word>;
type Rel: Rel<Endian = Self::Endian, Word = Self::Word>;
type Rela: Rela<Endian = Self::Endian, Word = Self::Word> + From<Self::Rel> + From<Crel>;
type Rela: Rela<Endian = Self::Endian, Word = Self::Word> + From<Self::Rel>;
type Relr: Relr<Endian = Self::Endian, Word = Self::Word>;

/// Return true if this type is a 64-bit header.
Expand Down
Loading
0