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