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