Skip to content

Commit

Permalink
Delete format specific variants in RelocationKind
Browse files Browse the repository at this point in the history
Replace uses of these variants with read::Relocation::flags
and write::Relocation::flags.
  • Loading branch information
philipc committed Nov 10, 2023
1 parent f37e1ea commit a0dd627
Show file tree
Hide file tree
Showing 33 changed files with 588 additions and 618 deletions.
4 changes: 1 addition & 3 deletions crates/examples/src/objcopy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,9 @@ pub fn copy(in_data: &[u8]) -> Vec<u8> {
};
let out_relocation = write::Relocation {
offset,
size: in_relocation.size(),
kind: in_relocation.kind(),
encoding: in_relocation.encoding(),
symbol,
addend: in_relocation.addend(),
flags: in_relocation.flags(),
};
out_object
.add_relocation(out_section, out_relocation)
Expand Down
18 changes: 9 additions & 9 deletions crates/examples/testfiles/coff/import_msvc.lib.objdump
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ Symbols
7: Symbol { name: "\u{7f}test_x64_NULL_THUNK_DATA", address: 0, size: 0, kind: Data, section: Undefined, scope: Linkage, weak: false, flags: None }

.idata$2 relocations
(c, Relocation { kind: ImageOffset, encoding: Generic, size: 20, target: Symbol(SymbolIndex(3)), addend: 0, implicit_addend: true })
(0, Relocation { kind: ImageOffset, encoding: Generic, size: 20, target: Symbol(SymbolIndex(4)), addend: 0, implicit_addend: true })
(10, Relocation { kind: ImageOffset, encoding: Generic, size: 20, target: Symbol(SymbolIndex(5)), addend: 0, implicit_addend: true })
(c, Relocation { kind: ImageOffset, encoding: Generic, size: 20, target: Symbol(SymbolIndex(3)), addend: 0, implicit_addend: true, flags: Coff { typ: 3 } })
(0, Relocation { kind: ImageOffset, encoding: Generic, size: 20, target: Symbol(SymbolIndex(4)), addend: 0, implicit_addend: true, flags: Coff { typ: 3 } })
(10, Relocation { kind: ImageOffset, encoding: Generic, size: 20, target: Symbol(SymbolIndex(5)), addend: 0, implicit_addend: true, flags: Coff { typ: 3 } })

Dynamic symbols

Expand Down Expand Up @@ -172,9 +172,9 @@ Symbols
7: Symbol { name: "\u{7f}test_x86_NULL_THUNK_DATA", address: 0, size: 0, kind: Data, section: Undefined, scope: Linkage, weak: false, flags: None }

.idata$2 relocations
(c, Relocation { kind: ImageOffset, encoding: Generic, size: 20, target: Symbol(SymbolIndex(3)), addend: 0, implicit_addend: true })
(0, Relocation { kind: ImageOffset, encoding: Generic, size: 20, target: Symbol(SymbolIndex(4)), addend: 0, implicit_addend: true })
(10, Relocation { kind: ImageOffset, encoding: Generic, size: 20, target: Symbol(SymbolIndex(5)), addend: 0, implicit_addend: true })
(c, Relocation { kind: ImageOffset, encoding: Generic, size: 20, target: Symbol(SymbolIndex(3)), addend: 0, implicit_addend: true, flags: Coff { typ: 7 } })
(0, Relocation { kind: ImageOffset, encoding: Generic, size: 20, target: Symbol(SymbolIndex(4)), addend: 0, implicit_addend: true, flags: Coff { typ: 7 } })
(10, Relocation { kind: ImageOffset, encoding: Generic, size: 20, target: Symbol(SymbolIndex(5)), addend: 0, implicit_addend: true, flags: Coff { typ: 7 } })

Dynamic symbols

Expand Down Expand Up @@ -249,8 +249,8 @@ Symbols
7: Symbol { name: "\u{7f}test_arm64ec_NULL_THUNK_DATA", address: 0, size: 0, kind: Data, section: Undefined, scope: Linkage, weak: false, flags: None }

.idata$2 relocations
(c, Relocation { kind: ImageOffset, encoding: Generic, size: 20, target: Symbol(SymbolIndex(3)), addend: 0, implicit_addend: true })
(0, Relocation { kind: ImageOffset, encoding: Generic, size: 20, target: Symbol(SymbolIndex(4)), addend: 0, implicit_addend: true })
(10, Relocation { kind: ImageOffset, encoding: Generic, size: 20, target: Symbol(SymbolIndex(5)), addend: 0, implicit_addend: true })
(c, Relocation { kind: ImageOffset, encoding: Generic, size: 20, target: Symbol(SymbolIndex(3)), addend: 0, implicit_addend: true, flags: Coff { typ: 2 } })
(0, Relocation { kind: ImageOffset, encoding: Generic, size: 20, target: Symbol(SymbolIndex(4)), addend: 0, implicit_addend: true, flags: Coff { typ: 2 } })
(10, Relocation { kind: ImageOffset, encoding: Generic, size: 20, target: Symbol(SymbolIndex(5)), addend: 0, implicit_addend: true, flags: Coff { typ: 2 } })

Dynamic symbols
6 changes: 3 additions & 3 deletions crates/examples/testfiles/elf/base.o.objdump
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ Symbols
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
(7, Relocation { kind: Relative, encoding: Generic, size: 20, target: Symbol(SymbolIndex(5)), addend: fffffffffffffffc, implicit_addend: false })
(11, Relocation { kind: PltRelative, encoding: Generic, size: 20, target: Symbol(SymbolIndex(b)), addend: fffffffffffffffc, implicit_addend: false })
(7, Relocation { kind: Relative, encoding: Generic, size: 20, target: Symbol(SymbolIndex(5)), addend: fffffffffffffffc, implicit_addend: false, flags: Elf { r_type: 2 } })
(11, Relocation { kind: PltRelative, encoding: Generic, size: 20, target: Symbol(SymbolIndex(b)), 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 })
(20, Relocation { kind: Relative, encoding: Generic, size: 20, target: Symbol(SymbolIndex(2)), addend: 0, implicit_addend: false, flags: Elf { r_type: 2 } })

Dynamic symbols

Expand Down
18 changes: 9 additions & 9 deletions crates/examples/testfiles/elf/base.objdump
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ Dynamic symbols
6: Symbol { name: "__cxa_finalize", address: 0, size: 0, kind: Text, section: Undefined, scope: Unknown, weak: true, flags: Elf { st_info: 22, st_other: 0 } }

Dynamic relocations
(200da8, Relocation { kind: Elf(8), encoding: Generic, size: 0, target: Absolute, addend: 670, implicit_addend: false })
(200db0, Relocation { kind: Elf(8), encoding: Generic, size: 0, target: Absolute, addend: 630, implicit_addend: false })
(201008, Relocation { kind: Elf(8), encoding: Generic, size: 0, target: Absolute, addend: 201008, implicit_addend: false })
(200fd8, Relocation { kind: Elf(6), encoding: Generic, size: 0, target: Symbol(SymbolIndex(1)), addend: 0, implicit_addend: false })
(200fe0, Relocation { kind: Elf(6), encoding: Generic, size: 0, target: Symbol(SymbolIndex(3)), addend: 0, implicit_addend: false })
(200fe8, Relocation { kind: Elf(6), encoding: Generic, size: 0, target: Symbol(SymbolIndex(4)), addend: 0, implicit_addend: false })
(200ff0, Relocation { kind: Elf(6), encoding: Generic, size: 0, target: Symbol(SymbolIndex(5)), addend: 0, implicit_addend: false })
(200ff8, Relocation { kind: Elf(6), encoding: Generic, size: 0, target: Symbol(SymbolIndex(6)), addend: 0, implicit_addend: false })
(200fd0, Relocation { kind: Elf(7), encoding: Generic, size: 0, target: Symbol(SymbolIndex(2)), addend: 0, implicit_addend: false })
(200da8, Relocation { kind: Unknown, encoding: Generic, size: 0, target: Absolute, addend: 670, implicit_addend: false, flags: Elf { r_type: 8 } })
(200db0, Relocation { kind: Unknown, encoding: Generic, size: 0, target: Absolute, addend: 630, implicit_addend: false, flags: Elf { r_type: 8 } })
(201008, Relocation { kind: Unknown, encoding: Generic, size: 0, target: Absolute, addend: 201008, implicit_addend: false, flags: Elf { r_type: 8 } })
(200fd8, Relocation { kind: Unknown, encoding: Generic, size: 0, target: Symbol(SymbolIndex(1)), addend: 0, implicit_addend: false, flags: Elf { r_type: 6 } })
(200fe0, Relocation { kind: Unknown, encoding: Generic, size: 0, target: Symbol(SymbolIndex(3)), addend: 0, implicit_addend: false, flags: Elf { r_type: 6 } })
(200fe8, Relocation { kind: Unknown, encoding: Generic, size: 0, target: Symbol(SymbolIndex(4)), addend: 0, implicit_addend: false, flags: Elf { r_type: 6 } })
(200ff0, Relocation { kind: Unknown, encoding: Generic, size: 0, target: Symbol(SymbolIndex(5)), addend: 0, implicit_addend: false, flags: Elf { r_type: 6 } })
(200ff8, Relocation { kind: Unknown, encoding: Generic, size: 0, target: Symbol(SymbolIndex(6)), addend: 0, implicit_addend: false, flags: Elf { r_type: 6 } })
(200fd0, Relocation { kind: Unknown, encoding: Generic, size: 0, target: Symbol(SymbolIndex(2)), addend: 0, implicit_addend: false, flags: Elf { r_type: 7 } })

Import { library: "", name: "_ITM_deregisterTMCloneTable" }
Import { library: "", name: "printf" }
Expand Down
14 changes: 7 additions & 7 deletions crates/examples/testfiles/macho/base-aarch64-debug.o.objdump
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ Symbols
5: Symbol { name: "_printf", address: 0, size: 0, kind: Unknown, section: Undefined, scope: Unknown, weak: false, flags: MachO { n_desc: 0 } }

__text relocations
(20, Relocation { kind: MachO { value: 2, relative: true }, encoding: Generic, size: 20, target: Symbol(SymbolIndex(5)), addend: 0, implicit_addend: true })
(1c, Relocation { kind: MachO { value: 4, relative: false }, encoding: Generic, size: 20, target: Symbol(SymbolIndex(1)), addend: 0, implicit_addend: true })
(18, Relocation { kind: MachO { value: 3, relative: true }, encoding: Generic, size: 20, target: Symbol(SymbolIndex(1)), addend: 0, implicit_addend: true })
(20, Relocation { kind: Unknown, encoding: Generic, size: 20, target: Symbol(SymbolIndex(5)), addend: 0, implicit_addend: true, flags: MachO { r_type: 2, r_pcrel: true, r_length: 2 } })
(1c, Relocation { kind: Unknown, encoding: Generic, size: 20, target: Symbol(SymbolIndex(1)), addend: 0, implicit_addend: true, flags: MachO { r_type: 4, r_pcrel: false, r_length: 2 } })
(18, Relocation { kind: Unknown, encoding: Generic, size: 20, target: Symbol(SymbolIndex(1)), addend: 0, implicit_addend: true, flags: MachO { r_type: 3, r_pcrel: true, r_length: 2 } })

__debug_info relocations
(33, Relocation { kind: Absolute, encoding: Generic, size: 40, target: Section(SectionIndex(1)), addend: 0, implicit_addend: true })
(26, Relocation { kind: Absolute, encoding: Generic, size: 40, target: Section(SectionIndex(1)), addend: 0, implicit_addend: true })
(33, Relocation { kind: Absolute, encoding: Generic, size: 40, target: Section(SectionIndex(1)), addend: 0, implicit_addend: true, flags: MachO { r_type: 0, r_pcrel: false, r_length: 3 } })
(26, Relocation { kind: Absolute, encoding: Generic, size: 40, target: Section(SectionIndex(1)), addend: 0, implicit_addend: true, flags: MachO { r_type: 0, r_pcrel: false, r_length: 3 } })

__compact_unwind relocations
(0, Relocation { kind: Absolute, encoding: Generic, size: 40, target: Section(SectionIndex(1)), addend: 0, implicit_addend: true })
(0, Relocation { kind: Absolute, encoding: Generic, size: 40, target: Section(SectionIndex(1)), addend: 0, implicit_addend: true, flags: MachO { r_type: 0, r_pcrel: false, r_length: 3 } })

__debug_line relocations
(2b, Relocation { kind: Absolute, encoding: Generic, size: 40, target: Section(SectionIndex(1)), addend: 0, implicit_addend: true })
(2b, Relocation { kind: Absolute, encoding: Generic, size: 40, target: Section(SectionIndex(1)), addend: 0, implicit_addend: true, flags: MachO { r_type: 0, r_pcrel: false, r_length: 3 } })

Dynamic symbols

Expand Down
8 changes: 4 additions & 4 deletions crates/examples/testfiles/macho/base-aarch64.o.objdump
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ Symbols
5: Symbol { name: "_printf", address: 0, size: 0, kind: Unknown, section: Undefined, scope: Unknown, weak: false, flags: MachO { n_desc: 0 } }

__text relocations
(20, Relocation { kind: MachO { value: 2, relative: true }, encoding: Generic, size: 20, target: Symbol(SymbolIndex(5)), addend: 0, implicit_addend: true })
(1c, Relocation { kind: MachO { value: 4, relative: false }, encoding: Generic, size: 20, target: Symbol(SymbolIndex(1)), addend: 0, implicit_addend: true })
(18, Relocation { kind: MachO { value: 3, relative: true }, encoding: Generic, size: 20, target: Symbol(SymbolIndex(1)), addend: 0, implicit_addend: true })
(20, Relocation { kind: Unknown, encoding: Generic, size: 20, target: Symbol(SymbolIndex(5)), addend: 0, implicit_addend: true, flags: MachO { r_type: 2, r_pcrel: true, r_length: 2 } })
(1c, Relocation { kind: Unknown, encoding: Generic, size: 20, target: Symbol(SymbolIndex(1)), addend: 0, implicit_addend: true, flags: MachO { r_type: 4, r_pcrel: false, r_length: 2 } })
(18, Relocation { kind: Unknown, encoding: Generic, size: 20, target: Symbol(SymbolIndex(1)), addend: 0, implicit_addend: true, flags: MachO { r_type: 3, r_pcrel: true, r_length: 2 } })

__compact_unwind relocations
(0, Relocation { kind: Absolute, encoding: Generic, size: 40, target: Section(SectionIndex(1)), addend: 0, implicit_addend: true })
(0, Relocation { kind: Absolute, encoding: Generic, size: 40, target: Section(SectionIndex(1)), addend: 0, implicit_addend: true, flags: MachO { r_type: 0, r_pcrel: false, r_length: 3 } })

Dynamic symbols

Expand Down
12 changes: 6 additions & 6 deletions crates/examples/testfiles/macho/base-x86_64-debug.o.objdump
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ Symbols
1: Symbol { name: "_printf", address: 0, size: 0, kind: Unknown, section: Undefined, scope: Unknown, weak: false, flags: MachO { n_desc: 0 } }

__text relocations
(19, Relocation { kind: Relative, encoding: X86Branch, size: 20, target: Symbol(SymbolIndex(1)), addend: fffffffffffffffc, implicit_addend: true })
(12, Relocation { kind: Relative, encoding: X86RipRelative, size: 20, target: Section(SectionIndex(2)), addend: fffffffffffffffc, implicit_addend: true })
(19, Relocation { kind: Relative, encoding: X86Branch, size: 20, target: Symbol(SymbolIndex(1)), addend: fffffffffffffffc, implicit_addend: true, flags: MachO { r_type: 2, r_pcrel: true, r_length: 2 } })
(12, Relocation { kind: Relative, encoding: X86RipRelative, size: 20, target: Section(SectionIndex(2)), addend: fffffffffffffffc, implicit_addend: true, flags: MachO { r_type: 1, r_pcrel: true, r_length: 2 } })

__debug_info relocations
(33, Relocation { kind: Absolute, encoding: Generic, size: 40, target: Section(SectionIndex(1)), addend: 0, implicit_addend: true })
(26, Relocation { kind: Absolute, encoding: Generic, size: 40, target: Section(SectionIndex(1)), addend: 0, implicit_addend: true })
(33, Relocation { kind: Absolute, encoding: Generic, size: 40, target: Section(SectionIndex(1)), addend: 0, implicit_addend: true, flags: MachO { r_type: 0, r_pcrel: false, r_length: 3 } })
(26, Relocation { kind: Absolute, encoding: Generic, size: 40, target: Section(SectionIndex(1)), addend: 0, implicit_addend: true, flags: MachO { r_type: 0, r_pcrel: false, r_length: 3 } })

__compact_unwind relocations
(0, Relocation { kind: Absolute, encoding: Generic, size: 40, target: Section(SectionIndex(1)), addend: 0, implicit_addend: true })
(0, Relocation { kind: Absolute, encoding: Generic, size: 40, target: Section(SectionIndex(1)), addend: 0, implicit_addend: true, flags: MachO { r_type: 0, r_pcrel: false, r_length: 3 } })

__debug_line relocations
(2b, Relocation { kind: Absolute, encoding: Generic, size: 40, target: Section(SectionIndex(1)), addend: 0, implicit_addend: true })
(2b, Relocation { kind: Absolute, encoding: Generic, size: 40, target: Section(SectionIndex(1)), addend: 0, implicit_addend: true, flags: MachO { r_type: 0, r_pcrel: false, r_length: 3 } })

Dynamic symbols

Expand Down
6 changes: 3 additions & 3 deletions crates/examples/testfiles/macho/base-x86_64.o.objdump
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ Symbols
1: Symbol { name: "_printf", address: 0, size: 0, kind: Unknown, section: Undefined, scope: Unknown, weak: false, flags: MachO { n_desc: 0 } }

__text relocations
(19, Relocation { kind: Relative, encoding: X86Branch, size: 20, target: Symbol(SymbolIndex(1)), addend: fffffffffffffffc, implicit_addend: true })
(12, Relocation { kind: Relative, encoding: X86RipRelative, size: 20, target: Section(SectionIndex(2)), addend: fffffffffffffffc, implicit_addend: true })
(19, Relocation { kind: Relative, encoding: X86Branch, size: 20, target: Symbol(SymbolIndex(1)), addend: fffffffffffffffc, implicit_addend: true, flags: MachO { r_type: 2, r_pcrel: true, r_length: 2 } })
(12, Relocation { kind: Relative, encoding: X86RipRelative, size: 20, target: Section(SectionIndex(2)), addend: fffffffffffffffc, implicit_addend: true, flags: MachO { r_type: 1, r_pcrel: true, r_length: 2 } })

__compact_unwind relocations
(0, Relocation { kind: Absolute, encoding: Generic, size: 40, target: Section(SectionIndex(1)), addend: 0, implicit_addend: true })
(0, Relocation { kind: Absolute, encoding: Generic, size: 40, target: Section(SectionIndex(1)), addend: 0, implicit_addend: true, flags: MachO { r_type: 0, r_pcrel: false, r_length: 3 } })

Dynamic symbols

Expand Down

0 comments on commit a0dd627

Please sign in to comment.