39 auto Len = strnlen(&Val[0], 16);
44 size_t CopySize = 16 >= Scalar.size() ? 16 : Scalar.size();
45 memcpy((
void *)Val, Scalar.data(), CopySize);
47 if (Scalar.size() < 16) {
48 memset((
void *)&Val[Scalar.size()], 0, 16 - Scalar.size());
54 QuotingType ScalarTraits<char_16>::mustQuote(
StringRef S) {
55 return needsQuotes(
S);
64 for (
size_t Idx = 0; Idx < Scalar.size(); ++Idx) {
65 if (Scalar[Idx] ==
'-' || OutIdx >= 16)
67 unsigned long long TempInt;
69 return "invalid number";
71 return "out of range number";
72 Val[OutIdx] =
static_cast<uint8_t
>(TempInt);
79 QuotingType ScalarTraits<uuid_t>::mustQuote(
StringRef S) {
80 return needsQuotes(
S);
85 IO.mapRequired(
"magic", FileHdr.
magic);
86 IO.mapRequired(
"cputype", FileHdr.
cputype);
87 IO.mapRequired(
"cpusubtype", FileHdr.
cpusubtype);
88 IO.mapRequired(
"filetype", FileHdr.
filetype);
89 IO.mapRequired(
"ncmds", FileHdr.
ncmds);
90 IO.mapRequired(
"sizeofcmds", FileHdr.
sizeofcmds);
91 IO.mapRequired(
"flags", FileHdr.
flags);
94 IO.mapRequired(
"reserved", FileHdr.
reserved);
101 if (!IO.getContext()) {
104 IO.mapTag(
"!mach-o",
true);
105 IO.mapOptional(
"IsLittleEndian",
Object.IsLittleEndian,
109 IO.mapRequired(
"FileHeader",
Object.Header);
112 IO.mapOptional(
"LoadCommands",
Object.LoadCommands);
114 if (
Object.RawLinkEditSegment || !IO.outputting())
115 IO.mapOptional(
"__LINKEDIT",
Object.RawLinkEditSegment);
116 if(!
Object.LinkEdit.isEmpty() || !IO.outputting())
117 IO.mapOptional(
"LinkEditData",
Object.LinkEdit);
119 if(!
Object.DWARF.isEmpty() || !IO.outputting())
120 IO.mapOptional(
"DWARF",
Object.DWARF);
122 if (IO.getContext() == &
Object)
123 IO.setContext(
nullptr);
128 IO.mapRequired(
"magic", FatHeader.
magic);
129 IO.mapRequired(
"nfat_arch", FatHeader.
nfat_arch);
134 IO.mapRequired(
"cputype", FatArch.
cputype);
135 IO.mapRequired(
"cpusubtype", FatArch.
cpusubtype);
136 IO.mapRequired(
"offset", FatArch.
offset);
137 IO.mapRequired(
"size", FatArch.
size);
138 IO.mapRequired(
"align", FatArch.
align);
139 IO.mapOptional(
"reserved", FatArch.
reserved,
140 static_cast<llvm::yaml::Hex32
>(0));
145 if (!IO.getContext()) {
146 IO.setContext(&UniversalBinary);
147 IO.mapTag(
"!fat-mach-o",
true);
149 IO.mapRequired(
"FatHeader", UniversalBinary.
Header);
150 IO.mapRequired(
"FatArchs", UniversalBinary.
FatArchs);
151 IO.mapRequired(
"Slices", UniversalBinary.
Slices);
153 if (IO.getContext() == &UniversalBinary)
154 IO.setContext(
nullptr);
160 IO.mapOptional(
"BindOpcodes", LinkEditData.
BindOpcodes);
164 IO.mapOptional(
"ExportTrie", LinkEditData.
ExportTrie);
165 IO.mapOptional(
"NameList", LinkEditData.
NameList);
166 IO.mapOptional(
"StringTable", LinkEditData.
StringTable);
182 IO.mapOptional(
"ULEBExtraData",
BindOpcode.ULEBExtraData);
183 IO.mapOptional(
"SLEBExtraData",
BindOpcode.SLEBExtraData);
189 IO.mapRequired(
"TerminalSize", ExportEntry.
TerminalSize);
190 IO.mapOptional(
"NodeOffset", ExportEntry.
NodeOffset);
191 IO.mapOptional(
"Name", ExportEntry.
Name);
192 IO.mapOptional(
"Flags", ExportEntry.
Flags);
193 IO.mapOptional(
"Address", ExportEntry.
Address);
194 IO.mapOptional(
"Other", ExportEntry.
Other);
195 IO.mapOptional(
"ImportName", ExportEntry.
ImportName);
196 IO.mapOptional(
"Children", ExportEntry.
Children);
201 IO.mapRequired(
"n_strx", NListEntry.
n_strx);
202 IO.mapRequired(
"n_type", NListEntry.
n_type);
203 IO.mapRequired(
"n_sect", NListEntry.
n_sect);
204 IO.mapRequired(
"n_desc", NListEntry.
n_desc);
205 IO.mapRequired(
"n_value", NListEntry.
n_value);
208 template <
typename StructType>
212 void mapLoadCommandData<MachO::segment_command>(
214 IO.mapOptional(
"Sections", LoadCommand.
Sections);
218 void mapLoadCommandData<MachO::segment_command_64>(
220 IO.mapOptional(
"Sections", LoadCommand.
Sections);
224 void mapLoadCommandData<MachO::dylib_command>(
226 IO.mapOptional(
"Content", LoadCommand.
Content);
230 void mapLoadCommandData<MachO::rpath_command>(
232 IO.mapOptional(
"Content", LoadCommand.
Content);
236 void mapLoadCommandData<MachO::dylinker_command>(
238 IO.mapOptional(
"Content", LoadCommand.
Content);
242 void mapLoadCommandData<MachO::sub_framework_command>(
244 IO.mapOptional(
"Content", LoadCommand.
Content);
248 void mapLoadCommandData<MachO::sub_umbrella_command>(
250 IO.mapOptional(
"Content", LoadCommand.
Content);
254 void mapLoadCommandData<MachO::sub_client_command>(
256 IO.mapOptional(
"Content", LoadCommand.
Content);
260 void mapLoadCommandData<MachO::sub_library_command>(
262 IO.mapOptional(
"Content", LoadCommand.
Content);
266 void mapLoadCommandData<MachO::build_version_command>(
268 IO.mapOptional(
"Tools", LoadCommand.
Tools);
274 LoadCommand.
Data.load_command_data.cmd);
275 IO.mapRequired(
"cmd", TempCmd);
276 LoadCommand.
Data.load_command_data.cmd = TempCmd;
277 IO.mapRequired(
"cmdsize", LoadCommand.
Data.load_command_data.cmdsize);
279 #define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \
280 case MachO::LCName: \
281 MappingTraits<MachO::LCStruct>::mapping(IO, \
282 LoadCommand.Data.LCStruct##_data); \
283 mapLoadCommandData<MachO::LCStruct>(IO, LoadCommand); \
286 switch (LoadCommand.
Data.load_command_data.cmd) {
287 #include "llvm/BinaryFormat/MachO.def"
289 IO.mapOptional(
"PayloadBytes", LoadCommand.
PayloadBytes);
295 IO.mapRequired(
"rebase_off", LoadCommand.
rebase_off);
296 IO.mapRequired(
"rebase_size", LoadCommand.
rebase_size);
297 IO.mapRequired(
"bind_off", LoadCommand.
bind_off);
298 IO.mapRequired(
"bind_size", LoadCommand.
bind_size);
303 IO.mapRequired(
"export_off", LoadCommand.
export_off);
304 IO.mapRequired(
"export_size", LoadCommand.
export_size);
309 IO.mapRequired(
"address", Relocation.
address);
310 IO.mapRequired(
"symbolnum", Relocation.
symbolnum);
311 IO.mapRequired(
"pcrel", Relocation.
is_pcrel);
312 IO.mapRequired(
"length", Relocation.
length);
313 IO.mapRequired(
"extern", Relocation.
is_extern);
314 IO.mapRequired(
"type", Relocation.
type);
316 IO.mapRequired(
"value", Relocation.
value);
321 IO.mapRequired(
"sectname", Section.sectname);
322 IO.mapRequired(
"segname", Section.segname);
323 IO.mapRequired(
"addr", Section.addr);
324 IO.mapRequired(
"size", Section.size);
325 IO.mapRequired(
"offset", Section.offset);
326 IO.mapRequired(
"align", Section.align);
327 IO.mapRequired(
"reloff", Section.reloff);
328 IO.mapRequired(
"nreloc", Section.nreloc);
329 IO.mapRequired(
"flags", Section.flags);
330 IO.mapRequired(
"reserved1", Section.reserved1);
331 IO.mapRequired(
"reserved2", Section.reserved2);
332 IO.mapOptional(
"reserved3", Section.reserved3);
333 IO.mapOptional(
"content", Section.content);
334 IO.mapOptional(
"relocations", Section.relocations);
340 if (Section.content && Section.size < Section.content->binary_size())
341 return "Section size must be greater than or equal to the content size";
347 IO.mapRequired(
"tool", tool.
tool);
348 IO.mapRequired(
"version", tool.
version);
352 IO.mapRequired(
"name", DylibStruct.
name);
353 IO.mapRequired(
"timestamp", DylibStruct.
timestamp);
360 IO.mapRequired(
"dylib", LoadCommand.
dylib);
363 void MappingTraits<MachO::dylinker_command>::mapping(
365 IO.mapRequired(
"name", LoadCommand.
name);
368 void MappingTraits<MachO::dysymtab_command>::mapping(
369 IO &IO, MachO::dysymtab_command &LoadCommand) {
370 IO.mapRequired(
"ilocalsym", LoadCommand.ilocalsym);
371 IO.mapRequired(
"nlocalsym", LoadCommand.nlocalsym);
372 IO.mapRequired(
"iextdefsym", LoadCommand.iextdefsym);
373 IO.mapRequired(
"nextdefsym", LoadCommand.nextdefsym);
374 IO.mapRequired(
"iundefsym", LoadCommand.iundefsym);
375 IO.mapRequired(
"nundefsym", LoadCommand.nundefsym);
376 IO.mapRequired(
"tocoff", LoadCommand.tocoff);
377 IO.mapRequired(
"ntoc", LoadCommand.ntoc);
378 IO.mapRequired(
"modtaboff", LoadCommand.modtaboff);
379 IO.mapRequired(
"nmodtab", LoadCommand.nmodtab);
380 IO.mapRequired(
"extrefsymoff", LoadCommand.extrefsymoff);
381 IO.mapRequired(
"nextrefsyms", LoadCommand.nextrefsyms);
382 IO.mapRequired(
"indirectsymoff", LoadCommand.indirectsymoff);
383 IO.mapRequired(
"nindirectsyms", LoadCommand.nindirectsyms);
384 IO.mapRequired(
"extreloff", LoadCommand.extreloff);
385 IO.mapRequired(
"nextrel", LoadCommand.nextrel);
386 IO.mapRequired(
"locreloff", LoadCommand.locreloff);
387 IO.mapRequired(
"nlocrel", LoadCommand.nlocrel);
390 void MappingTraits<MachO::encryption_info_command>::mapping(
391 IO &IO, MachO::encryption_info_command &LoadCommand) {
392 IO.mapRequired(
"cryptoff", LoadCommand.cryptoff);
393 IO.mapRequired(
"cryptsize", LoadCommand.cryptsize);
394 IO.mapRequired(
"cryptid", LoadCommand.cryptid);
397 void MappingTraits<MachO::encryption_info_command_64>::mapping(
398 IO &IO, MachO::encryption_info_command_64 &LoadCommand) {
399 IO.mapRequired(
"cryptoff", LoadCommand.cryptoff);
400 IO.mapRequired(
"cryptsize", LoadCommand.cryptsize);
401 IO.mapRequired(
"cryptid", LoadCommand.cryptid);
402 IO.mapRequired(
"pad", LoadCommand.pad);
405 void MappingTraits<MachO::entry_point_command>::mapping(
406 IO &IO, MachO::entry_point_command &LoadCommand) {
407 IO.mapRequired(
"entryoff", LoadCommand.entryoff);
408 IO.mapRequired(
"stacksize", LoadCommand.stacksize);
411 void MappingTraits<MachO::fvmfile_command>::mapping(
412 IO &IO, MachO::fvmfile_command &LoadCommand) {
413 IO.mapRequired(
"name", LoadCommand.name);
414 IO.mapRequired(
"header_addr", LoadCommand.header_addr);
418 IO.mapRequired(
"name", FVMLib.
name);
425 IO.mapRequired(
"fvmlib", LoadCommand.
fvmlib);
428 void MappingTraits<MachO::ident_command>::mapping(
431 void MappingTraits<MachO::linkedit_data_command>::mapping(
432 IO &IO, MachO::linkedit_data_command &LoadCommand) {
433 IO.mapRequired(
"dataoff", LoadCommand.dataoff);
434 IO.mapRequired(
"datasize", LoadCommand.datasize);
437 void MappingTraits<MachO::linker_option_command>::mapping(
438 IO &IO, MachO::linker_option_command &LoadCommand) {
439 IO.mapRequired(
"count", LoadCommand.count);
442 void MappingTraits<MachO::prebind_cksum_command>::mapping(
443 IO &IO, MachO::prebind_cksum_command &LoadCommand) {
444 IO.mapRequired(
"cksum", LoadCommand.cksum);
447 void MappingTraits<MachO::load_command>::mapping(
448 IO &IO, MachO::load_command &LoadCommand) {}
450 void MappingTraits<MachO::prebound_dylib_command>::mapping(
451 IO &IO, MachO::prebound_dylib_command &LoadCommand) {
452 IO.mapRequired(
"name", LoadCommand.name);
453 IO.mapRequired(
"nmodules", LoadCommand.nmodules);
454 IO.mapRequired(
"linked_modules", LoadCommand.linked_modules);
457 void MappingTraits<MachO::routines_command>::mapping(
458 IO &IO, MachO::routines_command &LoadCommand) {
459 IO.mapRequired(
"init_address", LoadCommand.init_address);
460 IO.mapRequired(
"init_module", LoadCommand.init_module);
461 IO.mapRequired(
"reserved1", LoadCommand.reserved1);
462 IO.mapRequired(
"reserved2", LoadCommand.reserved2);
463 IO.mapRequired(
"reserved3", LoadCommand.reserved3);
464 IO.mapRequired(
"reserved4", LoadCommand.reserved4);
465 IO.mapRequired(
"reserved5", LoadCommand.reserved5);
466 IO.mapRequired(
"reserved6", LoadCommand.reserved6);
469 void MappingTraits<MachO::routines_command_64>::mapping(
470 IO &IO, MachO::routines_command_64 &LoadCommand) {
471 IO.mapRequired(
"init_address", LoadCommand.init_address);
472 IO.mapRequired(
"init_module", LoadCommand.init_module);
473 IO.mapRequired(
"reserved1", LoadCommand.reserved1);
474 IO.mapRequired(
"reserved2", LoadCommand.reserved2);
475 IO.mapRequired(
"reserved3", LoadCommand.reserved3);
476 IO.mapRequired(
"reserved4", LoadCommand.reserved4);
477 IO.mapRequired(
"reserved5", LoadCommand.reserved5);
478 IO.mapRequired(
"reserved6", LoadCommand.reserved6);
481 void MappingTraits<MachO::rpath_command>::mapping(
482 IO &IO, MachO::rpath_command &LoadCommand) {
483 IO.mapRequired(
"path", LoadCommand.path);
487 IO.mapRequired(
"sectname", Section.sectname);
488 IO.mapRequired(
"segname", Section.segname);
489 IO.mapRequired(
"addr", Section.addr);
490 IO.mapRequired(
"size", Section.size);
491 IO.mapRequired(
"offset", Section.offset);
492 IO.mapRequired(
"align", Section.align);
493 IO.mapRequired(
"reloff", Section.reloff);
494 IO.mapRequired(
"nreloc", Section.nreloc);
495 IO.mapRequired(
"flags", Section.flags);
496 IO.mapRequired(
"reserved1", Section.reserved1);
497 IO.mapRequired(
"reserved2", Section.reserved2);
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 IO.mapRequired(
"reserved3", Section.reserved3);
518 IO.mapRequired(
"segname", LoadCommand.
segname);
519 IO.mapRequired(
"vmaddr", LoadCommand.
vmaddr);
520 IO.mapRequired(
"vmsize", LoadCommand.
vmsize);
521 IO.mapRequired(
"fileoff", LoadCommand.
fileoff);
522 IO.mapRequired(
"filesize", LoadCommand.
filesize);
523 IO.mapRequired(
"maxprot", LoadCommand.
maxprot);
524 IO.mapRequired(
"initprot", LoadCommand.
initprot);
525 IO.mapRequired(
"nsects", LoadCommand.
nsects);
526 IO.mapRequired(
"flags", LoadCommand.
flags);
529 void MappingTraits<MachO::segment_command_64>::mapping(
531 IO.mapRequired(
"segname", LoadCommand.
segname);
532 IO.mapRequired(
"vmaddr", LoadCommand.
vmaddr);
533 IO.mapRequired(
"vmsize", LoadCommand.
vmsize);
534 IO.mapRequired(
"fileoff", LoadCommand.
fileoff);
535 IO.mapRequired(
"filesize", LoadCommand.
filesize);
536 IO.mapRequired(
"maxprot", LoadCommand.
maxprot);
537 IO.mapRequired(
"initprot", LoadCommand.
initprot);
538 IO.mapRequired(
"nsects", LoadCommand.
nsects);
539 IO.mapRequired(
"flags", LoadCommand.
flags);
542 void MappingTraits<MachO::source_version_command>::mapping(
543 IO &IO, MachO::source_version_command &LoadCommand) {
544 IO.mapRequired(
"version", LoadCommand.version);
547 void MappingTraits<MachO::sub_client_command>::mapping(
548 IO &IO, MachO::sub_client_command &LoadCommand) {
549 IO.mapRequired(
"client", LoadCommand.client);
552 void MappingTraits<MachO::sub_framework_command>::mapping(
553 IO &IO, MachO::sub_framework_command &LoadCommand) {
554 IO.mapRequired(
"umbrella", LoadCommand.umbrella);
557 void MappingTraits<MachO::sub_library_command>::mapping(
558 IO &IO, MachO::sub_library_command &LoadCommand) {
559 IO.mapRequired(
"sub_library", LoadCommand.sub_library);
562 void MappingTraits<MachO::sub_umbrella_command>::mapping(
563 IO &IO, MachO::sub_umbrella_command &LoadCommand) {
564 IO.mapRequired(
"sub_umbrella", LoadCommand.sub_umbrella);
567 void MappingTraits<MachO::symseg_command>::mapping(
568 IO &IO, MachO::symseg_command &LoadCommand) {
569 IO.mapRequired(
"offset", LoadCommand.offset);
570 IO.mapRequired(
"size", LoadCommand.size);
573 void MappingTraits<MachO::symtab_command>::mapping(
574 IO &IO, MachO::symtab_command &LoadCommand) {
575 IO.mapRequired(
"symoff", LoadCommand.symoff);
576 IO.mapRequired(
"nsyms", LoadCommand.nsyms);
577 IO.mapRequired(
"stroff", LoadCommand.stroff);
578 IO.mapRequired(
"strsize", LoadCommand.strsize);
581 void MappingTraits<MachO::thread_command>::mapping(
582 IO &IO, MachO::thread_command &LoadCommand) {}
584 void MappingTraits<MachO::twolevel_hints_command>::mapping(
585 IO &IO, MachO::twolevel_hints_command &LoadCommand) {
586 IO.mapRequired(
"offset", LoadCommand.offset);
587 IO.mapRequired(
"nhints", LoadCommand.nhints);
590 void MappingTraits<MachO::uuid_command>::mapping(
591 IO &IO, MachO::uuid_command &LoadCommand) {
592 IO.mapRequired(
"uuid", LoadCommand.uuid);
595 void MappingTraits<MachO::version_min_command>::mapping(
596 IO &IO, MachO::version_min_command &LoadCommand) {
597 IO.mapRequired(
"version", LoadCommand.version);
598 IO.mapRequired(
"sdk", LoadCommand.sdk);
601 void MappingTraits<MachO::note_command>::mapping(
602 IO &IO, MachO::note_command &LoadCommand) {
603 IO.mapRequired(
"data_owner", LoadCommand.data_owner);
604 IO.mapRequired(
"offset", LoadCommand.offset);
605 IO.mapRequired(
"size", LoadCommand.size);
608 void MappingTraits<MachO::build_version_command>::mapping(
609 IO &IO, MachO::build_version_command &LoadCommand) {
610 IO.mapRequired(
"platform", LoadCommand.platform);
611 IO.mapRequired(
"minos", LoadCommand.minos);
612 IO.mapRequired(
"sdk", LoadCommand.sdk);
613 IO.mapRequired(
"ntools", LoadCommand.ntools);