At Jim Grosbach's request detemplate Object/MachO.h.

We are still able to handle mixed endian objects by swapping one struct at a
time.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179778 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2013-04-18 18:08:55 +00:00
parent 77327fd652
commit fd7aa38e30
11 changed files with 2053 additions and 1769 deletions

View File

@ -100,7 +100,8 @@ public:
}
bool isLittleEndian() const {
return !(TypeID == ID_ELF32B || TypeID == ID_ELF64B);
return !(TypeID == ID_ELF32B || TypeID == ID_ELF64B ||
TypeID == ID_MachO32B || TypeID == ID_MachO64B);
}
};

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -10,6 +10,8 @@ RUN: llvm-readobj -r %p/Inputs/trivial.obj.macho-ppc \
RUN: | FileCheck %s -check-prefix MACHO-PPC
RUN: llvm-readobj -r %p/Inputs/trivial.obj.macho-ppc64 \
RUN: | FileCheck %s -check-prefix MACHO-PPC64
RUN: llvm-readobj -r -expand-relocs %p/Inputs/trivial.obj.macho-arm \
RUN: | FileCheck %s -check-prefix MACHO-ARM
COFF: Relocations [
COFF-NEXT: Section (1) .text {
@ -82,3 +84,90 @@ MACHO-PPC64-NEXT: Section __la_symbol_ptr {
MACHO-PPC64-NEXT: 0x0 0 3 1 0 dyld_stub_binding_helper
MACHO-PPC64-NEXT: }
MACHO-PPC64-NEXT: ]
MACHO-ARM: Relocations [
MACHO-ARM-NEXT: Section __text {
MACHO-ARM-NEXT: Relocation {
MACHO-ARM-NEXT: Offset: 0x38
MACHO-ARM-NEXT: PCRel: 0
MACHO-ARM-NEXT: Length: 2
MACHO-ARM-NEXT: Extern: N/A
MACHO-ARM-NEXT: Type: ARM_RELOC_SECTDIFF (2)
MACHO-ARM-NEXT: Symbol: _b
MACHO-ARM-NEXT: Scattered: 1
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Relocation {
MACHO-ARM-NEXT: Offset: 0x0
MACHO-ARM-NEXT: PCRel: 0
MACHO-ARM-NEXT: Length: 2
MACHO-ARM-NEXT: Extern: N/A
MACHO-ARM-NEXT: Type: ARM_RELOC_PAIR (1)
MACHO-ARM-NEXT: Symbol: _b
MACHO-ARM-NEXT: Scattered: 1
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Relocation {
MACHO-ARM-NEXT: Offset: 0x20
MACHO-ARM-NEXT: PCRel: 1
MACHO-ARM-NEXT: Length: 2
MACHO-ARM-NEXT: Extern: 1
MACHO-ARM-NEXT: Type: ARM_RELOC_BR24 (5)
MACHO-ARM-NEXT: Symbol: _g
MACHO-ARM-NEXT: Scattered: 0
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Relocation {
MACHO-ARM-NEXT: Offset: 0x1C
MACHO-ARM-NEXT: PCRel: 0
MACHO-ARM-NEXT: Length: 1
MACHO-ARM-NEXT: Extern: 1
MACHO-ARM-NEXT: Type: ARM_RELOC_HALF (8)
MACHO-ARM-NEXT: Symbol: _g
MACHO-ARM-NEXT: Scattered: 0
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Relocation {
MACHO-ARM-NEXT: Offset: 0x0
MACHO-ARM-NEXT: PCRel: 0
MACHO-ARM-NEXT: Length: 1
MACHO-ARM-NEXT: Extern: 0
MACHO-ARM-NEXT: Type: ARM_RELOC_PAIR (1)
MACHO-ARM-NEXT: Symbol: _b
MACHO-ARM-NEXT: Scattered: 0
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Relocation {
MACHO-ARM-NEXT: Offset: 0x18
MACHO-ARM-NEXT: PCRel: 0
MACHO-ARM-NEXT: Length: 0
MACHO-ARM-NEXT: Extern: 1
MACHO-ARM-NEXT: Type: ARM_RELOC_HALF (8)
MACHO-ARM-NEXT: Symbol: _g
MACHO-ARM-NEXT: Scattered: 0
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Relocation {
MACHO-ARM-NEXT: Offset: 0x0
MACHO-ARM-NEXT: PCRel: 0
MACHO-ARM-NEXT: Length: 0
MACHO-ARM-NEXT: Extern: 0
MACHO-ARM-NEXT: Type: ARM_RELOC_PAIR (1)
MACHO-ARM-NEXT: Symbol: _b
MACHO-ARM-NEXT: Scattered: 0
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Relocation {
MACHO-ARM-NEXT: Offset: 0xC
MACHO-ARM-NEXT: PCRel: 0
MACHO-ARM-NEXT: Length: 2
MACHO-ARM-NEXT: Extern: N/A
MACHO-ARM-NEXT: Type: ARM_RELOC_SECTDIFF (2)
MACHO-ARM-NEXT: Symbol: _b
MACHO-ARM-NEXT: Scattered: 1
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Relocation {
MACHO-ARM-NEXT: Offset: 0x0
MACHO-ARM-NEXT: PCRel: 0
MACHO-ARM-NEXT: Length: 2
MACHO-ARM-NEXT: Extern: N/A
MACHO-ARM-NEXT: Type: ARM_RELOC_PAIR (1)
MACHO-ARM-NEXT: Symbol: _b
MACHO-ARM-NEXT: Scattered: 1
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: ]

View File

@ -10,6 +10,8 @@ RUN: llvm-readobj -s -st -sr -sd %p/Inputs/trivial.obj.macho-ppc \
RUN: | FileCheck %s -check-prefix MACHO-PPC
RUN: llvm-readobj -s -st -sr -sd %p/Inputs/trivial.obj.macho-ppc64 \
RUN: | FileCheck %s -check-prefix MACHO-PPC64
RUN: llvm-readobj -expand-relocs -s -st -sr -sd %p/Inputs/trivial.obj.macho-arm \
RUN: | FileCheck %s -check-prefix MACHO-ARM
COFF: Sections [
COFF-NEXT: Section {
@ -562,3 +564,278 @@ MACHO-PPC64-NEXT: 0000: 00000000 00000000 |........|
MACHO-PPC64-NEXT: )
MACHO-PPC64-NEXT: }
MACHO-PPC64-NEXT: ]
MACHO-ARM: Sections [
MACHO-ARM-NEXT: Section {
MACHO-ARM-NEXT: Index: 0
MACHO-ARM-NEXT: Name: __text (5F 5F 74 65 78 74 00 00 00 00 00 00 00 00 00 00)
MACHO-ARM-NEXT: Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00)
MACHO-ARM-NEXT: Address: 0x0
MACHO-ARM-NEXT: Size: 0x3C
MACHO-ARM-NEXT: Offset: 664
MACHO-ARM-NEXT: Alignment: 2
MACHO-ARM-NEXT: RelocationOffset: 0x2E0
MACHO-ARM-NEXT: RelocationCount: 9
MACHO-ARM-NEXT: Type: 0x0
MACHO-ARM-NEXT: Attributes [ (0x800004)
MACHO-ARM-NEXT: PureInstructions (0x800000)
MACHO-ARM-NEXT: SomeInstructions (0x4)
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: Reserved1: 0x0
MACHO-ARM-NEXT: Reserved2: 0x0
MACHO-ARM-NEXT: Relocations [
MACHO-ARM-NEXT: Relocation {
MACHO-ARM-NEXT: Offset: 0x38
MACHO-ARM-NEXT: PCRel: 0
MACHO-ARM-NEXT: Length: 2
MACHO-ARM-NEXT: Extern: N/A
MACHO-ARM-NEXT: Type: ARM_RELOC_SECTDIFF (2)
MACHO-ARM-NEXT: Symbol: _b
MACHO-ARM-NEXT: Scattered: 1
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Relocation {
MACHO-ARM-NEXT: Offset: 0x0
MACHO-ARM-NEXT: PCRel: 0
MACHO-ARM-NEXT: Length: 2
MACHO-ARM-NEXT: Extern: N/A
MACHO-ARM-NEXT: Type: ARM_RELOC_PAIR (1)
MACHO-ARM-NEXT: Symbol: _b
MACHO-ARM-NEXT: Scattered: 1
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Relocation {
MACHO-ARM-NEXT: Offset: 0x20
MACHO-ARM-NEXT: PCRel: 1
MACHO-ARM-NEXT: Length: 2
MACHO-ARM-NEXT: Extern: 1
MACHO-ARM-NEXT: Type: ARM_RELOC_BR24 (5)
MACHO-ARM-NEXT: Symbol: _g
MACHO-ARM-NEXT: Scattered: 0
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Relocation {
MACHO-ARM-NEXT: Offset: 0x1C
MACHO-ARM-NEXT: PCRel: 0
MACHO-ARM-NEXT: Length: 1
MACHO-ARM-NEXT: Extern: 1
MACHO-ARM-NEXT: Type: ARM_RELOC_HALF (8)
MACHO-ARM-NEXT: Symbol: _g
MACHO-ARM-NEXT: Scattered: 0
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Relocation {
MACHO-ARM-NEXT: Offset: 0x0
MACHO-ARM-NEXT: PCRel: 0
MACHO-ARM-NEXT: Length: 1
MACHO-ARM-NEXT: Extern: 0
MACHO-ARM-NEXT: Type: ARM_RELOC_PAIR (1)
MACHO-ARM-NEXT: Symbol: _b
MACHO-ARM-NEXT: Scattered: 0
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Relocation {
MACHO-ARM-NEXT: Offset: 0x18
MACHO-ARM-NEXT: PCRel: 0
MACHO-ARM-NEXT: Length: 0
MACHO-ARM-NEXT: Extern: 1
MACHO-ARM-NEXT: Type: ARM_RELOC_HALF (8)
MACHO-ARM-NEXT: Symbol: _g
MACHO-ARM-NEXT: Scattered: 0
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Relocation {
MACHO-ARM-NEXT: Offset: 0x0
MACHO-ARM-NEXT: PCRel: 0
MACHO-ARM-NEXT: Length: 0
MACHO-ARM-NEXT: Extern: 0
MACHO-ARM-NEXT: Type: ARM_RELOC_PAIR (1)
MACHO-ARM-NEXT: Symbol: _b
MACHO-ARM-NEXT: Scattered: 0
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Relocation {
MACHO-ARM-NEXT: Offset: 0xC
MACHO-ARM-NEXT: PCRel: 0
MACHO-ARM-NEXT: Length: 2
MACHO-ARM-NEXT: Extern: N/A
MACHO-ARM-NEXT: Type: ARM_RELOC_SECTDIFF (2)
MACHO-ARM-NEXT: Symbol: _b
MACHO-ARM-NEXT: Scattered: 1
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Relocation {
MACHO-ARM-NEXT: Offset: 0x0
MACHO-ARM-NEXT: PCRel: 0
MACHO-ARM-NEXT: Length: 2
MACHO-ARM-NEXT: Extern: N/A
MACHO-ARM-NEXT: Type: ARM_RELOC_PAIR (1)
MACHO-ARM-NEXT: Symbol: _b
MACHO-ARM-NEXT: Scattered: 1
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: Symbols [
MACHO-ARM-NEXT: Symbol {
MACHO-ARM-NEXT: Name: _f (4)
MACHO-ARM-NEXT: Type: 0xF
MACHO-ARM-NEXT: Section: __text (0x1)
MACHO-ARM-NEXT: RefType: UndefinedNonLazy (0x0)
MACHO-ARM-NEXT: Flags [ (0x0)
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: Value: 0x10
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Symbol {
MACHO-ARM-NEXT: Name: _h (1)
MACHO-ARM-NEXT: Type: 0xF
MACHO-ARM-NEXT: Section: __text (0x1)
MACHO-ARM-NEXT: RefType: UndefinedNonLazy (0x0)
MACHO-ARM-NEXT: Flags [ (0x0)
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: Value: 0x0
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: SectionData (
MACHO-ARM-NEXT: 0000: 04009FE5 00009FE7 1EFF2FE1 38000000 |........../.8...|
MACHO-ARM-NEXT: 0010: 80402DE9 0D70A0E1 000000E3 000040E3 |.@-..p........@.|
MACHO-ARM-NEXT: 0020: F6FFFFEB 0C009FE5 00009FE7 000090E5 |................|
MACHO-ARM-NEXT: 0030: 8040BDE8 1EFF2FE1 10000000 |.@..../.....|
MACHO-ARM-NEXT: )
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Section {
MACHO-ARM-NEXT: Index: 1
MACHO-ARM-NEXT: Name: __textcoal_nt (5F 5F 74 65 78 74 63 6F 61 6C 5F 6E 74 00 00 00)
MACHO-ARM-NEXT: Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00)
MACHO-ARM-NEXT: Address: 0x3C
MACHO-ARM-NEXT: Size: 0x0
MACHO-ARM-NEXT: Offset: 724
MACHO-ARM-NEXT: Alignment: 0
MACHO-ARM-NEXT: RelocationOffset: 0x0
MACHO-ARM-NEXT: RelocationCount: 0
MACHO-ARM-NEXT: Type: 0xB
MACHO-ARM-NEXT: Attributes [ (0x800000)
MACHO-ARM-NEXT: PureInstructions (0x800000)
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: Reserved1: 0x0
MACHO-ARM-NEXT: Reserved2: 0x0
MACHO-ARM-NEXT: Relocations [
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: Symbols [
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: SectionData (
MACHO-ARM-NEXT: )
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Section {
MACHO-ARM-NEXT: Index: 2
MACHO-ARM-NEXT: Name: __const_coal (5F 5F 63 6F 6E 73 74 5F 63 6F 61 6C 00 00 00 00)
MACHO-ARM-NEXT: Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00)
MACHO-ARM-NEXT: Address: 0x3C
MACHO-ARM-NEXT: Size: 0x0
MACHO-ARM-NEXT: Offset: 724
MACHO-ARM-NEXT: Alignment: 0
MACHO-ARM-NEXT: RelocationOffset: 0x0
MACHO-ARM-NEXT: RelocationCount: 0
MACHO-ARM-NEXT: Type: 0xB
MACHO-ARM-NEXT: Attributes [ (0x0)
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: Reserved1: 0x0
MACHO-ARM-NEXT: Reserved2: 0x0
MACHO-ARM-NEXT: Relocations [
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: Symbols [
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: SectionData (
MACHO-ARM-NEXT: )
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Section {
MACHO-ARM-NEXT: Index: 3
MACHO-ARM-NEXT: Name: __picsymbolstub4 (5F 5F 70 69 63 73 79 6D 62 6F 6C 73 74 75 62 34)
MACHO-ARM-NEXT: Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00)
MACHO-ARM-NEXT: Address: 0x3C
MACHO-ARM-NEXT: Size: 0x0
MACHO-ARM-NEXT: Offset: 724
MACHO-ARM-NEXT: Alignment: 0
MACHO-ARM-NEXT: RelocationOffset: 0x0
MACHO-ARM-NEXT: RelocationCount: 0
MACHO-ARM-NEXT: Type: 0x8
MACHO-ARM-NEXT: Attributes [ (0x0)
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: Reserved1: 0x0
MACHO-ARM-NEXT: Reserved2: 0x10
MACHO-ARM-NEXT: Relocations [
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: Symbols [
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: SectionData (
MACHO-ARM-NEXT: )
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Section {
MACHO-ARM-NEXT: Index: 4
MACHO-ARM-NEXT: Name: __StaticInit (5F 5F 53 74 61 74 69 63 49 6E 69 74 00 00 00 00)
MACHO-ARM-NEXT: Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00)
MACHO-ARM-NEXT: Address: 0x3C
MACHO-ARM-NEXT: Size: 0x0
MACHO-ARM-NEXT: Offset: 724
MACHO-ARM-NEXT: Alignment: 0
MACHO-ARM-NEXT: RelocationOffset: 0x0
MACHO-ARM-NEXT: RelocationCount: 0
MACHO-ARM-NEXT: Type: 0x0
MACHO-ARM-NEXT: Attributes [ (0x800000)
MACHO-ARM-NEXT: PureInstructions (0x800000)
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: Reserved1: 0x0
MACHO-ARM-NEXT: Reserved2: 0x0
MACHO-ARM-NEXT: Relocations [
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: Symbols [
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: SectionData (
MACHO-ARM-NEXT: )
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Section {
MACHO-ARM-NEXT: Index: 5
MACHO-ARM-NEXT: Name: __data (5F 5F 64 61 74 61 00 00 00 00 00 00 00 00 00 00)
MACHO-ARM-NEXT: Segment: __DATA (5F 5F 44 41 54 41 00 00 00 00 00 00 00 00 00 00)
MACHO-ARM-NEXT: Address: 0x3C
MACHO-ARM-NEXT: Size: 0x4
MACHO-ARM-NEXT: Offset: 724
MACHO-ARM-NEXT: Alignment: 2
MACHO-ARM-NEXT: RelocationOffset: 0x0
MACHO-ARM-NEXT: RelocationCount: 0
MACHO-ARM-NEXT: Type: 0x0
MACHO-ARM-NEXT: Attributes [ (0x0)
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: Reserved1: 0x0
MACHO-ARM-NEXT: Reserved2: 0x0
MACHO-ARM-NEXT: Relocations [
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: Symbols [
MACHO-ARM-NEXT: Symbol {
MACHO-ARM-NEXT: Name: _b (10)
MACHO-ARM-NEXT: Type: 0xF
MACHO-ARM-NEXT: Section: __data (0x6)
MACHO-ARM-NEXT: RefType: UndefinedNonLazy (0x0)
MACHO-ARM-NEXT: Flags [ (0x0)
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: Value: 0x3C
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: SectionData (
MACHO-ARM-NEXT: 0000: 2A000000 |*...|
MACHO-ARM-NEXT: )
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Section {
MACHO-ARM-NEXT: Index: 6
MACHO-ARM-NEXT: Name: __nl_symbol_ptr (5F 5F 6E 6C 5F 73 79 6D 62 6F 6C 5F 70 74 72 00)
MACHO-ARM-NEXT: Segment: __DATA (5F 5F 44 41 54 41 00 00 00 00 00 00 00 00 00 00)
MACHO-ARM-NEXT: Address: 0x40
MACHO-ARM-NEXT: Size: 0x8
MACHO-ARM-NEXT: Offset: 728
MACHO-ARM-NEXT: Alignment: 2
MACHO-ARM-NEXT: RelocationOffset: 0x0
MACHO-ARM-NEXT: RelocationCount: 0
MACHO-ARM-NEXT: Type: 0x6
MACHO-ARM-NEXT: Attributes [ (0x0)
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: Reserved1: 0x0
MACHO-ARM-NEXT: Reserved2: 0x0
MACHO-ARM-NEXT: Relocations [
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: Symbols [
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: SectionData (
MACHO-ARM-NEXT: 0000: 00000000 00000000 |........|
MACHO-ARM-NEXT: )
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: ]

View File

@ -10,6 +10,8 @@ RUN: llvm-readobj -s %p/Inputs/trivial.obj.macho-ppc \
RUN: | FileCheck %s -check-prefix MACHO-PPC
RUN: llvm-readobj -s %p/Inputs/trivial.obj.macho-ppc64 \
RUN: | FileCheck %s -check-prefix MACHO-PPC64
RUN: llvm-readobj -s %p/Inputs/trivial.obj.macho-arm \
RUN: | FileCheck %s -check-prefix MACHO-ARM
COFF: Sections [
COFF-NEXT: Section {
@ -329,3 +331,122 @@ MACHO-PPC64-NEXT: Reserved1: 0x2
MACHO-PPC64-NEXT: Reserved2: 0x0
MACHO-PPC64-NEXT: }
MACHO-PPC64-NEXT: ]
MACHO-ARM: Sections [
MACHO-ARM-NEXT: Section {
MACHO-ARM-NEXT: Index: 0
MACHO-ARM-NEXT: Name: __text (5F 5F 74 65 78 74 00 00 00 00 00 00 00 00 00 00)
MACHO-ARM-NEXT: Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00)
MACHO-ARM-NEXT: Address: 0x0
MACHO-ARM-NEXT: Size: 0x3C
MACHO-ARM-NEXT: Offset: 664
MACHO-ARM-NEXT: Alignment: 2
MACHO-ARM-NEXT: RelocationOffset: 0x2E0
MACHO-ARM-NEXT: RelocationCount: 9
MACHO-ARM-NEXT: Type: 0x0
MACHO-ARM-NEXT: Attributes [ (0x800004)
MACHO-ARM-NEXT: PureInstructions (0x800000)
MACHO-ARM-NEXT: SomeInstructions (0x4)
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: Reserved1: 0x0
MACHO-ARM-NEXT: Reserved2: 0x0
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Section {
MACHO-ARM-NEXT: Index: 1
MACHO-ARM-NEXT: Name: __textcoal_nt (5F 5F 74 65 78 74 63 6F 61 6C 5F 6E 74 00 00 00)
MACHO-ARM-NEXT: Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00)
MACHO-ARM-NEXT: Address: 0x3C
MACHO-ARM-NEXT: Size: 0x0
MACHO-ARM-NEXT: Offset: 724
MACHO-ARM-NEXT: Alignment: 0
MACHO-ARM-NEXT: RelocationOffset: 0x0
MACHO-ARM-NEXT: RelocationCount: 0
MACHO-ARM-NEXT: Type: 0xB
MACHO-ARM-NEXT: Attributes [ (0x800000)
MACHO-ARM-NEXT: PureInstructions (0x800000)
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: Reserved1: 0x0
MACHO-ARM-NEXT: Reserved2: 0x0
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Section {
MACHO-ARM-NEXT: Index: 2
MACHO-ARM-NEXT: Name: __const_coal (5F 5F 63 6F 6E 73 74 5F 63 6F 61 6C 00 00 00 00)
MACHO-ARM-NEXT: Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00)
MACHO-ARM-NEXT: Address: 0x3C
MACHO-ARM-NEXT: Size: 0x0
MACHO-ARM-NEXT: Offset: 724
MACHO-ARM-NEXT: Alignment: 0
MACHO-ARM-NEXT: RelocationOffset: 0x0
MACHO-ARM-NEXT: RelocationCount: 0
MACHO-ARM-NEXT: Type: 0xB
MACHO-ARM-NEXT: Attributes [ (0x0)
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: Reserved1: 0x0
MACHO-ARM-NEXT: Reserved2: 0x0
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Section {
MACHO-ARM-NEXT: Index: 3
MACHO-ARM-NEXT: Name: __picsymbolstub4 (5F 5F 70 69 63 73 79 6D 62 6F 6C 73 74 75 62 34)
MACHO-ARM-NEXT: Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00)
MACHO-ARM-NEXT: Address: 0x3C
MACHO-ARM-NEXT: Size: 0x0
MACHO-ARM-NEXT: Offset: 724
MACHO-ARM-NEXT: Alignment: 0
MACHO-ARM-NEXT: RelocationOffset: 0x0
MACHO-ARM-NEXT: RelocationCount: 0
MACHO-ARM-NEXT: Type: 0x8
MACHO-ARM-NEXT: Attributes [ (0x0)
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: Reserved1: 0x0
MACHO-ARM-NEXT: Reserved2: 0x10
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Section {
MACHO-ARM-NEXT: Index: 4
MACHO-ARM-NEXT: Name: __StaticInit (5F 5F 53 74 61 74 69 63 49 6E 69 74 00 00 00 00)
MACHO-ARM-NEXT: Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00)
MACHO-ARM-NEXT: Address: 0x3C
MACHO-ARM-NEXT: Size: 0x0
MACHO-ARM-NEXT: Offset: 724
MACHO-ARM-NEXT: Alignment: 0
MACHO-ARM-NEXT: RelocationOffset: 0x0
MACHO-ARM-NEXT: RelocationCount: 0
MACHO-ARM-NEXT: Type: 0x0
MACHO-ARM-NEXT: Attributes [ (0x800000)
MACHO-ARM-NEXT: PureInstructions (0x800000)
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: Reserved1: 0x0
MACHO-ARM-NEXT: Reserved2: 0x0
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Section {
MACHO-ARM-NEXT: Index: 5
MACHO-ARM-NEXT: Name: __data (5F 5F 64 61 74 61 00 00 00 00 00 00 00 00 00 00)
MACHO-ARM-NEXT: Segment: __DATA (5F 5F 44 41 54 41 00 00 00 00 00 00 00 00 00 00)
MACHO-ARM-NEXT: Address: 0x3C
MACHO-ARM-NEXT: Size: 0x4
MACHO-ARM-NEXT: Offset: 724
MACHO-ARM-NEXT: Alignment: 2
MACHO-ARM-NEXT: RelocationOffset: 0x0
MACHO-ARM-NEXT: RelocationCount: 0
MACHO-ARM-NEXT: Type: 0x0
MACHO-ARM-NEXT: Attributes [ (0x0)
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: Reserved1: 0x0
MACHO-ARM-NEXT: Reserved2: 0x0
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT: Section {
MACHO-ARM-NEXT: Index: 6
MACHO-ARM-NEXT: Name: __nl_symbol_ptr (5F 5F 6E 6C 5F 73 79 6D 62 6F 6C 5F 70 74 72 00)
MACHO-ARM-NEXT: Segment: __DATA (5F 5F 44 41 54 41 00 00 00 00 00 00 00 00 00 00)
MACHO-ARM-NEXT: Address: 0x40
MACHO-ARM-NEXT: Size: 0x8
MACHO-ARM-NEXT: Offset: 728
MACHO-ARM-NEXT: Alignment: 2
MACHO-ARM-NEXT: RelocationOffset: 0x0
MACHO-ARM-NEXT: RelocationCount: 0
MACHO-ARM-NEXT: Type: 0x6
MACHO-ARM-NEXT: Attributes [ (0x0)
MACHO-ARM-NEXT: ]
MACHO-ARM-NEXT: Reserved1: 0x0
MACHO-ARM-NEXT: Reserved2: 0x0
MACHO-ARM-NEXT: }
MACHO-ARM-NEXT:]

View File

@ -53,7 +53,7 @@ static cl::opt<bool>
static cl::opt<std::string>
DSYMFile("dsym", cl::desc("Use .dSYM file for debug info"));
static const Target *GetTarget(const MachOObjectFileBase *MachOObj) {
static const Target *GetTarget(const MachOObjectFile *MachOObj) {
// Figure out the target triple.
if (TripleName.empty()) {
llvm::Triple TT("unknown-unknown-unknown");
@ -93,7 +93,7 @@ struct SymbolSorter {
// Print additional information about an address, if available.
static void DumpAddress(uint64_t Address, ArrayRef<SectionRef> Sections,
const MachOObjectFileBase *MachOObj, raw_ostream &OS) {
const MachOObjectFile *MachOObj, raw_ostream &OS) {
for (unsigned i = 0; i != Sections.size(); ++i) {
uint64_t SectAddr = 0, SectSize = 0;
Sections[i].getAddress(SectAddr);
@ -184,14 +184,12 @@ static void emitDOTFile(const char *FileName, const MCFunction &f,
Out << "}\n";
}
template<endianness E>
static void
getSectionsAndSymbols(const typename MachOObjectFileMiddle<E>::Header *Header,
const MachOObjectFileMiddle<E> *MachOObj,
getSectionsAndSymbols(const macho::Header Header,
MachOObjectFile *MachOObj,
std::vector<SectionRef> &Sections,
std::vector<SymbolRef> &Symbols,
SmallVectorImpl<uint64_t> &FoundFns) {
typedef MachOObjectFileMiddle<E> ObjType;
error_code ec;
for (symbol_iterator SI = MachOObj->begin_symbols(),
SE = MachOObj->end_symbols(); SI != SE; SI.increment(ec))
@ -205,23 +203,23 @@ getSectionsAndSymbols(const typename MachOObjectFileMiddle<E>::Header *Header,
Sections.push_back(*SI);
}
for (unsigned i = 0; i != Header->NumLoadCommands; ++i) {
const typename ObjType::LoadCommand *Command =
MachOObj->getLoadCommandInfo(i);
if (Command->Type == macho::LCT_FunctionStarts) {
MachOObjectFile::LoadCommandInfo Command =
MachOObj->getFirstLoadCommandInfo();
for (unsigned i = 0; i != Header.NumLoadCommands; ++i) {
if (Command.C.Type == macho::LCT_FunctionStarts) {
// We found a function starts segment, parse the addresses for later
// consumption.
const typename ObjType::LinkeditDataLoadCommand *LLC =
reinterpret_cast<const typename ObjType::LinkeditDataLoadCommand*>(Command);
macho::LinkeditDataLoadCommand LLC =
MachOObj->getLinkeditDataLoadCommand(Command);
MachOObj->ReadULEB128s(LLC->DataOffset, FoundFns);
MachOObj->ReadULEB128s(LLC.DataOffset, FoundFns);
}
Command = MachOObj->getNextLoadCommandInfo(Command);
}
}
template<endianness E>
static void DisassembleInputMachO2(StringRef Filename,
MachOObjectFileMiddle<E> *MachOOF);
MachOObjectFile *MachOOF);
void llvm::DisassembleInputMachO(StringRef Filename) {
OwningPtr<MemoryBuffer> Buff;
@ -231,20 +229,14 @@ void llvm::DisassembleInputMachO(StringRef Filename) {
return;
}
OwningPtr<MachOObjectFileBase> MachOOF(static_cast<MachOObjectFileBase*>(
OwningPtr<MachOObjectFile> MachOOF(static_cast<MachOObjectFile*>(
ObjectFile::createMachOObjectFile(Buff.take())));
if (MachOObjectFileLE *O = dyn_cast<MachOObjectFileLE>(MachOOF.get())) {
DisassembleInputMachO2(Filename, O);
return;
}
MachOObjectFileBE *O = cast<MachOObjectFileBE>(MachOOF.get());
DisassembleInputMachO2(Filename, O);
DisassembleInputMachO2(Filename, MachOOF.get());
}
template<endianness E>
static void DisassembleInputMachO2(StringRef Filename,
MachOObjectFileMiddle<E> *MachOOF) {
MachOObjectFile *MachOOF) {
const Target *TheTarget = GetTarget(MachOOF);
if (!TheTarget) {
// GetTarget prints out stuff.
@ -273,8 +265,7 @@ static void DisassembleInputMachO2(StringRef Filename,
outs() << '\n' << Filename << ":\n\n";
const typename MachOObjectFileMiddle<E>::Header *Header =
MachOOF->getHeader();
macho::Header Header = MachOOF->getHeader();
std::vector<SectionRef> Sections;
std::vector<SymbolRef> Symbols;

View File

@ -191,14 +191,6 @@ bool llvm::RelocAddressLess(RelocationRef a, RelocationRef b) {
return a_addr < b_addr;
}
StringRef
getSectionFinalSegmentName(const MachOObjectFileBase *MachO, DataRefImpl DR) {
if (const MachOObjectFileLE *O = dyn_cast<MachOObjectFileLE>(MachO))
return O->getSectionFinalSegmentName(DR);
const MachOObjectFileBE *O = dyn_cast<MachOObjectFileBE>(MachO);
return O->getSectionFinalSegmentName(DR);
}
static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
const Target *TheTarget = getTarget(Obj);
// getTarget() will have already issued a diagnostic if necessary, so
@ -263,10 +255,10 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
std::sort(Rels.begin(), Rels.end(), RelocAddressLess);
StringRef SegmentName = "";
if (const MachOObjectFileBase *MachO =
dyn_cast<const MachOObjectFileBase>(Obj)) {
if (const MachOObjectFile *MachO =
dyn_cast<const MachOObjectFile>(Obj)) {
DataRefImpl DR = i->getRawDataRefImpl();
SegmentName = getSectionFinalSegmentName(MachO, DR);
SegmentName = MachO->getSectionFinalSegmentName(DR);
}
StringRef name;
if (error(i->getName(name))) break;
@ -608,10 +600,10 @@ static void PrintSymbolTable(const ObjectFile *o) {
else if (Section == o->end_sections())
outs() << "*UND*";
else {
if (const MachOObjectFileBase *MachO =
dyn_cast<const MachOObjectFileBase>(o)) {
if (const MachOObjectFile *MachO =
dyn_cast<const MachOObjectFile>(o)) {
DataRefImpl DR = Section->getRawDataRefImpl();
StringRef SegmentName = getSectionFinalSegmentName(MachO, DR);
StringRef SegmentName = MachO->getSectionFinalSegmentName(DR);
outs() << SegmentName << ",";
}
StringRef SectionName;

View File

@ -27,7 +27,7 @@ namespace {
class MachODumper : public ObjDumper {
public:
MachODumper(const MachOObjectFileBase *Obj, StreamWriter& Writer)
MachODumper(const MachOObjectFile *Obj, StreamWriter& Writer)
: ObjDumper(Writer)
, Obj(Obj) { }
@ -43,14 +43,12 @@ private:
void printRelocation(section_iterator SecI, relocation_iterator RelI);
template<support::endianness E>
void printRelocation(const MachOObjectFileMiddle<E> *Obj,
void printRelocation(const MachOObjectFile *Obj,
section_iterator SecI, relocation_iterator RelI);
template<support::endianness E>
void printSections(const MachOObjectFileMiddle<E> *Obj);
void printSections(const MachOObjectFile *Obj);
const MachOObjectFileBase *Obj;
const MachOObjectFile *Obj;
};
} // namespace
@ -61,7 +59,7 @@ namespace llvm {
error_code createMachODumper(const object::ObjectFile *Obj,
StreamWriter& Writer,
OwningPtr<ObjDumper> &Result) {
const MachOObjectFileBase *MachOObj = dyn_cast<MachOObjectFileBase>(Obj);
const MachOObjectFile *MachOObj = dyn_cast<MachOObjectFile>(Obj);
if (!MachOObj)
return readobj_error::unsupported_obj_file_format;
@ -164,59 +162,53 @@ namespace {
};
}
template<class MachOT>
static void getSection(const MachOObjectFile<MachOT> *Obj,
DataRefImpl DRI,
static void getSection(const MachOObjectFile *Obj,
DataRefImpl Sec,
MachOSection &Section) {
const typename MachOObjectFile<MachOT>::Section *Sect = Obj->getSection(DRI);
Section.Address = Sect->Address;
Section.Size = Sect->Size;
Section.Offset = Sect->Offset;
Section.Alignment = Sect->Align;
Section.RelocationTableOffset = Sect->RelocationTableOffset;
Section.NumRelocationTableEntries = Sect->NumRelocationTableEntries;
Section.Flags = Sect->Flags;
Section.Reserved1 = Sect->Reserved1;
Section.Reserved2 = Sect->Reserved2;
if (!Obj->is64Bit()) {
macho::Section Sect = Obj->getSection(Sec);
Section.Address = Sect.Address;
Section.Size = Sect.Size;
Section.Offset = Sect.Offset;
Section.Alignment = Sect.Align;
Section.RelocationTableOffset = Sect.RelocationTableOffset;
Section.NumRelocationTableEntries = Sect.NumRelocationTableEntries;
Section.Flags = Sect.Flags;
Section.Reserved1 = Sect.Reserved1;
Section.Reserved2 = Sect.Reserved2;
return;
}
macho::Section64 Sect = Obj->getSection64(Sec);
Section.Address = Sect.Address;
Section.Size = Sect.Size;
Section.Offset = Sect.Offset;
Section.Alignment = Sect.Align;
Section.RelocationTableOffset = Sect.RelocationTableOffset;
Section.NumRelocationTableEntries = Sect.NumRelocationTableEntries;
Section.Flags = Sect.Flags;
Section.Reserved1 = Sect.Reserved1;
Section.Reserved2 = Sect.Reserved2;
}
static void getSection(const MachOObjectFileBase *Obj,
DataRefImpl DRI,
MachOSection &Section) {
if (const MachOObjectFileLE32 *O = dyn_cast<MachOObjectFileLE32>(Obj))
return getSection(O, DRI, Section);
if (const MachOObjectFileLE64 *O = dyn_cast<MachOObjectFileLE64>(Obj))
return getSection(O, DRI, Section);
if (const MachOObjectFileBE32 *O = dyn_cast<MachOObjectFileBE32>(Obj))
return getSection(O, DRI, Section);
const MachOObjectFileBE64 *O = cast<MachOObjectFileBE64>(Obj);
getSection(O, DRI, Section);
}
template<class MachOT>
static void getSymbol(const MachOObjectFile<MachOT> *Obj,
static void getSymbol(const MachOObjectFile *Obj,
DataRefImpl DRI,
MachOSymbol &Symbol) {
const typename MachOObjectFile<MachOT>::SymbolTableEntry *Entry =
Obj->getSymbolTableEntry(DRI);
Symbol.StringIndex = Entry->StringIndex;
Symbol.Type = Entry->Type;
Symbol.SectionIndex = Entry->SectionIndex;
Symbol.Flags = Entry->Flags;
Symbol.Value = Entry->Value;
}
static void getSymbol(const MachOObjectFileBase *Obj,
DataRefImpl DRI,
MachOSymbol &Symbol) {
if (const MachOObjectFileLE32 *O = dyn_cast<MachOObjectFileLE32>(Obj))
return getSymbol(O, DRI, Symbol);
if (const MachOObjectFileLE64 *O = dyn_cast<MachOObjectFileLE64>(Obj))
return getSymbol(O, DRI, Symbol);
if (const MachOObjectFileBE32 *O = dyn_cast<MachOObjectFileBE32>(Obj))
return getSymbol(O, DRI, Symbol);
const MachOObjectFileBE64 *O = cast<MachOObjectFileBE64>(Obj);
getSymbol(O, DRI, Symbol);
if (!Obj->is64Bit()) {
macho::SymbolTableEntry Entry = Obj->getSymbolTableEntry(DRI);
Symbol.StringIndex = Entry.StringIndex;
Symbol.Type = Entry.Type;
Symbol.SectionIndex = Entry.SectionIndex;
Symbol.Flags = Entry.Flags;
Symbol.Value = Entry.Value;
return;
}
macho::Symbol64TableEntry Entry = Obj->getSymbol64TableEntry(DRI);
Symbol.StringIndex = Entry.StringIndex;
Symbol.Type = Entry.Type;
Symbol.SectionIndex = Entry.SectionIndex;
Symbol.Flags = Entry.Flags;
Symbol.Value = Entry.Value;
}
void MachODumper::printFileHeaders() {
@ -224,14 +216,10 @@ void MachODumper::printFileHeaders() {
}
void MachODumper::printSections() {
if (const MachOObjectFileLE *O = dyn_cast<MachOObjectFileLE>(Obj))
return printSections(O);
const MachOObjectFileBE *O = cast<MachOObjectFileBE>(Obj);
return printSections(O);
return printSections(Obj);
}
template<support::endianness E>
void MachODumper::printSections(const MachOObjectFileMiddle<E> *Obj) {
void MachODumper::printSections(const MachOObjectFile *Obj) {
ListScope Group(W, "Sections");
int SectionIndex = -1;
@ -344,14 +332,10 @@ void MachODumper::printRelocations() {
void MachODumper::printRelocation(section_iterator SecI,
relocation_iterator RelI) {
if (const MachOObjectFileLE *O = dyn_cast<MachOObjectFileLE>(Obj))
return printRelocation(O, SecI, RelI);
const MachOObjectFileBE *O = cast<MachOObjectFileBE>(Obj);
return printRelocation(O, SecI, RelI);
return printRelocation(Obj, SecI, RelI);
}
template<support::endianness E>
void MachODumper::printRelocation(const MachOObjectFileMiddle<E> *Obj,
void MachODumper::printRelocation(const MachOObjectFile *Obj,
section_iterator SecI,
relocation_iterator RelI) {
uint64_t Offset;
@ -364,31 +348,30 @@ void MachODumper::printRelocation(const MachOObjectFileMiddle<E> *Obj,
if (error(Symbol.getName(SymbolName))) return;
DataRefImpl DR = RelI->getRawDataRefImpl();
const typename MachOObjectFileMiddle<E>::RelocationEntry *RE =
Obj->getRelocation(DR);
macho::RelocationEntry RE = Obj->getRelocation(DR);
bool IsScattered = Obj->isRelocationScattered(RE);
if (opts::ExpandRelocs) {
DictScope Group(W, "Relocation");
W.printHex("Offset", Offset);
W.printNumber("PCRel", Obj->isRelocationPCRel(RE));
W.printNumber("Length", Obj->getRelocationLength(RE));
W.printNumber("PCRel", Obj->getAnyRelocationPCRel(RE));
W.printNumber("Length", Obj->getAnyRelocationLength(RE));
if (IsScattered)
W.printString("Extern", StringRef("N/A"));
else
W.printNumber("Extern", RE->External);
W.printNumber("Type", RelocName, RE->Type);
W.printNumber("Extern", Obj->getPlainRelocationExternal(RE));
W.printNumber("Type", RelocName, Obj->getAnyRelocationType(RE));
W.printString("Symbol", SymbolName.size() > 0 ? SymbolName : "-");
W.printNumber("Scattered", IsScattered);
} else {
raw_ostream& OS = W.startLine();
OS << W.hex(Offset)
<< " " << Obj->isRelocationPCRel(RE)
<< " " << Obj->getRelocationLength(RE);
<< " " << Obj->getAnyRelocationPCRel(RE)
<< " " << Obj->getAnyRelocationLength(RE);
if (IsScattered)
OS << " n/a";
else
OS << " " << RE->External;
OS << " " << Obj->getPlainRelocationExternal(RE);
OS << " " << RelocName
<< " " << IsScattered
<< " " << (SymbolName.size() > 0 ? SymbolName : "-")

View File

@ -233,7 +233,7 @@ LLVMSymbolizer::getOrCreateModuleInfo(const std::string &ModuleName) {
// On Darwin we may find DWARF in separate object file in
// resource directory.
ObjectFile *DbgObj = Obj;
if (isa<MachOObjectFileBase>(Obj)) {
if (isa<MachOObjectFile>(Obj)) {
const std::string &ResourceName =
getDarwinDWARFResourceForModule(ModuleName);
ObjectFile *ResourceObj = getObjectFile(ResourceName);