Skip to content

Commit

Permalink
macho: add test files
Browse files Browse the repository at this point in the history
  • Loading branch information
philipc committed Oct 24, 2023
1 parent 41b1490 commit 312015d
Show file tree
Hide file tree
Showing 22 changed files with 2,977 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/examples/src/readobj/macho.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ fn print_macho<Mach: MachHeader<Endian = Endianness>>(

fn print_mach_header<Mach: MachHeader>(p: &mut Printer<'_>, endian: Mach::Endian, header: &Mach) {
p.group("MachHeader", |p| {
p.field_hex("Magic", header.magic().to_be());
p.field_hex("Magic", header.magic());
print_cputype(p, header.cputype(endian), header.cpusubtype(endian));
p.field_enum("FileType", header.filetype(endian), FLAGS_MH_FILETYPE);
p.field("NumberOfCmds", header.ncmds(endian));
Expand Down
47 changes: 47 additions & 0 deletions crates/examples/testfiles/macho/base-aarch64-debug.o.objdump
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Format: MachO Little-endian 64-bit
Kind: Relocatable
Architecture: Aarch64
Flags: MachO { flags: 2000 }
Relative Address Base: 0
Entry Address: 0
Segment { name: "", address: 0, size: 2ca }
1: Section { segment: "__TEXT", name: "__text", address: 0, size: 34, align: 4, kind: Text, flags: MachO { flags: 80000400 } }
2: Section { segment: "__TEXT", name: "__cstring", address: 34, size: d, align: 1, kind: ReadOnlyString, flags: MachO { flags: 2 } }
3: Section { segment: "__DWARF", name: "__debug_abbrev", address: 41, size: 3a, align: 1, kind: Debug, flags: MachO { flags: 2000000 } }
4: Section { segment: "__DWARF", name: "__debug_info", address: 7b, size: 53, align: 1, kind: Debug, flags: MachO { flags: 2000000 } }
5: Section { segment: "__DWARF", name: "__debug_str", address: ce, size: cb, align: 1, kind: Debug, flags: MachO { flags: 2000000 } }
6: Section { segment: "__DWARF", name: "__apple_names", address: 199, size: 3c, align: 1, kind: Debug, flags: MachO { flags: 2000000 } }
7: Section { segment: "__DWARF", name: "__apple_objc", address: 1d5, size: 24, align: 1, kind: Debug, flags: MachO { flags: 2000000 } }
8: Section { segment: "__DWARF", name: "__apple_namespac", address: 1f9, size: 24, align: 1, kind: Debug, flags: MachO { flags: 2000000 } }
9: Section { segment: "__DWARF", name: "__apple_types", address: 21d, size: 47, align: 1, kind: Debug, flags: MachO { flags: 2000000 } }
10: Section { segment: "__LD", name: "__compact_unwind", address: 268, size: 20, align: 8, kind: Unknown, flags: MachO { flags: 2000000 } }
11: Section { segment: "__DWARF", name: "__debug_line", address: 288, size: 42, align: 1, kind: Debug, flags: MachO { flags: 2000000 } }

Symbols
0: Symbol { name: "ltmp0", address: 0, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Compilation, weak: false, flags: MachO { n_desc: 0 } }
1: Symbol { name: "l_.str", address: 34, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Compilation, weak: false, flags: MachO { n_desc: 0 } }
2: Symbol { name: "ltmp1", address: 34, size: 0, kind: Data, section: Section(SectionIndex(2)), scope: Compilation, weak: false, flags: MachO { n_desc: 0 } }
3: Symbol { name: "ltmp2", address: 268, size: 0, kind: Unknown, section: Section(SectionIndex(a)), scope: Compilation, weak: false, flags: MachO { n_desc: 0 } }
4: Symbol { name: "_main", address: 0, size: 0, kind: Text, section: Section(SectionIndex(1)), scope: Dynamic, weak: false, flags: MachO { n_desc: 0 } }
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: fffffffffffffffc, 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: fffffffffffffffc, implicit_addend: true })

__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 })

__compact_unwind relocations
(0, Relocation { kind: Absolute, encoding: Generic, size: 40, target: Section(SectionIndex(1)), addend: 0, implicit_addend: true })

__debug_line relocations
(2b, Relocation { kind: Absolute, encoding: Generic, size: 40, target: Section(SectionIndex(1)), addend: 0, implicit_addend: true })

Dynamic symbols

Import { library: "", name: "_printf" }

Export { name: "_main", address: 0 }
330 changes: 330 additions & 0 deletions crates/examples/testfiles/macho/base-aarch64-debug.o.readobj
Original file line number Diff line number Diff line change
@@ -0,0 +1,330 @@
Format: Mach-O 64-bit
MachHeader {
Magic: 0xCFFAEDFE
CpuType: CPU_TYPE_ARM64 (0x100000C)
CpuSubtype: 0x0
CPU_SUBTYPE_ARM64_ALL (0x0)
FileType: MH_OBJECT (0x1)
NumberOfCmds: 4
SizeOfCmds: 0x438
Flags: MH_SUBSECTIONS_VIA_SYMBOLS (0x2000)
}
SegmentCommand {
Cmd: LC_SEGMENT_64 (0x19)
CmdSize: 0x3B8
SegmentName: ""
VmAddress: 0x0
VmSize: 0x2CA
FileOffset: 0x458
FileSize: 0x2CA
MaxProt: 0x7
VM_PROT_READ (0x1)
VM_PROT_WRITE (0x2)
VM_PROT_EXECUTE (0x4)
InitProt: 0x7
VM_PROT_READ (0x1)
VM_PROT_WRITE (0x2)
VM_PROT_EXECUTE (0x4)
NumberOfSections: 11
Flags: 0x0
Section {
Index: 0
SectionName: "__text"
SegmentName: "__TEXT"
Address: 0x0
Size: 0x34
Offset: 0x458
Align: 0x2
RelocationOffset: 0x728
NumberOfRelocations: 0x3
Flags: 0x80000400
S_REGULAR (0x0)
S_ATTR_PURE_INSTRUCTIONS (0x80000000)
S_ATTR_SOME_INSTRUCTIONS (0x400)
RelocationInfo {
Address: 0x20
Extern: yes
Symbol: "_printf" (0x5)
PcRel: yes
Length: 2
Type: ARM64_RELOC_BRANCH26 (0x2)
}
RelocationInfo {
Address: 0x1C
Extern: yes
Symbol: "l_.str" (0x1)
PcRel: no
Length: 2
Type: ARM64_RELOC_PAGEOFF12 (0x4)
}
RelocationInfo {
Address: 0x18
Extern: yes
Symbol: "l_.str" (0x1)
PcRel: yes
Length: 2
Type: ARM64_RELOC_PAGE21 (0x3)
}
}
Section {
Index: 1
SectionName: "__cstring"
SegmentName: "__TEXT"
Address: 0x34
Size: 0xD
Offset: 0x48C
Align: 0x0
RelocationOffset: 0x0
NumberOfRelocations: 0x0
Flags: S_CSTRING_LITERALS (0x2)
}
Section {
Index: 2
SectionName: "__debug_abbrev"
SegmentName: "__DWARF"
Address: 0x41
Size: 0x3A
Offset: 0x499
Align: 0x0
RelocationOffset: 0x0
NumberOfRelocations: 0x0
Flags: 0x2000000
S_REGULAR (0x0)
S_ATTR_DEBUG (0x2000000)
}
Section {
Index: 3
SectionName: "__debug_info"
SegmentName: "__DWARF"
Address: 0x7B
Size: 0x53
Offset: 0x4D3
Align: 0x0
RelocationOffset: 0x740
NumberOfRelocations: 0x2
Flags: 0x2000000
S_REGULAR (0x0)
S_ATTR_DEBUG (0x2000000)
RelocationInfo {
Address: 0x33
Extern: no
Section: "__TEXT,__text" (0x1)
PcRel: no
Length: 3
Type: ARM64_RELOC_UNSIGNED (0x0)
}
RelocationInfo {
Address: 0x26
Extern: no
Section: "__TEXT,__text" (0x1)
PcRel: no
Length: 3
Type: ARM64_RELOC_UNSIGNED (0x0)
}
}
Section {
Index: 4
SectionName: "__debug_str"
SegmentName: "__DWARF"
Address: 0xCE
Size: 0xCB
Offset: 0x526
Align: 0x0
RelocationOffset: 0x0
NumberOfRelocations: 0x0
Flags: 0x2000000
S_REGULAR (0x0)
S_ATTR_DEBUG (0x2000000)
}
Section {
Index: 5
SectionName: "__apple_names"
SegmentName: "__DWARF"
Address: 0x199
Size: 0x3C
Offset: 0x5F1
Align: 0x0
RelocationOffset: 0x0
NumberOfRelocations: 0x0
Flags: 0x2000000
S_REGULAR (0x0)
S_ATTR_DEBUG (0x2000000)
}
Section {
Index: 6
SectionName: "__apple_objc"
SegmentName: "__DWARF"
Address: 0x1D5
Size: 0x24
Offset: 0x62D
Align: 0x0
RelocationOffset: 0x0
NumberOfRelocations: 0x0
Flags: 0x2000000
S_REGULAR (0x0)
S_ATTR_DEBUG (0x2000000)
}
Section {
Index: 7
SectionName: "__apple_namespac"
SegmentName: "__DWARF"
Address: 0x1F9
Size: 0x24
Offset: 0x651
Align: 0x0
RelocationOffset: 0x0
NumberOfRelocations: 0x0
Flags: 0x2000000
S_REGULAR (0x0)
S_ATTR_DEBUG (0x2000000)
}
Section {
Index: 8
SectionName: "__apple_types"
SegmentName: "__DWARF"
Address: 0x21D
Size: 0x47
Offset: 0x675
Align: 0x0
RelocationOffset: 0x0
NumberOfRelocations: 0x0
Flags: 0x2000000
S_REGULAR (0x0)
S_ATTR_DEBUG (0x2000000)
}
Section {
Index: 9
SectionName: "__compact_unwind"
SegmentName: "__LD"
Address: 0x268
Size: 0x20
Offset: 0x6C0
Align: 0x3
RelocationOffset: 0x750
NumberOfRelocations: 0x1
Flags: 0x2000000
S_REGULAR (0x0)
S_ATTR_DEBUG (0x2000000)
RelocationInfo {
Address: 0x0
Extern: no
Section: "__TEXT,__text" (0x1)
PcRel: no
Length: 3
Type: ARM64_RELOC_UNSIGNED (0x0)
}
}
Section {
Index: 10
SectionName: "__debug_line"
SegmentName: "__DWARF"
Address: 0x288
Size: 0x42
Offset: 0x6E0
Align: 0x0
RelocationOffset: 0x758
NumberOfRelocations: 0x1
Flags: 0x2000000
S_REGULAR (0x0)
S_ATTR_DEBUG (0x2000000)
RelocationInfo {
Address: 0x2B
Extern: no
Section: "__TEXT,__text" (0x1)
PcRel: no
Length: 3
Type: ARM64_RELOC_UNSIGNED (0x0)
}
}
}
BuildVersionCommand {
Cmd: LC_BUILD_VERSION (0x32)
CmdSize: 0x18
Platform: PLATFORM_MACOS (0x1)
MinOs: 0xD0000
Sdk: 0xD0300
NumberOfTools: 0x0
}
SymtabCommand {
Cmd: LC_SYMTAB (0x2)
CmdSize: 0x18
SymbolOffset: 0x760
NumberOfSymbols: 0x6
StringOffset: 0x7C0
StringSize: 0x28
Nlist {
Index: 0
String: "ltmp0" (0x22)
Type: N_SECT (0xE)
Section: "__TEXT,__text" (0x1)
Desc: 0x0
Value: 0x0
}
Nlist {
Index: 1
String: "l_.str" (0x1)
Type: N_SECT (0xE)
Section: "__TEXT,__cstring" (0x2)
Desc: 0x0
Value: 0x34
}
Nlist {
Index: 2
String: "ltmp1" (0x1C)
Type: N_SECT (0xE)
Section: "__TEXT,__cstring" (0x2)
Desc: 0x0
Value: 0x34
}
Nlist {
Index: 3
String: "ltmp2" (0x16)
Type: N_SECT (0xE)
Section: "__LD,__compact_unwind" (0xA)
Desc: 0x0
Value: 0x268
}
Nlist {
Index: 4
String: "_main" (0x8)
Type: 0xF
N_SECT (0xE)
N_EXT (0x1)
Section: "__TEXT,__text" (0x1)
Desc: 0x0
Value: 0x0
}
Nlist {
Index: 5
String: "_printf" (0xE)
Type: 0x1
N_UNDF (0x0)
N_EXT (0x1)
Section: "" (0x0)
Desc: 0x0
REFERENCE_FLAG_UNDEFINED_NON_LAZY (0x0)
Value: 0x0
}
}
DysymtabCommand {
Cmd: LC_DYSYMTAB (0xB)
CmdSize: 0x50
IndexOfLocalSymbols: 0
NumberOfLocalSymbols: 4
IndexOfExternallyDefinedSymbols: 4
NumberOfExternallyDefinedSymbols: 1
IndexOfUndefinedSymbols: 5
NumberOfUndefinedSymbols: 1
TocOffset: 0x0
NumberOfTocEntries: 0
ModuleTableOffset: 0x0
NumberOfModuleTableEntries: 0
ExternalRefSymbolOffset: 0x0
NumberOfExternalRefSymbols: 0
IndirectSymbolOffset: 0x0
NumberOfIndirectSymbols: 0
ExternalRelocationOffset: 0x0
NumberOfExternalRelocations: 0
LocalRelocationOffset: 0x0
NumberOfLocalRelocations: 0
}
Loading

0 comments on commit 312015d

Please sign in to comment.