LLVM: lib/ObjectYAML/MachOYAML.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
19#include
20#include
21
22namespace llvm {
23
25
33
34namespace yaml {
35
38 auto Len = strnlen(&Val[0], 16);
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
51}
52
56
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;
68 return "invalid number";
69 if (TempInt > 0xFF)
70 return "out of range number";
71 Val[OutIdx] = static_cast<uint8_t>(TempInt);
72 ++Idx;
73 ++OutIdx;
74 }
76}
77
81
95
98
99
102 }
104 IO.mapOptional("IsLittleEndian", Object.IsLittleEndian,
106 Object.DWARF.IsLittleEndian = Object.IsLittleEndian;
107
109 Object.DWARF.Is64BitAddrSize = Object.Header.magic == MachO::MH_MAGIC_64 ||
111 IO.mapOptional("LoadCommands", Object.LoadCommands);
112
113 if (Object.RawLinkEditSegment || .outputting())
114 IO.mapOptional("__LINKEDIT", Object.RawLinkEditSegment);
115 if(!Object.LinkEdit.isEmpty() || .outputting())
117
118 if(!Object.DWARF.isEmpty() || .outputting())
120
123}
124
130
139 static_castllvm::yaml::Hex32\(0));
140}
141
146 IO.mapTag("!fat-mach-o", true);
147 }
151
154}
155
171
178
183 IO.mapOptional("ULEBExtraData", BindOpcode.ULEBExtraData);
184 IO.mapOptional("SLEBExtraData", BindOpcode.SLEBExtraData);
186}
187
199
208
215
216template
218
219template <>
224
225template <>
230
231template <>
236
237template <>
242
243template <>
248
249template <>
254
255template <>
260
261template <>
266
267template <>
272
273template <>
278
282 LoadCommand.Data.load_command_data.cmd);
284 LoadCommand.Data.load_command_data.cmd = TempCmd;
285 IO.mapRequired("cmdsize", LoadCommand.Data.load_command_data.cmdsize);
286
287#define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \
288 case MachO::LCName: \
289 MappingTraitsMachO::LCStruct::mapping(IO, \
290 LoadCommand.Data.LCStruct##_data); \
291 mapLoadCommandDataMachO::LCStruct(IO, LoadCommand); \
292 break;
293
294 switch (LoadCommand.Data.load_command_data.cmd) {
295#include "llvm/BinaryFormat/MachO.def"
296 }
299}
300
313}
314
326
344
345std::string
348
349
350 if (.error() && Section.content &&
351 Section.size < Section.content->binary_size())
352 return "Section size must be greater than or equal to the content size";
353 return "";
354}
355
361
368
372}
373
374void MappingTraitsMachO::dylinker\_command::mapping(
376 IO.mapRequired("name", LoadCommand.name);
377}
378
379void MappingTraitsMachO::dysymtab\_command::mapping(
380 IO &IO, MachO::dysymtab_command &LoadCommand) {
381 IO.mapRequired("ilocalsym", LoadCommand.ilocalsym);
382 IO.mapRequired("nlocalsym", LoadCommand.nlocalsym);
383 IO.mapRequired("iextdefsym", LoadCommand.iextdefsym);
384 IO.mapRequired("nextdefsym", LoadCommand.nextdefsym);
385 IO.mapRequired("iundefsym", LoadCommand.iundefsym);
386 IO.mapRequired("nundefsym", LoadCommand.nundefsym);
387 IO.mapRequired("tocoff", LoadCommand.tocoff);
388 IO.mapRequired("ntoc", LoadCommand.ntoc);
389 IO.mapRequired("modtaboff", LoadCommand.modtaboff);
390 IO.mapRequired("nmodtab", LoadCommand.nmodtab);
391 IO.mapRequired("extrefsymoff", LoadCommand.extrefsymoff);
392 IO.mapRequired("nextrefsyms", LoadCommand.nextrefsyms);
393 IO.mapRequired("indirectsymoff", LoadCommand.indirectsymoff);
394 IO.mapRequired("nindirectsyms", LoadCommand.nindirectsyms);
395 IO.mapRequired("extreloff", LoadCommand.extreloff);
396 IO.mapRequired("nextrel", LoadCommand.nextrel);
397 IO.mapRequired("locreloff", LoadCommand.locreloff);
398 IO.mapRequired("nlocrel", LoadCommand.nlocrel);
399}
400
401void MappingTraitsMachO::encryption\_info\_command::mapping(
402 IO &IO, MachO::encryption_info_command &LoadCommand) {
403 IO.mapRequired("cryptoff", LoadCommand.cryptoff);
404 IO.mapRequired("cryptsize", LoadCommand.cryptsize);
405 IO.mapRequired("cryptid", LoadCommand.cryptid);
406}
407
408void MappingTraitsMachO::encryption\_info\_command\_64::mapping(
409 IO &IO, MachO::encryption_info_command_64 &LoadCommand) {
410 IO.mapRequired("cryptoff", LoadCommand.cryptoff);
411 IO.mapRequired("cryptsize", LoadCommand.cryptsize);
412 IO.mapRequired("cryptid", LoadCommand.cryptid);
413 IO.mapRequired("pad", LoadCommand.pad);
414}
415
416void MappingTraitsMachO::entry\_point\_command::mapping(
417 IO &IO, MachO::entry_point_command &LoadCommand) {
418 IO.mapRequired("entryoff", LoadCommand.entryoff);
419 IO.mapRequired("stacksize", LoadCommand.stacksize);
420}
421
422void MappingTraitsMachO::fvmfile\_command::mapping(
423 IO &IO, MachO::fvmfile_command &LoadCommand) {
424 IO.mapRequired("name", LoadCommand.name);
425 IO.mapRequired("header_addr", LoadCommand.header_addr);
426}
427
433
437}
438
439void MappingTraitsMachO::ident\_command::mapping(
441
442void MappingTraitsMachO::linkedit\_data\_command::mapping(
443 IO &IO, MachO::linkedit_data_command &LoadCommand) {
444 IO.mapRequired("dataoff", LoadCommand.dataoff);
445 IO.mapRequired("datasize", LoadCommand.datasize);
446}
447
448void MappingTraitsMachO::linker\_option\_command::mapping(
449 IO &IO, MachO::linker_option_command &LoadCommand) {
450 IO.mapRequired("count", LoadCommand.count);
451}
452
453void MappingTraitsMachO::prebind\_cksum\_command::mapping(
454 IO &IO, MachO::prebind_cksum_command &LoadCommand) {
455 IO.mapRequired("cksum", LoadCommand.cksum);
456}
457
458void MappingTraitsMachO::load\_command::mapping(
459 IO &IO, MachO::load_command &LoadCommand) {}
460
461void MappingTraitsMachO::prebound\_dylib\_command::mapping(
462 IO &IO, MachO::prebound_dylib_command &LoadCommand) {
463 IO.mapRequired("name", LoadCommand.name);
464 IO.mapRequired("nmodules", LoadCommand.nmodules);
465 IO.mapRequired("linked_modules", LoadCommand.linked_modules);
466}
467
468void MappingTraitsMachO::routines\_command::mapping(
469 IO &IO, MachO::routines_command &LoadCommand) {
470 IO.mapRequired("init_address", LoadCommand.init_address);
471 IO.mapRequired("init_module", LoadCommand.init_module);
472 IO.mapRequired("reserved1", LoadCommand.reserved1);
473 IO.mapRequired("reserved2", LoadCommand.reserved2);
474 IO.mapRequired("reserved3", LoadCommand.reserved3);
475 IO.mapRequired("reserved4", LoadCommand.reserved4);
476 IO.mapRequired("reserved5", LoadCommand.reserved5);
477 IO.mapRequired("reserved6", LoadCommand.reserved6);
478}
479
480void MappingTraitsMachO::routines\_command\_64::mapping(
481 IO &IO, MachO::routines_command_64 &LoadCommand) {
482 IO.mapRequired("init_address", LoadCommand.init_address);
483 IO.mapRequired("init_module", LoadCommand.init_module);
484 IO.mapRequired("reserved1", LoadCommand.reserved1);
485 IO.mapRequired("reserved2", LoadCommand.reserved2);
486 IO.mapRequired("reserved3", LoadCommand.reserved3);
487 IO.mapRequired("reserved4", LoadCommand.reserved4);
488 IO.mapRequired("reserved5", LoadCommand.reserved5);
489 IO.mapRequired("reserved6", LoadCommand.reserved6);
490}
491
492void MappingTraitsMachO::rpath\_command::mapping(
493 IO &IO, MachO::rpath_command &LoadCommand) {
494 IO.mapRequired("path", LoadCommand.path);
495}
496
510
526
538}
539
540void MappingTraitsMachO::segment\_command\_64::mapping(
542 IO.mapRequired("segname", LoadCommand.segname);
543 IO.mapRequired("vmaddr", LoadCommand.vmaddr);
544 IO.mapRequired("vmsize", LoadCommand.vmsize);
545 IO.mapRequired("fileoff", LoadCommand.fileoff);
546 IO.mapRequired("filesize", LoadCommand.filesize);
547 IO.mapRequired("maxprot", LoadCommand.maxprot);
548 IO.mapRequired("initprot", LoadCommand.initprot);
549 IO.mapRequired("nsects", LoadCommand.nsects);
550 IO.mapRequired("flags", LoadCommand.flags);
551}
552
553void MappingTraitsMachO::source\_version\_command::mapping(
554 IO &IO, MachO::source_version_command &LoadCommand) {
555 IO.mapRequired("version", LoadCommand.version);
556}
557
558void MappingTraitsMachO::sub\_client\_command::mapping(
559 IO &IO, MachO::sub_client_command &LoadCommand) {
560 IO.mapRequired("client", LoadCommand.client);
561}
562
563void MappingTraitsMachO::sub\_framework\_command::mapping(
564 IO &IO, MachO::sub_framework_command &LoadCommand) {
565 IO.mapRequired("umbrella", LoadCommand.umbrella);
566}
567
568void MappingTraitsMachO::sub\_library\_command::mapping(
569 IO &IO, MachO::sub_library_command &LoadCommand) {
570 IO.mapRequired("sub_library", LoadCommand.sub_library);
571}
572
573void MappingTraitsMachO::sub\_umbrella\_command::mapping(
574 IO &IO, MachO::sub_umbrella_command &LoadCommand) {
575 IO.mapRequired("sub_umbrella", LoadCommand.sub_umbrella);
576}
577
578void MappingTraitsMachO::symseg\_command::mapping(
579 IO &IO, MachO::symseg_command &LoadCommand) {
580 IO.mapRequired("offset", LoadCommand.offset);
581 IO.mapRequired("size", LoadCommand.size);
582}
583
584void MappingTraitsMachO::symtab\_command::mapping(
585 IO &IO, MachO::symtab_command &LoadCommand) {
586 IO.mapRequired("symoff", LoadCommand.symoff);
587 IO.mapRequired("nsyms", LoadCommand.nsyms);
588 IO.mapRequired("stroff", LoadCommand.stroff);
589 IO.mapRequired("strsize", LoadCommand.strsize);
590}
591
592void MappingTraitsMachO::thread\_command::mapping(
593 IO &IO, MachO::thread_command &LoadCommand) {}
594
595void MappingTraitsMachO::twolevel\_hints\_command::mapping(
596 IO &IO, MachO::twolevel_hints_command &LoadCommand) {
597 IO.mapRequired("offset", LoadCommand.offset);
598 IO.mapRequired("nhints", LoadCommand.nhints);
599}
600
601void MappingTraitsMachO::uuid\_command::mapping(
602 IO &IO, MachO::uuid_command &LoadCommand) {
603 IO.mapRequired("uuid", LoadCommand.uuid);
604}
605
606void MappingTraitsMachO::version\_min\_command::mapping(
607 IO &IO, MachO::version_min_command &LoadCommand) {
608 IO.mapRequired("version", LoadCommand.version);
609 IO.mapRequired("sdk", LoadCommand.sdk);
610}
611
612void MappingTraitsMachO::note\_command::mapping(
613 IO &IO, MachO::note_command &LoadCommand) {
614 IO.mapRequired("data_owner", LoadCommand.data_owner);
615 IO.mapRequired("offset", LoadCommand.offset);
616 IO.mapRequired("size", LoadCommand.size);
617}
618
619void MappingTraitsMachO::build\_version\_command::mapping(
620 IO &IO, MachO::build_version_command &LoadCommand) {
621 IO.mapRequired("platform", LoadCommand.platform);
622 IO.mapRequired("minos", LoadCommand.minos);
623 IO.mapRequired("sdk", LoadCommand.sdk);
624 IO.mapRequired("ntools", LoadCommand.ntools);
625}
626
627void MappingTraitsMachO::fileset\_entry\_command::mapping(
628 IO &IO, MachO::fileset_entry_command &LoadCommand) {
629 IO.mapRequired("vmaddr", LoadCommand.vmaddr);
630 IO.mapRequired("fileoff", LoadCommand.fileoff);
631 IO.mapRequired("id", LoadCommand.entry_id.offset);
632 IO.mapOptional("reserved", LoadCommand.reserved);
633}
634
635}
636
637}
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)
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)
void * getContext() const
void mapRequired(StringRef Key, T &Val)
constexpr bool IsLittleEndianHost
raw_ostream::uuid_t uuid_t
QuotingType
Describe which type of quotes should be used when quoting is necessary.
void mapLoadCommandData(IO &IO, MachOYAML::LoadCommand &LoadCommand)
Definition MachOYAML.cpp:217
QuotingType needsQuotes(StringRef S, bool ForcePreserveAsString=true)
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
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
bool isEmpty() const
Definition MachOYAML.cpp:26
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
This class should be specialized by any type that needs to be converted to/from a YAML mapping.
This class should be specialized by type that requires custom conversion to/from a yaml scalar.