1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00

[ObjectYAML][MachO] Add support for relocations

Add support for relocations for MachO to ObjectYAML / yaml2obj / obj2yaml.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D77844
This commit is contained in:
Alexander Shaposhnikov 2020-04-22 11:50:55 -07:00
parent 75d2b100b0
commit b5506fb989
10 changed files with 2744 additions and 41 deletions

View File

@ -27,6 +27,20 @@
namespace llvm {
namespace MachOYAML {
struct Relocation {
// Offset in the section to what is being relocated.
llvm::yaml::Hex32 address;
// Symbol index if r_extern == 1 else section index.
uint32_t symbolnum;
bool is_pcrel;
// Real length = 2 ^ length.
uint8_t length;
bool is_extern;
uint8_t type;
bool is_scattered;
int32_t value;
};
struct Section {
char sectname[16];
char segname[16];
@ -41,6 +55,7 @@ struct Section {
llvm::yaml::Hex32 reserved2;
llvm::yaml::Hex32 reserved3;
Optional<llvm::yaml::BinaryRef> content;
std::vector<Relocation> relocations;
};
struct FileHeader {
@ -143,6 +158,7 @@ struct UniversalBinary {
} // end namespace llvm
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::LoadCommand)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::Relocation)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::Section)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::RebaseOpcode)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::BindOpcode)
@ -198,6 +214,10 @@ template <> struct MappingTraits<MachOYAML::ExportEntry> {
static void mapping(IO &IO, MachOYAML::ExportEntry &ExportEntry);
};
template <> struct MappingTraits<MachOYAML::Relocation> {
static void mapping(IO &IO, MachOYAML::Relocation &R);
};
template <> struct MappingTraits<MachOYAML::Section> {
static void mapping(IO &IO, MachOYAML::Section &Section);
static StringRef validate(IO &io, MachOYAML::Section &Section);

View File

@ -39,6 +39,7 @@ private:
void writeHeader(raw_ostream &OS);
void writeLoadCommands(raw_ostream &OS);
void writeSectionData(raw_ostream &OS);
void writeRelocations(raw_ostream &OS);
void writeLinkEditData(raw_ostream &OS);
void writeBindOpcodes(raw_ostream &OS,
@ -58,8 +59,11 @@ private:
MachOYAML::Object &Obj;
bool is64Bit;
uint64_t fileStart;
MachO::mach_header_64 Header;
// Old PPC Object Files didn't have __LINKEDIT segments, the data was just
// stuck at the end of the file.
bool FoundLinkEditSeg = false;
};
void MachOWriter::writeMachO(raw_ostream &OS) {
@ -67,6 +71,9 @@ void MachOWriter::writeMachO(raw_ostream &OS) {
writeHeader(OS);
writeLoadCommands(OS);
writeSectionData(OS);
writeRelocations(OS);
if (!FoundLinkEditSeg)
writeLinkEditData(OS);
}
void MachOWriter::writeHeader(raw_ostream &OS) {
@ -255,7 +262,6 @@ void MachOWriter::writeLoadCommands(raw_ostream &OS) {
}
void MachOWriter::writeSectionData(raw_ostream &OS) {
bool FoundLinkEditSeg = false;
for (auto &LC : Obj.LoadCommands) {
switch (LC.Data.load_command_data.cmd) {
case MachO::LC_SEGMENT:
@ -315,10 +321,60 @@ void MachOWriter::writeSectionData(raw_ostream &OS) {
break;
}
}
// Old PPC Object Files didn't have __LINKEDIT segments, the data was just
// stuck at the end of the file.
if (!FoundLinkEditSeg)
writeLinkEditData(OS);
}
// The implementation of makeRelocationInfo and makeScatteredRelocationInfo is
// consistent with how libObject parses MachO binary files. For the reference
// see getStruct, getRelocation, getPlainRelocationPCRel,
// getPlainRelocationLength and related methods in MachOObjectFile.cpp
static MachO::any_relocation_info
makeRelocationInfo(const MachOYAML::Relocation &R, bool IsLE) {
assert(!R.is_scattered && "non-scattered relocation expected");
MachO::any_relocation_info MRE;
MRE.r_word0 = R.address;
if (IsLE)
MRE.r_word1 = ((unsigned)R.symbolnum << 0) | ((unsigned)R.is_pcrel << 24) |
((unsigned)R.length << 25) | ((unsigned)R.is_extern << 27) |
((unsigned)R.type << 28);
else
MRE.r_word1 = ((unsigned)R.symbolnum << 8) | ((unsigned)R.is_pcrel << 7) |
((unsigned)R.length << 5) | ((unsigned)R.is_extern << 4) |
((unsigned)R.type << 0);
return MRE;
}
static MachO::any_relocation_info
makeScatteredRelocationInfo(const MachOYAML::Relocation &R) {
assert(R.is_scattered && "scattered relocation expected");
MachO::any_relocation_info MRE;
MRE.r_word0 = (((unsigned)R.address << 0) | ((unsigned)R.type << 24) |
((unsigned)R.length << 28) | ((unsigned)R.is_pcrel << 30) |
MachO::R_SCATTERED);
MRE.r_word1 = R.value;
return MRE;
}
void MachOWriter::writeRelocations(raw_ostream &OS) {
for (const MachOYAML::LoadCommand &LC : Obj.LoadCommands) {
switch (LC.Data.load_command_data.cmd) {
case MachO::LC_SEGMENT:
case MachO::LC_SEGMENT_64:
for (const MachOYAML::Section &Sec : LC.Sections) {
if (Sec.relocations.empty())
continue;
ZeroToOffset(OS, Sec.reloff);
for (const MachOYAML::Relocation &R : Sec.relocations) {
MachO::any_relocation_info MRE =
R.is_scattered ? makeScatteredRelocationInfo(R)
: makeRelocationInfo(R, Obj.IsLittleEndian);
if (Obj.IsLittleEndian != sys::IsLittleEndianHost)
MachO::swapStruct(MRE);
OS.write(reinterpret_cast<const char *>(&MRE),
sizeof(MachO::any_relocation_info));
}
}
}
}
}
void MachOWriter::writeBindOpcodes(

View File

@ -273,6 +273,18 @@ void MappingTraits<MachO::dyld_info_command>::mapping(
IO.mapRequired("export_size", LoadCommand.export_size);
}
void MappingTraits<MachOYAML::Relocation>::mapping(
IO &IO, MachOYAML::Relocation &Relocation) {
IO.mapRequired("address", Relocation.address);
IO.mapRequired("symbolnum", Relocation.symbolnum);
IO.mapRequired("pcrel", Relocation.is_pcrel);
IO.mapRequired("length", Relocation.length);
IO.mapRequired("extern", Relocation.is_extern);
IO.mapRequired("type", Relocation.type);
IO.mapRequired("scattered", Relocation.is_scattered);
IO.mapRequired("value", Relocation.value);
}
void MappingTraits<MachOYAML::Section>::mapping(IO &IO,
MachOYAML::Section &Section) {
IO.mapRequired("sectname", Section.sectname);
@ -288,6 +300,7 @@ void MappingTraits<MachOYAML::Section>::mapping(IO &IO,
IO.mapRequired("reserved2", Section.reserved2);
IO.mapOptional("reserved3", Section.reserved3);
IO.mapOptional("content", Section.content);
IO.mapOptional("relocations", Section.relocations);
}
StringRef

View File

@ -0,0 +1,590 @@
# RUN: yaml2obj %s -o %t
# RUN: llvm-objdump --macho --reloc %t | FileCheck %s --check-prefix=OBJDUMP-VERIFY
# OBJDUMP-VERIFY: Relocation information (__TEXT,__text) 4 entries
# OBJDUMP-VERIFY-NEXT: address pcrel length extern type scattered symbolnum/value
# OBJDUMP-VERIFY-NEXT: 00000018 False long True PAGOF12 False _w
# OBJDUMP-VERIFY-NEXT: 00000014 True long True PAGE21 False _w
# OBJDUMP-VERIFY-NEXT: 0000000c False long True PAGOF12 False _z
# OBJDUMP-VERIFY-NEXT: 00000008 True long True PAGE21 False _z
# OBJDUMP-VERIFY-NEXT: Relocation information (__TEXT,__StaticInit) 7 entries
# OBJDUMP-VERIFY-NEXT: address pcrel length extern type scattered symbolnum/value
# OBJDUMP-VERIFY-NEXT: 0000002c True long True BR26 False ___cxx_global_var_init
# OBJDUMP-VERIFY-NEXT: 00000018 False long True PAGOF12 False _w
# OBJDUMP-VERIFY-NEXT: 00000014 True long True PAGE21 False _w
# OBJDUMP-VERIFY-NEXT: 0000000c False long True PAGOF12 False _y
# OBJDUMP-VERIFY-NEXT: 00000008 True long True PAGE21 False _y
# OBJDUMP-VERIFY-NEXT: 00000004 False long True PAGOF12 False _x
# OBJDUMP-VERIFY-NEXT: 00000000 True long True PAGE21 False _x
# OBJDUMP-VERIFY-NEXT: Relocation information (__DATA,__data) 1 entries
# OBJDUMP-VERIFY-NEXT: address pcrel length extern type scattered symbolnum/value
# OBJDUMP-VERIFY-NEXT: 00000008 False ?( 3) True UNSIGND False _x
# OBJDUMP-VERIFY-NEXT: Relocation information (__DATA,__mod_init_func) 1 entries
# OBJDUMP-VERIFY-NEXT: address pcrel length extern type scattered symbolnum/value
# OBJDUMP-VERIFY-NEXT: 00000000 False ?( 3) True UNSIGND False __GLOBAL__sub_I_main.cpp
# OBJDUMP-VERIFY-NEXT: Relocation information (__LD,__compact_unwind) 3 entries
# OBJDUMP-VERIFY-NEXT: address pcrel length extern type scattered symbolnum/value
# OBJDUMP-VERIFY-NEXT: 00000040 False ?( 3) False UNSIGND False 2 (__TEXT,__StaticInit)
# OBJDUMP-VERIFY-NEXT: 00000020 False ?( 3) False UNSIGND False 1 (__TEXT,__text)
# OBJDUMP-VERIFY-NEXT: 00000000 False ?( 3) False UNSIGND False 2 (__TEXT,__StaticInit)
# RUN: obj2yaml %t | FileCheck %s
# CHECK: Sections:
# CHECK-NEXT: - sectname: __text
# CHECK-NEXT: segname: __TEXT
# CHECK-NEXT: addr: 0x0000000000000000
# CHECK-NEXT: size: 48
# CHECK-NEXT: offset: 0x000002C0
# CHECK-NEXT: align: 2
# CHECK-NEXT: reloff: 0x000003A0
# CHECK-NEXT: nreloc: 4
# CHECK-NEXT: flags: 0x80000400
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: content:
# CHECK-NEXT: relocations:
# CHECK-NEXT: - address: 0x00000018
# CHECK-NEXT: symbolnum: 9
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: true
# CHECK-NEXT: type: 4
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - address: 0x00000014
# CHECK-NEXT: symbolnum: 9
# CHECK-NEXT: pcrel: true
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: true
# CHECK-NEXT: type: 3
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - address: 0x0000000C
# CHECK-NEXT: symbolnum: 12
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: true
# CHECK-NEXT: type: 4
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - address: 0x00000008
# CHECK-NEXT: symbolnum: 12
# CHECK-NEXT: pcrel: true
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: true
# CHECK-NEXT: type: 3
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - sectname: __StaticInit
# CHECK-NEXT: segname: __TEXT
# CHECK-NEXT: addr: 0x0000000000000030
# CHECK-NEXT: size: 56
# CHECK-NEXT: offset: 0x000002F0
# CHECK-NEXT: align: 2
# CHECK-NEXT: reloff: 0x000003C0
# CHECK-NEXT: nreloc: 7
# CHECK-NEXT: flags: 0x80000400
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: content:
# CHECK-NEXT: relocations:
# CHECK-NEXT: - address: 0x0000002C
# CHECK-NEXT: symbolnum: 2
# CHECK-NEXT: pcrel: true
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: true
# CHECK-NEXT: type: 2
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - address: 0x00000018
# CHECK-NEXT: symbolnum: 9
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: true
# CHECK-NEXT: type: 4
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - address: 0x00000014
# CHECK-NEXT: symbolnum: 9
# CHECK-NEXT: pcrel: true
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: true
# CHECK-NEXT: type: 3
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - address: 0x0000000C
# CHECK-NEXT: symbolnum: 11
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: true
# CHECK-NEXT: type: 4
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - address: 0x00000008
# CHECK-NEXT: symbolnum: 11
# CHECK-NEXT: pcrel: true
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: true
# CHECK-NEXT: type: 3
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - address: 0x00000004
# CHECK-NEXT: symbolnum: 10
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: true
# CHECK-NEXT: type: 4
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - address: 0x00000000
# CHECK-NEXT: symbolnum: 10
# CHECK-NEXT: pcrel: true
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: true
# CHECK-NEXT: type: 3
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - sectname: __data
# CHECK-NEXT: segname: __DATA
# CHECK-NEXT: addr: 0x0000000000000068
# CHECK-NEXT: size: 16
# CHECK-NEXT: offset: 0x00000328
# CHECK-NEXT: align: 3
# CHECK-NEXT: reloff: 0x000003F8
# CHECK-NEXT: nreloc: 1
# CHECK-NEXT: flags: 0x00000000
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: content:
# CHECK-NEXT: relocations:
# CHECK-NEXT: - address: 0x00000008
# CHECK-NEXT: symbolnum: 10
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 3
# CHECK-NEXT: extern: true
# CHECK-NEXT: type: 0
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - sectname: __common
# CHECK-NEXT: segname: __DATA
# CHECK-NEXT: addr: 0x00000000000000E0
# CHECK-NEXT: size: 8
# CHECK-NEXT: offset: 0x00000000
# CHECK-NEXT: align: 3
# CHECK-NEXT: reloff: 0x00000000
# CHECK-NEXT: nreloc: 0
# CHECK-NEXT: flags: 0x00000001
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: - sectname: __mod_init_func
# CHECK-NEXT: segname: __DATA
# CHECK-NEXT: addr: 0x0000000000000078
# CHECK-NEXT: size: 8
# CHECK-NEXT: offset: 0x00000338
# CHECK-NEXT: align: 3
# CHECK-NEXT: reloff: 0x00000400
# CHECK-NEXT: nreloc: 1
# CHECK-NEXT: flags: 0x00000009
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: content:
# CHECK-NEXT: relocations:
# CHECK-NEXT: - address: 0x00000000
# CHECK-NEXT: symbolnum: 3
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 3
# CHECK-NEXT: extern: true
# CHECK-NEXT: type: 0
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - sectname: __compact_unwind
# CHECK-NEXT: segname: __LD
# CHECK-NEXT: addr: 0x0000000000000080
# CHECK-NEXT: size: 96
# CHECK-NEXT: offset: 0x00000340
# CHECK-NEXT: align: 3
# CHECK-NEXT: reloff: 0x00000408
# CHECK-NEXT: nreloc: 3
# CHECK-NEXT: flags: 0x02000000
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: content:
# CHECK-NEXT: relocations:
# CHECK-NEXT: - address: 0x00000040
# CHECK-NEXT: symbolnum: 2
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 3
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 0
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - address: 0x00000020
# CHECK-NEXT: symbolnum: 1
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 3
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 0
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - address: 0x00000000
# CHECK-NEXT: symbolnum: 2
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 3
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 0
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
--- !mach-o
FileHeader:
magic: 0xFEEDFACF
cputype: 0x0100000C
cpusubtype: 0x00000000
filetype: 0x00000001
ncmds: 4
sizeofcmds: 672
flags: 0x00002000
reserved: 0x00000000
LoadCommands:
- cmd: LC_SEGMENT_64
cmdsize: 552
segname: ''
vmaddr: 0
vmsize: 232
fileoff: 704
filesize: 224
maxprot: 7
initprot: 7
nsects: 6
flags: 0
Sections:
- sectname: __text
segname: __TEXT
addr: 0x0000000000000000
size: 48
offset: 0x000002C0
align: 2
reloff: 0x000003A0
nreloc: 4
flags: 0x80000400
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: FF4300D1FF0F00B90800009008010091080140F90900009029010091290140F90801098BE00308AAFF430091C0035FD6
relocations:
- address: 0x00000018
symbolnum: 9
pcrel: false
length: 2
extern: true
type: 4
scattered: false
value: 0
- address: 0x00000014
symbolnum: 9
pcrel: true
length: 2
extern: true
type: 3
scattered: false
value: 0
- address: 0x0000000C
symbolnum: 12
pcrel: false
length: 2
extern: true
type: 4
scattered: false
value: 0
- address: 0x00000008
symbolnum: 12
pcrel: true
length: 2
extern: true
type: 3
scattered: false
value: 0
- sectname: __StaticInit
segname: __TEXT
addr: 0x0000000000000030
size: 56
offset: 0x000002F0
align: 2
reloff: 0x000003C0
nreloc: 7
flags: 0x80000400
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: 08000090080100910900009029010091080109EB0900009029010091280100F9C0035FD6FD7BBFA9FD03009100000094FD7BC1A8C0035FD6
relocations:
- address: 0x0000002C
symbolnum: 2
pcrel: true
length: 2
extern: true
type: 2
scattered: false
value: 0
- address: 0x00000018
symbolnum: 9
pcrel: false
length: 2
extern: true
type: 4
scattered: false
value: 0
- address: 0x00000014
symbolnum: 9
pcrel: true
length: 2
extern: true
type: 3
scattered: false
value: 0
- address: 0x0000000C
symbolnum: 11
pcrel: false
length: 2
extern: true
type: 4
scattered: false
value: 0
- address: 0x00000008
symbolnum: 11
pcrel: true
length: 2
extern: true
type: 3
scattered: false
value: 0
- address: 0x00000004
symbolnum: 10
pcrel: false
length: 2
extern: true
type: 4
scattered: false
value: 0
- address: 0x00000000
symbolnum: 10
pcrel: true
length: 2
extern: true
type: 3
scattered: false
value: 0
- sectname: __data
segname: __DATA
addr: 0x0000000000000068
size: 16
offset: 0x00000328
align: 3
reloff: 0x000003F8
nreloc: 1
flags: 0x00000000
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: '01000000020000000000000000000000'
relocations:
- address: 0x00000008
symbolnum: 10
pcrel: false
length: 3
extern: true
type: 0
scattered: false
value: 0
- sectname: __common
segname: __DATA
addr: 0x00000000000000E0
size: 8
offset: 0x00000000
align: 3
reloff: 0x00000000
nreloc: 0
flags: 0x00000001
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
- sectname: __mod_init_func
segname: __DATA
addr: 0x0000000000000078
size: 8
offset: 0x00000338
align: 3
reloff: 0x00000400
nreloc: 1
flags: 0x00000009
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: '0000000000000000'
relocations:
- address: 0x00000000
symbolnum: 3
pcrel: false
length: 3
extern: true
type: 0
scattered: false
value: 0
- sectname: __compact_unwind
segname: __LD
addr: 0x0000000000000080
size: 96
offset: 0x00000340
align: 3
reloff: 0x00000408
nreloc: 3
flags: 0x02000000
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: '300000000000000024000000000000020000000000000000000000000000000000000000000000003000000000100002000000000000000000000000000000005400000000000000140000000000000400000000000000000000000000000000'
relocations:
- address: 0x00000040
symbolnum: 2
pcrel: false
length: 3
extern: false
type: 0
scattered: false
value: 0
- address: 0x00000020
symbolnum: 1
pcrel: false
length: 3
extern: false
type: 0
scattered: false
value: 0
- address: 0x00000000
symbolnum: 2
pcrel: false
length: 3
extern: false
type: 0
scattered: false
value: 0
- cmd: LC_VERSION_MIN_IPHONEOS
cmdsize: 16
version: 655360
sdk: 0
- cmd: LC_SYMTAB
cmdsize: 24
symoff: 1056
nsyms: 13
stroff: 1264
strsize: 104
- cmd: LC_DYSYMTAB
cmdsize: 80
ilocalsym: 0
nlocalsym: 8
iextdefsym: 8
nextdefsym: 5
iundefsym: 13
nundefsym: 0
tocoff: 0
ntoc: 0
modtaboff: 0
nmodtab: 0
extrefsymoff: 0
nextrefsyms: 0
indirectsymoff: 0
nindirectsyms: 0
extreloff: 0
nextrel: 0
locreloff: 0
nlocrel: 0
LinkEditData:
NameList:
- n_strx: 97
n_type: 0x0E
n_sect: 1
n_desc: 0
n_value: 0
- n_strx: 91
n_type: 0x0E
n_sect: 2
n_desc: 0
n_value: 48
- n_strx: 13
n_type: 0x0E
n_sect: 2
n_desc: 0
n_value: 48
- n_strx: 36
n_type: 0x0E
n_sect: 2
n_desc: 0
n_value: 84
- n_strx: 85
n_type: 0x0E
n_sect: 3
n_desc: 0
n_value: 104
- n_strx: 79
n_type: 0x0E
n_sect: 4
n_desc: 0
n_value: 224
- n_strx: 73
n_type: 0x0E
n_sect: 5
n_desc: 0
n_value: 120
- n_strx: 67
n_type: 0x0E
n_sect: 6
n_desc: 0
n_value: 128
- n_strx: 61
n_type: 0x0F
n_sect: 1
n_desc: 0
n_value: 0
- n_strx: 10
n_type: 0x0F
n_sect: 4
n_desc: 0
n_value: 224
- n_strx: 7
n_type: 0x0F
n_sect: 3
n_desc: 0
n_value: 104
- n_strx: 4
n_type: 0x0F
n_sect: 3
n_desc: 0
n_value: 108
- n_strx: 1
n_type: 0x0F
n_sect: 3
n_desc: 0
n_value: 112
StringTable:
- ''
- _z
- _y
- _x
- _w
- ___cxx_global_var_init
- __GLOBAL__sub_I_main.cpp
- _main
- ltmp5
- ltmp4
- ltmp3
- ltmp2
- ltmp1
- ltmp0
- ''
...

View File

@ -0,0 +1,642 @@
# RUN: yaml2obj %s -o %t
# RUN: llvm-objdump --macho --reloc %t | FileCheck %s --check-prefix=OBJDUMP-VERIFY
# OBJDUMP-VERIFY: Relocation information (__TEXT,__text) 8 entries
# OBJDUMP-VERIFY-NEXT: address pcrel length extern type scattered symbolnum/value
# OBJDUMP-VERIFY-NEXT: 00000016 False hi/thm n/a HALFDIF True 0x00000064
# OBJDUMP-VERIFY-NEXT: False hi/thm n/a PAIR True 0x0000001a half = 0x0046
# OBJDUMP-VERIFY-NEXT: 00000012 False lo/arm n/a HALFDIF True 0x00000064
# OBJDUMP-VERIFY-NEXT: False lo/arm n/a PAIR True 0x0000001a half = 0x0000
# OBJDUMP-VERIFY-NEXT: 0000000a False hi/thm n/a HALFDIF True 0x0000005c
# OBJDUMP-VERIFY-NEXT: False hi/thm n/a PAIR True 0x0000000e half = 0x004a
# OBJDUMP-VERIFY-NEXT: 00000006 False lo/arm n/a HALFDIF True 0x0000005c
# OBJDUMP-VERIFY-NEXT: False lo/arm n/a PAIR True 0x0000000e half = 0x0000
# OBJDUMP-VERIFY-NEXT: Relocation information (__TEXT,__StaticInit) 13 entries
# OBJDUMP-VERIFY-NEXT: address pcrel length extern type scattered symbolnum/value
# OBJDUMP-VERIFY-NEXT: 00000028 True long False T_BR22 False 2 (__TEXT,__StaticInit)
# OBJDUMP-VERIFY-NEXT: 0000001a False hi/thm n/a HALFDIF True 0x00000064
# OBJDUMP-VERIFY-NEXT: False hi/thm n/a PAIR True 0x00000042 half = 0x001e
# OBJDUMP-VERIFY-NEXT: 00000016 False lo/arm n/a HALFDIF True 0x00000064
# OBJDUMP-VERIFY-NEXT: False lo/arm n/a PAIR True 0x00000042 half = 0x0000
# OBJDUMP-VERIFY-NEXT: 0000000e False hi/thm n/a HALFDIF True 0x00000054
# OBJDUMP-VERIFY-NEXT: False hi/thm n/a PAIR True 0x00000036 half = 0x001a
# OBJDUMP-VERIFY-NEXT: 0000000a False lo/arm n/a HALFDIF True 0x00000054
# OBJDUMP-VERIFY-NEXT: False lo/arm n/a PAIR True 0x00000036 half = 0x0000
# OBJDUMP-VERIFY-NEXT: 00000004 False hi/thm n/a HALFDIF True 0x00000058
# OBJDUMP-VERIFY-NEXT: False hi/thm n/a PAIR True 0x0000002c half = 0x0028
# OBJDUMP-VERIFY-NEXT: 00000000 False lo/arm n/a HALFDIF True 0x00000058
# OBJDUMP-VERIFY-NEXT: False lo/arm n/a PAIR True 0x0000002c half = 0x0000
# OBJDUMP-VERIFY-NEXT: Relocation information (__DATA,__data) 1 entries
# OBJDUMP-VERIFY-NEXT: address pcrel length extern type scattered symbolnum/value
# OBJDUMP-VERIFY-NEXT: 00000008 False long False VANILLA False 3 (__DATA,__data)
# OBJDUMP-VERIFY-NEXT: Relocation information (__DATA,__mod_init_func) 1 entries
# OBJDUMP-VERIFY-NEXT: address pcrel length extern type scattered symbolnum/value
# OBJDUMP-VERIFY-NEXT: 00000000 False long False VANILLA False 2 (__TEXT,__StaticInit)
# RUN: obj2yaml %t | FileCheck %s
# CHECK: Sections:
# CHECK-NEXT: - sectname: __text
# CHECK-NEXT: segname: __TEXT
# CHECK-NEXT: addr: 0x0000000000000000
# CHECK-NEXT: size: 36
# CHECK-NEXT: offset: 0x00000220
# CHECK-NEXT: align: 1
# CHECK-NEXT: reloff: 0x00000284
# CHECK-NEXT: nreloc: 8
# CHECK-NEXT: flags: 0x80000400
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: content:
# CHECK-NEXT: relocations:
# CHECK-NEXT: - address: 0x00000016
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 3
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 9
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 100
# CHECK-NEXT: - address: 0x00000046
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 3
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 1
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 26
# CHECK-NEXT: - address: 0x00000012
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 9
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 100
# CHECK-NEXT: - address: 0x00000000
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 1
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 26
# CHECK-NEXT: - address: 0x0000000A
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 3
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 9
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 92
# CHECK-NEXT: - address: 0x0000004A
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 3
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 1
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 14
# CHECK-NEXT: - address: 0x00000006
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 9
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 92
# CHECK-NEXT: - address: 0x00000000
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 1
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 14
# CHECK-NEXT: - sectname: __StaticInit
# CHECK-NEXT: segname: __TEXT
# CHECK-NEXT: addr: 0x0000000000000024
# CHECK-NEXT: size: 46
# CHECK-NEXT: offset: 0x00000244
# CHECK-NEXT: align: 1
# CHECK-NEXT: reloff: 0x000002C4
# CHECK-NEXT: nreloc: 13
# CHECK-NEXT: flags: 0x80000400
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: content:
# CHECK-NEXT: relocations:
# CHECK-NEXT: - address: 0x00000028
# CHECK-NEXT: symbolnum: 2
# CHECK-NEXT: pcrel: true
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 6
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - address: 0x0000001A
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 3
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 9
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 100
# CHECK-NEXT: - address: 0x0000001E
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 3
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 1
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 66
# CHECK-NEXT: - address: 0x00000016
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 9
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 100
# CHECK-NEXT: - address: 0x00000000
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 1
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 66
# CHECK-NEXT: - address: 0x0000000E
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 3
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 9
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 84
# CHECK-NEXT: - address: 0x0000001A
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 3
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 1
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 54
# CHECK-NEXT: - address: 0x0000000A
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 9
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 84
# CHECK-NEXT: - address: 0x00000000
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 1
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 54
# CHECK-NEXT: - address: 0x00000004
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 3
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 9
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 88
# CHECK-NEXT: - address: 0x00000028
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 3
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 1
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 44
# CHECK-NEXT: - address: 0x00000000
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 9
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 88
# CHECK-NEXT: - address: 0x00000000
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 1
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 44
# CHECK-NEXT: - sectname: __data
# CHECK-NEXT: segname: __DATA
# CHECK-NEXT: addr: 0x0000000000000054
# CHECK-NEXT: size: 12
# CHECK-NEXT: offset: 0x00000274
# CHECK-NEXT: align: 2
# CHECK-NEXT: reloff: 0x0000032C
# CHECK-NEXT: nreloc: 1
# CHECK-NEXT: flags: 0x00000000
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: content:
# CHECK-NEXT: relocations:
# CHECK-NEXT: - address: 0x00000008
# CHECK-NEXT: symbolnum: 3
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 0
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - sectname: __common
# CHECK-NEXT: segname: __DATA
# CHECK-NEXT: addr: 0x0000000000000064
# CHECK-NEXT: size: 4
# CHECK-NEXT: offset: 0x00000000
# CHECK-NEXT: align: 2
# CHECK-NEXT: reloff: 0x00000000
# CHECK-NEXT: nreloc: 0
# CHECK-NEXT: flags: 0x00000001
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: - sectname: __mod_init_func
# CHECK-NEXT: segname: __DATA
# CHECK-NEXT: addr: 0x0000000000000060
# CHECK-NEXT: size: 4
# CHECK-NEXT: offset: 0x00000280
# CHECK-NEXT: align: 2
# CHECK-NEXT: reloff: 0x00000334
# CHECK-NEXT: nreloc: 1
# CHECK-NEXT: flags: 0x00000009
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: content: '48000000'
# CHECK-NEXT: relocations:
# CHECK-NEXT: - address: 0x00000000
# CHECK-NEXT: symbolnum: 2
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 0
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
--- !mach-o
FileHeader:
magic: 0xFEEDFACE
cputype: 0x0000000C
cpusubtype: 0x00000009
filetype: 0x00000001
ncmds: 4
sizeofcmds: 516
flags: 0x00002000
LoadCommands:
- cmd: LC_SEGMENT
cmdsize: 396
segname: ''
vmaddr: 0
vmsize: 104
fileoff: 544
filesize: 100
maxprot: 7
initprot: 7
nsects: 5
flags: 0
Sections:
- sectname: __text
segname: __TEXT
addr: 0x0000000000000000
size: 36
offset: 0x00000220
align: 1
reloff: 0x00000284
nreloc: 8
flags: 0x80000400
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: 81B00020009040F24A00C0F200007844006840F24601C0F2000179440968084401B07047
relocations:
- address: 0x00000016
symbolnum: 0
pcrel: false
length: 3
extern: false
type: 9
scattered: true
value: 100
- address: 0x00000046
symbolnum: 0
pcrel: false
length: 3
extern: false
type: 1
scattered: true
value: 26
- address: 0x00000012
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 9
scattered: true
value: 100
- address: 0x00000000
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 1
scattered: true
value: 26
- address: 0x0000000A
symbolnum: 0
pcrel: false
length: 3
extern: false
type: 9
scattered: true
value: 92
- address: 0x0000004A
symbolnum: 0
pcrel: false
length: 3
extern: false
type: 1
scattered: true
value: 14
- address: 0x00000006
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 9
scattered: true
value: 92
- address: 0x00000000
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 1
scattered: true
value: 14
- sectname: __StaticInit
segname: __TEXT
addr: 0x0000000000000024
size: 46
offset: 0x00000244
align: 1
reloff: 0x000002C4
nreloc: 13
flags: 0x80000400
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: 40F22800C0F20000784440F21A01C0F200017944081A40F21E01C0F2000179440860704780B56F46FFF7EAFF80BD
relocations:
- address: 0x00000028
symbolnum: 2
pcrel: true
length: 2
extern: false
type: 6
scattered: false
value: 0
- address: 0x0000001A
symbolnum: 0
pcrel: false
length: 3
extern: false
type: 9
scattered: true
value: 100
- address: 0x0000001E
symbolnum: 0
pcrel: false
length: 3
extern: false
type: 1
scattered: true
value: 66
- address: 0x00000016
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 9
scattered: true
value: 100
- address: 0x00000000
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 1
scattered: true
value: 66
- address: 0x0000000E
symbolnum: 0
pcrel: false
length: 3
extern: false
type: 9
scattered: true
value: 84
- address: 0x0000001A
symbolnum: 0
pcrel: false
length: 3
extern: false
type: 1
scattered: true
value: 54
- address: 0x0000000A
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 9
scattered: true
value: 84
- address: 0x00000000
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 1
scattered: true
value: 54
- address: 0x00000004
symbolnum: 0
pcrel: false
length: 3
extern: false
type: 9
scattered: true
value: 88
- address: 0x00000028
symbolnum: 0
pcrel: false
length: 3
extern: false
type: 1
scattered: true
value: 44
- address: 0x00000000
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 9
scattered: true
value: 88
- address: 0x00000000
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 1
scattered: true
value: 44
- sectname: __data
segname: __DATA
addr: 0x0000000000000054
size: 12
offset: 0x00000274
align: 2
reloff: 0x0000032C
nreloc: 1
flags: 0x00000000
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: '010000000200000054000000'
relocations:
- address: 0x00000008
symbolnum: 3
pcrel: false
length: 2
extern: false
type: 0
scattered: false
value: 0
- sectname: __common
segname: __DATA
addr: 0x0000000000000064
size: 4
offset: 0x00000000
align: 2
reloff: 0x00000000
nreloc: 0
flags: 0x00000001
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
- sectname: __mod_init_func
segname: __DATA
addr: 0x0000000000000060
size: 4
offset: 0x00000280
align: 2
reloff: 0x00000334
nreloc: 1
flags: 0x00000009
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: '48000000'
relocations:
- address: 0x00000000
symbolnum: 2
pcrel: false
length: 2
extern: false
type: 0
scattered: false
value: 0
- cmd: LC_VERSION_MIN_IPHONEOS
cmdsize: 16
version: 589824
sdk: 0
- cmd: LC_SYMTAB
cmdsize: 24
symoff: 828
nsyms: 7
stroff: 912
strsize: 68
- cmd: LC_DYSYMTAB
cmdsize: 80
ilocalsym: 0
nlocalsym: 2
iextdefsym: 2
nextdefsym: 5
iundefsym: 7
nundefsym: 0
tocoff: 0
ntoc: 0
modtaboff: 0
nmodtab: 0
extrefsymoff: 0
nextrefsyms: 0
indirectsymoff: 0
nindirectsyms: 0
extreloff: 0
nextrel: 0
locreloff: 0
nlocrel: 0
LinkEditData:
NameList:
- n_strx: 13
n_type: 0x0E
n_sect: 2
n_desc: 8
n_value: 36
- n_strx: 36
n_type: 0x0E
n_sect: 2
n_desc: 8
n_value: 72
- n_strx: 61
n_type: 0x0F
n_sect: 1
n_desc: 8
n_value: 0
- n_strx: 10
n_type: 0x0F
n_sect: 4
n_desc: 0
n_value: 100
- n_strx: 7
n_type: 0x0F
n_sect: 3
n_desc: 0
n_value: 84
- n_strx: 4
n_type: 0x0F
n_sect: 3
n_desc: 0
n_value: 88
- n_strx: 1
n_type: 0x0F
n_sect: 3
n_desc: 0
n_value: 92
StringTable:
- ''
- _z
- _y
- _x
- _w
- ___cxx_global_var_init
- __GLOBAL__sub_I_main.cpp
- _main
- ''
...

View File

@ -0,0 +1,65 @@
# RUN: yaml2obj %s -o %t
# RUN: llvm-objdump --macho --reloc %t | FileCheck %s --check-prefix=OBJDUMP-VERIFY
# OBJDUMP-VERIFY-NOT: Relocation information
# RUN: obj2yaml %t | FileCheck %s
# CHECK: Sections:
# CHECK-NEXT: - sectname: __text
# CHECK-NEXT: segname: __TEXT
# CHECK-NEXT: addr: 0x0000000000000000
# CHECK-NEXT: size: 0
# CHECK-NEXT: offset: 0x000000C8
# CHECK-NEXT: align: 0
# CHECK-NEXT: reloff: 0x00000000
# CHECK-NEXT: nreloc: 0
# CHECK-NEXT: flags: 0x80000000
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: content: ''
# CHECK-NOT: relocations:
--- !mach-o
FileHeader:
magic: 0xFEEDFACF
cputype: 0x01000007
cpusubtype: 0x00000003
filetype: 0x00000001
ncmds: 2
sizeofcmds: 168
flags: 0x00002000
reserved: 0x00000000
LoadCommands:
- cmd: LC_SEGMENT_64
cmdsize: 152
segname: ''
vmaddr: 0
vmsize: 0
fileoff: 200
filesize: 0
maxprot: 7
initprot: 7
nsects: 1
flags: 0
Sections:
- sectname: __text
segname: __TEXT
addr: 0x0000000000000000
size: 0
offset: 0x000000C8
align: 0
reloff: 0x00000000
nreloc: 0
flags: 0x80000000
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: ''
relocations: []
- cmd: LC_VERSION_MIN_MACOSX
cmdsize: 16
version: 658944
sdk: 0
...

View File

@ -0,0 +1,777 @@
# RUN: yaml2obj %s -o %t
# RUN: llvm-objdump --macho --reloc %t | FileCheck %s --check-prefix=OBJDUMP-VERIFY
# OBJDUMP-VERIFY: Relocation information (__TEXT,__text) 8 entries
# OBJDUMP-VERIFY-NEXT: address pcrel length extern type scattered symbolnum/value
# OBJDUMP-VERIFY-NEXT: 00000030 False long n/a 11 True 0x00000144
# OBJDUMP-VERIFY-NEXT: 00000000 False long n/a 1 True 0x00000018
# OBJDUMP-VERIFY-NEXT: 0000002c False long n/a 12 True 0x00000144
# OBJDUMP-VERIFY-NEXT: 0000012c False long n/a 1 True 0x00000018
# OBJDUMP-VERIFY-NEXT: 00000028 False long n/a 11 True 0x000000d4
# OBJDUMP-VERIFY-NEXT: 00000000 False long n/a 1 True 0x00000018
# OBJDUMP-VERIFY-NEXT: 00000024 False long n/a 12 True 0x000000d4
# OBJDUMP-VERIFY-NEXT: 000000bc False long n/a 1 True 0x00000018
# OBJDUMP-VERIFY-NEXT: Relocation information (__TEXT,__StaticInit) 13 entries
# OBJDUMP-VERIFY-NEXT: address pcrel length extern type scattered symbolnum/value
# OBJDUMP-VERIFY-NEXT: 00000064 True long False 3 False 4 (__TEXT,__StaticInit)
# OBJDUMP-VERIFY-NEXT: 00000034 False long n/a 11 True 0x00000144
# OBJDUMP-VERIFY-NEXT: 00000000 False long n/a 1 True 0x00000068
# OBJDUMP-VERIFY-NEXT: 00000030 False long n/a 12 True 0x00000144
# OBJDUMP-VERIFY-NEXT: 000000dc False long n/a 1 True 0x00000068
# OBJDUMP-VERIFY-NEXT: 00000028 False long n/a 11 True 0x000000d0
# OBJDUMP-VERIFY-NEXT: 00000000 False long n/a 1 True 0x00000068
# OBJDUMP-VERIFY-NEXT: 00000024 False long n/a 12 True 0x000000d0
# OBJDUMP-VERIFY-NEXT: 00000068 False long n/a 1 True 0x00000068
# OBJDUMP-VERIFY-NEXT: 00000020 False long n/a 11 True 0x000000cc
# OBJDUMP-VERIFY-NEXT: 00000000 False long n/a 1 True 0x00000068
# OBJDUMP-VERIFY-NEXT: 0000001c False long n/a 12 True 0x000000cc
# OBJDUMP-VERIFY-NEXT: 00000064 False long n/a 1 True 0x00000068
# OBJDUMP-VERIFY-NEXT: Relocation information (__DATA,__data) 1 entries
# OBJDUMP-VERIFY-NEXT: address pcrel length extern type scattered symbolnum/value
# OBJDUMP-VERIFY-NEXT: 00000008 False long False 0 False 5 (__DATA,__data)
# OBJDUMP-VERIFY-NEXT: Relocation information (__DATA,__mod_init_func) 1 entries
# OBJDUMP-VERIFY-NEXT: address pcrel length extern type scattered symbolnum/value
# OBJDUMP-VERIFY-NEXT: 00000000 False long False 0 False 4 (__TEXT,__StaticInit)
# OBJDUMP-VERIFY-NEXT: Relocation information (__TEXT,__eh_frame) 3 entries
# OBJDUMP-VERIFY-NEXT: address pcrel length extern type scattered symbolnum/value
# OBJDUMP-VERIFY-NEXT: 00000054 False long n/a 0 True 0x000000a0
# OBJDUMP-VERIFY-NEXT: 00000038 False long n/a 0 True 0x00000000
# OBJDUMP-VERIFY-NEXT: 0000001c False long n/a 0 True 0x00000050
# RUN: obj2yaml %t | FileCheck %s
# CHECK: Sections:
# CHECK-NEXT: - sectname: __text
# CHECK-NEXT: segname: __TEXT
# CHECK-NEXT: addr: 0x0000000000000000
# CHECK-NEXT: size: 76
# CHECK-NEXT: offset: 0x000002EC
# CHECK-NEXT: align: 4
# CHECK-NEXT: reloff: 0x00000430
# CHECK-NEXT: nreloc: 8
# CHECK-NEXT: flags: 0x80000400
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: content:
# CHECK-NEXT: relocations:
# CHECK-NEXT: - address: 0x00000030
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 11
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 324
# CHECK-NEXT: - address: 0x00000000
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 1
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 24
# CHECK-NEXT: - address: 0x0000002C
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 12
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 324
# CHECK-NEXT: - address: 0x0000012C
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 1
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 24
# CHECK-NEXT: - address: 0x00000028
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 11
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 212
# CHECK-NEXT: - address: 0x00000000
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 1
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 24
# CHECK-NEXT: - address: 0x00000024
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 12
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 212
# CHECK-NEXT: - address: 0x000000BC
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 1
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 24
# CHECK-NEXT: - sectname: __textcoal_nt
# CHECK-NEXT: segname: __TEXT
# CHECK-NEXT: addr: 0x000000000000004C
# CHECK-NEXT: size: 0
# CHECK-NEXT: offset: 0x00000338
# CHECK-NEXT: align: 0
# CHECK-NEXT: reloff: 0x00000000
# CHECK-NEXT: nreloc: 0
# CHECK-NEXT: flags: 0x8000000B
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: content: ''
# CHECK-NEXT: - sectname: __picsymbolstub1
# CHECK-NEXT: segname: __TEXT
# CHECK-NEXT: addr: 0x000000000000004C
# CHECK-NEXT: size: 0
# CHECK-NEXT: offset: 0x00000338
# CHECK-NEXT: align: 0
# CHECK-NEXT: reloff: 0x00000000
# CHECK-NEXT: nreloc: 0
# CHECK-NEXT: flags: 0x80000008
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000020
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: content: ''
# CHECK-NEXT: - sectname: __StaticInit
# CHECK-NEXT: segname: __TEXT
# CHECK-NEXT: addr: 0x0000000000000050
# CHECK-NEXT: size: 124
# CHECK-NEXT: offset: 0x0000033C
# CHECK-NEXT: align: 4
# CHECK-NEXT: reloff: 0x00000470
# CHECK-NEXT: nreloc: 13
# CHECK-NEXT: flags: 0x80000400
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: content:
# CHECK-NEXT: relocations:
# CHECK-NEXT: - address: 0x00000064
# CHECK-NEXT: symbolnum: 4
# CHECK-NEXT: pcrel: true
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 3
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - address: 0x00000034
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 11
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 324
# CHECK-NEXT: - address: 0x00000000
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 1
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 104
# CHECK-NEXT: - address: 0x00000030
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 12
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 324
# CHECK-NEXT: - address: 0x000000DC
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 1
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 104
# CHECK-NEXT: - address: 0x00000028
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 11
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 208
# CHECK-NEXT: - address: 0x00000000
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 1
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 104
# CHECK-NEXT: - address: 0x00000024
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 12
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 208
# CHECK-NEXT: - address: 0x00000068
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 1
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 104
# CHECK-NEXT: - address: 0x00000020
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 11
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 204
# CHECK-NEXT: - address: 0x00000000
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 1
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 104
# CHECK-NEXT: - address: 0x0000001C
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 12
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 204
# CHECK-NEXT: - address: 0x00000064
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 1
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 104
# CHECK-NEXT: - sectname: __data
# CHECK-NEXT: segname: __DATA
# CHECK-NEXT: addr: 0x00000000000000CC
# CHECK-NEXT: size: 12
# CHECK-NEXT: offset: 0x000003B8
# CHECK-NEXT: align: 2
# CHECK-NEXT: reloff: 0x000004D8
# CHECK-NEXT: nreloc: 1
# CHECK-NEXT: flags: 0x00000000
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: content:
# CHECK-NEXT: relocations:
# CHECK-NEXT: - address: 0x00000008
# CHECK-NEXT: symbolnum: 5
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 0
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - sectname: __common
# CHECK-NEXT: segname: __DATA
# CHECK-NEXT: addr: 0x0000000000000144
# CHECK-NEXT: size: 4
# CHECK-NEXT: offset: 0x00000000
# CHECK-NEXT: align: 2
# CHECK-NEXT: reloff: 0x00000000
# CHECK-NEXT: nreloc: 0
# CHECK-NEXT: flags: 0x00000001
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: - sectname: __mod_init_func
# CHECK-NEXT: segname: __DATA
# CHECK-NEXT: addr: 0x00000000000000D8
# CHECK-NEXT: size: 4
# CHECK-NEXT: offset: 0x000003C4
# CHECK-NEXT: align: 2
# CHECK-NEXT: reloff: 0x000004E0
# CHECK-NEXT: nreloc: 1
# CHECK-NEXT: flags: 0x00000009
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: content: 000000A0
# CHECK-NEXT: relocations:
# CHECK-NEXT: - address: 0x00000000
# CHECK-NEXT: symbolnum: 4
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 0
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - sectname: __eh_frame
# CHECK-NEXT: segname: __TEXT
# CHECK-NEXT: addr: 0x00000000000000DC
# CHECK-NEXT: size: 104
# CHECK-NEXT: offset: 0x000003C8
# CHECK-NEXT: align: 2
# CHECK-NEXT: reloff: 0x000004E8
# CHECK-NEXT: nreloc: 3
# CHECK-NEXT: flags: 0x6800000B
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: content:
# CHECK-NEXT: relocations:
# CHECK-NEXT: - address: 0x00000054
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 0
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 160
# CHECK-NEXT: - address: 0x00000038
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 0
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 0
# CHECK-NEXT: - address: 0x0000001C
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 0
# CHECK-NEXT: scattered: true
# CHECK-NEXT: value: 80
--- !mach-o
IsLittleEndian: false
FileHeader:
magic: 0xFEEDFACE
cputype: 0x00000012
cpusubtype: 0x00000000
filetype: 0x00000001
ncmds: 4
sizeofcmds: 720
flags: 0x00002000
LoadCommands:
- cmd: LC_SEGMENT
cmdsize: 600
segname: ''
vmaddr: 0
vmsize: 328
fileoff: 748
filesize: 324
maxprot: 7
initprot: 7
nsects: 8
flags: 0
Sections:
- sectname: __text
segname: __TEXT
addr: 0x0000000000000000
size: 76
offset: 0x000002EC
align: 4
reloff: 0x00000430
nreloc: 8
flags: 0x80000400
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: 7C0802A693E1FFFC900100089421FFE07C3F0B78480000057C4802A638600000907F00183C620000806300BC3C4200008042012C7C631214382100208001000883E1FFFC7C0803A64E800020
relocations:
- address: 0x00000030
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 11
scattered: true
value: 324
- address: 0x00000000
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 1
scattered: true
value: 24
- address: 0x0000002C
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 12
scattered: true
value: 324
- address: 0x0000012C
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 1
scattered: true
value: 24
- address: 0x00000028
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 11
scattered: true
value: 212
- address: 0x00000000
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 1
scattered: true
value: 24
- address: 0x00000024
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 12
scattered: true
value: 212
- address: 0x000000BC
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 1
scattered: true
value: 24
- sectname: __textcoal_nt
segname: __TEXT
addr: 0x000000000000004C
size: 0
offset: 0x00000338
align: 0
reloff: 0x00000000
nreloc: 0
flags: 0x8000000B
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: ''
- sectname: __picsymbolstub1
segname: __TEXT
addr: 0x000000000000004C
size: 0
offset: 0x00000338
align: 0
reloff: 0x00000000
nreloc: 0
flags: 0x80000008
reserved1: 0x00000000
reserved2: 0x00000020
reserved3: 0x00000000
content: ''
- sectname: __StaticInit
segname: __TEXT
addr: 0x0000000000000050
size: 124
offset: 0x0000033C
align: 4
reloff: 0x00000470
nreloc: 13
flags: 0x80000400
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: 7C0802A693E1FFFC900100089421FFE07C3F0B78480000057C4802A63C620000386300643C820000388400687C6418503C420000906200DC382100208001000883E1FFFC7C0803A64E800020600000007C0802A693E1FFFC900100089421FFC07C3F0B784BFFFF9D382100408001000883E1FFFC7C0803A64E800020
relocations:
- address: 0x00000064
symbolnum: 4
pcrel: true
length: 2
extern: false
type: 3
scattered: false
value: 0
- address: 0x00000034
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 11
scattered: true
value: 324
- address: 0x00000000
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 1
scattered: true
value: 104
- address: 0x00000030
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 12
scattered: true
value: 324
- address: 0x000000DC
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 1
scattered: true
value: 104
- address: 0x00000028
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 11
scattered: true
value: 208
- address: 0x00000000
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 1
scattered: true
value: 104
- address: 0x00000024
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 12
scattered: true
value: 208
- address: 0x00000068
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 1
scattered: true
value: 104
- address: 0x00000020
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 11
scattered: true
value: 204
- address: 0x00000000
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 1
scattered: true
value: 104
- address: 0x0000001C
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 12
scattered: true
value: 204
- address: 0x00000064
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 1
scattered: true
value: 104
- sectname: __data
segname: __DATA
addr: 0x00000000000000CC
size: 12
offset: 0x000003B8
align: 2
reloff: 0x000004D8
nreloc: 1
flags: 0x00000000
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: 0000000100000002000000CC
relocations:
- address: 0x00000008
symbolnum: 5
pcrel: false
length: 2
extern: false
type: 0
scattered: false
value: 0
- sectname: __common
segname: __DATA
addr: 0x0000000000000144
size: 4
offset: 0x00000000
align: 2
reloff: 0x00000000
nreloc: 0
flags: 0x00000001
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
- sectname: __mod_init_func
segname: __DATA
addr: 0x00000000000000D8
size: 4
offset: 0x000003C4
align: 2
reloff: 0x000004E0
nreloc: 1
flags: 0x00000009
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: 000000A0
relocations:
- address: 0x00000000
symbolnum: 4
pcrel: false
length: 2
extern: false
type: 0
scattered: false
value: 0
- sectname: __eh_frame
segname: __TEXT
addr: 0x00000000000000DC
size: 104
offset: 0x000003C8
align: 2
reloff: 0x000004E8
nreloc: 3
flags: 0x6800000B
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: 0000001000000000017A5200017C4101100C01000000001800000018FFFFFF580000004C00500E209F0111417E440D1F0000001800000034FFFFFEEC0000004C00500E209F0111417E440D1F0000001800000050FFFFFF700000002C00500E409F0111417E440D1F
relocations:
- address: 0x00000054
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 0
scattered: true
value: 160
- address: 0x00000038
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 0
scattered: true
value: 0
- address: 0x0000001C
symbolnum: 0
pcrel: false
length: 2
extern: false
type: 0
scattered: true
value: 80
- cmd: LC_VERSION_MIN_MACOSX
cmdsize: 16
version: 656384
sdk: 0
- cmd: LC_SYMTAB
cmdsize: 24
symoff: 1280
nsyms: 7
stroff: 1364
strsize: 68
- cmd: LC_DYSYMTAB
cmdsize: 80
ilocalsym: 0
nlocalsym: 2
iextdefsym: 2
nextdefsym: 5
iundefsym: 7
nundefsym: 0
tocoff: 0
ntoc: 0
modtaboff: 0
nmodtab: 0
extrefsymoff: 0
nextrefsyms: 0
indirectsymoff: 0
nindirectsyms: 0
extreloff: 0
nextrel: 0
locreloff: 0
nlocrel: 0
LinkEditData:
NameList:
- n_strx: 13
n_type: 0x0E
n_sect: 4
n_desc: 0
n_value: 80
- n_strx: 36
n_type: 0x0E
n_sect: 4
n_desc: 0
n_value: 160
- n_strx: 61
n_type: 0x0F
n_sect: 1
n_desc: 0
n_value: 0
- n_strx: 10
n_type: 0x0F
n_sect: 6
n_desc: 0
n_value: 324
- n_strx: 7
n_type: 0x0F
n_sect: 5
n_desc: 0
n_value: 204
- n_strx: 4
n_type: 0x0F
n_sect: 5
n_desc: 0
n_value: 208
- n_strx: 1
n_type: 0x0F
n_sect: 5
n_desc: 0
n_value: 212
StringTable:
- ''
- _z
- _y
- _x
- _w
- ___cxx_global_var_init
- __GLOBAL__sub_I_main.cpp
- _main
- ''
...

View File

@ -0,0 +1,494 @@
# RUN: yaml2obj %s -o %t
# RUN: llvm-objdump --macho --reloc %t | FileCheck %s --check-prefix=OBJDUMP-VERIFY
# OBJDUMP-VERIFY: Relocation information (__TEXT,__text) 2 entries
# OBJDUMP-VERIFY-NEXT: address pcrel length extern type scattered symbolnum/value
# OBJDUMP-VERIFY-NEXT: 00000015 True long True SIGNED False _w
# OBJDUMP-VERIFY-NEXT: 0000000e True long True SIGNED False _z
# OBJDUMP-VERIFY-NEXT: Relocation information (__TEXT,__StaticInit) 4 entries
# OBJDUMP-VERIFY-NEXT: address pcrel length extern type scattered symbolnum/value
# OBJDUMP-VERIFY-NEXT: 00000025 True long True BRANCH False ___cxx_global_var_init
# OBJDUMP-VERIFY-NEXT: 00000018 True long True SIGNED False _w
# OBJDUMP-VERIFY-NEXT: 0000000e True long True SIGNED False _x
# OBJDUMP-VERIFY-NEXT: 00000007 True long True SIGNED False _y
# OBJDUMP-VERIFY-NEXT: Relocation information (__DATA,__data) 1 entries
# OBJDUMP-VERIFY-NEXT: address pcrel length extern type scattered symbolnum/value
# OBJDUMP-VERIFY-NEXT: 00000008 False quad True UNSIGND False _x
# OBJDUMP-VERIFY-NEXT: Relocation information (__DATA,__mod_init_func) 1 entries
# OBJDUMP-VERIFY-NEXT: address pcrel length extern type scattered symbolnum/value
# OBJDUMP-VERIFY-NEXT: 00000000 False quad True UNSIGND False __GLOBAL__sub_I_main.cpp
# OBJDUMP-VERIFY-NEXT: Relocation information (__LD,__compact_unwind) 3 entries
# OBJDUMP-VERIFY-NEXT: address pcrel length extern type scattered symbolnum/value
# OBJDUMP-VERIFY-NEXT: 00000040 False quad False UNSIGND False 2 (__TEXT,__StaticInit)
# OBJDUMP-VERIFY-NEXT: 00000020 False quad False UNSIGND False 1 (__TEXT,__text)
# OBJDUMP-VERIFY-NEXT: 00000000 False quad False UNSIGND False 2 (__TEXT,__StaticInit)
# RUN: obj2yaml %t | FileCheck %s
# CHECK: Sections:
# CHECK-NEXT: - sectname: __text
# CHECK-NEXT: segname: __TEXT
# CHECK-NEXT: addr: 0x0000000000000000
# CHECK-NEXT: size: 27
# CHECK-NEXT: offset: 0x00000310
# CHECK-NEXT: align: 4
# CHECK-NEXT: reloff: 0x00000468
# CHECK-NEXT: nreloc: 2
# CHECK-NEXT: flags: 0x80000400
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: content:
# CHECK-NEXT: relocations:
# CHECK-NEXT: - address: 0x00000015
# CHECK-NEXT: symbolnum: 3
# CHECK-NEXT: pcrel: true
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: true
# CHECK-NEXT: type: 1
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - address: 0x0000000E
# CHECK-NEXT: symbolnum: 6
# CHECK-NEXT: pcrel: true
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: true
# CHECK-NEXT: type: 1
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - sectname: __StaticInit
# CHECK-NEXT: segname: __TEXT
# CHECK-NEXT: addr: 0x0000000000000020
# CHECK-NEXT: size: 43
# CHECK-NEXT: offset: 0x00000330
# CHECK-NEXT: align: 4
# CHECK-NEXT: reloff: 0x00000478
# CHECK-NEXT: nreloc: 4
# CHECK-NEXT: flags: 0x80000400
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: content:
# CHECK-NEXT: relocations:
# CHECK-NEXT: - address: 0x00000025
# CHECK-NEXT: symbolnum: 0
# CHECK-NEXT: pcrel: true
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: true
# CHECK-NEXT: type: 2
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - address: 0x00000018
# CHECK-NEXT: symbolnum: 3
# CHECK-NEXT: pcrel: true
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: true
# CHECK-NEXT: type: 1
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - address: 0x0000000E
# CHECK-NEXT: symbolnum: 4
# CHECK-NEXT: pcrel: true
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: true
# CHECK-NEXT: type: 1
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - address: 0x00000007
# CHECK-NEXT: symbolnum: 5
# CHECK-NEXT: pcrel: true
# CHECK-NEXT: length: 2
# CHECK-NEXT: extern: true
# CHECK-NEXT: type: 1
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - sectname: __data
# CHECK-NEXT: segname: __DATA
# CHECK-NEXT: addr: 0x0000000000000050
# CHECK-NEXT: size: 16
# CHECK-NEXT: offset: 0x00000360
# CHECK-NEXT: align: 3
# CHECK-NEXT: reloff: 0x00000498
# CHECK-NEXT: nreloc: 1
# CHECK-NEXT: flags: 0x00000000
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: content: '01000000020000000000000000000000'
# CHECK-NEXT: relocations:
# CHECK-NEXT: - address: 0x00000008
# CHECK-NEXT: symbolnum: 4
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 3
# CHECK-NEXT: extern: true
# CHECK-NEXT: type: 0
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - sectname: __common
# CHECK-NEXT: segname: __DATA
# CHECK-NEXT: addr: 0x0000000000000158
# CHECK-NEXT: size: 8
# CHECK-NEXT: offset: 0x00000000
# CHECK-NEXT: align: 3
# CHECK-NEXT: reloff: 0x00000000
# CHECK-NEXT: nreloc: 0
# CHECK-NEXT: flags: 0x00000001
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: - sectname: __mod_init_func
# CHECK-NEXT: segname: __DATA
# CHECK-NEXT: addr: 0x0000000000000060
# CHECK-NEXT: size: 8
# CHECK-NEXT: offset: 0x00000370
# CHECK-NEXT: align: 3
# CHECK-NEXT: reloff: 0x000004A0
# CHECK-NEXT: nreloc: 1
# CHECK-NEXT: flags: 0x00000009
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: content:
# CHECK-NEXT: relocations:
# CHECK-NEXT: - address: 0x00000000
# CHECK-NEXT: symbolnum: 1
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 3
# CHECK-NEXT: extern: true
# CHECK-NEXT: type: 0
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - sectname: __compact_unwind
# CHECK-NEXT: segname: __LD
# CHECK-NEXT: addr: 0x0000000000000068
# CHECK-NEXT: size: 96
# CHECK-NEXT: offset: 0x00000378
# CHECK-NEXT: align: 3
# CHECK-NEXT: reloff: 0x000004A8
# CHECK-NEXT: nreloc: 3
# CHECK-NEXT: flags: 0x02000000
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
# CHECK-NEXT: content:
# CHECK-NEXT: relocations:
# CHECK-NEXT: - address: 0x00000040
# CHECK-NEXT: symbolnum: 2
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 3
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 0
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - address: 0x00000020
# CHECK-NEXT: symbolnum: 1
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 3
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 0
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - address: 0x00000000
# CHECK-NEXT: symbolnum: 2
# CHECK-NEXT: pcrel: false
# CHECK-NEXT: length: 3
# CHECK-NEXT: extern: false
# CHECK-NEXT: type: 0
# CHECK-NEXT: scattered: false
# CHECK-NEXT: value: 0
# CHECK-NEXT: - sectname: __eh_frame
# CHECK-NEXT: segname: __TEXT
# CHECK-NEXT: addr: 0x00000000000000C8
# CHECK-NEXT: size: 144
# CHECK-NEXT: offset: 0x000003D8
# CHECK-NEXT: align: 3
# CHECK-NEXT: reloff: 0x00000000
# CHECK-NEXT: nreloc: 0
# CHECK-NEXT: flags: 0x6800000B
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
# CHECK-NEXT: reserved3: 0x00000000
--- !mach-o
FileHeader:
magic: 0xFEEDFACF
cputype: 0x01000007
cpusubtype: 0x00000003
filetype: 0x00000001
ncmds: 4
sizeofcmds: 752
flags: 0x00002000
reserved: 0x00000000
LoadCommands:
- cmd: LC_SEGMENT_64
cmdsize: 632
segname: ''
vmaddr: 0
vmsize: 352
fileoff: 784
filesize: 344
maxprot: 7
initprot: 7
nsects: 7
flags: 0
Sections:
- sectname: __text
segname: __TEXT
addr: 0x0000000000000000
size: 27
offset: 0x00000310
align: 4
reloff: 0x00000468
nreloc: 2
flags: 0x80000400
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: 554889E5C745FC00000000488B0500000000480305000000005DC3
relocations:
- address: 0x00000015
symbolnum: 3
pcrel: true
length: 2
extern: true
type: 1
scattered: false
value: 0
- address: 0x0000000E
symbolnum: 6
pcrel: true
length: 2
extern: true
type: 1
scattered: false
value: 0
- sectname: __StaticInit
segname: __TEXT
addr: 0x0000000000000020
size: 43
offset: 0x00000330
align: 4
reloff: 0x00000478
nreloc: 4
flags: 0x80000400
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: 554889E5488D0500000000488D0D000000004829C148890D000000005DC36690554889E5E8000000005DC3
relocations:
- address: 0x00000025
symbolnum: 0
pcrel: true
length: 2
extern: true
type: 2
scattered: false
value: 0
- address: 0x00000018
symbolnum: 3
pcrel: true
length: 2
extern: true
type: 1
scattered: false
value: 0
- address: 0x0000000E
symbolnum: 4
pcrel: true
length: 2
extern: true
type: 1
scattered: false
value: 0
- address: 0x00000007
symbolnum: 5
pcrel: true
length: 2
extern: true
type: 1
scattered: false
value: 0
- sectname: __data
segname: __DATA
addr: 0x0000000000000050
size: 16
offset: 0x00000360
align: 3
reloff: 0x00000498
nreloc: 1
flags: 0x00000000
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: '01000000020000000000000000000000'
relocations:
- address: 0x00000008
symbolnum: 4
pcrel: false
length: 3
extern: true
type: 0
scattered: false
value: 0
- sectname: __common
segname: __DATA
addr: 0x0000000000000158
size: 8
offset: 0x00000000
align: 3
reloff: 0x00000000
nreloc: 0
flags: 0x00000001
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
- sectname: __mod_init_func
segname: __DATA
addr: 0x0000000000000060
size: 8
offset: 0x00000370
align: 3
reloff: 0x000004A0
nreloc: 1
flags: 0x00000009
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: '0000000000000000'
relocations:
- address: 0x00000000
symbolnum: 1
pcrel: false
length: 3
extern: true
type: 0
scattered: false
value: 0
- sectname: __compact_unwind
segname: __LD
addr: 0x0000000000000068
size: 96
offset: 0x00000378
align: 3
reloff: 0x000004A8
nreloc: 3
flags: 0x02000000
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: 20000000000000001E000000000000010000000000000000000000000000000000000000000000001B000000000000010000000000000000000000000000000040000000000000000B0000000000000100000000000000000000000000000000
relocations:
- address: 0x00000040
symbolnum: 2
pcrel: false
length: 3
extern: false
type: 0
scattered: false
value: 0
- address: 0x00000020
symbolnum: 1
pcrel: false
length: 3
extern: false
type: 0
scattered: false
value: 0
- address: 0x00000000
symbolnum: 2
pcrel: false
length: 3
extern: false
type: 0
scattered: false
value: 0
- sectname: __eh_frame
segname: __TEXT
addr: 0x00000000000000C8
size: 144
offset: 0x000003D8
align: 3
reloff: 0x00000000
nreloc: 0
flags: 0x6800000B
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
content: 1400000000000000017A520001781001100C070890010000240000001C00000038FFFFFFFFFFFFFF1E0000000000000000410E108602430D06000000000000002400000044000000F0FEFFFFFFFFFFFF1B0000000000000000410E108602430D0600000000000000240000006C00000008FFFFFFFFFFFFFF0B0000000000000000410E108602430D0600000000000000
- cmd: LC_VERSION_MIN_MACOSX
cmdsize: 16
version: 658944
sdk: 0
- cmd: LC_SYMTAB
cmdsize: 24
symoff: 1216
nsyms: 7
stroff: 1328
strsize: 68
- cmd: LC_DYSYMTAB
cmdsize: 80
ilocalsym: 0
nlocalsym: 2
iextdefsym: 2
nextdefsym: 5
iundefsym: 7
nundefsym: 0
tocoff: 0
ntoc: 0
modtaboff: 0
nmodtab: 0
extrefsymoff: 0
nextrefsyms: 0
indirectsymoff: 0
nindirectsyms: 0
extreloff: 0
nextrel: 0
locreloff: 0
nlocrel: 0
LinkEditData:
NameList:
- n_strx: 13
n_type: 0x0E
n_sect: 2
n_desc: 0
n_value: 32
- n_strx: 36
n_type: 0x0E
n_sect: 2
n_desc: 0
n_value: 64
- n_strx: 61
n_type: 0x0F
n_sect: 1
n_desc: 0
n_value: 0
- n_strx: 10
n_type: 0x0F
n_sect: 4
n_desc: 0
n_value: 344
- n_strx: 7
n_type: 0x0F
n_sect: 3
n_desc: 0
n_value: 80
- n_strx: 4
n_type: 0x0F
n_sect: 3
n_desc: 0
n_value: 84
- n_strx: 1
n_type: 0x0F
n_sect: 3
n_desc: 0
n_value: 88
StringTable:
- ''
- _z
- _y
- _x
- _w
- ___cxx_global_var_init
- __GLOBAL__sub_I_main.cpp
- _main
- ''
...

View File

@ -29,7 +29,7 @@ LoadCommands:
offset: 0x000002B0
align: 4
reloff: 0x00000350
nreloc: 7
nreloc: 0
flags: 0x80000400
reserved1: 0x00000000
reserved2: 0x00000000
@ -77,7 +77,7 @@ LoadCommands:
offset: 0x000002FC
align: 0
reloff: 0x00000388
nreloc: 2
nreloc: 0
flags: 0x00000013
reserved1: 0x00000000
reserved2: 0x00000000
@ -170,7 +170,7 @@ LinkEditData:
# CHECK-NEXT: offset: 0x000002B0
# CHECK-NEXT: align: 4
# CHECK-NEXT: reloff: 0x00000350
# CHECK-NEXT: nreloc: 7
# CHECK-NEXT: nreloc: 0
# CHECK-NEXT: flags: 0x80000400
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000
@ -220,7 +220,7 @@ LinkEditData:
# CHECK-NEXT: offset: 0x000002FC
# CHECK-NEXT: align: 0
# CHECK-NEXT: reloff: 0x00000388
# CHECK-NEXT: nreloc: 2
# CHECK-NEXT: nreloc: 0
# CHECK-NEXT: flags: 0x00000013
# CHECK-NEXT: reserved1: 0x00000000
# CHECK-NEXT: reserved2: 0x00000000

View File

@ -21,13 +21,13 @@ using namespace llvm;
class MachODumper {
template <typename StructType>
const char *processLoadCommandData(
Expected<const char *> processLoadCommandData(
MachOYAML::LoadCommand &LC,
const llvm::object::MachOObjectFile::LoadCommandInfo &LoadCmd);
const object::MachOObjectFile &Obj;
void dumpHeader(std::unique_ptr<MachOYAML::Object> &Y);
void dumpLoadCommands(std::unique_ptr<MachOYAML::Object> &Y);
Error dumpLoadCommands(std::unique_ptr<MachOYAML::Object> &Y);
void dumpLinkEdit(std::unique_ptr<MachOYAML::Object> &Y);
void dumpRebaseOpcodes(std::unique_ptr<MachOYAML::Object> &Y);
void dumpBindOpcodes(std::vector<MachOYAML::BindOpcode> &BindOpcodes,
@ -40,11 +40,13 @@ class MachODumper {
std::unique_ptr<MachOYAML::Object> &Y);
template <typename SectionType>
MachOYAML::Section constructSectionCommon(SectionType Sec);
Expected<MachOYAML::Section> constructSectionCommon(SectionType Sec,
size_t SecIndex);
template <typename SectionType>
MachOYAML::Section constructSection(SectionType Sec);
Expected<MachOYAML::Section> constructSection(SectionType Sec,
size_t SecIndex);
template <typename SectionType, typename SegmentType>
const char *
Expected<const char *>
extractSections(const llvm::object::MachOObjectFile::LoadCommandInfo &LoadCmd,
std::vector<MachOYAML::Section> &Sections);
@ -59,11 +61,16 @@ public:
sizeof(MachO::LCStruct)); \
if (Obj.isLittleEndian() != sys::IsLittleEndianHost) \
MachO::swapStruct(LC.Data.LCStruct##_data); \
EndPtr = processLoadCommandData<MachO::LCStruct>(LC, LoadCmd); \
if (Expected<const char *> ExpectedEndPtr = \
processLoadCommandData<MachO::LCStruct>(LC, LoadCmd)) \
EndPtr = *ExpectedEndPtr; \
else \
return ExpectedEndPtr.takeError(); \
break;
template <typename SectionType>
MachOYAML::Section MachODumper::constructSectionCommon(SectionType Sec) {
Expected<MachOYAML::Section>
MachODumper::constructSectionCommon(SectionType Sec, size_t SecIndex) {
MachOYAML::Section TempSec;
memcpy(reinterpret_cast<void *>(&TempSec.sectname[0]), &Sec.sectname[0], 16);
memcpy(reinterpret_cast<void *>(&TempSec.segname[0]), &Sec.segname[0], 16);
@ -80,52 +87,80 @@ MachOYAML::Section MachODumper::constructSectionCommon(SectionType Sec) {
if (!MachO::isVirtualSection(Sec.flags & MachO::SECTION_TYPE))
TempSec.content =
yaml::BinaryRef(Obj.getSectionContents(Sec.offset, Sec.size));
if (Expected<object::SectionRef> SecRef = Obj.getSection(SecIndex)) {
TempSec.relocations.reserve(TempSec.nreloc);
for (const object::RelocationRef &Reloc : SecRef->relocations()) {
const object::DataRefImpl Rel = Reloc.getRawDataRefImpl();
const MachO::any_relocation_info RE = Obj.getRelocation(Rel);
MachOYAML::Relocation R;
R.address = Obj.getAnyRelocationAddress(RE);
R.is_pcrel = Obj.getAnyRelocationPCRel(RE);
R.length = Obj.getAnyRelocationLength(RE);
R.type = Obj.getAnyRelocationType(RE);
R.is_scattered = Obj.isRelocationScattered(RE);
R.symbolnum = (R.is_scattered ? 0 : Obj.getPlainRelocationSymbolNum(RE));
R.is_extern =
(R.is_scattered ? false : Obj.getPlainRelocationExternal(RE));
R.value = (R.is_scattered ? Obj.getScatteredRelocationValue(RE) : 0);
TempSec.relocations.push_back(R);
}
} else {
return SecRef.takeError();
}
return TempSec;
}
template <>
MachOYAML::Section MachODumper::constructSection(MachO::section Sec) {
MachOYAML::Section TempSec = constructSectionCommon(Sec);
TempSec.reserved3 = 0;
Expected<MachOYAML::Section> MachODumper::constructSection(MachO::section Sec,
size_t SecIndex) {
Expected<MachOYAML::Section> TempSec = constructSectionCommon(Sec, SecIndex);
if (TempSec)
TempSec->reserved3 = 0;
return TempSec;
}
template <>
MachOYAML::Section MachODumper::constructSection(MachO::section_64 Sec) {
MachOYAML::Section TempSec = constructSectionCommon(Sec);
TempSec.reserved3 = Sec.reserved3;
Expected<MachOYAML::Section>
MachODumper::constructSection(MachO::section_64 Sec, size_t SecIndex) {
Expected<MachOYAML::Section> TempSec = constructSectionCommon(Sec, SecIndex);
if (TempSec)
TempSec->reserved3 = Sec.reserved3;
return TempSec;
}
template <typename SectionType, typename SegmentType>
const char *MachODumper::extractSections(
Expected<const char *> MachODumper::extractSections(
const llvm::object::MachOObjectFile::LoadCommandInfo &LoadCmd,
std::vector<MachOYAML::Section> &Sections) {
auto End = LoadCmd.Ptr + LoadCmd.C.cmdsize;
const SectionType *Curr =
reinterpret_cast<const SectionType *>(LoadCmd.Ptr + sizeof(SegmentType));
for (; reinterpret_cast<const void *>(Curr) < End; Curr++) {
if (Obj.isLittleEndian() != sys::IsLittleEndianHost) {
SectionType Sec;
memcpy((void *)&Sec, Curr, sizeof(SectionType));
if (Obj.isLittleEndian() != sys::IsLittleEndianHost)
MachO::swapStruct(Sec);
Sections.push_back(constructSection(Sec));
} else {
Sections.push_back(constructSection(*Curr));
}
// For MachO section indices start from 1.
if (Expected<MachOYAML::Section> S =
constructSection(Sec, Sections.size() + 1))
Sections.push_back(std::move(*S));
else
return S.takeError();
}
return reinterpret_cast<const char *>(Curr);
}
template <typename StructType>
const char *MachODumper::processLoadCommandData(
Expected<const char *> MachODumper::processLoadCommandData(
MachOYAML::LoadCommand &LC,
const llvm::object::MachOObjectFile::LoadCommandInfo &LoadCmd) {
return LoadCmd.Ptr + sizeof(StructType);
}
template <>
const char *MachODumper::processLoadCommandData<MachO::segment_command>(
Expected<const char *>
MachODumper::processLoadCommandData<MachO::segment_command>(
MachOYAML::LoadCommand &LC,
const llvm::object::MachOObjectFile::LoadCommandInfo &LoadCmd) {
return extractSections<MachO::section, MachO::segment_command>(LoadCmd,
@ -133,7 +168,8 @@ const char *MachODumper::processLoadCommandData<MachO::segment_command>(
}
template <>
const char *MachODumper::processLoadCommandData<MachO::segment_command_64>(
Expected<const char *>
MachODumper::processLoadCommandData<MachO::segment_command_64>(
MachOYAML::LoadCommand &LC,
const llvm::object::MachOObjectFile::LoadCommandInfo &LoadCmd) {
return extractSections<MachO::section_64, MachO::segment_command_64>(
@ -152,28 +188,32 @@ readString(MachOYAML::LoadCommand &LC,
}
template <>
const char *MachODumper::processLoadCommandData<MachO::dylib_command>(
Expected<const char *>
MachODumper::processLoadCommandData<MachO::dylib_command>(
MachOYAML::LoadCommand &LC,
const llvm::object::MachOObjectFile::LoadCommandInfo &LoadCmd) {
return readString<MachO::dylib_command>(LC, LoadCmd);
}
template <>
const char *MachODumper::processLoadCommandData<MachO::dylinker_command>(
Expected<const char *>
MachODumper::processLoadCommandData<MachO::dylinker_command>(
MachOYAML::LoadCommand &LC,
const llvm::object::MachOObjectFile::LoadCommandInfo &LoadCmd) {
return readString<MachO::dylinker_command>(LC, LoadCmd);
}
template <>
const char *MachODumper::processLoadCommandData<MachO::rpath_command>(
Expected<const char *>
MachODumper::processLoadCommandData<MachO::rpath_command>(
MachOYAML::LoadCommand &LC,
const llvm::object::MachOObjectFile::LoadCommandInfo &LoadCmd) {
return readString<MachO::rpath_command>(LC, LoadCmd);
}
template <>
const char *MachODumper::processLoadCommandData<MachO::build_version_command>(
Expected<const char *>
MachODumper::processLoadCommandData<MachO::build_version_command>(
MachOYAML::LoadCommand &LC,
const llvm::object::MachOObjectFile::LoadCommandInfo &LoadCmd) {
auto Start = LoadCmd.Ptr + sizeof(MachO::build_version_command);
@ -193,7 +233,8 @@ Expected<std::unique_ptr<MachOYAML::Object>> MachODumper::dump() {
auto Y = std::make_unique<MachOYAML::Object>();
Y->IsLittleEndian = Obj.isLittleEndian();
dumpHeader(Y);
dumpLoadCommands(Y);
if (Error Err = dumpLoadCommands(Y))
return std::move(Err);
dumpLinkEdit(Y);
std::unique_ptr<DWARFContext> DICtx = DWARFContext::create(Obj);
@ -213,7 +254,7 @@ void MachODumper::dumpHeader(std::unique_ptr<MachOYAML::Object> &Y) {
Y->Header.reserved = 0;
}
void MachODumper::dumpLoadCommands(std::unique_ptr<MachOYAML::Object> &Y) {
Error MachODumper::dumpLoadCommands(std::unique_ptr<MachOYAML::Object> &Y) {
for (auto LoadCmd : Obj.load_commands()) {
MachOYAML::LoadCommand LC;
const char *EndPtr = LoadCmd.Ptr;
@ -223,7 +264,11 @@ void MachODumper::dumpLoadCommands(std::unique_ptr<MachOYAML::Object> &Y) {
sizeof(MachO::load_command));
if (Obj.isLittleEndian() != sys::IsLittleEndianHost)
MachO::swapStruct(LC.Data.load_command_data);
EndPtr = processLoadCommandData<MachO::load_command>(LC, LoadCmd);
if (Expected<const char *> ExpectedEndPtr =
processLoadCommandData<MachO::load_command>(LC, LoadCmd))
EndPtr = *ExpectedEndPtr;
else
return ExpectedEndPtr.takeError();
break;
#include "llvm/BinaryFormat/MachO.def"
}
@ -237,6 +282,7 @@ void MachODumper::dumpLoadCommands(std::unique_ptr<MachOYAML::Object> &Y) {
LC.ZeroPadBytes = RemainingBytes;
Y->LoadCommands.push_back(std::move(LC));
}
return Error::success();
}
void MachODumper::dumpLinkEdit(std::unique_ptr<MachOYAML::Object> &Y) {