• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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("PayloadString", LoadCommand.PayloadString);
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("PayloadString", LoadCommand.PayloadString);
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("PayloadString", LoadCommand.PayloadString);
234 }
235 
236 template <>
mapLoadCommandData(IO & IO,MachOYAML::LoadCommand & LoadCommand)237 void mapLoadCommandData<MachO::build_version_command>(
238     IO &IO, MachOYAML::LoadCommand &LoadCommand) {
239   IO.mapOptional("Tools", LoadCommand.Tools);
240 }
241 
mapping(IO & IO,MachOYAML::LoadCommand & LoadCommand)242 void MappingTraits<MachOYAML::LoadCommand>::mapping(
243     IO &IO, MachOYAML::LoadCommand &LoadCommand) {
244   MachO::LoadCommandType TempCmd = static_cast<MachO::LoadCommandType>(
245       LoadCommand.Data.load_command_data.cmd);
246   IO.mapRequired("cmd", TempCmd);
247   LoadCommand.Data.load_command_data.cmd = TempCmd;
248   IO.mapRequired("cmdsize", LoadCommand.Data.load_command_data.cmdsize);
249 
250 #define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct)                         \
251   case MachO::LCName:                                                          \
252     MappingTraits<MachO::LCStruct>::mapping(IO,                                \
253                                             LoadCommand.Data.LCStruct##_data); \
254     mapLoadCommandData<MachO::LCStruct>(IO, LoadCommand);                      \
255     break;
256 
257   switch (LoadCommand.Data.load_command_data.cmd) {
258 #include "llvm/BinaryFormat/MachO.def"
259   }
260   IO.mapOptional("PayloadBytes", LoadCommand.PayloadBytes);
261   IO.mapOptional("ZeroPadBytes", LoadCommand.ZeroPadBytes, (uint64_t)0ull);
262 }
263 
mapping(IO & IO,MachO::dyld_info_command & LoadCommand)264 void MappingTraits<MachO::dyld_info_command>::mapping(
265     IO &IO, MachO::dyld_info_command &LoadCommand) {
266   IO.mapRequired("rebase_off", LoadCommand.rebase_off);
267   IO.mapRequired("rebase_size", LoadCommand.rebase_size);
268   IO.mapRequired("bind_off", LoadCommand.bind_off);
269   IO.mapRequired("bind_size", LoadCommand.bind_size);
270   IO.mapRequired("weak_bind_off", LoadCommand.weak_bind_off);
271   IO.mapRequired("weak_bind_size", LoadCommand.weak_bind_size);
272   IO.mapRequired("lazy_bind_off", LoadCommand.lazy_bind_off);
273   IO.mapRequired("lazy_bind_size", LoadCommand.lazy_bind_size);
274   IO.mapRequired("export_off", LoadCommand.export_off);
275   IO.mapRequired("export_size", LoadCommand.export_size);
276 }
277 
mapping(IO & IO,MachOYAML::Relocation & Relocation)278 void MappingTraits<MachOYAML::Relocation>::mapping(
279     IO &IO, MachOYAML::Relocation &Relocation) {
280   IO.mapRequired("address", Relocation.address);
281   IO.mapRequired("symbolnum", Relocation.symbolnum);
282   IO.mapRequired("pcrel", Relocation.is_pcrel);
283   IO.mapRequired("length", Relocation.length);
284   IO.mapRequired("extern", Relocation.is_extern);
285   IO.mapRequired("type", Relocation.type);
286   IO.mapRequired("scattered", Relocation.is_scattered);
287   IO.mapRequired("value", Relocation.value);
288 }
289 
mapping(IO & IO,MachOYAML::Section & Section)290 void MappingTraits<MachOYAML::Section>::mapping(IO &IO,
291                                                 MachOYAML::Section &Section) {
292   IO.mapRequired("sectname", Section.sectname);
293   IO.mapRequired("segname", Section.segname);
294   IO.mapRequired("addr", Section.addr);
295   IO.mapRequired("size", Section.size);
296   IO.mapRequired("offset", Section.offset);
297   IO.mapRequired("align", Section.align);
298   IO.mapRequired("reloff", Section.reloff);
299   IO.mapRequired("nreloc", Section.nreloc);
300   IO.mapRequired("flags", Section.flags);
301   IO.mapRequired("reserved1", Section.reserved1);
302   IO.mapRequired("reserved2", Section.reserved2);
303   IO.mapOptional("reserved3", Section.reserved3);
304   IO.mapOptional("content", Section.content);
305   IO.mapOptional("relocations", Section.relocations);
306 }
307 
308 std::string
validate(IO & IO,MachOYAML::Section & Section)309 MappingTraits<MachOYAML::Section>::validate(IO &IO,
310                                             MachOYAML::Section &Section) {
311   if (Section.content && Section.size < Section.content->binary_size())
312     return "Section size must be greater than or equal to the content size";
313   return "";
314 }
315 
mapping(IO & IO,MachO::build_tool_version & tool)316 void MappingTraits<MachO::build_tool_version>::mapping(
317     IO &IO, MachO::build_tool_version &tool) {
318   IO.mapRequired("tool", tool.tool);
319   IO.mapRequired("version", tool.version);
320 }
321 
mapping(IO & IO,MachO::dylib & DylibStruct)322 void MappingTraits<MachO::dylib>::mapping(IO &IO, MachO::dylib &DylibStruct) {
323   IO.mapRequired("name", DylibStruct.name);
324   IO.mapRequired("timestamp", DylibStruct.timestamp);
325   IO.mapRequired("current_version", DylibStruct.current_version);
326   IO.mapRequired("compatibility_version", DylibStruct.compatibility_version);
327 }
328 
mapping(IO & IO,MachO::dylib_command & LoadCommand)329 void MappingTraits<MachO::dylib_command>::mapping(
330     IO &IO, MachO::dylib_command &LoadCommand) {
331   IO.mapRequired("dylib", LoadCommand.dylib);
332 }
333 
mapping(IO & IO,MachO::dylinker_command & LoadCommand)334 void MappingTraits<MachO::dylinker_command>::mapping(
335     IO &IO, MachO::dylinker_command &LoadCommand) {
336   IO.mapRequired("name", LoadCommand.name);
337 }
338 
mapping(IO & IO,MachO::dysymtab_command & LoadCommand)339 void MappingTraits<MachO::dysymtab_command>::mapping(
340     IO &IO, MachO::dysymtab_command &LoadCommand) {
341   IO.mapRequired("ilocalsym", LoadCommand.ilocalsym);
342   IO.mapRequired("nlocalsym", LoadCommand.nlocalsym);
343   IO.mapRequired("iextdefsym", LoadCommand.iextdefsym);
344   IO.mapRequired("nextdefsym", LoadCommand.nextdefsym);
345   IO.mapRequired("iundefsym", LoadCommand.iundefsym);
346   IO.mapRequired("nundefsym", LoadCommand.nundefsym);
347   IO.mapRequired("tocoff", LoadCommand.tocoff);
348   IO.mapRequired("ntoc", LoadCommand.ntoc);
349   IO.mapRequired("modtaboff", LoadCommand.modtaboff);
350   IO.mapRequired("nmodtab", LoadCommand.nmodtab);
351   IO.mapRequired("extrefsymoff", LoadCommand.extrefsymoff);
352   IO.mapRequired("nextrefsyms", LoadCommand.nextrefsyms);
353   IO.mapRequired("indirectsymoff", LoadCommand.indirectsymoff);
354   IO.mapRequired("nindirectsyms", LoadCommand.nindirectsyms);
355   IO.mapRequired("extreloff", LoadCommand.extreloff);
356   IO.mapRequired("nextrel", LoadCommand.nextrel);
357   IO.mapRequired("locreloff", LoadCommand.locreloff);
358   IO.mapRequired("nlocrel", LoadCommand.nlocrel);
359 }
360 
mapping(IO & IO,MachO::encryption_info_command & LoadCommand)361 void MappingTraits<MachO::encryption_info_command>::mapping(
362     IO &IO, MachO::encryption_info_command &LoadCommand) {
363   IO.mapRequired("cryptoff", LoadCommand.cryptoff);
364   IO.mapRequired("cryptsize", LoadCommand.cryptsize);
365   IO.mapRequired("cryptid", LoadCommand.cryptid);
366 }
367 
mapping(IO & IO,MachO::encryption_info_command_64 & LoadCommand)368 void MappingTraits<MachO::encryption_info_command_64>::mapping(
369     IO &IO, MachO::encryption_info_command_64 &LoadCommand) {
370   IO.mapRequired("cryptoff", LoadCommand.cryptoff);
371   IO.mapRequired("cryptsize", LoadCommand.cryptsize);
372   IO.mapRequired("cryptid", LoadCommand.cryptid);
373   IO.mapRequired("pad", LoadCommand.pad);
374 }
375 
mapping(IO & IO,MachO::entry_point_command & LoadCommand)376 void MappingTraits<MachO::entry_point_command>::mapping(
377     IO &IO, MachO::entry_point_command &LoadCommand) {
378   IO.mapRequired("entryoff", LoadCommand.entryoff);
379   IO.mapRequired("stacksize", LoadCommand.stacksize);
380 }
381 
mapping(IO & IO,MachO::fvmfile_command & LoadCommand)382 void MappingTraits<MachO::fvmfile_command>::mapping(
383     IO &IO, MachO::fvmfile_command &LoadCommand) {
384   IO.mapRequired("name", LoadCommand.name);
385   IO.mapRequired("header_addr", LoadCommand.header_addr);
386 }
387 
mapping(IO & IO,MachO::fvmlib & FVMLib)388 void MappingTraits<MachO::fvmlib>::mapping(IO &IO, MachO::fvmlib &FVMLib) {
389   IO.mapRequired("name", FVMLib.name);
390   IO.mapRequired("minor_version", FVMLib.minor_version);
391   IO.mapRequired("header_addr", FVMLib.header_addr);
392 }
393 
mapping(IO & IO,MachO::fvmlib_command & LoadCommand)394 void MappingTraits<MachO::fvmlib_command>::mapping(
395     IO &IO, MachO::fvmlib_command &LoadCommand) {
396   IO.mapRequired("fvmlib", LoadCommand.fvmlib);
397 }
398 
mapping(IO & IO,MachO::ident_command & LoadCommand)399 void MappingTraits<MachO::ident_command>::mapping(
400     IO &IO, MachO::ident_command &LoadCommand) {}
401 
mapping(IO & IO,MachO::linkedit_data_command & LoadCommand)402 void MappingTraits<MachO::linkedit_data_command>::mapping(
403     IO &IO, MachO::linkedit_data_command &LoadCommand) {
404   IO.mapRequired("dataoff", LoadCommand.dataoff);
405   IO.mapRequired("datasize", LoadCommand.datasize);
406 }
407 
mapping(IO & IO,MachO::linker_option_command & LoadCommand)408 void MappingTraits<MachO::linker_option_command>::mapping(
409     IO &IO, MachO::linker_option_command &LoadCommand) {
410   IO.mapRequired("count", LoadCommand.count);
411 }
412 
mapping(IO & IO,MachO::prebind_cksum_command & LoadCommand)413 void MappingTraits<MachO::prebind_cksum_command>::mapping(
414     IO &IO, MachO::prebind_cksum_command &LoadCommand) {
415   IO.mapRequired("cksum", LoadCommand.cksum);
416 }
417 
mapping(IO & IO,MachO::load_command & LoadCommand)418 void MappingTraits<MachO::load_command>::mapping(
419     IO &IO, MachO::load_command &LoadCommand) {}
420 
mapping(IO & IO,MachO::prebound_dylib_command & LoadCommand)421 void MappingTraits<MachO::prebound_dylib_command>::mapping(
422     IO &IO, MachO::prebound_dylib_command &LoadCommand) {
423   IO.mapRequired("name", LoadCommand.name);
424   IO.mapRequired("nmodules", LoadCommand.nmodules);
425   IO.mapRequired("linked_modules", LoadCommand.linked_modules);
426 }
427 
mapping(IO & IO,MachO::routines_command & LoadCommand)428 void MappingTraits<MachO::routines_command>::mapping(
429     IO &IO, MachO::routines_command &LoadCommand) {
430   IO.mapRequired("init_address", LoadCommand.init_address);
431   IO.mapRequired("init_module", LoadCommand.init_module);
432   IO.mapRequired("reserved1", LoadCommand.reserved1);
433   IO.mapRequired("reserved2", LoadCommand.reserved2);
434   IO.mapRequired("reserved3", LoadCommand.reserved3);
435   IO.mapRequired("reserved4", LoadCommand.reserved4);
436   IO.mapRequired("reserved5", LoadCommand.reserved5);
437   IO.mapRequired("reserved6", LoadCommand.reserved6);
438 }
439 
mapping(IO & IO,MachO::routines_command_64 & LoadCommand)440 void MappingTraits<MachO::routines_command_64>::mapping(
441     IO &IO, MachO::routines_command_64 &LoadCommand) {
442   IO.mapRequired("init_address", LoadCommand.init_address);
443   IO.mapRequired("init_module", LoadCommand.init_module);
444   IO.mapRequired("reserved1", LoadCommand.reserved1);
445   IO.mapRequired("reserved2", LoadCommand.reserved2);
446   IO.mapRequired("reserved3", LoadCommand.reserved3);
447   IO.mapRequired("reserved4", LoadCommand.reserved4);
448   IO.mapRequired("reserved5", LoadCommand.reserved5);
449   IO.mapRequired("reserved6", LoadCommand.reserved6);
450 }
451 
mapping(IO & IO,MachO::rpath_command & LoadCommand)452 void MappingTraits<MachO::rpath_command>::mapping(
453     IO &IO, MachO::rpath_command &LoadCommand) {
454   IO.mapRequired("path", LoadCommand.path);
455 }
456 
mapping(IO & IO,MachO::section & Section)457 void MappingTraits<MachO::section>::mapping(IO &IO, MachO::section &Section) {
458   IO.mapRequired("sectname", Section.sectname);
459   IO.mapRequired("segname", Section.segname);
460   IO.mapRequired("addr", Section.addr);
461   IO.mapRequired("size", Section.size);
462   IO.mapRequired("offset", Section.offset);
463   IO.mapRequired("align", Section.align);
464   IO.mapRequired("reloff", Section.reloff);
465   IO.mapRequired("nreloc", Section.nreloc);
466   IO.mapRequired("flags", Section.flags);
467   IO.mapRequired("reserved1", Section.reserved1);
468   IO.mapRequired("reserved2", Section.reserved2);
469 }
470 
mapping(IO & IO,MachO::section_64 & Section)471 void MappingTraits<MachO::section_64>::mapping(IO &IO,
472                                                MachO::section_64 &Section) {
473   IO.mapRequired("sectname", Section.sectname);
474   IO.mapRequired("segname", Section.segname);
475   IO.mapRequired("addr", Section.addr);
476   IO.mapRequired("size", Section.size);
477   IO.mapRequired("offset", Section.offset);
478   IO.mapRequired("align", Section.align);
479   IO.mapRequired("reloff", Section.reloff);
480   IO.mapRequired("nreloc", Section.nreloc);
481   IO.mapRequired("flags", Section.flags);
482   IO.mapRequired("reserved1", Section.reserved1);
483   IO.mapRequired("reserved2", Section.reserved2);
484   IO.mapRequired("reserved3", Section.reserved3);
485 }
486 
mapping(IO & IO,MachO::segment_command & LoadCommand)487 void MappingTraits<MachO::segment_command>::mapping(
488     IO &IO, MachO::segment_command &LoadCommand) {
489   IO.mapRequired("segname", LoadCommand.segname);
490   IO.mapRequired("vmaddr", LoadCommand.vmaddr);
491   IO.mapRequired("vmsize", LoadCommand.vmsize);
492   IO.mapRequired("fileoff", LoadCommand.fileoff);
493   IO.mapRequired("filesize", LoadCommand.filesize);
494   IO.mapRequired("maxprot", LoadCommand.maxprot);
495   IO.mapRequired("initprot", LoadCommand.initprot);
496   IO.mapRequired("nsects", LoadCommand.nsects);
497   IO.mapRequired("flags", LoadCommand.flags);
498 }
499 
mapping(IO & IO,MachO::segment_command_64 & LoadCommand)500 void MappingTraits<MachO::segment_command_64>::mapping(
501     IO &IO, MachO::segment_command_64 &LoadCommand) {
502   IO.mapRequired("segname", LoadCommand.segname);
503   IO.mapRequired("vmaddr", LoadCommand.vmaddr);
504   IO.mapRequired("vmsize", LoadCommand.vmsize);
505   IO.mapRequired("fileoff", LoadCommand.fileoff);
506   IO.mapRequired("filesize", LoadCommand.filesize);
507   IO.mapRequired("maxprot", LoadCommand.maxprot);
508   IO.mapRequired("initprot", LoadCommand.initprot);
509   IO.mapRequired("nsects", LoadCommand.nsects);
510   IO.mapRequired("flags", LoadCommand.flags);
511 }
512 
mapping(IO & IO,MachO::source_version_command & LoadCommand)513 void MappingTraits<MachO::source_version_command>::mapping(
514     IO &IO, MachO::source_version_command &LoadCommand) {
515   IO.mapRequired("version", LoadCommand.version);
516 }
517 
mapping(IO & IO,MachO::sub_client_command & LoadCommand)518 void MappingTraits<MachO::sub_client_command>::mapping(
519     IO &IO, MachO::sub_client_command &LoadCommand) {
520   IO.mapRequired("client", LoadCommand.client);
521 }
522 
mapping(IO & IO,MachO::sub_framework_command & LoadCommand)523 void MappingTraits<MachO::sub_framework_command>::mapping(
524     IO &IO, MachO::sub_framework_command &LoadCommand) {
525   IO.mapRequired("umbrella", LoadCommand.umbrella);
526 }
527 
mapping(IO & IO,MachO::sub_library_command & LoadCommand)528 void MappingTraits<MachO::sub_library_command>::mapping(
529     IO &IO, MachO::sub_library_command &LoadCommand) {
530   IO.mapRequired("sub_library", LoadCommand.sub_library);
531 }
532 
mapping(IO & IO,MachO::sub_umbrella_command & LoadCommand)533 void MappingTraits<MachO::sub_umbrella_command>::mapping(
534     IO &IO, MachO::sub_umbrella_command &LoadCommand) {
535   IO.mapRequired("sub_umbrella", LoadCommand.sub_umbrella);
536 }
537 
mapping(IO & IO,MachO::symseg_command & LoadCommand)538 void MappingTraits<MachO::symseg_command>::mapping(
539     IO &IO, MachO::symseg_command &LoadCommand) {
540   IO.mapRequired("offset", LoadCommand.offset);
541   IO.mapRequired("size", LoadCommand.size);
542 }
543 
mapping(IO & IO,MachO::symtab_command & LoadCommand)544 void MappingTraits<MachO::symtab_command>::mapping(
545     IO &IO, MachO::symtab_command &LoadCommand) {
546   IO.mapRequired("symoff", LoadCommand.symoff);
547   IO.mapRequired("nsyms", LoadCommand.nsyms);
548   IO.mapRequired("stroff", LoadCommand.stroff);
549   IO.mapRequired("strsize", LoadCommand.strsize);
550 }
551 
mapping(IO & IO,MachO::thread_command & LoadCommand)552 void MappingTraits<MachO::thread_command>::mapping(
553     IO &IO, MachO::thread_command &LoadCommand) {}
554 
mapping(IO & IO,MachO::twolevel_hints_command & LoadCommand)555 void MappingTraits<MachO::twolevel_hints_command>::mapping(
556     IO &IO, MachO::twolevel_hints_command &LoadCommand) {
557   IO.mapRequired("offset", LoadCommand.offset);
558   IO.mapRequired("nhints", LoadCommand.nhints);
559 }
560 
mapping(IO & IO,MachO::uuid_command & LoadCommand)561 void MappingTraits<MachO::uuid_command>::mapping(
562     IO &IO, MachO::uuid_command &LoadCommand) {
563   IO.mapRequired("uuid", LoadCommand.uuid);
564 }
565 
mapping(IO & IO,MachO::version_min_command & LoadCommand)566 void MappingTraits<MachO::version_min_command>::mapping(
567     IO &IO, MachO::version_min_command &LoadCommand) {
568   IO.mapRequired("version", LoadCommand.version);
569   IO.mapRequired("sdk", LoadCommand.sdk);
570 }
571 
mapping(IO & IO,MachO::note_command & LoadCommand)572 void MappingTraits<MachO::note_command>::mapping(
573     IO &IO, MachO::note_command &LoadCommand) {
574   IO.mapRequired("data_owner", LoadCommand.data_owner);
575   IO.mapRequired("offset", LoadCommand.offset);
576   IO.mapRequired("size", LoadCommand.size);
577 }
578 
mapping(IO & IO,MachO::build_version_command & LoadCommand)579 void MappingTraits<MachO::build_version_command>::mapping(
580     IO &IO, MachO::build_version_command &LoadCommand) {
581   IO.mapRequired("platform", LoadCommand.platform);
582   IO.mapRequired("minos", LoadCommand.minos);
583   IO.mapRequired("sdk", LoadCommand.sdk);
584   IO.mapRequired("ntools", LoadCommand.ntools);
585 }
586 
587 } // end namespace yaml
588 
589 } // end namespace llvm
590