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