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