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