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 
28 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 
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 
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 
54 QuotingType ScalarTraits<char_16>::mustQuote(StringRef S) {
55   return needsQuotes(S);
56 }
57 
58 void ScalarTraits<uuid_t>::output(const uuid_t &Val, void *, raw_ostream &Out) {
59   Out.write_uuid(Val);
60 }
61 
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 
79 QuotingType ScalarTraits<uuid_t>::mustQuote(StringRef S) {
80   return needsQuotes(S);
81 }
82 
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 
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   IO.mapOptional("LoadCommands", Object.LoadCommands);
111   if(!Object.LinkEdit.isEmpty() || !IO.outputting())
112     IO.mapOptional("LinkEditData", Object.LinkEdit);
113 
114   if(!Object.DWARF.isEmpty() || !IO.outputting())
115     IO.mapOptional("DWARF", Object.DWARF);
116 
117   if (IO.getContext() == &Object)
118     IO.setContext(nullptr);
119 }
120 
121 void MappingTraits<MachOYAML::FatHeader>::mapping(
122     IO &IO, MachOYAML::FatHeader &FatHeader) {
123   IO.mapRequired("magic", FatHeader.magic);
124   IO.mapRequired("nfat_arch", FatHeader.nfat_arch);
125 }
126 
127 void MappingTraits<MachOYAML::FatArch>::mapping(IO &IO,
128                                                 MachOYAML::FatArch &FatArch) {
129   IO.mapRequired("cputype", FatArch.cputype);
130   IO.mapRequired("cpusubtype", FatArch.cpusubtype);
131   IO.mapRequired("offset", FatArch.offset);
132   IO.mapRequired("size", FatArch.size);
133   IO.mapRequired("align", FatArch.align);
134   IO.mapOptional("reserved", FatArch.reserved,
135                  static_cast<llvm::yaml::Hex32>(0));
136 }
137 
138 void MappingTraits<MachOYAML::UniversalBinary>::mapping(
139     IO &IO, MachOYAML::UniversalBinary &UniversalBinary) {
140   if (!IO.getContext()) {
141     IO.setContext(&UniversalBinary);
142     IO.mapTag("!fat-mach-o", true);
143   }
144   IO.mapRequired("FatHeader", UniversalBinary.Header);
145   IO.mapRequired("FatArchs", UniversalBinary.FatArchs);
146   IO.mapRequired("Slices", UniversalBinary.Slices);
147 
148   if (IO.getContext() == &UniversalBinary)
149     IO.setContext(nullptr);
150 }
151 
152 void MappingTraits<MachOYAML::LinkEditData>::mapping(
153     IO &IO, MachOYAML::LinkEditData &LinkEditData) {
154   IO.mapOptional("RebaseOpcodes", LinkEditData.RebaseOpcodes);
155   IO.mapOptional("BindOpcodes", LinkEditData.BindOpcodes);
156   IO.mapOptional("WeakBindOpcodes", LinkEditData.WeakBindOpcodes);
157   IO.mapOptional("LazyBindOpcodes", LinkEditData.LazyBindOpcodes);
158   if (!LinkEditData.ExportTrie.Children.empty() || !IO.outputting())
159     IO.mapOptional("ExportTrie", LinkEditData.ExportTrie);
160   IO.mapOptional("NameList", LinkEditData.NameList);
161   IO.mapOptional("StringTable", LinkEditData.StringTable);
162 }
163 
164 void MappingTraits<MachOYAML::RebaseOpcode>::mapping(
165     IO &IO, MachOYAML::RebaseOpcode &RebaseOpcode) {
166   IO.mapRequired("Opcode", RebaseOpcode.Opcode);
167   IO.mapRequired("Imm", RebaseOpcode.Imm);
168   IO.mapOptional("ExtraData", RebaseOpcode.ExtraData);
169 }
170 
171 void MappingTraits<MachOYAML::BindOpcode>::mapping(
172     IO &IO, MachOYAML::BindOpcode &BindOpcode) {
173   IO.mapRequired("Opcode", BindOpcode.Opcode);
174   IO.mapRequired("Imm", BindOpcode.Imm);
175   IO.mapOptional("ULEBExtraData", BindOpcode.ULEBExtraData);
176   IO.mapOptional("SLEBExtraData", BindOpcode.SLEBExtraData);
177   IO.mapOptional("Symbol", BindOpcode.Symbol);
178 }
179 
180 void MappingTraits<MachOYAML::ExportEntry>::mapping(
181     IO &IO, MachOYAML::ExportEntry &ExportEntry) {
182   IO.mapRequired("TerminalSize", ExportEntry.TerminalSize);
183   IO.mapOptional("NodeOffset", ExportEntry.NodeOffset);
184   IO.mapOptional("Name", ExportEntry.Name);
185   IO.mapOptional("Flags", ExportEntry.Flags);
186   IO.mapOptional("Address", ExportEntry.Address);
187   IO.mapOptional("Other", ExportEntry.Other);
188   IO.mapOptional("ImportName", ExportEntry.ImportName);
189   IO.mapOptional("Children", ExportEntry.Children);
190 }
191 
192 void MappingTraits<MachOYAML::NListEntry>::mapping(
193     IO &IO, MachOYAML::NListEntry &NListEntry) {
194   IO.mapRequired("n_strx", NListEntry.n_strx);
195   IO.mapRequired("n_type", NListEntry.n_type);
196   IO.mapRequired("n_sect", NListEntry.n_sect);
197   IO.mapRequired("n_desc", NListEntry.n_desc);
198   IO.mapRequired("n_value", NListEntry.n_value);
199 }
200 
201 template <typename StructType>
202 void mapLoadCommandData(IO &IO, MachOYAML::LoadCommand &LoadCommand) {}
203 
204 template <>
205 void mapLoadCommandData<MachO::segment_command>(
206     IO &IO, MachOYAML::LoadCommand &LoadCommand) {
207   IO.mapOptional("Sections", LoadCommand.Sections);
208 }
209 
210 template <>
211 void mapLoadCommandData<MachO::segment_command_64>(
212     IO &IO, MachOYAML::LoadCommand &LoadCommand) {
213   IO.mapOptional("Sections", LoadCommand.Sections);
214 }
215 
216 template <>
217 void mapLoadCommandData<MachO::dylib_command>(
218     IO &IO, MachOYAML::LoadCommand &LoadCommand) {
219   IO.mapOptional("PayloadString", LoadCommand.PayloadString);
220 }
221 
222 template <>
223 void mapLoadCommandData<MachO::rpath_command>(
224     IO &IO, MachOYAML::LoadCommand &LoadCommand) {
225   IO.mapOptional("PayloadString", LoadCommand.PayloadString);
226 }
227 
228 template <>
229 void mapLoadCommandData<MachO::dylinker_command>(
230     IO &IO, MachOYAML::LoadCommand &LoadCommand) {
231   IO.mapOptional("PayloadString", LoadCommand.PayloadString);
232 }
233 
234 template <>
235 void mapLoadCommandData<MachO::build_version_command>(
236     IO &IO, MachOYAML::LoadCommand &LoadCommand) {
237   IO.mapOptional("Tools", LoadCommand.Tools);
238 }
239 
240 void MappingTraits<MachOYAML::LoadCommand>::mapping(
241     IO &IO, MachOYAML::LoadCommand &LoadCommand) {
242   MachO::LoadCommandType TempCmd = static_cast<MachO::LoadCommandType>(
243       LoadCommand.Data.load_command_data.cmd);
244   IO.mapRequired("cmd", TempCmd);
245   LoadCommand.Data.load_command_data.cmd = TempCmd;
246   IO.mapRequired("cmdsize", LoadCommand.Data.load_command_data.cmdsize);
247 
248 #define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct)                         \
249   case MachO::LCName:                                                          \
250     MappingTraits<MachO::LCStruct>::mapping(IO,                                \
251                                             LoadCommand.Data.LCStruct##_data); \
252     mapLoadCommandData<MachO::LCStruct>(IO, LoadCommand);                      \
253     break;
254 
255   switch (LoadCommand.Data.load_command_data.cmd) {
256 #include "llvm/BinaryFormat/MachO.def"
257   }
258   IO.mapOptional("PayloadBytes", LoadCommand.PayloadBytes);
259   IO.mapOptional("ZeroPadBytes", LoadCommand.ZeroPadBytes, (uint64_t)0ull);
260 }
261 
262 void MappingTraits<MachO::dyld_info_command>::mapping(
263     IO &IO, MachO::dyld_info_command &LoadCommand) {
264   IO.mapRequired("rebase_off", LoadCommand.rebase_off);
265   IO.mapRequired("rebase_size", LoadCommand.rebase_size);
266   IO.mapRequired("bind_off", LoadCommand.bind_off);
267   IO.mapRequired("bind_size", LoadCommand.bind_size);
268   IO.mapRequired("weak_bind_off", LoadCommand.weak_bind_off);
269   IO.mapRequired("weak_bind_size", LoadCommand.weak_bind_size);
270   IO.mapRequired("lazy_bind_off", LoadCommand.lazy_bind_off);
271   IO.mapRequired("lazy_bind_size", LoadCommand.lazy_bind_size);
272   IO.mapRequired("export_off", LoadCommand.export_off);
273   IO.mapRequired("export_size", LoadCommand.export_size);
274 }
275 
276 void MappingTraits<MachOYAML::Relocation>::mapping(
277     IO &IO, MachOYAML::Relocation &Relocation) {
278   IO.mapRequired("address", Relocation.address);
279   IO.mapRequired("symbolnum", Relocation.symbolnum);
280   IO.mapRequired("pcrel", Relocation.is_pcrel);
281   IO.mapRequired("length", Relocation.length);
282   IO.mapRequired("extern", Relocation.is_extern);
283   IO.mapRequired("type", Relocation.type);
284   IO.mapRequired("scattered", Relocation.is_scattered);
285   IO.mapRequired("value", Relocation.value);
286 }
287 
288 void MappingTraits<MachOYAML::Section>::mapping(IO &IO,
289                                                 MachOYAML::Section &Section) {
290   IO.mapRequired("sectname", Section.sectname);
291   IO.mapRequired("segname", Section.segname);
292   IO.mapRequired("addr", Section.addr);
293   IO.mapRequired("size", Section.size);
294   IO.mapRequired("offset", Section.offset);
295   IO.mapRequired("align", Section.align);
296   IO.mapRequired("reloff", Section.reloff);
297   IO.mapRequired("nreloc", Section.nreloc);
298   IO.mapRequired("flags", Section.flags);
299   IO.mapRequired("reserved1", Section.reserved1);
300   IO.mapRequired("reserved2", Section.reserved2);
301   IO.mapOptional("reserved3", Section.reserved3);
302   IO.mapOptional("content", Section.content);
303   IO.mapOptional("relocations", Section.relocations);
304 }
305 
306 StringRef
307 MappingTraits<MachOYAML::Section>::validate(IO &IO,
308                                             MachOYAML::Section &Section) {
309   if (Section.content && Section.size < Section.content->binary_size())
310     return "Section size must be greater than or equal to the content size";
311   return {};
312 }
313 
314 void MappingTraits<MachO::build_tool_version>::mapping(
315     IO &IO, MachO::build_tool_version &tool) {
316   IO.mapRequired("tool", tool.tool);
317   IO.mapRequired("version", tool.version);
318 }
319 
320 void MappingTraits<MachO::dylib>::mapping(IO &IO, MachO::dylib &DylibStruct) {
321   IO.mapRequired("name", DylibStruct.name);
322   IO.mapRequired("timestamp", DylibStruct.timestamp);
323   IO.mapRequired("current_version", DylibStruct.current_version);
324   IO.mapRequired("compatibility_version", DylibStruct.compatibility_version);
325 }
326 
327 void MappingTraits<MachO::dylib_command>::mapping(
328     IO &IO, MachO::dylib_command &LoadCommand) {
329   IO.mapRequired("dylib", LoadCommand.dylib);
330 }
331 
332 void MappingTraits<MachO::dylinker_command>::mapping(
333     IO &IO, MachO::dylinker_command &LoadCommand) {
334   IO.mapRequired("name", LoadCommand.name);
335 }
336 
337 void MappingTraits<MachO::dysymtab_command>::mapping(
338     IO &IO, MachO::dysymtab_command &LoadCommand) {
339   IO.mapRequired("ilocalsym", LoadCommand.ilocalsym);
340   IO.mapRequired("nlocalsym", LoadCommand.nlocalsym);
341   IO.mapRequired("iextdefsym", LoadCommand.iextdefsym);
342   IO.mapRequired("nextdefsym", LoadCommand.nextdefsym);
343   IO.mapRequired("iundefsym", LoadCommand.iundefsym);
344   IO.mapRequired("nundefsym", LoadCommand.nundefsym);
345   IO.mapRequired("tocoff", LoadCommand.tocoff);
346   IO.mapRequired("ntoc", LoadCommand.ntoc);
347   IO.mapRequired("modtaboff", LoadCommand.modtaboff);
348   IO.mapRequired("nmodtab", LoadCommand.nmodtab);
349   IO.mapRequired("extrefsymoff", LoadCommand.extrefsymoff);
350   IO.mapRequired("nextrefsyms", LoadCommand.nextrefsyms);
351   IO.mapRequired("indirectsymoff", LoadCommand.indirectsymoff);
352   IO.mapRequired("nindirectsyms", LoadCommand.nindirectsyms);
353   IO.mapRequired("extreloff", LoadCommand.extreloff);
354   IO.mapRequired("nextrel", LoadCommand.nextrel);
355   IO.mapRequired("locreloff", LoadCommand.locreloff);
356   IO.mapRequired("nlocrel", LoadCommand.nlocrel);
357 }
358 
359 void MappingTraits<MachO::encryption_info_command>::mapping(
360     IO &IO, MachO::encryption_info_command &LoadCommand) {
361   IO.mapRequired("cryptoff", LoadCommand.cryptoff);
362   IO.mapRequired("cryptsize", LoadCommand.cryptsize);
363   IO.mapRequired("cryptid", LoadCommand.cryptid);
364 }
365 
366 void MappingTraits<MachO::encryption_info_command_64>::mapping(
367     IO &IO, MachO::encryption_info_command_64 &LoadCommand) {
368   IO.mapRequired("cryptoff", LoadCommand.cryptoff);
369   IO.mapRequired("cryptsize", LoadCommand.cryptsize);
370   IO.mapRequired("cryptid", LoadCommand.cryptid);
371   IO.mapRequired("pad", LoadCommand.pad);
372 }
373 
374 void MappingTraits<MachO::entry_point_command>::mapping(
375     IO &IO, MachO::entry_point_command &LoadCommand) {
376   IO.mapRequired("entryoff", LoadCommand.entryoff);
377   IO.mapRequired("stacksize", LoadCommand.stacksize);
378 }
379 
380 void MappingTraits<MachO::fvmfile_command>::mapping(
381     IO &IO, MachO::fvmfile_command &LoadCommand) {
382   IO.mapRequired("name", LoadCommand.name);
383   IO.mapRequired("header_addr", LoadCommand.header_addr);
384 }
385 
386 void MappingTraits<MachO::fvmlib>::mapping(IO &IO, MachO::fvmlib &FVMLib) {
387   IO.mapRequired("name", FVMLib.name);
388   IO.mapRequired("minor_version", FVMLib.minor_version);
389   IO.mapRequired("header_addr", FVMLib.header_addr);
390 }
391 
392 void MappingTraits<MachO::fvmlib_command>::mapping(
393     IO &IO, MachO::fvmlib_command &LoadCommand) {
394   IO.mapRequired("fvmlib", LoadCommand.fvmlib);
395 }
396 
397 void MappingTraits<MachO::ident_command>::mapping(
398     IO &IO, MachO::ident_command &LoadCommand) {}
399 
400 void MappingTraits<MachO::linkedit_data_command>::mapping(
401     IO &IO, MachO::linkedit_data_command &LoadCommand) {
402   IO.mapRequired("dataoff", LoadCommand.dataoff);
403   IO.mapRequired("datasize", LoadCommand.datasize);
404 }
405 
406 void MappingTraits<MachO::linker_option_command>::mapping(
407     IO &IO, MachO::linker_option_command &LoadCommand) {
408   IO.mapRequired("count", LoadCommand.count);
409 }
410 
411 void MappingTraits<MachO::prebind_cksum_command>::mapping(
412     IO &IO, MachO::prebind_cksum_command &LoadCommand) {
413   IO.mapRequired("cksum", LoadCommand.cksum);
414 }
415 
416 void MappingTraits<MachO::load_command>::mapping(
417     IO &IO, MachO::load_command &LoadCommand) {}
418 
419 void MappingTraits<MachO::prebound_dylib_command>::mapping(
420     IO &IO, MachO::prebound_dylib_command &LoadCommand) {
421   IO.mapRequired("name", LoadCommand.name);
422   IO.mapRequired("nmodules", LoadCommand.nmodules);
423   IO.mapRequired("linked_modules", LoadCommand.linked_modules);
424 }
425 
426 void MappingTraits<MachO::routines_command>::mapping(
427     IO &IO, MachO::routines_command &LoadCommand) {
428   IO.mapRequired("init_address", LoadCommand.init_address);
429   IO.mapRequired("init_module", LoadCommand.init_module);
430   IO.mapRequired("reserved1", LoadCommand.reserved1);
431   IO.mapRequired("reserved2", LoadCommand.reserved2);
432   IO.mapRequired("reserved3", LoadCommand.reserved3);
433   IO.mapRequired("reserved4", LoadCommand.reserved4);
434   IO.mapRequired("reserved5", LoadCommand.reserved5);
435   IO.mapRequired("reserved6", LoadCommand.reserved6);
436 }
437 
438 void MappingTraits<MachO::routines_command_64>::mapping(
439     IO &IO, MachO::routines_command_64 &LoadCommand) {
440   IO.mapRequired("init_address", LoadCommand.init_address);
441   IO.mapRequired("init_module", LoadCommand.init_module);
442   IO.mapRequired("reserved1", LoadCommand.reserved1);
443   IO.mapRequired("reserved2", LoadCommand.reserved2);
444   IO.mapRequired("reserved3", LoadCommand.reserved3);
445   IO.mapRequired("reserved4", LoadCommand.reserved4);
446   IO.mapRequired("reserved5", LoadCommand.reserved5);
447   IO.mapRequired("reserved6", LoadCommand.reserved6);
448 }
449 
450 void MappingTraits<MachO::rpath_command>::mapping(
451     IO &IO, MachO::rpath_command &LoadCommand) {
452   IO.mapRequired("path", LoadCommand.path);
453 }
454 
455 void MappingTraits<MachO::section>::mapping(IO &IO, MachO::section &Section) {
456   IO.mapRequired("sectname", Section.sectname);
457   IO.mapRequired("segname", Section.segname);
458   IO.mapRequired("addr", Section.addr);
459   IO.mapRequired("size", Section.size);
460   IO.mapRequired("offset", Section.offset);
461   IO.mapRequired("align", Section.align);
462   IO.mapRequired("reloff", Section.reloff);
463   IO.mapRequired("nreloc", Section.nreloc);
464   IO.mapRequired("flags", Section.flags);
465   IO.mapRequired("reserved1", Section.reserved1);
466   IO.mapRequired("reserved2", Section.reserved2);
467 }
468 
469 void MappingTraits<MachO::section_64>::mapping(IO &IO,
470                                                MachO::section_64 &Section) {
471   IO.mapRequired("sectname", Section.sectname);
472   IO.mapRequired("segname", Section.segname);
473   IO.mapRequired("addr", Section.addr);
474   IO.mapRequired("size", Section.size);
475   IO.mapRequired("offset", Section.offset);
476   IO.mapRequired("align", Section.align);
477   IO.mapRequired("reloff", Section.reloff);
478   IO.mapRequired("nreloc", Section.nreloc);
479   IO.mapRequired("flags", Section.flags);
480   IO.mapRequired("reserved1", Section.reserved1);
481   IO.mapRequired("reserved2", Section.reserved2);
482   IO.mapRequired("reserved3", Section.reserved3);
483 }
484 
485 void MappingTraits<MachO::segment_command>::mapping(
486     IO &IO, MachO::segment_command &LoadCommand) {
487   IO.mapRequired("segname", LoadCommand.segname);
488   IO.mapRequired("vmaddr", LoadCommand.vmaddr);
489   IO.mapRequired("vmsize", LoadCommand.vmsize);
490   IO.mapRequired("fileoff", LoadCommand.fileoff);
491   IO.mapRequired("filesize", LoadCommand.filesize);
492   IO.mapRequired("maxprot", LoadCommand.maxprot);
493   IO.mapRequired("initprot", LoadCommand.initprot);
494   IO.mapRequired("nsects", LoadCommand.nsects);
495   IO.mapRequired("flags", LoadCommand.flags);
496 }
497 
498 void MappingTraits<MachO::segment_command_64>::mapping(
499     IO &IO, MachO::segment_command_64 &LoadCommand) {
500   IO.mapRequired("segname", LoadCommand.segname);
501   IO.mapRequired("vmaddr", LoadCommand.vmaddr);
502   IO.mapRequired("vmsize", LoadCommand.vmsize);
503   IO.mapRequired("fileoff", LoadCommand.fileoff);
504   IO.mapRequired("filesize", LoadCommand.filesize);
505   IO.mapRequired("maxprot", LoadCommand.maxprot);
506   IO.mapRequired("initprot", LoadCommand.initprot);
507   IO.mapRequired("nsects", LoadCommand.nsects);
508   IO.mapRequired("flags", LoadCommand.flags);
509 }
510 
511 void MappingTraits<MachO::source_version_command>::mapping(
512     IO &IO, MachO::source_version_command &LoadCommand) {
513   IO.mapRequired("version", LoadCommand.version);
514 }
515 
516 void MappingTraits<MachO::sub_client_command>::mapping(
517     IO &IO, MachO::sub_client_command &LoadCommand) {
518   IO.mapRequired("client", LoadCommand.client);
519 }
520 
521 void MappingTraits<MachO::sub_framework_command>::mapping(
522     IO &IO, MachO::sub_framework_command &LoadCommand) {
523   IO.mapRequired("umbrella", LoadCommand.umbrella);
524 }
525 
526 void MappingTraits<MachO::sub_library_command>::mapping(
527     IO &IO, MachO::sub_library_command &LoadCommand) {
528   IO.mapRequired("sub_library", LoadCommand.sub_library);
529 }
530 
531 void MappingTraits<MachO::sub_umbrella_command>::mapping(
532     IO &IO, MachO::sub_umbrella_command &LoadCommand) {
533   IO.mapRequired("sub_umbrella", LoadCommand.sub_umbrella);
534 }
535 
536 void MappingTraits<MachO::symseg_command>::mapping(
537     IO &IO, MachO::symseg_command &LoadCommand) {
538   IO.mapRequired("offset", LoadCommand.offset);
539   IO.mapRequired("size", LoadCommand.size);
540 }
541 
542 void MappingTraits<MachO::symtab_command>::mapping(
543     IO &IO, MachO::symtab_command &LoadCommand) {
544   IO.mapRequired("symoff", LoadCommand.symoff);
545   IO.mapRequired("nsyms", LoadCommand.nsyms);
546   IO.mapRequired("stroff", LoadCommand.stroff);
547   IO.mapRequired("strsize", LoadCommand.strsize);
548 }
549 
550 void MappingTraits<MachO::thread_command>::mapping(
551     IO &IO, MachO::thread_command &LoadCommand) {}
552 
553 void MappingTraits<MachO::twolevel_hints_command>::mapping(
554     IO &IO, MachO::twolevel_hints_command &LoadCommand) {
555   IO.mapRequired("offset", LoadCommand.offset);
556   IO.mapRequired("nhints", LoadCommand.nhints);
557 }
558 
559 void MappingTraits<MachO::uuid_command>::mapping(
560     IO &IO, MachO::uuid_command &LoadCommand) {
561   IO.mapRequired("uuid", LoadCommand.uuid);
562 }
563 
564 void MappingTraits<MachO::version_min_command>::mapping(
565     IO &IO, MachO::version_min_command &LoadCommand) {
566   IO.mapRequired("version", LoadCommand.version);
567   IO.mapRequired("sdk", LoadCommand.sdk);
568 }
569 
570 void MappingTraits<MachO::note_command>::mapping(
571     IO &IO, MachO::note_command &LoadCommand) {
572   IO.mapRequired("data_owner", LoadCommand.data_owner);
573   IO.mapRequired("offset", LoadCommand.offset);
574   IO.mapRequired("size", LoadCommand.size);
575 }
576 
577 void MappingTraits<MachO::build_version_command>::mapping(
578     IO &IO, MachO::build_version_command &LoadCommand) {
579   IO.mapRequired("platform", LoadCommand.platform);
580   IO.mapRequired("minos", LoadCommand.minos);
581   IO.mapRequired("sdk", LoadCommand.sdk);
582   IO.mapRequired("ntools", LoadCommand.ntools);
583 }
584 
585 } // end namespace yaml
586 
587 } // end namespace llvm
588