[llvm] r269320 - [yaml2macho] Handle mach_header_64 reserved field
Chris Bieneman via llvm-commits
llvm-commits at lists.llvm.org
Thu May 12 11:21:09 PDT 2016
Author: cbieneman
Date: Thu May 12 13:21:09 2016
New Revision: 269320
URL: http://llvm.org/viewvc/llvm-project?rev=269320&view=rev
Log:
[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.
Modified:
llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h
llvm/trunk/lib/ObjectYAML/MachOYAML.cpp
llvm/trunk/test/ObjectYAML/MachO/mach_header_64.yaml
llvm/trunk/tools/yaml2obj/yaml2macho.cpp
Modified: llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h?rev=269320&r1=269319&r2=269320&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h (original)
+++ llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h Thu May 12 13:21:09 2016
@@ -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 {
Modified: llvm/trunk/lib/ObjectYAML/MachOYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/MachOYAML.cpp?rev=269320&r1=269319&r2=269320&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/MachOYAML.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/MachOYAML.cpp Thu May 12 13:21:09 2016
@@ -27,6 +27,8 @@ void MappingTraits<MachOYAML::FileHeader
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,
Modified: llvm/trunk/test/ObjectYAML/MachO/mach_header_64.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ObjectYAML/MachO/mach_header_64.yaml?rev=269320&r1=269319&r2=269320&view=diff
==============================================================================
--- llvm/trunk/test/ObjectYAML/MachO/mach_header_64.yaml (original)
+++ llvm/trunk/test/ObjectYAML/MachO/mach_header_64.yaml Thu May 12 13:21:09 2016
@@ -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: ...
Modified: llvm/trunk/tools/yaml2obj/yaml2macho.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2macho.cpp?rev=269320&r1=269319&r2=269320&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2macho.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2macho.cpp Thu May 12 13:21:09 2016
@@ -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_ostre
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));
More information about the llvm-commits
mailing list