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