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