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

source code of llvm/lib/ObjectYAML/MachOYAML.cpp