37 void ScalarTraits<char_16>::output(
const char_16 &Val,
void *,
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()) {
102 IO.setContext(&Object);
104 IO.mapTag(
"!mach-o",
true);
109 IO.mapRequired(
"FileHeader", Object.
Header);
112 IO.mapOptional(
"LinkEditData", Object.
LinkEdit);
115 IO.mapOptional(
"DWARF", Object.
DWARF);
117 if (IO.getContext() == &Object)
118 IO.setContext(
nullptr);
123 IO.mapRequired(
"magic", FatHeader.
magic);
124 IO.mapRequired(
"nfat_arch", FatHeader.
nfat_arch);
129 IO.mapRequired(
"cputype", FatArch.
cputype);
130 IO.mapRequired(
"cpusubtype", FatArch.
cpusubtype);
131 IO.mapRequired(
"offset", FatArch.
offset);
132 IO.mapRequired(
"size", FatArch.
size);
133 IO.mapRequired(
"align", FatArch.
align);
134 IO.mapOptional(
"reserved", FatArch.
reserved,
135 static_cast<llvm::yaml::Hex32>(0));
140 if (!IO.getContext()) {
141 IO.setContext(&UniversalBinary);
142 IO.mapTag(
"!fat-mach-o",
true);
144 IO.mapRequired(
"FatHeader", UniversalBinary.
Header);
145 IO.mapRequired(
"FatArchs", UniversalBinary.
FatArchs);
146 IO.mapRequired(
"Slices", UniversalBinary.
Slices);
148 if (IO.getContext() == &UniversalBinary)
149 IO.setContext(
nullptr);
155 IO.mapOptional(
"BindOpcodes", LinkEditData.
BindOpcodes);
159 IO.mapOptional(
"ExportTrie", LinkEditData.
ExportTrie);
160 IO.mapOptional(
"NameList", LinkEditData.
NameList);
161 IO.mapOptional(
"StringTable", LinkEditData.
StringTable);
166 IO.mapRequired(
"Opcode", RebaseOpcode.
Opcode);
167 IO.mapRequired(
"Imm", RebaseOpcode.
Imm);
168 IO.mapOptional(
"ExtraData", RebaseOpcode.
ExtraData);
173 IO.mapRequired(
"Opcode", BindOpcode.
Opcode);
174 IO.mapRequired(
"Imm", BindOpcode.
Imm);
177 IO.mapOptional(
"Symbol", BindOpcode.
Symbol);
182 IO.mapRequired(
"TerminalSize", ExportEntry.
TerminalSize);
183 IO.mapOptional(
"NodeOffset", ExportEntry.
NodeOffset);
184 IO.mapOptional(
"Name", ExportEntry.
Name);
185 IO.mapOptional(
"Flags", ExportEntry.
Flags);
186 IO.mapOptional(
"Address", ExportEntry.
Address);
187 IO.mapOptional(
"Other", ExportEntry.
Other);
188 IO.mapOptional(
"ImportName", ExportEntry.
ImportName);
189 IO.mapOptional(
"Children", ExportEntry.
Children);
194 IO.mapRequired(
"n_strx", NListEntry.
n_strx);
195 IO.mapRequired(
"n_type", NListEntry.
n_type);
196 IO.mapRequired(
"n_sect", NListEntry.
n_sect);
197 IO.mapRequired(
"n_desc", NListEntry.
n_desc);
198 IO.mapRequired(
"n_value", NListEntry.
n_value);
201 template <
typename StructType>
205 void mapLoadCommandData<MachO::segment_command>(
207 IO.mapOptional(
"Sections", LoadCommand.Sections);
211 void mapLoadCommandData<MachO::segment_command_64>(
213 IO.mapOptional(
"Sections", LoadCommand.Sections);
217 void mapLoadCommandData<MachO::dylib_command>(
219 IO.mapOptional(
"PayloadString", LoadCommand.PayloadString);
223 void mapLoadCommandData<MachO::rpath_command>(
225 IO.mapOptional(
"PayloadString", LoadCommand.PayloadString);
229 void mapLoadCommandData<MachO::dylinker_command>(
231 IO.mapOptional(
"PayloadString", LoadCommand.PayloadString);
235 void mapLoadCommandData<MachO::build_version_command>(
237 IO.mapOptional(
"Tools", LoadCommand.Tools);
243 LoadCommand.
Data.load_command_data.cmd);
244 IO.mapRequired(
"cmd", TempCmd);
245 LoadCommand.
Data.load_command_data.cmd = TempCmd;
246 IO.mapRequired(
"cmdsize", LoadCommand.
Data.load_command_data.cmdsize);
248 #define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \ 249 case MachO::LCName: \ 250 MappingTraits<MachO::LCStruct>::mapping(IO, \ 251 LoadCommand.Data.LCStruct##_data); \ 252 mapLoadCommandData<MachO::LCStruct>(IO, LoadCommand); \ 255 switch (LoadCommand.
Data.load_command_data.cmd) {
256 #include "llvm/BinaryFormat/MachO.def" 258 IO.mapOptional(
"PayloadBytes", LoadCommand.
PayloadBytes);
259 IO.mapOptional(
"ZeroPadBytes", LoadCommand.
ZeroPadBytes, (uint64_t)0ull);
264 IO.mapRequired(
"rebase_off", LoadCommand.
rebase_off);
265 IO.mapRequired(
"rebase_size", LoadCommand.
rebase_size);
266 IO.mapRequired(
"bind_off", LoadCommand.
bind_off);
267 IO.mapRequired(
"bind_size", LoadCommand.
bind_size);
272 IO.mapRequired(
"export_off", LoadCommand.
export_off);
273 IO.mapRequired(
"export_size", LoadCommand.
export_size);
278 IO.mapRequired(
"sectname", Section.
sectname);
279 IO.mapRequired(
"segname", Section.
segname);
280 IO.mapRequired(
"addr", Section.
addr);
281 IO.mapRequired(
"size", Section.
size);
282 IO.mapRequired(
"offset", Section.
offset);
283 IO.mapRequired(
"align", Section.
align);
284 IO.mapRequired(
"reloff", Section.
reloff);
285 IO.mapRequired(
"nreloc", Section.
nreloc);
286 IO.mapRequired(
"flags", Section.
flags);
287 IO.mapRequired(
"reserved1", Section.
reserved1);
288 IO.mapRequired(
"reserved2", Section.
reserved2);
289 IO.mapOptional(
"reserved3", Section.
reserved3);
290 IO.mapOptional(
"content", Section.
content);
297 return "Section size must be greater than or equal to the content size";
303 IO.mapRequired(
"tool", tool.
tool);
304 IO.mapRequired(
"version", tool.
version);
308 IO.mapRequired(
"name", DylibStruct.
name);
309 IO.mapRequired(
"timestamp", DylibStruct.
timestamp);
316 IO.mapRequired(
"dylib", LoadCommand.
dylib);
321 IO.mapRequired(
"name", LoadCommand.
name);
326 IO.mapRequired(
"ilocalsym", LoadCommand.
ilocalsym);
327 IO.mapRequired(
"nlocalsym", LoadCommand.
nlocalsym);
328 IO.mapRequired(
"iextdefsym", LoadCommand.
iextdefsym);
329 IO.mapRequired(
"nextdefsym", LoadCommand.
nextdefsym);
330 IO.mapRequired(
"iundefsym", LoadCommand.
iundefsym);
331 IO.mapRequired(
"nundefsym", LoadCommand.
nundefsym);
332 IO.mapRequired(
"tocoff", LoadCommand.
tocoff);
333 IO.mapRequired(
"ntoc", LoadCommand.
ntoc);
334 IO.mapRequired(
"modtaboff", LoadCommand.
modtaboff);
335 IO.mapRequired(
"nmodtab", LoadCommand.
nmodtab);
336 IO.mapRequired(
"extrefsymoff", LoadCommand.
extrefsymoff);
337 IO.mapRequired(
"nextrefsyms", LoadCommand.
nextrefsyms);
340 IO.mapRequired(
"extreloff", LoadCommand.
extreloff);
341 IO.mapRequired(
"nextrel", LoadCommand.
nextrel);
342 IO.mapRequired(
"locreloff", LoadCommand.
locreloff);
343 IO.mapRequired(
"nlocrel", LoadCommand.
nlocrel);
348 IO.mapRequired(
"cryptoff", LoadCommand.
cryptoff);
349 IO.mapRequired(
"cryptsize", LoadCommand.
cryptsize);
350 IO.mapRequired(
"cryptid", LoadCommand.
cryptid);
355 IO.mapRequired(
"cryptoff", LoadCommand.
cryptoff);
356 IO.mapRequired(
"cryptsize", LoadCommand.
cryptsize);
357 IO.mapRequired(
"cryptid", LoadCommand.
cryptid);
358 IO.mapRequired(
"pad", LoadCommand.
pad);
363 IO.mapRequired(
"entryoff", LoadCommand.
entryoff);
364 IO.mapRequired(
"stacksize", LoadCommand.
stacksize);
369 IO.mapRequired(
"name", LoadCommand.
name);
370 IO.mapRequired(
"header_addr", LoadCommand.
header_addr);
374 IO.mapRequired(
"name", FVMLib.
name);
381 IO.mapRequired(
"fvmlib", LoadCommand.
fvmlib);
389 IO.mapRequired(
"dataoff", LoadCommand.
dataoff);
390 IO.mapRequired(
"datasize", LoadCommand.
datasize);
395 IO.mapRequired(
"count", LoadCommand.
count);
400 IO.mapRequired(
"cksum", LoadCommand.
cksum);
408 IO.mapRequired(
"name", LoadCommand.
name);
409 IO.mapRequired(
"nmodules", LoadCommand.
nmodules);
415 IO.mapRequired(
"init_address", LoadCommand.
init_address);
416 IO.mapRequired(
"init_module", LoadCommand.
init_module);
417 IO.mapRequired(
"reserved1", LoadCommand.
reserved1);
418 IO.mapRequired(
"reserved2", LoadCommand.
reserved2);
419 IO.mapRequired(
"reserved3", LoadCommand.
reserved3);
420 IO.mapRequired(
"reserved4", LoadCommand.
reserved4);
421 IO.mapRequired(
"reserved5", LoadCommand.
reserved5);
422 IO.mapRequired(
"reserved6", LoadCommand.
reserved6);
427 IO.mapRequired(
"init_address", LoadCommand.
init_address);
428 IO.mapRequired(
"init_module", LoadCommand.
init_module);
429 IO.mapRequired(
"reserved1", LoadCommand.
reserved1);
430 IO.mapRequired(
"reserved2", LoadCommand.
reserved2);
431 IO.mapRequired(
"reserved3", LoadCommand.
reserved3);
432 IO.mapRequired(
"reserved4", LoadCommand.
reserved4);
433 IO.mapRequired(
"reserved5", LoadCommand.
reserved5);
434 IO.mapRequired(
"reserved6", LoadCommand.
reserved6);
439 IO.mapRequired(
"path", LoadCommand.
path);
443 IO.mapRequired(
"sectname", Section.
sectname);
444 IO.mapRequired(
"segname", Section.
segname);
445 IO.mapRequired(
"addr", Section.
addr);
446 IO.mapRequired(
"size", Section.
size);
447 IO.mapRequired(
"offset", Section.
offset);
448 IO.mapRequired(
"align", Section.
align);
449 IO.mapRequired(
"reloff", Section.
reloff);
450 IO.mapRequired(
"nreloc", Section.
nreloc);
451 IO.mapRequired(
"flags", Section.
flags);
452 IO.mapRequired(
"reserved1", Section.
reserved1);
453 IO.mapRequired(
"reserved2", Section.
reserved2);
458 IO.mapRequired(
"sectname", Section.
sectname);
459 IO.mapRequired(
"segname", Section.
segname);
460 IO.mapRequired(
"addr", Section.
addr);
461 IO.mapRequired(
"size", Section.
size);
462 IO.mapRequired(
"offset", Section.
offset);
463 IO.mapRequired(
"align", Section.
align);
464 IO.mapRequired(
"reloff", Section.
reloff);
465 IO.mapRequired(
"nreloc", Section.
nreloc);
466 IO.mapRequired(
"flags", Section.
flags);
467 IO.mapRequired(
"reserved1", Section.
reserved1);
468 IO.mapRequired(
"reserved2", Section.
reserved2);
469 IO.mapRequired(
"reserved3", Section.
reserved3);
474 IO.mapRequired(
"segname", LoadCommand.
segname);
475 IO.mapRequired(
"vmaddr", LoadCommand.
vmaddr);
476 IO.mapRequired(
"vmsize", LoadCommand.
vmsize);
477 IO.mapRequired(
"fileoff", LoadCommand.
fileoff);
478 IO.mapRequired(
"filesize", LoadCommand.
filesize);
479 IO.mapRequired(
"maxprot", LoadCommand.
maxprot);
480 IO.mapRequired(
"initprot", LoadCommand.
initprot);
481 IO.mapRequired(
"nsects", LoadCommand.
nsects);
482 IO.mapRequired(
"flags", LoadCommand.
flags);
487 IO.mapRequired(
"segname", LoadCommand.
segname);
488 IO.mapRequired(
"vmaddr", LoadCommand.
vmaddr);
489 IO.mapRequired(
"vmsize", LoadCommand.
vmsize);
490 IO.mapRequired(
"fileoff", LoadCommand.
fileoff);
491 IO.mapRequired(
"filesize", LoadCommand.
filesize);
492 IO.mapRequired(
"maxprot", LoadCommand.
maxprot);
493 IO.mapRequired(
"initprot", LoadCommand.
initprot);
494 IO.mapRequired(
"nsects", LoadCommand.
nsects);
495 IO.mapRequired(
"flags", LoadCommand.
flags);
500 IO.mapRequired(
"version", LoadCommand.
version);
505 IO.mapRequired(
"client", LoadCommand.
client);
510 IO.mapRequired(
"umbrella", LoadCommand.
umbrella);
515 IO.mapRequired(
"sub_library", LoadCommand.
sub_library);
520 IO.mapRequired(
"sub_umbrella", LoadCommand.
sub_umbrella);
525 IO.mapRequired(
"offset", LoadCommand.
offset);
526 IO.mapRequired(
"size", LoadCommand.
size);
531 IO.mapRequired(
"symoff", LoadCommand.
symoff);
532 IO.mapRequired(
"nsyms", LoadCommand.
nsyms);
533 IO.mapRequired(
"stroff", LoadCommand.
stroff);
534 IO.mapRequired(
"strsize", LoadCommand.
strsize);
542 IO.mapRequired(
"offset", LoadCommand.
offset);
543 IO.mapRequired(
"nhints", LoadCommand.
nhints);
548 IO.mapRequired(
"uuid", LoadCommand.
uuid);
553 IO.mapRequired(
"version", LoadCommand.
version);
554 IO.mapRequired(
"sdk", LoadCommand.
sdk);
559 IO.mapRequired(
"data_owner", LoadCommand.
data_owner);
560 IO.mapRequired(
"offset", LoadCommand.
offset);
561 IO.mapRequired(
"size", LoadCommand.
size);
566 IO.mapRequired(
"platform", LoadCommand.
platform);
567 IO.mapRequired(
"minos", LoadCommand.
minos);
568 IO.mapRequired(
"sdk", LoadCommand.
sdk);
569 IO.mapRequired(
"ntools", LoadCommand.
ntools);
This class represents lattice values for constants.
std::vector< Object > Slices
std::vector< MachOYAML::ExportEntry > Children
std::vector< llvm::yaml::Hex8 > PayloadBytes
bool getAsUnsignedInteger(StringRef Str, unsigned Radix, unsigned long long &Result)
Helper functions for StringRef::getAsInteger.
std::vector< int64_t > SLEBExtraData
raw_ostream & write_uuid(const uuid_t UUID)
std::vector< MachOYAML::RebaseOpcode > RebaseOpcodes
LLVM_NODISCARD StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
llvm::yaml::Hex32 cputype
static const bool IsLittleEndianHost
llvm::yaml::Hex32 cpusubtype
std::vector< yaml::Hex64 > ExtraData
LLVM_NODISCARD size_t size() const
size - Get the string size.
std::vector< LoadCommand > LoadCommands
llvm::yaml::Hex64 Address
std::vector< MachOYAML::BindOpcode > WeakBindOpcodes
MachOYAML::ExportEntry ExportTrie
std::vector< yaml::Hex64 > ULEBExtraData
MachO::RebaseOpcode Opcode
std::vector< MachOYAML::BindOpcode > BindOpcodes
ArrayRef< uint8_t >::size_type binary_size() const
The number of bytes that are represented by this BinaryRef.
std::vector< FatArch > FatArchs
Optional< llvm::yaml::BinaryRef > content
This file declares classes for handling the YAML representation of Mach-O.
llvm::yaml::Hex32 reserved3
std::vector< NListEntry > NameList
void mapLoadCommandData(IO &IO, MachOYAML::LoadCommand &LoadCommand)
llvm::yaml::Hex32 reserved2
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
This class implements an extremely fast bulk output stream that can only output to a stream...
std::vector< StringRef > StringTable
StringRef - Represent a constant reference to a string, i.e.
llvm::MachO::macho_load_command Data
llvm::yaml::Hex32 reserved
std::vector< MachOYAML::BindOpcode > LazyBindOpcodes
uint32_t compatibility_version
void validate(const Triple &TT, const FeatureBitset &FeatureBits)
llvm::yaml::Hex32 reserved1
raw_ostream::uuid_t uuid_t