mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-14 07:09:08 +00:00
[yaml2macho] Handle mach_header_64 reserved field
I've added the reserved field as an "optional" in YAML, but I've added asserts in the yaml2macho code to enforce that the field is present in mach_header_64, but not in mach_header. llvm-svn: 269320
This commit is contained in:
parent
b2ccc15f74
commit
e395ee54e4
@ -30,7 +30,7 @@ struct FileHeader {
|
||||
uint32_t ncmds;
|
||||
uint32_t sizeofcmds;
|
||||
llvm::yaml::Hex32 flags;
|
||||
// TODO: Need to handle the reserved field in mach_header_64
|
||||
llvm::yaml::Hex32 reserved;
|
||||
};
|
||||
|
||||
struct Object {
|
||||
|
@ -27,6 +27,8 @@ void MappingTraits<MachOYAML::FileHeader>::mapping(
|
||||
IO.mapRequired("ncmds", FileHdr.ncmds);
|
||||
IO.mapRequired("sizeofcmds", FileHdr.sizeofcmds);
|
||||
IO.mapRequired("flags", FileHdr.flags);
|
||||
IO.mapOptional("reserved", FileHdr.reserved,
|
||||
static_cast<llvm::yaml::Hex32>(0xDEADBEEFu));
|
||||
}
|
||||
|
||||
void MappingTraits<MachOYAML::Object>::mapping(IO &IO,
|
||||
|
@ -9,6 +9,7 @@ FileHeader:
|
||||
ncmds: 0
|
||||
sizeofcmds: 0
|
||||
flags: 0x00218085
|
||||
reserved: 0x00000000
|
||||
...
|
||||
|
||||
# CHECK: --- !mach-o
|
||||
@ -20,4 +21,5 @@ FileHeader:
|
||||
# CHECK: ncmds: 0
|
||||
# CHECK: sizeofcmds: 0
|
||||
# CHECK: flags: 0x00218085
|
||||
# CHECK: reserved: 0x00000000
|
||||
# CHECK: ...
|
||||
|
@ -30,6 +30,10 @@ public:
|
||||
Obj.Header.magic == MachO::MH_CIGAM_64;
|
||||
memset(reinterpret_cast<void *>(&Header64), 0,
|
||||
sizeof(MachO::mach_header_64));
|
||||
assert((is64Bit || Obj.Header.reserved == 0xDEADBEEFu) &&
|
||||
"32-bit MachO has reserved in header");
|
||||
assert((!is64Bit || Obj.Header.reserved != 0xDEADBEEFu) &&
|
||||
"64-bit MachO has missing reserved in header");
|
||||
}
|
||||
|
||||
Error writeMachO(raw_ostream &OS);
|
||||
@ -60,9 +64,11 @@ Error MachOWriter::writeHeader(raw_ostream &OS) {
|
||||
Header.ncmds = Obj.Header.ncmds;
|
||||
Header.sizeofcmds = Obj.Header.sizeofcmds;
|
||||
Header.flags = Obj.Header.flags;
|
||||
Header64.reserved = Obj.Header.reserved;
|
||||
|
||||
if (is64Bit)
|
||||
if (is64Bit) {
|
||||
OS.write((const char *)&Header64, sizeof(MachO::mach_header_64));
|
||||
}
|
||||
else
|
||||
OS.write((const char *)&Header, sizeof(MachO::mach_header));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user