Skip to content

Commit

Permalink
[ObjectYAML] MachO support for endianness
Browse files Browse the repository at this point in the history
This patch adds support to the macho<->yaml tools for preserving endianness in MachO structures and DWARF data.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290381 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Chris Bieneman committed Dec 22, 2016
1 parent 981855c commit 5e76a3f
Show file tree
Hide file tree
Showing 11 changed files with 1,317 additions and 89 deletions.
1 change: 1 addition & 0 deletions include/llvm/ObjectYAML/DWARFYAML.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ struct PubSection {
};

struct Data {
bool IsLittleEndian;
std::vector<Abbrev> AbbrevDecls;
std::vector<StringRef> DebugStrings;
std::vector<ARange> ARanges;
Expand Down
1 change: 1 addition & 0 deletions include/llvm/ObjectYAML/MachOYAML.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ struct LinkEditData {
};

struct Object {
bool IsLittleEndian;
FileHeader Header;
std::vector<LoadCommand> LoadCommands;
std::vector<Section> Sections;
Expand Down
5 changes: 5 additions & 0 deletions lib/ObjectYAML/MachOYAML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "llvm/ObjectYAML/MachOYAML.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/MachO.h"

#include <string.h> // For memcpy, memset and strnlen.
Expand Down Expand Up @@ -100,6 +101,10 @@ void MappingTraits<MachOYAML::Object>::mapping(IO &IO,
IO.setContext(&Object);
}
IO.mapTag("!mach-o", true);
IO.mapOptional("IsLittleEndian", Object.IsLittleEndian,
sys::IsLittleEndianHost);
Object.DWARF.IsLittleEndian = Object.IsLittleEndian;

IO.mapRequired("FileHeader", Object.Header);
IO.mapOptional("LoadCommands", Object.LoadCommands);
if(!Object.LinkEdit.isEmpty() || !IO.outputting())
Expand Down
100 changes: 100 additions & 0 deletions test/ObjectYAML/MachO/BigEndian.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# RUN: yaml2obj %s | obj2yaml | FileCheck %s

--- !mach-o
IsLittleEndian: false
FileHeader:
magic: 0xFEEDFACE
cputype: 0x00000012
cpusubtype: 0x00000000
filetype: 0x00000001
ncmds: 3
sizeofcmds: 368
flags: 0x00002000
LoadCommands:
- cmd: LC_SEGMENT
cmdsize: 328
segname: ''
vmaddr: 0
vmsize: 236
fileoff: 476
filesize: 236
maxprot: 7
initprot: 7
nsects: 4
flags: 0
Sections:
- sectname: __text
segname: __TEXT
addr: 0x0000000000000000
size: 188
offset: 0x000001DC
align: 4
reloff: 0x000002C8
nreloc: 9
flags: 0x80000400
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
- sectname: __textcoal_nt
segname: __TEXT
addr: 0x00000000000000BC
size: 0
offset: 0x00000298
align: 0
reloff: 0x00000000
nreloc: 0
flags: 0x8000000B
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
- sectname: __picsymbolstub1
segname: __TEXT
addr: 0x00000000000000BC
size: 0
offset: 0x00000298
align: 0
reloff: 0x00000000
nreloc: 0
flags: 0x80000008
reserved1: 0x00000000
reserved2: 0x00000020
reserved3: 0x00000000
- sectname: __cstring
segname: __TEXT
addr: 0x00000000000000BC
size: 48
offset: 0x00000298
align: 0
reloff: 0x00000000
nreloc: 0
flags: 0x00000002
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
- cmd: LC_VERSION_MIN_MACOSX
cmdsize: 16
version: 658432
sdk: 0
- cmd: LC_SYMTAB
cmdsize: 24
symoff: 784
nsyms: 0
stroff: 808
strsize: 36
LinkEditData:
StringTable:
- ''
- _compilerrt_abort_impl
- ___absvdi2
- ''
...

#CHECK: IsLittleEndian: false
#CHECK: FileHeader:
#CHECK: magic: 0xFEEDFACE
#CHECK: cputype: 0x00000012
#CHECK: cpusubtype: 0x00000000
#CHECK: filetype: 0x00000001
#CHECK: ncmds: 3
#CHECK: sizeofcmds: 368
#CHECK: flags: 0x00002000
Loading

0 comments on commit 5e76a3f

Please sign in to comment.