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