38void ScalarTraits<char_16>::output(
const char_16 &Val,
void *,
40 auto Len = strnlen(&Val[0], 16);
45 size_t CopySize = 16 >= Scalar.size() ? 16 : Scalar.size();
46 memcpy((
void *)Val, Scalar.data(), CopySize);
48 if (Scalar.size() < 16) {
49 memset((
void *)&Val[Scalar.size()], 0, 16 - Scalar.size());
55QuotingType ScalarTraits<char_16>::mustQuote(
StringRef S) {
56 return needsQuotes(S);
65 for (
size_t Idx = 0;
Idx < Scalar.size(); ++
Idx) {
66 if (Scalar[
Idx] ==
'-' || OutIdx >= 16)
68 unsigned long long TempInt;
70 return "invalid number";
72 return "out of range number";
73 Val[OutIdx] =
static_cast<uint8_t
>(TempInt);
80QuotingType ScalarTraits<uuid_t>::mustQuote(
StringRef S) {
81 return needsQuotes(S);
86 IO.mapRequired(
"magic", FileHdr.
magic);
87 IO.mapRequired(
"cputype", FileHdr.
cputype);
88 IO.mapRequired(
"cpusubtype", FileHdr.
cpusubtype);
89 IO.mapRequired(
"filetype", FileHdr.
filetype);
90 IO.mapRequired(
"ncmds", FileHdr.
ncmds);
91 IO.mapRequired(
"sizeofcmds", FileHdr.
sizeofcmds);
92 IO.mapRequired(
"flags", FileHdr.
flags);
93 if (FileHdr.
magic == MachO::MH_MAGIC_64 ||
94 FileHdr.
magic == MachO::MH_CIGAM_64)
95 IO.mapRequired(
"reserved", FileHdr.
reserved);
102 if (!IO.getContext()) {
105 IO.mapTag(
"!mach-o",
true);
106 IO.mapOptional(
"IsLittleEndian",
Object.IsLittleEndian,
107 sys::IsLittleEndianHost);
110 IO.mapRequired(
"FileHeader",
Object.Header);
111 Object.DWARF.Is64BitAddrSize =
Object.Header.magic == MachO::MH_MAGIC_64 ||
112 Object.Header.magic == MachO::MH_CIGAM_64;
113 IO.mapOptional(
"LoadCommands",
Object.LoadCommands);
115 if (
Object.RawLinkEditSegment || !IO.outputting())
116 IO.mapOptional(
"__LINKEDIT",
Object.RawLinkEditSegment);
117 if(!
Object.LinkEdit.isEmpty() || !IO.outputting())
118 IO.mapOptional(
"LinkEditData",
Object.LinkEdit);
120 if(!
Object.DWARF.isEmpty() || !IO.outputting())
121 IO.mapOptional(
"DWARF",
Object.DWARF);
123 if (IO.getContext() == &
Object)
124 IO.setContext(
nullptr);
129 IO.mapRequired(
"magic", FatHeader.
magic);
130 IO.mapRequired(
"nfat_arch", FatHeader.
nfat_arch);
135 IO.mapRequired(
"cputype", FatArch.
cputype);
136 IO.mapRequired(
"cpusubtype", FatArch.
cpusubtype);
137 IO.mapRequired(
"offset", FatArch.
offset);
138 IO.mapRequired(
"size", FatArch.
size);
139 IO.mapRequired(
"align", FatArch.
align);
140 IO.mapOptional(
"reserved", FatArch.
reserved,
141 static_cast<llvm::yaml::Hex32
>(0));
146 if (!IO.getContext()) {
147 IO.setContext(&UniversalBinary);
148 IO.mapTag(
"!fat-mach-o",
true);
150 IO.mapRequired(
"FatHeader", UniversalBinary.
Header);
151 IO.mapRequired(
"FatArchs", UniversalBinary.
FatArchs);
152 IO.mapRequired(
"Slices", UniversalBinary.
Slices);
154 if (IO.getContext() == &UniversalBinary)
155 IO.setContext(
nullptr);
161 IO.mapOptional(
"BindOpcodes", LinkEditData.
BindOpcodes);
165 IO.mapOptional(
"ExportTrie", LinkEditData.
ExportTrie);
166 IO.mapOptional(
"NameList", LinkEditData.
NameList);
167 IO.mapOptional(
"StringTable", LinkEditData.
StringTable);
171 IO.mapOptional(
"DataInCode", LinkEditData.
DataInCode);
176 IO.mapRequired(
"Opcode", RebaseOpcode.Opcode);
177 IO.mapRequired(
"Imm", RebaseOpcode.Imm);
178 IO.mapOptional(
"ExtraData", RebaseOpcode.ExtraData);
183 IO.mapRequired(
"Opcode", BindOpcode.Opcode);
184 IO.mapRequired(
"Imm", BindOpcode.Imm);
185 IO.mapOptional(
"ULEBExtraData", BindOpcode.ULEBExtraData);
186 IO.mapOptional(
"SLEBExtraData", BindOpcode.SLEBExtraData);
187 IO.mapOptional(
"Symbol", BindOpcode.Symbol);
192 IO.mapRequired(
"TerminalSize", ExportEntry.
TerminalSize);
193 IO.mapOptional(
"NodeOffset", ExportEntry.
NodeOffset);
194 IO.mapOptional(
"Name", ExportEntry.
Name);
195 IO.mapOptional(
"Flags", ExportEntry.
Flags);
196 IO.mapOptional(
"Address", ExportEntry.
Address);
197 IO.mapOptional(
"Other", ExportEntry.
Other);
198 IO.mapOptional(
"ImportName", ExportEntry.
ImportName);
199 IO.mapOptional(
"Children", ExportEntry.
Children);
204 IO.mapRequired(
"n_strx", NListEntry.
n_strx);
205 IO.mapRequired(
"n_type", NListEntry.
n_type);
206 IO.mapRequired(
"n_sect", NListEntry.
n_sect);
207 IO.mapRequired(
"n_desc", NListEntry.
n_desc);
208 IO.mapRequired(
"n_value", NListEntry.
n_value);
213 IO.mapRequired(
"Offset", DataInCodeEntry.
Offset);
214 IO.mapRequired(
"Length", DataInCodeEntry.
Length);
215 IO.mapRequired(
"Kind", DataInCodeEntry.
Kind);
218template <
typename StructType>
222void mapLoadCommandData<MachO::segment_command>(
224 IO.mapOptional(
"Sections", LoadCommand.
Sections);
228void mapLoadCommandData<MachO::segment_command_64>(
230 IO.mapOptional(
"Sections", LoadCommand.
Sections);
234void mapLoadCommandData<MachO::dylib_command>(
236 IO.mapOptional(
"Content", LoadCommand.
Content);
240void mapLoadCommandData<MachO::rpath_command>(
242 IO.mapOptional(
"Content", LoadCommand.
Content);
246void mapLoadCommandData<MachO::dylinker_command>(
248 IO.mapOptional(
"Content", LoadCommand.
Content);
252void mapLoadCommandData<MachO::sub_framework_command>(
254 IO.mapOptional(
"Content", LoadCommand.
Content);
258void mapLoadCommandData<MachO::sub_umbrella_command>(
260 IO.mapOptional(
"Content", LoadCommand.
Content);
264void mapLoadCommandData<MachO::sub_client_command>(
266 IO.mapOptional(
"Content", LoadCommand.
Content);
270void mapLoadCommandData<MachO::sub_library_command>(
272 IO.mapOptional(
"Content", LoadCommand.
Content);
276void mapLoadCommandData<MachO::build_version_command>(
278 IO.mapOptional(
"Tools", LoadCommand.
Tools);
284 LoadCommand.
Data.load_command_data.cmd);
285 IO.mapRequired(
"cmd", TempCmd);
286 LoadCommand.
Data.load_command_data.cmd = TempCmd;
287 IO.mapRequired(
"cmdsize", LoadCommand.
Data.load_command_data.cmdsize);
289#define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \
290 case MachO::LCName: \
291 MappingTraits<MachO::LCStruct>::mapping(IO, \
292 LoadCommand.Data.LCStruct##_data); \
293 mapLoadCommandData<MachO::LCStruct>(IO, LoadCommand); \
296 switch (LoadCommand.
Data.load_command_data.cmd) {
297#include "llvm/BinaryFormat/MachO.def"
299 IO.mapOptional(
"PayloadBytes", LoadCommand.
PayloadBytes);
305 IO.mapRequired(
"rebase_off", LoadCommand.
rebase_off);
306 IO.mapRequired(
"rebase_size", LoadCommand.
rebase_size);
307 IO.mapRequired(
"bind_off", LoadCommand.
bind_off);
308 IO.mapRequired(
"bind_size", LoadCommand.
bind_size);
313 IO.mapRequired(
"export_off", LoadCommand.
export_off);
314 IO.mapRequired(
"export_size", LoadCommand.
export_size);
319 IO.mapRequired(
"address", Relocation.
address);
320 IO.mapRequired(
"symbolnum", Relocation.
symbolnum);
321 IO.mapRequired(
"pcrel", Relocation.
is_pcrel);
322 IO.mapRequired(
"length", Relocation.
length);
323 IO.mapRequired(
"extern", Relocation.
is_extern);
324 IO.mapRequired(
"type", Relocation.
type);
326 IO.mapRequired(
"value", Relocation.
value);
331 IO.mapRequired(
"sectname", Section.sectname);
332 IO.mapRequired(
"segname", Section.segname);
333 IO.mapRequired(
"addr", Section.addr);
334 IO.mapRequired(
"size", Section.size);
335 IO.mapRequired(
"offset", Section.offset);
336 IO.mapRequired(
"align", Section.align);
337 IO.mapRequired(
"reloff", Section.reloff);
338 IO.mapRequired(
"nreloc", Section.nreloc);
339 IO.mapRequired(
"flags", Section.flags);
340 IO.mapRequired(
"reserved1", Section.reserved1);
341 IO.mapRequired(
"reserved2", Section.reserved2);
342 IO.mapOptional(
"reserved3", Section.reserved3);
343 IO.mapOptional(
"content", Section.content);
344 IO.mapOptional(
"relocations", Section.relocations);
350 if (Section.content && Section.size < Section.content->binary_size())
351 return "Section size must be greater than or equal to the content size";
357 IO.mapRequired(
"tool", tool.
tool);
358 IO.mapRequired(
"version", tool.
version);
362 IO.mapRequired(
"name", DylibStruct.
name);
363 IO.mapRequired(
"timestamp", DylibStruct.
timestamp);
370 IO.mapRequired(
"dylib", LoadCommand.
dylib);
373void MappingTraits<MachO::dylinker_command>::mapping(
375 IO.mapRequired(
"name", LoadCommand.
name);
378void MappingTraits<MachO::dysymtab_command>::mapping(
379 IO &IO, MachO::dysymtab_command &LoadCommand) {
380 IO.mapRequired(
"ilocalsym", LoadCommand.ilocalsym);
381 IO.mapRequired(
"nlocalsym", LoadCommand.nlocalsym);
382 IO.mapRequired(
"iextdefsym", LoadCommand.iextdefsym);
383 IO.mapRequired(
"nextdefsym", LoadCommand.nextdefsym);
384 IO.mapRequired(
"iundefsym", LoadCommand.iundefsym);
385 IO.mapRequired(
"nundefsym", LoadCommand.nundefsym);
386 IO.mapRequired(
"tocoff", LoadCommand.tocoff);
387 IO.mapRequired(
"ntoc", LoadCommand.ntoc);
388 IO.mapRequired(
"modtaboff", LoadCommand.modtaboff);
389 IO.mapRequired(
"nmodtab", LoadCommand.nmodtab);
390 IO.mapRequired(
"extrefsymoff", LoadCommand.extrefsymoff);
391 IO.mapRequired(
"nextrefsyms", LoadCommand.nextrefsyms);
392 IO.mapRequired(
"indirectsymoff", LoadCommand.indirectsymoff);
393 IO.mapRequired(
"nindirectsyms", LoadCommand.nindirectsyms);
394 IO.mapRequired(
"extreloff", LoadCommand.extreloff);
395 IO.mapRequired(
"nextrel", LoadCommand.nextrel);
396 IO.mapRequired(
"locreloff", LoadCommand.locreloff);
397 IO.mapRequired(
"nlocrel", LoadCommand.nlocrel);
400void MappingTraits<MachO::encryption_info_command>::mapping(
401 IO &IO, MachO::encryption_info_command &LoadCommand) {
402 IO.mapRequired(
"cryptoff", LoadCommand.cryptoff);
403 IO.mapRequired(
"cryptsize", LoadCommand.cryptsize);
404 IO.mapRequired(
"cryptid", LoadCommand.cryptid);
407void MappingTraits<MachO::encryption_info_command_64>::mapping(
408 IO &IO, MachO::encryption_info_command_64 &LoadCommand) {
409 IO.mapRequired(
"cryptoff", LoadCommand.cryptoff);
410 IO.mapRequired(
"cryptsize", LoadCommand.cryptsize);
411 IO.mapRequired(
"cryptid", LoadCommand.cryptid);
412 IO.mapRequired(
"pad", LoadCommand.pad);
415void MappingTraits<MachO::entry_point_command>::mapping(
416 IO &IO, MachO::entry_point_command &LoadCommand) {
417 IO.mapRequired(
"entryoff", LoadCommand.entryoff);
418 IO.mapRequired(
"stacksize", LoadCommand.stacksize);
421void MappingTraits<MachO::fvmfile_command>::mapping(
422 IO &IO, MachO::fvmfile_command &LoadCommand) {
423 IO.mapRequired(
"name", LoadCommand.name);
424 IO.mapRequired(
"header_addr", LoadCommand.header_addr);
428 IO.mapRequired(
"name", FVMLib.
name);
435 IO.mapRequired(
"fvmlib", LoadCommand.
fvmlib);
438void MappingTraits<MachO::ident_command>::mapping(
441void MappingTraits<MachO::linkedit_data_command>::mapping(
442 IO &IO, MachO::linkedit_data_command &LoadCommand) {
443 IO.mapRequired(
"dataoff", LoadCommand.dataoff);
444 IO.mapRequired(
"datasize", LoadCommand.datasize);
447void MappingTraits<MachO::linker_option_command>::mapping(
448 IO &IO, MachO::linker_option_command &LoadCommand) {
449 IO.mapRequired(
"count", LoadCommand.count);
452void MappingTraits<MachO::prebind_cksum_command>::mapping(
453 IO &IO, MachO::prebind_cksum_command &LoadCommand) {
454 IO.mapRequired(
"cksum", LoadCommand.cksum);
457void MappingTraits<MachO::load_command>::mapping(
458 IO &IO, MachO::load_command &LoadCommand) {}
460void MappingTraits<MachO::prebound_dylib_command>::mapping(
461 IO &IO, MachO::prebound_dylib_command &LoadCommand) {
462 IO.mapRequired(
"name", LoadCommand.name);
463 IO.mapRequired(
"nmodules", LoadCommand.nmodules);
464 IO.mapRequired(
"linked_modules", LoadCommand.linked_modules);
467void MappingTraits<MachO::routines_command>::mapping(
468 IO &IO, MachO::routines_command &LoadCommand) {
469 IO.mapRequired(
"init_address", LoadCommand.init_address);
470 IO.mapRequired(
"init_module", LoadCommand.init_module);
471 IO.mapRequired(
"reserved1", LoadCommand.reserved1);
472 IO.mapRequired(
"reserved2", LoadCommand.reserved2);
473 IO.mapRequired(
"reserved3", LoadCommand.reserved3);
474 IO.mapRequired(
"reserved4", LoadCommand.reserved4);
475 IO.mapRequired(
"reserved5", LoadCommand.reserved5);
476 IO.mapRequired(
"reserved6", LoadCommand.reserved6);
479void MappingTraits<MachO::routines_command_64>::mapping(
480 IO &IO, MachO::routines_command_64 &LoadCommand) {
481 IO.mapRequired(
"init_address", LoadCommand.init_address);
482 IO.mapRequired(
"init_module", LoadCommand.init_module);
483 IO.mapRequired(
"reserved1", LoadCommand.reserved1);
484 IO.mapRequired(
"reserved2", LoadCommand.reserved2);
485 IO.mapRequired(
"reserved3", LoadCommand.reserved3);
486 IO.mapRequired(
"reserved4", LoadCommand.reserved4);
487 IO.mapRequired(
"reserved5", LoadCommand.reserved5);
488 IO.mapRequired(
"reserved6", LoadCommand.reserved6);
491void MappingTraits<MachO::rpath_command>::mapping(
492 IO &IO, MachO::rpath_command &LoadCommand) {
493 IO.mapRequired(
"path", LoadCommand.path);
497 IO.mapRequired(
"sectname", Section.sectname);
498 IO.mapRequired(
"segname", Section.segname);
499 IO.mapRequired(
"addr", Section.addr);
500 IO.mapRequired(
"size", Section.size);
501 IO.mapRequired(
"offset", Section.offset);
502 IO.mapRequired(
"align", Section.align);
503 IO.mapRequired(
"reloff", Section.reloff);
504 IO.mapRequired(
"nreloc", Section.nreloc);
505 IO.mapRequired(
"flags", Section.flags);
506 IO.mapRequired(
"reserved1", Section.reserved1);
507 IO.mapRequired(
"reserved2", Section.reserved2);
512 IO.mapRequired(
"sectname", Section.sectname);
513 IO.mapRequired(
"segname", Section.segname);
514 IO.mapRequired(
"addr", Section.addr);
515 IO.mapRequired(
"size", Section.size);
516 IO.mapRequired(
"offset", Section.offset);
517 IO.mapRequired(
"align", Section.align);
518 IO.mapRequired(
"reloff", Section.reloff);
519 IO.mapRequired(
"nreloc", Section.nreloc);
520 IO.mapRequired(
"flags", Section.flags);
521 IO.mapRequired(
"reserved1", Section.reserved1);
522 IO.mapRequired(
"reserved2", Section.reserved2);
523 IO.mapRequired(
"reserved3", Section.reserved3);
528 IO.mapRequired(
"segname", LoadCommand.
segname);
529 IO.mapRequired(
"vmaddr", LoadCommand.
vmaddr);
530 IO.mapRequired(
"vmsize", LoadCommand.
vmsize);
531 IO.mapRequired(
"fileoff", LoadCommand.
fileoff);
532 IO.mapRequired(
"filesize", LoadCommand.
filesize);
533 IO.mapRequired(
"maxprot", LoadCommand.
maxprot);
534 IO.mapRequired(
"initprot", LoadCommand.
initprot);
535 IO.mapRequired(
"nsects", LoadCommand.
nsects);
536 IO.mapRequired(
"flags", LoadCommand.
flags);
539void MappingTraits<MachO::segment_command_64>::mapping(
541 IO.mapRequired(
"segname", LoadCommand.
segname);
542 IO.mapRequired(
"vmaddr", LoadCommand.
vmaddr);
543 IO.mapRequired(
"vmsize", LoadCommand.
vmsize);
544 IO.mapRequired(
"fileoff", LoadCommand.
fileoff);
545 IO.mapRequired(
"filesize", LoadCommand.
filesize);
546 IO.mapRequired(
"maxprot", LoadCommand.
maxprot);
547 IO.mapRequired(
"initprot", LoadCommand.
initprot);
548 IO.mapRequired(
"nsects", LoadCommand.
nsects);
549 IO.mapRequired(
"flags", LoadCommand.
flags);
552void MappingTraits<MachO::source_version_command>::mapping(
553 IO &IO, MachO::source_version_command &LoadCommand) {
554 IO.mapRequired(
"version", LoadCommand.version);
557void MappingTraits<MachO::sub_client_command>::mapping(
558 IO &IO, MachO::sub_client_command &LoadCommand) {
559 IO.mapRequired(
"client", LoadCommand.client);
562void MappingTraits<MachO::sub_framework_command>::mapping(
563 IO &IO, MachO::sub_framework_command &LoadCommand) {
564 IO.mapRequired(
"umbrella", LoadCommand.umbrella);
567void MappingTraits<MachO::sub_library_command>::mapping(
568 IO &IO, MachO::sub_library_command &LoadCommand) {
569 IO.mapRequired(
"sub_library", LoadCommand.sub_library);
572void MappingTraits<MachO::sub_umbrella_command>::mapping(
573 IO &IO, MachO::sub_umbrella_command &LoadCommand) {
574 IO.mapRequired(
"sub_umbrella", LoadCommand.sub_umbrella);
577void MappingTraits<MachO::symseg_command>::mapping(
578 IO &IO, MachO::symseg_command &LoadCommand) {
579 IO.mapRequired(
"offset", LoadCommand.offset);
580 IO.mapRequired(
"size", LoadCommand.size);
583void MappingTraits<MachO::symtab_command>::mapping(
584 IO &IO, MachO::symtab_command &LoadCommand) {
585 IO.mapRequired(
"symoff", LoadCommand.symoff);
586 IO.mapRequired(
"nsyms", LoadCommand.nsyms);
587 IO.mapRequired(
"stroff", LoadCommand.stroff);
588 IO.mapRequired(
"strsize", LoadCommand.strsize);
591void MappingTraits<MachO::thread_command>::mapping(
592 IO &IO, MachO::thread_command &LoadCommand) {}
594void MappingTraits<MachO::twolevel_hints_command>::mapping(
595 IO &IO, MachO::twolevel_hints_command &LoadCommand) {
596 IO.mapRequired(
"offset", LoadCommand.offset);
597 IO.mapRequired(
"nhints", LoadCommand.nhints);
600void MappingTraits<MachO::uuid_command>::mapping(
601 IO &IO, MachO::uuid_command &LoadCommand) {
602 IO.mapRequired(
"uuid", LoadCommand.uuid);
605void MappingTraits<MachO::version_min_command>::mapping(
606 IO &IO, MachO::version_min_command &LoadCommand) {
607 IO.mapRequired(
"version", LoadCommand.version);
608 IO.mapRequired(
"sdk", LoadCommand.sdk);
611void MappingTraits<MachO::note_command>::mapping(
612 IO &IO, MachO::note_command &LoadCommand) {
613 IO.mapRequired(
"data_owner", LoadCommand.data_owner);
614 IO.mapRequired(
"offset", LoadCommand.offset);
615 IO.mapRequired(
"size", LoadCommand.size);
618void MappingTraits<MachO::build_version_command>::mapping(
619 IO &IO, MachO::build_version_command &LoadCommand) {
620 IO.mapRequired(
"platform", LoadCommand.platform);
621 IO.mapRequired(
"minos", LoadCommand.minos);
622 IO.mapRequired(
"sdk", LoadCommand.sdk);
623 IO.mapRequired(
"ntools", LoadCommand.ntools);
626void MappingTraits<MachO::fileset_entry_command>::mapping(
627 IO &IO, MachO::fileset_entry_command &LoadCommand) {
628 IO.mapRequired(
"vmaddr", LoadCommand.vmaddr);
629 IO.mapRequired(
"fileoff", LoadCommand.fileoff);
630 IO.mapRequired(
"id", LoadCommand.entry_id);
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file declares classes for handling the YAML representation of Mach-O.
StringRef - Represent a constant reference to a string, i.e.
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write_uuid(const uuid_t UUID)
void mapLoadCommandData(IO &IO, MachOYAML::LoadCommand &LoadCommand)
raw_ostream::uuid_t uuid_t
This is an optimization pass for GlobalISel generic memory operations.
bool getAsUnsignedInteger(StringRef Str, unsigned Radix, unsigned long long &Result)
Helper functions for StringRef::getAsInteger.
std::vector< MachOYAML::ExportEntry > Children
llvm::yaml::Hex64 Address
llvm::yaml::Hex32 cputype
llvm::yaml::Hex32 cpusubtype
llvm::yaml::Hex32 reserved
std::vector< MachOYAML::BindOpcode > WeakBindOpcodes
std::vector< DataInCodeEntry > DataInCode
std::vector< yaml::Hex8 > ChainedFixups
std::vector< MachOYAML::BindOpcode > LazyBindOpcodes
std::vector< MachOYAML::BindOpcode > BindOpcodes
std::vector< MachOYAML::RebaseOpcode > RebaseOpcodes
std::vector< StringRef > StringTable
std::vector< yaml::Hex32 > IndirectSymbols
std::vector< yaml::Hex64 > FunctionStarts
MachOYAML::ExportEntry ExportTrie
std::vector< NListEntry > NameList
llvm::MachO::macho_load_command Data
std::vector< Section > Sections
std::vector< MachO::build_tool_version > Tools
std::vector< llvm::yaml::Hex8 > PayloadBytes
llvm::yaml::Hex32 address
std::vector< Object > Slices
std::vector< FatArch > FatArchs
uint32_t compatibility_version