From 10dcd3bd3b4b688755e9a067ddcf092695953d0f Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Thu, 23 Jun 2016 22:36:31 +0000 Subject: [yaml2macho] Removing asserts in favor of explicit yaml parse error 32-bit Mach headers don't have reserved fields. When generating the mapping for 32-bit headers leaving off the reserved field will result in parse errors if the field is present in the yaml. Added a CHECK-NOT line to ensure that mach_header.yaml isn't adding a reserved field, and a test to ensure that the parser error gets hit with 32-bit headers. llvm-svn: 273623 --- llvm/lib/ObjectYAML/MachOYAML.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'llvm/lib/ObjectYAML/MachOYAML.cpp') diff --git a/llvm/lib/ObjectYAML/MachOYAML.cpp b/llvm/lib/ObjectYAML/MachOYAML.cpp index b4e808552df..d13c84eb04f 100644 --- a/llvm/lib/ObjectYAML/MachOYAML.cpp +++ b/llvm/lib/ObjectYAML/MachOYAML.cpp @@ -14,6 +14,7 @@ #include "llvm/ObjectYAML/MachOYAML.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Format.h" +#include "llvm/Support/MachO.h" #include // For memcpy, memset and strnlen. @@ -79,8 +80,9 @@ void MappingTraits::mapping( IO.mapRequired("ncmds", FileHdr.ncmds); IO.mapRequired("sizeofcmds", FileHdr.sizeofcmds); IO.mapRequired("flags", FileHdr.flags); - IO.mapOptional("reserved", FileHdr.reserved, - static_cast(0xDEADBEEFu)); + if (FileHdr.magic == MachO::MH_MAGIC_64 || + FileHdr.magic == MachO::MH_CIGAM_64) + IO.mapRequired("reserved", FileHdr.reserved); } void MappingTraits::mapping(IO &IO, -- cgit v1.2.3