1 //===- MachOYAML.cpp - MachO YAMLIO implementation ------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines classes for handling the YAML representation of MachO.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "llvm/ObjectYAML/MachOYAML.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/BinaryFormat/MachO.h"
16 #include "llvm/Support/Format.h"
17 #include "llvm/Support/Host.h"
18 #include "llvm/Support/YAMLTraits.h"
19 #include "llvm/Support/raw_ostream.h"
20 #include <cinttypes>
21 #include <cstdint>
22 #include <cstring>
23 
24 namespace llvm {
25 
26 MachOYAML::LoadCommand::~LoadCommand() = default;
27 
isEmpty() const28 bool MachOYAML::LinkEditData::isEmpty() const {
29   return 0 ==
30          RebaseOpcodes.size() + BindOpcodes.size() + WeakBindOpcodes.size() +
31              LazyBindOpcodes.size() + ExportTrie.Children.size() +
32              NameList.size() + StringTable.size();
33 }
34 
35 namespace yaml {
36 
output(const char_16 & Val,void *,raw_ostream & Out)37 void ScalarTraits<char_16>::output(const char_16 &Val, void *,
38                                    raw_ostream &Out) {
39   auto Len = strnlen(&Val[0], 16);
40   Out << StringRef(&Val[0], Len);
41 }
42 
input(StringRef Scalar,void *,char_16 & Val)43 StringRef ScalarTraits<char_16>::input(StringRef Scalar, void *, char_16 &Val) {
44   size_t CopySize = 16 >= Scalar.size() ? 16 : Scalar.size();
45   memcpy((void *)Val, Scalar.data(), CopySize);
46 
47   if (Scalar.size() < 16) {
48     memset((void *)&Val[Scalar.size()], 0, 16 - Scalar.size());
49   }
50 
51   return StringRef();
52 }
53 
mustQuote(StringRef S)54 QuotingType ScalarTraits<char_16>::mustQuote(StringRef S) {
55   return needsQuotes(S);
56 }
57 
output(const uuid_t & Val,void *,raw_ostream & Out)58 void ScalarTraits<uuid_t>::output(const uuid_t &Val, void *, raw_ostream &Out) {
59   Out.write_uuid(Val);
60 }
61 
input(StringRef Scalar,void *,uuid_t & Val)62 StringRef ScalarTraits<uuid_t>::input(StringRef Scalar, void *, uuid_t &Val) {
63   size_t OutIdx = 0;
64   for (size_t Idx = 0; Idx < Scalar.size(); ++Idx) {
65     if (Scalar[Idx] == '-' || OutIdx >= 16)
66       continue;
67     unsigned long long TempInt;
68     if (getAsUnsignedInteger(Scalar.slice(Idx, Idx + 2), 16, TempInt))
69       return "invalid number";
70     if (TempInt > 0xFF)
71       return "out of range number";
72     Val[OutIdx] = static_cast<uint8_t>(TempInt);
73     ++Idx; // increment idx an extra time because we're consuming 2 chars
74     ++OutIdx;
75   }
76   return StringRef();
77 }
78 
mustQuote(StringRef S)79 QuotingType ScalarTraits<uuid_t>::mustQuote(StringRef S) {
80   return needsQuotes(S);
81 }
82 
mapping(IO & IO,MachOYAML::FileHeader & FileHdr)83 void MappingTraits<MachOYAML::FileHeader>::mapping(
84     IO &IO, MachOYAML::FileHeader &FileHdr) {
85   IO.mapRequired("magic", FileHdr.magic);
86   IO.mapRequired("cputype", FileHdr.cputype);
87   IO.mapRequired("cpusubtype", FileHdr.cpusubtype);
88   IO.mapRequired("filetype", FileHdr.filetype);
89   IO.mapRequired("ncmds", FileHdr.ncmds);
90   IO.mapRequired("sizeofcmds", FileHdr.sizeofcmds);
91   IO.mapRequired("flags", FileHdr.flags);
92   if (FileHdr.magic == MachO::MH_MAGIC_64 ||
93       FileHdr.magic == MachO::MH_CIGAM_64)
94     IO.mapRequired("reserved", FileHdr.reserved);
95 }
96 
mapping(IO & IO,MachOYAML::Object & Object)97 void MappingTraits<MachOYAML::Object>::mapping(IO &IO,
98                                                MachOYAML::Object &Object) {
99   // If the context isn't already set, tag the document as !mach-o.
100   // For Fat files there will be a different tag so they can be differentiated.
101   if (!IO.getContext()) {
102     IO.setContext(&Object);
103   }
104   IO.mapTag("!mach-o", true);
105   IO.mapOptional("IsLittleEndian", Object.IsLittleEndian,
106                  sys::IsLittleEndianHost);
107   Object.DWARF.IsLittleEndian = Object.IsLittleEndian;
108 
109   IO.mapRequired("FileHeader", Object.Header);
110   Object.DWARF.Is64BitAddrSize = Object.Header.magic == MachO::MH_MAGIC_64 ||
111                                  Object.Header.magic == MachO::MH_CIGAM_64;
112   IO.mapOptional("LoadCommands", Object.LoadCommands);
113   if(!Object.LinkEdit.isEmpty() || !IO.outputting())
114     IO.mapOptional("LinkEditData", Object.LinkEdit);
115 
116   if(!Object.DWARF.isEmpty() || !IO.outputting())
117     IO.mapOptional("DWARF", Object.DWARF);
118 
119   if (IO.getContext() == &Object)
120     IO.setContext(nullptr);
121 }
122 
mapping(IO & IO,MachOYAML::FatHeader & FatHeader)123 void MappingTraits<MachOYAML::FatHeader>::mapping(
124     IO &IO, MachOYAML::FatHeader &FatHeader) {
125   IO.mapRequired("magic", FatHeader.magic);
126   IO.mapRequired("nfat_arch", FatHeader.nfat_arch);
127 }
128 
mapping(IO & IO,MachOYAML::FatArch & FatArch)129 void MappingTraits<MachOYAML::FatArch>::mapping(IO &IO,
130                                                 MachOYAML::FatArch &FatArch) {
131   IO.mapRequired("cputype", FatArch.cputype);
132   IO.mapRequired("cpusubtype", FatArch.cpusubtype);
133   IO.mapRequired("offset", FatArch.offset);
134   IO.mapRequired("size", FatArch.size);
135   IO.mapRequired("align", FatArch.align);
136   IO.mapOptional("reserved", FatArch.reserved,
137                  static_cast<llvm::yaml::Hex32>(0));
138 }
139 
mapping(IO & IO,MachOYAML::UniversalBinary & UniversalBinary)140 void MappingTraits<MachOYAML::UniversalBinary>::mapping(
141     IO &IO, MachOYAML::UniversalBinary &UniversalBinary) {
142   if (!IO.getContext()) {
143     IO.setContext(&UniversalBinary);
144     IO.mapTag("!fat-mach-o", true);
145   }
146   IO.mapRequired("FatHeader", UniversalBinary.Header);
147   IO.mapRequired("FatArchs", UniversalBinary.FatArchs);
148   IO.mapRequired("Slices", UniversalBinary.Slices);
149 
150   if (IO.getContext() == &UniversalBinary)
151     IO.setContext(nullptr);
152 }
153 
mapping(IO & IO,MachOYAML::LinkEditData & LinkEditData)154 void MappingTraits<MachOYAML::LinkEditData>::mapping(
155     IO &IO, MachOYAML::LinkEditData &LinkEditData) {
156   IO.mapOptional("RebaseOpcodes", LinkEditData.RebaseOpcodes);
157   IO.mapOptional("BindOpcodes", LinkEditData.BindOpcodes);
158   IO.mapOptional("WeakBindOpcodes", LinkEditData.WeakBindOpcodes);
159   IO.mapOptional("LazyBindOpcodes", LinkEditData.LazyBindOpcodes);
160   if (!LinkEditData.ExportTrie.Children.empty() || !IO.outputting())
161     IO.mapOptional("ExportTrie", LinkEditData.ExportTrie);
162   IO.mapOptional("NameList", LinkEditData.NameList);
163   IO.mapOptional("StringTable", LinkEditData.StringTable);
164 }
165 
mapping(IO & IO,MachOYAML::RebaseOpcode & RebaseOpcode)166 void MappingTraits<MachOYAML::RebaseOpcode>::mapping(
167     IO &IO, MachOYAML::RebaseOpcode &RebaseOpcode) {
168   IO.mapRequired("Opcode", RebaseOpcode.Opcode);
169   IO.mapRequired("Imm", RebaseOpcode.Imm);
170   IO.mapOptional("ExtraData", RebaseOpcode.ExtraData);
171 }
172 
mapping(IO & IO,MachOYAML::BindOpcode & BindOpcode)173 void MappingTraits<MachOYAML::BindOpcode>::mapping(
174     IO &IO, MachOYAML::BindOpcode &BindOpcode) {
175   IO.mapRequired("Opcode", BindOpcode.Opcode);
176   IO.mapRequired("Imm", BindOpcode.Imm);
177   IO.mapOptional("ULEBExtraData", BindOpcode.ULEBExtraData);
178   IO.mapOptional("SLEBExtraData", BindOpcode.SLEBExtraData);
179   IO.mapOptional("Symbol", BindOpcode.Symbol);
180 }
181 
mapping(IO & IO,MachOYAML::ExportEntry & ExportEntry)182 void MappingTraits<MachOYAML::ExportEntry>::mapping(
183     IO &IO, MachOYAML::ExportEntry &ExportEntry) {
184   IO.mapRequired("TerminalSize", ExportEntry.TerminalSize);
185   IO.mapOptional("NodeOffset", ExportEntry.NodeOffset);
186   IO.mapOptional("Name", ExportEntry.Name);
187   IO.mapOptional("Flags", ExportEntry.Flags);
188   IO.mapOptional("Address", ExportEntry.Address);
189   IO.mapOptional("Other", ExportEntry.Other);
190   IO.mapOptional("ImportName", ExportEntry.ImportName);
191   IO.mapOptional("Children", ExportEntry.Children);
192 }
193 
mapping(IO & IO,MachOYAML::NListEntry & NListEntry)194 void MappingTraits<MachOYAML::NListEntry>::mapping(
195     IO &IO, MachOYAML::NListEntry &NListEntry) {
196   IO.mapRequired("n_strx", NListEntry.n_strx);
197   IO.mapRequired("n_type", NListEntry.n_type);
198   IO.mapRequired("n_sect", NListEntry.n_sect);
199   IO.mapRequired("n_desc", NListEntry.n_desc);
200   IO.mapRequired("n_value", NListEntry.n_value);
201 }
202 
203 template <typename StructType>
mapLoadCommandData(IO & IO,MachOYAML::LoadCommand & LoadCommand)204 void mapLoadCommandData(IO &IO, MachOYAML::LoadCommand &LoadCommand) {}
205 
206 template <>
mapLoadCommandData(IO & IO,MachOYAML::LoadCommand & LoadCommand)207 void mapLoadCommandData<MachO::segment_command>(
208     IO &IO, MachOYAML::LoadCommand &LoadCommand) {
209   IO.mapOptional("Sections", LoadCommand.Sections);
210 }
211 
212 template <>
mapLoadCommandData(IO & IO,MachOYAML::LoadCommand & LoadCommand)213 void mapLoadCommandData<MachO::segment_command_64>(
214     IO &IO, MachOYAML::LoadCommand &LoadCommand) {
215   IO.mapOptional("Sections", LoadCommand.Sections);
216 }
217 
218 template <>
mapLoadCommandData(IO & IO,MachOYAML::LoadCommand & LoadCommand)219 void mapLoadCommandData<MachO::dylib_command>(
220     IO &IO, MachOYAML::LoadCommand &LoadCommand) {
221   IO.mapOptional("Content", LoadCommand.Content);
222 }
223 
224 template <>
mapLoadCommandData(IO & IO,MachOYAML::LoadCommand & LoadCommand)225 void mapLoadCommandData<MachO::rpath_command>(
226     IO &IO, MachOYAML::LoadCommand &LoadCommand) {
227   IO.mapOptional("Content", LoadCommand.Content);
228 }
229 
230 template <>
mapLoadCommandData(IO & IO,MachOYAML::LoadCommand & LoadCommand)231 void mapLoadCommandData<MachO::dylinker_command>(
232     IO &IO, MachOYAML::LoadCommand &LoadCommand) {
233   IO.mapOptional("Content", LoadCommand.Content);
234 }
235 
236 template <>
mapLoadCommandData(IO & IO,MachOYAML::LoadCommand & LoadCommand)237 void mapLoadCommandData<MachO::sub_framework_command>(
238     IO &IO, MachOYAML::LoadCommand &LoadCommand) {
239   IO.mapOptional("Content", LoadCommand.Content);
240 }
241 
242 template <>
mapLoadCommandData(IO & IO,MachOYAML::LoadCommand & LoadCommand)243 void mapLoadCommandData<MachO::sub_umbrella_command>(
244     IO &IO, MachOYAML::LoadCommand &LoadCommand) {
245   IO.mapOptional("Content", LoadCommand.Content);
246 }
247 
248 template <>
mapLoadCommandData(IO & IO,MachOYAML::LoadCommand & LoadCommand)249 void mapLoadCommandData<MachO::sub_client_command>(
250     IO &IO, MachOYAML::LoadCommand &LoadCommand) {
251   IO.mapOptional("Content", LoadCommand.Content);
252 }
253 
254 template <>
mapLoadCommandData(IO & IO,MachOYAML::LoadCommand & LoadCommand)255 void mapLoadCommandData<MachO::sub_library_command>(
256     IO &IO, MachOYAML::LoadCommand &LoadCommand) {
257   IO.mapOptional("Content", LoadCommand.Content);
258 }
259 
260 template <>
mapLoadCommandData(IO & IO,MachOYAML::LoadCommand & LoadCommand)261 void mapLoadCommandData<MachO::build_version_command>(
262     IO &IO, MachOYAML::LoadCommand &LoadCommand) {
263   IO.mapOptional("Tools", LoadCommand.Tools);
264 }
265 
mapping(IO & IO,MachOYAML::LoadCommand & LoadCommand)266 void MappingTraits<MachOYAML::LoadCommand>::mapping(
267     IO &IO, MachOYAML::LoadCommand &LoadCommand) {
268   MachO::LoadCommandType TempCmd = static_cast<MachO::LoadCommandType>(
269       LoadCommand.Data.load_command_data.cmd);
270   IO.mapRequired("cmd", TempCmd);
271   LoadCommand.Data.load_command_data.cmd = TempCmd;
272   IO.mapRequired("cmdsize", LoadCommand.Data.load_command_data.cmdsize);
273 
274 #define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct)                         \
275   case MachO::LCName:                                                          \
276     MappingTraits<MachO::LCStruct>::mapping(IO,                                \
277                                             LoadCommand.Data.LCStruct##_data); \
278     mapLoadCommandData<MachO::LCStruct>(IO, LoadCommand);                      \
279     break;
280 
281   switch (LoadCommand.Data.load_command_data.cmd) {
282 #include "llvm/BinaryFormat/MachO.def"
283   }
284   IO.mapOptional("PayloadBytes", LoadCommand.PayloadBytes);
285   IO.mapOptional("ZeroPadBytes", LoadCommand.ZeroPadBytes, (uint64_t)0ull);
286 }
287 
mapping(IO & IO,MachO::dyld_info_command & LoadCommand)288 void MappingTraits<MachO::dyld_info_command>::mapping(
289     IO &IO, MachO::dyld_info_command &LoadCommand) {
290   IO.mapRequired("rebase_off", LoadCommand.rebase_off);
291   IO.mapRequired("rebase_size", LoadCommand.rebase_size);
292   IO.mapRequired("bind_off", LoadCommand.bind_off);
293   IO.mapRequired("bind_size", LoadCommand.bind_size);
294   IO.mapRequired("weak_bind_off", LoadCommand.weak_bind_off);
295   IO.mapRequired("weak_bind_size", LoadCommand.weak_bind_size);
296   IO.mapRequired("lazy_bind_off", LoadCommand.lazy_bind_off);
297   IO.mapRequired("lazy_bind_size", LoadCommand.lazy_bind_size);
298   IO.mapRequired("export_off", LoadCommand.export_off);
299   IO.mapRequired("export_size", LoadCommand.export_size);
300 }
301 
mapping(IO & IO,MachOYAML::Relocation & Relocation)302 void MappingTraits<MachOYAML::Relocation>::mapping(
303     IO &IO, MachOYAML::Relocation &Relocation) {
304   IO.mapRequired("address", Relocation.address);
305   IO.mapRequired("symbolnum", Relocation.symbolnum);
306   IO.mapRequired("pcrel", Relocation.is_pcrel);
307   IO.mapRequired("length", Relocation.length);
308   IO.mapRequired("extern", Relocation.is_extern);
309   IO.mapRequired("type", Relocation.type);
310   IO.mapRequired("scattered", Relocation.is_scattered);
311   IO.mapRequired("value", Relocation.value);
312 }
313 
mapping(IO & IO,MachOYAML::Section & Section)314 void MappingTraits<MachOYAML::Section>::mapping(IO &IO,
315                                                 MachOYAML::Section &Section) {
316   IO.mapRequired("sectname", Section.sectname);
317   IO.mapRequired("segname", Section.segname);
318   IO.mapRequired("addr", Section.addr);
319   IO.mapRequired("size", Section.size);
320   IO.mapRequired("offset", Section.offset);
321   IO.mapRequired("align", Section.align);
322   IO.mapRequired("reloff", Section.reloff);
323   IO.mapRequired("nreloc", Section.nreloc);
324   IO.mapRequired("flags", Section.flags);
325   IO.mapRequired("reserved1", Section.reserved1);
326   IO.mapRequired("reserved2", Section.reserved2);
327   IO.mapOptional("reserved3", Section.reserved3);
328   IO.mapOptional("content", Section.content);
329   IO.mapOptional("relocations", Section.relocations);
330 }
331 
332 std::string
validate(IO & IO,MachOYAML::Section & Section)333 MappingTraits<MachOYAML::Section>::validate(IO &IO,
334                                             MachOYAML::Section &Section) {
335   if (Section.content && Section.size < Section.content->binary_size())
336     return "Section size must be greater than or equal to the content size";
337   return "";
338 }
339 
mapping(IO & IO,MachO::build_tool_version & tool)340 void MappingTraits<MachO::build_tool_version>::mapping(
341     IO &IO, MachO::build_tool_version &tool) {
342   IO.mapRequired("tool", tool.tool);
343   IO.mapRequired("version", tool.version);
344 }
345 
mapping(IO & IO,MachO::dylib & DylibStruct)346 void MappingTraits<MachO::dylib>::mapping(IO &IO, MachO::dylib &DylibStruct) {
347   IO.mapRequired("name", DylibStruct.name);
348   IO.mapRequired("timestamp", DylibStruct.timestamp);
349   IO.mapRequired("current_version", DylibStruct.current_version);
350   IO.mapRequired("compatibility_version", DylibStruct.compatibility_version);
351 }
352 
mapping(IO & IO,MachO::dylib_command & LoadCommand)353 void MappingTraits<MachO::dylib_command>::mapping(
354     IO &IO, MachO::dylib_command &LoadCommand) {
355   IO.mapRequired("dylib", LoadCommand.dylib);
356 }
357 
mapping(IO & IO,MachO::dylinker_command & LoadCommand)358 void MappingTraits<MachO::dylinker_command>::mapping(
359     IO &IO, MachO::dylinker_command &LoadCommand) {
360   IO.mapRequired("name", LoadCommand.name);
361 }
362 
mapping(IO & IO,MachO::dysymtab_command & LoadCommand)363 void MappingTraits<MachO::dysymtab_command>::mapping(
364     IO &IO, MachO::dysymtab_command &LoadCommand) {
365   IO.mapRequired("ilocalsym", LoadCommand.ilocalsym);
366   IO.mapRequired("nlocalsym", LoadCommand.nlocalsym);
367   IO.mapRequired("iextdefsym", LoadCommand.iextdefsym);
368   IO.mapRequired("nextdefsym", LoadCommand.nextdefsym);
369   IO.mapRequired("iundefsym", LoadCommand.iundefsym);
370   IO.mapRequired("nundefsym", LoadCommand.nundefsym);
371   IO.mapRequired("tocoff", LoadCommand.tocoff);
372   IO.mapRequired("ntoc", LoadCommand.ntoc);
373   IO.mapRequired("modtaboff", LoadCommand.modtaboff);
374   IO.mapRequired("nmodtab", LoadCommand.nmodtab);
375   IO.mapRequired("extrefsymoff", LoadCommand.extrefsymoff);
376   IO.mapRequired("nextrefsyms", LoadCommand.nextrefsyms);
377   IO.mapRequired("indirectsymoff", LoadCommand.indirectsymoff);
378   IO.mapRequired("nindirectsyms", LoadCommand.nindirectsyms);
379   IO.mapRequired("extreloff", LoadCommand.extreloff);
380   IO.mapRequired("nextrel", LoadCommand.nextrel);
381   IO.mapRequired("locreloff", LoadCommand.locreloff);
382   IO.mapRequired("nlocrel", LoadCommand.nlocrel);
383 }
384 
mapping(IO & IO,MachO::encryption_info_command & LoadCommand)385 void MappingTraits<MachO::encryption_info_command>::mapping(
386     IO &IO, MachO::encryption_info_command &LoadCommand) {
387   IO.mapRequired("cryptoff", LoadCommand.cryptoff);
388   IO.mapRequired("cryptsize", LoadCommand.cryptsize);
389   IO.mapRequired("cryptid", LoadCommand.cryptid);
390 }
391 
mapping(IO & IO,MachO::encryption_info_command_64 & LoadCommand)392 void MappingTraits<MachO::encryption_info_command_64>::mapping(
393     IO &IO, MachO::encryption_info_command_64 &LoadCommand) {
394   IO.mapRequired("cryptoff", LoadCommand.cryptoff);
395   IO.mapRequired("cryptsize", LoadCommand.cryptsize);
396   IO.mapRequired("cryptid", LoadCommand.cryptid);
397   IO.mapRequired("pad", LoadCommand.pad);
398 }
399 
mapping(IO & IO,MachO::entry_point_command & LoadCommand)400 void MappingTraits<MachO::entry_point_command>::mapping(
401     IO &IO, MachO::entry_point_command &LoadCommand) {
402   IO.mapRequired("entryoff", LoadCommand.entryoff);
403   IO.mapRequired("stacksize", LoadCommand.stacksize);
404 }
405 
mapping(IO & IO,MachO::fvmfile_command & LoadCommand)406 void MappingTraits<MachO::fvmfile_command>::mapping(
407     IO &IO, MachO::fvmfile_command &LoadCommand) {
408   IO.mapRequired("name", LoadCommand.name);
409   IO.mapRequired("header_addr", LoadCommand.header_addr);
410 }
411 
mapping(IO & IO,MachO::fvmlib & FVMLib)412 void MappingTraits<MachO::fvmlib>::mapping(IO &IO, MachO::fvmlib &FVMLib) {
413   IO.mapRequired("name", FVMLib.name);
414   IO.mapRequired("minor_version", FVMLib.minor_version);
415   IO.mapRequired("header_addr", FVMLib.header_addr);
416 }
417 
mapping(IO & IO,MachO::fvmlib_command & LoadCommand)418 void MappingTraits<MachO::fvmlib_command>::mapping(
419     IO &IO, MachO::fvmlib_command &LoadCommand) {
420   IO.mapRequired("fvmlib", LoadCommand.fvmlib);
421 }
422 
mapping(IO & IO,MachO::ident_command & LoadCommand)423 void MappingTraits<MachO::ident_command>::mapping(
424     IO &IO, MachO::ident_command &LoadCommand) {}
425 
mapping(IO & IO,MachO::linkedit_data_command & LoadCommand)426 void MappingTraits<MachO::linkedit_data_command>::mapping(
427     IO &IO, MachO::linkedit_data_command &LoadCommand) {
428   IO.mapRequired("dataoff", LoadCommand.dataoff);
429   IO.mapRequired("datasize", LoadCommand.datasize);
430 }
431 
mapping(IO & IO,MachO::linker_option_command & LoadCommand)432 void MappingTraits<MachO::linker_option_command>::mapping(
433     IO &IO, MachO::linker_option_command &LoadCommand) {
434   IO.mapRequired("count", LoadCommand.count);
435 }
436 
mapping(IO & IO,MachO::prebind_cksum_command & LoadCommand)437 void MappingTraits<MachO::prebind_cksum_command>::mapping(
438     IO &IO, MachO::prebind_cksum_command &LoadCommand) {
439   IO.mapRequired("cksum", LoadCommand.cksum);
440 }
441 
mapping(IO & IO,MachO::load_command & LoadCommand)442 void MappingTraits<MachO::load_command>::mapping(
443     IO &IO, MachO::load_command &LoadCommand) {}
444 
mapping(IO & IO,MachO::prebound_dylib_command & LoadCommand)445 void MappingTraits<MachO::prebound_dylib_command>::mapping(
446     IO &IO, MachO::prebound_dylib_command &LoadCommand) {
447   IO.mapRequired("name", LoadCommand.name);
448   IO.mapRequired("nmodules", LoadCommand.nmodules);
449   IO.mapRequired("linked_modules", LoadCommand.linked_modules);
450 }
451 
mapping(IO & IO,MachO::routines_command & LoadCommand)452 void MappingTraits<MachO::routines_command>::mapping(
453     IO &IO, MachO::routines_command &LoadCommand) {
454   IO.mapRequired("init_address", LoadCommand.init_address);
455   IO.mapRequired("init_module", LoadCommand.init_module);
456   IO.mapRequired("reserved1", LoadCommand.reserved1);
457   IO.mapRequired("reserved2", LoadCommand.reserved2);
458   IO.mapRequired("reserved3", LoadCommand.reserved3);
459   IO.mapRequired("reserved4", LoadCommand.reserved4);
460   IO.mapRequired("reserved5", LoadCommand.reserved5);
461   IO.mapRequired("reserved6", LoadCommand.reserved6);
462 }
463 
mapping(IO & IO,MachO::routines_command_64 & LoadCommand)464 void MappingTraits<MachO::routines_command_64>::mapping(
465     IO &IO, MachO::routines_command_64 &LoadCommand) {
466   IO.mapRequired("init_address", LoadCommand.init_address);
467   IO.mapRequired("init_module", LoadCommand.init_module);
468   IO.mapRequired("reserved1", LoadCommand.reserved1);
469   IO.mapRequired("reserved2", LoadCommand.reserved2);
470   IO.mapRequired("reserved3", LoadCommand.reserved3);
471   IO.mapRequired("reserved4", LoadCommand.reserved4);
472   IO.mapRequired("reserved5", LoadCommand.reserved5);
473   IO.mapRequired("reserved6", LoadCommand.reserved6);
474 }
475 
mapping(IO & IO,MachO::rpath_command & LoadCommand)476 void MappingTraits<MachO::rpath_command>::mapping(
477     IO &IO, MachO::rpath_command &LoadCommand) {
478   IO.mapRequired("path", LoadCommand.path);
479 }
480 
mapping(IO & IO,MachO::section & Section)481 void MappingTraits<MachO::section>::mapping(IO &IO, MachO::section &Section) {
482   IO.mapRequired("sectname", Section.sectname);
483   IO.mapRequired("segname", Section.segname);
484   IO.mapRequired("addr", Section.addr);
485   IO.mapRequired("size", Section.size);
486   IO.mapRequired("offset", Section.offset);
487   IO.mapRequired("align", Section.align);
488   IO.mapRequired("reloff", Section.reloff);
489   IO.mapRequired("nreloc", Section.nreloc);
490   IO.mapRequired("flags", Section.flags);
491   IO.mapRequired("reserved1", Section.reserved1);
492   IO.mapRequired("reserved2", Section.reserved2);
493 }
494 
mapping(IO & IO,MachO::section_64 & Section)495 void MappingTraits<MachO::section_64>::mapping(IO &IO,
496                                                MachO::section_64 &Section) {
497   IO.mapRequired("sectname", Section.sectname);
498   IO.mapRequired("segname", Section.segname);
499   IO.mapRequired("addr", Section.addr);
500   IO.mapRequired("size", Section.size);
501   IO.mapRequired("offset", Section.offset);
502   IO.mapRequired("align", Section.align);
503   IO.mapRequired("reloff", Section.reloff);
504   IO.mapRequired("nreloc", Section.nreloc);
505   IO.mapRequired("flags", Section.flags);
506   IO.mapRequired("reserved1", Section.reserved1);
507   IO.mapRequired("reserved2", Section.reserved2);
508   IO.mapRequired("reserved3", Section.reserved3);
509 }
510 
mapping(IO & IO,MachO::segment_command & LoadCommand)511 void MappingTraits<MachO::segment_command>::mapping(
512     IO &IO, MachO::segment_command &LoadCommand) {
513   IO.mapRequired("segname", LoadCommand.segname);
514   IO.mapRequired("vmaddr", LoadCommand.vmaddr);
515   IO.mapRequired("vmsize", LoadCommand.vmsize);
516   IO.mapRequired("fileoff", LoadCommand.fileoff);
517   IO.mapRequired("filesize", LoadCommand.filesize);
518   IO.mapRequired("maxprot", LoadCommand.maxprot);
519   IO.mapRequired("initprot", LoadCommand.initprot);
520   IO.mapRequired("nsects", LoadCommand.nsects);
521   IO.mapRequired("flags", LoadCommand.flags);
522 }
523 
mapping(IO & IO,MachO::segment_command_64 & LoadCommand)524 void MappingTraits<MachO::segment_command_64>::mapping(
525     IO &IO, MachO::segment_command_64 &LoadCommand) {
526   IO.mapRequired("segname", LoadCommand.segname);
527   IO.mapRequired("vmaddr", LoadCommand.vmaddr);
528   IO.mapRequired("vmsize", LoadCommand.vmsize);
529   IO.mapRequired("fileoff", LoadCommand.fileoff);
530   IO.mapRequired("filesize", LoadCommand.filesize);
531   IO.mapRequired("maxprot", LoadCommand.maxprot);
532   IO.mapRequired("initprot", LoadCommand.initprot);
533   IO.mapRequired("nsects", LoadCommand.nsects);
534   IO.mapRequired("flags", LoadCommand.flags);
535 }
536 
mapping(IO & IO,MachO::source_version_command & LoadCommand)537 void MappingTraits<MachO::source_version_command>::mapping(
538     IO &IO, MachO::source_version_command &LoadCommand) {
539   IO.mapRequired("version", LoadCommand.version);
540 }
541 
mapping(IO & IO,MachO::sub_client_command & LoadCommand)542 void MappingTraits<MachO::sub_client_command>::mapping(
543     IO &IO, MachO::sub_client_command &LoadCommand) {
544   IO.mapRequired("client", LoadCommand.client);
545 }
546 
mapping(IO & IO,MachO::sub_framework_command & LoadCommand)547 void MappingTraits<MachO::sub_framework_command>::mapping(
548     IO &IO, MachO::sub_framework_command &LoadCommand) {
549   IO.mapRequired("umbrella", LoadCommand.umbrella);
550 }
551 
mapping(IO & IO,MachO::sub_library_command & LoadCommand)552 void MappingTraits<MachO::sub_library_command>::mapping(
553     IO &IO, MachO::sub_library_command &LoadCommand) {
554   IO.mapRequired("sub_library", LoadCommand.sub_library);
555 }
556 
mapping(IO & IO,MachO::sub_umbrella_command & LoadCommand)557 void MappingTraits<MachO::sub_umbrella_command>::mapping(
558     IO &IO, MachO::sub_umbrella_command &LoadCommand) {
559   IO.mapRequired("sub_umbrella", LoadCommand.sub_umbrella);
560 }
561 
mapping(IO & IO,MachO::symseg_command & LoadCommand)562 void MappingTraits<MachO::symseg_command>::mapping(
563     IO &IO, MachO::symseg_command &LoadCommand) {
564   IO.mapRequired("offset", LoadCommand.offset);
565   IO.mapRequired("size", LoadCommand.size);
566 }
567 
mapping(IO & IO,MachO::symtab_command & LoadCommand)568 void MappingTraits<MachO::symtab_command>::mapping(
569     IO &IO, MachO::symtab_command &LoadCommand) {
570   IO.mapRequired("symoff", LoadCommand.symoff);
571   IO.mapRequired("nsyms", LoadCommand.nsyms);
572   IO.mapRequired("stroff", LoadCommand.stroff);
573   IO.mapRequired("strsize", LoadCommand.strsize);
574 }
575 
mapping(IO & IO,MachO::thread_command & LoadCommand)576 void MappingTraits<MachO::thread_command>::mapping(
577     IO &IO, MachO::thread_command &LoadCommand) {}
578 
mapping(IO & IO,MachO::twolevel_hints_command & LoadCommand)579 void MappingTraits<MachO::twolevel_hints_command>::mapping(
580     IO &IO, MachO::twolevel_hints_command &LoadCommand) {
581   IO.mapRequired("offset", LoadCommand.offset);
582   IO.mapRequired("nhints", LoadCommand.nhints);
583 }
584 
mapping(IO & IO,MachO::uuid_command & LoadCommand)585 void MappingTraits<MachO::uuid_command>::mapping(
586     IO &IO, MachO::uuid_command &LoadCommand) {
587   IO.mapRequired("uuid", LoadCommand.uuid);
588 }
589 
mapping(IO & IO,MachO::version_min_command & LoadCommand)590 void MappingTraits<MachO::version_min_command>::mapping(
591     IO &IO, MachO::version_min_command &LoadCommand) {
592   IO.mapRequired("version", LoadCommand.version);
593   IO.mapRequired("sdk", LoadCommand.sdk);
594 }
595 
mapping(IO & IO,MachO::note_command & LoadCommand)596 void MappingTraits<MachO::note_command>::mapping(
597     IO &IO, MachO::note_command &LoadCommand) {
598   IO.mapRequired("data_owner", LoadCommand.data_owner);
599   IO.mapRequired("offset", LoadCommand.offset);
600   IO.mapRequired("size", LoadCommand.size);
601 }
602 
mapping(IO & IO,MachO::build_version_command & LoadCommand)603 void MappingTraits<MachO::build_version_command>::mapping(
604     IO &IO, MachO::build_version_command &LoadCommand) {
605   IO.mapRequired("platform", LoadCommand.platform);
606   IO.mapRequired("minos", LoadCommand.minos);
607   IO.mapRequired("sdk", LoadCommand.sdk);
608   IO.mapRequired("ntools", LoadCommand.ntools);
609 }
610 
611 } // end namespace yaml
612 
613 } // end namespace llvm
614