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