llvm.org GIT mirror llvm / 46c1e8f
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273623 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Bieneman 3 years ago
4 changed file(s) with 20 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
1313 #include "llvm/ObjectYAML/MachOYAML.h"
1414 #include "llvm/Support/Casting.h"
1515 #include "llvm/Support/Format.h"
16 #include "llvm/Support/MachO.h"
1617
1718 #include // For memcpy, memset and strnlen.
1819
7879 IO.mapRequired("ncmds", FileHdr.ncmds);
7980 IO.mapRequired("sizeofcmds", FileHdr.sizeofcmds);
8081 IO.mapRequired("flags", FileHdr.flags);
81 IO.mapOptional("reserved", FileHdr.reserved,
82 static_cast(0xDEADBEEFu));
82 if (FileHdr.magic == MachO::MH_MAGIC_64 ||
83 FileHdr.magic == MachO::MH_CIGAM_64)
84 IO.mapRequired("reserved", FileHdr.reserved);
8385 }
8486
8587 void MappingTraits::mapping(IO &IO,
1919 # CHECK: ncmds: 0
2020 # CHECK: sizeofcmds: 0
2121 # CHECK: flags: 0x00218085
22 # CHECK-NOT: reserved:
2223 # CHECK: ...
0 # RUN: not yaml2obj -format=macho %s 2>&1 | FileCheck %s
1
2 --- !mach-o
3 FileHeader:
4 magic: 0xFEEDFACE
5 cputype: 0x00000007
6 cpusubtype: 0x80000003
7 filetype: 0x00000002
8 ncmds: 0
9 sizeofcmds: 0
10 flags: 0x00218085
11 reserved: 0
12 ...
13
14 # CHECK: error: unknown key 'reserved'
3131 is64Bit = Obj.Header.magic == MachO::MH_MAGIC_64 ||
3232 Obj.Header.magic == MachO::MH_CIGAM_64;
3333 memset(reinterpret_cast(&Header), 0, sizeof(MachO::mach_header_64));
34 assert((is64Bit || Obj.Header.reserved == 0xDEADBEEFu) &&
35 "32-bit MachO has reserved in header");
36 assert((!is64Bit || Obj.Header.reserved != 0xDEADBEEFu) &&
37 "64-bit MachO has missing reserved in header");
3834 }
3935
4036 Error writeMachO(raw_ostream &OS);