llvm.org GIT mirror llvm / d6f6aaf
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269320 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Bieneman 3 years ago
4 changed file(s) with 12 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
2929 uint32_t ncmds;
3030 uint32_t sizeofcmds;
3131 llvm::yaml::Hex32 flags;
32 // TODO: Need to handle the reserved field in mach_header_64
32 llvm::yaml::Hex32 reserved;
3333 };
3434
3535 struct Object {
2626 IO.mapRequired("ncmds", FileHdr.ncmds);
2727 IO.mapRequired("sizeofcmds", FileHdr.sizeofcmds);
2828 IO.mapRequired("flags", FileHdr.flags);
29 IO.mapOptional("reserved", FileHdr.reserved,
30 static_cast(0xDEADBEEFu));
2931 }
3032
3133 void MappingTraits::mapping(IO &IO,
88 ncmds: 0
99 sizeofcmds: 0
1010 flags: 0x00218085
11 reserved: 0x00000000
1112 ...
1213
1314 # CHECK: --- !mach-o
1920 # CHECK: ncmds: 0
2021 # CHECK: sizeofcmds: 0
2122 # CHECK: flags: 0x00218085
23 # CHECK: reserved: 0x00000000
2224 # CHECK: ...
2929 Obj.Header.magic == MachO::MH_CIGAM_64;
3030 memset(reinterpret_cast(&Header64), 0,
3131 sizeof(MachO::mach_header_64));
32 assert((is64Bit || Obj.Header.reserved == 0xDEADBEEFu) &&
33 "32-bit MachO has reserved in header");
34 assert((!is64Bit || Obj.Header.reserved != 0xDEADBEEFu) &&
35 "64-bit MachO has missing reserved in header");
3236 }
3337
3438 Error writeMachO(raw_ostream &OS);
5963 Header.ncmds = Obj.Header.ncmds;
6064 Header.sizeofcmds = Obj.Header.sizeofcmds;
6165 Header.flags = Obj.Header.flags;
66 Header64.reserved = Obj.Header.reserved;
6267
63 if (is64Bit)
68 if (is64Bit) {
6469 OS.write((const char *)&Header64, sizeof(MachO::mach_header_64));
70 }
6571 else
6672 OS.write((const char *)&Header, sizeof(MachO::mach_header));
6773