LLVM  17.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"
16 #include "llvm/Support/Format.h"
17 #include "llvm/Support/Host.h"
20 #include <cinttypes>
21 #include <cstdint>
22 #include <cstring>
23 
24 namespace llvm {
25 
27 
29  return 0 == RebaseOpcodes.size() + BindOpcodes.size() +
30  WeakBindOpcodes.size() + LazyBindOpcodes.size() +
31  ExportTrie.Children.size() + NameList.size() +
32  StringTable.size() + FunctionStarts.size() +
33  ChainedFixups.size() + DataInCode.size();
34 }
35 
36 namespace yaml {
37 
38 void ScalarTraits<char_16>::output(const char_16 &Val, void *,
39  raw_ostream &Out) {
40  auto Len = strnlen(&Val[0], 16);
41  Out << StringRef(&Val[0], Len);
42 }
43 
45  size_t CopySize = 16 >= Scalar.size() ? 16 : Scalar.size();
46  memcpy((void *)Val, Scalar.data(), CopySize);
47 
48  if (Scalar.size() < 16) {
49  memset((void *)&Val[Scalar.size()], 0, 16 - Scalar.size());
50  }
51 
52  return StringRef();
53 }
54 
55 QuotingType ScalarTraits<char_16>::mustQuote(StringRef S) {
56  return needsQuotes(S);
57 }
58 
59 void ScalarTraits<uuid_t>::output(const uuid_t &Val, void *, raw_ostream &Out) {
60  Out.write_uuid(Val);
61 }
62 
64  size_t OutIdx = 0;
65  for (size_t Idx = 0; Idx < Scalar.size(); ++Idx) {
66  if (Scalar[Idx] == '-' || OutIdx >= 16)
67  continue;
68  unsigned long long TempInt;
69  if (getAsUnsignedInteger(Scalar.slice(Idx, Idx + 2), 16, TempInt))
70  return "invalid number";
71  if (TempInt > 0xFF)
72  return "out of range number";
73  Val[OutIdx] = static_cast<uint8_t>(TempInt);
74  ++Idx; // increment idx an extra time because we're consuming 2 chars
75  ++OutIdx;
76  }
77  return StringRef();
78 }
79 
80 QuotingType ScalarTraits<uuid_t>::mustQuote(StringRef S) {
81  return needsQuotes(S);
82 }
83 
85  IO &IO, MachOYAML::FileHeader &FileHdr) {
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);
96 }
97 
99  MachOYAML::Object &Object) {
100  // If the context isn't already set, tag the document as !mach-o.
101  // For Fat files there will be a different tag so they can be differentiated.
102  if (!IO.getContext()) {
103  IO.setContext(&Object);
104  }
105  IO.mapTag("!mach-o", true);
106  IO.mapOptional("IsLittleEndian", Object.IsLittleEndian,
108  Object.DWARF.IsLittleEndian = Object.IsLittleEndian;
109 
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);
114 
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);
119 
120  if(!Object.DWARF.isEmpty() || !IO.outputting())
121  IO.mapOptional("DWARF", Object.DWARF);
122 
123  if (IO.getContext() == &Object)
124  IO.setContext(nullptr);
125 }
126 
128  IO &IO, MachOYAML::FatHeader &FatHeader) {
129  IO.mapRequired("magic", FatHeader.magic);
130  IO.mapRequired("nfat_arch", FatHeader.nfat_arch);
131 }
132 
134  MachOYAML::FatArch &FatArch) {
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));
142 }
143 
145  IO &IO, MachOYAML::UniversalBinary &UniversalBinary) {
146  if (!IO.getContext()) {
147  IO.setContext(&UniversalBinary);
148  IO.mapTag("!fat-mach-o", true);
149  }
150  IO.mapRequired("FatHeader", UniversalBinary.Header);
151  IO.mapRequired("FatArchs", UniversalBinary.FatArchs);
152  IO.mapRequired("Slices", UniversalBinary.Slices);
153 
154  if (IO.getContext() == &UniversalBinary)
155  IO.setContext(nullptr);
156 }
157 
159  IO &IO, MachOYAML::LinkEditData &LinkEditData) {
160  IO.mapOptional("RebaseOpcodes", LinkEditData.RebaseOpcodes);
161  IO.mapOptional("BindOpcodes", LinkEditData.BindOpcodes);
162  IO.mapOptional("WeakBindOpcodes", LinkEditData.WeakBindOpcodes);
163  IO.mapOptional("LazyBindOpcodes", LinkEditData.LazyBindOpcodes);
164  if (!LinkEditData.ExportTrie.Children.empty() || !IO.outputting())
165  IO.mapOptional("ExportTrie", LinkEditData.ExportTrie);
166  IO.mapOptional("NameList", LinkEditData.NameList);
167  IO.mapOptional("StringTable", LinkEditData.StringTable);
168  IO.mapOptional("IndirectSymbols", LinkEditData.IndirectSymbols);
169  IO.mapOptional("FunctionStarts", LinkEditData.FunctionStarts);
170  IO.mapOptional("ChainedFixups", LinkEditData.ChainedFixups);
171  IO.mapOptional("DataInCode", LinkEditData.DataInCode);
172 }
173 
176  IO.mapRequired("Opcode", RebaseOpcode.Opcode);
177  IO.mapRequired("Imm", RebaseOpcode.Imm);
178  IO.mapOptional("ExtraData", RebaseOpcode.ExtraData);
179 }
180 
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);
188 }
189 
191  IO &IO, MachOYAML::ExportEntry &ExportEntry) {
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);
200 }
201 
203  IO &IO, MachOYAML::NListEntry &NListEntry) {
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);
209 }
210 
212  IO &IO, MachOYAML::DataInCodeEntry &DataInCodeEntry) {
213  IO.mapRequired("Offset", DataInCodeEntry.Offset);
214  IO.mapRequired("Length", DataInCodeEntry.Length);
215  IO.mapRequired("Kind", DataInCodeEntry.Kind);
216 }
217 
218 template <typename StructType>
219 void mapLoadCommandData(IO &IO, MachOYAML::LoadCommand &LoadCommand) {}
220 
221 template <>
222 void mapLoadCommandData<MachO::segment_command>(
223  IO &IO, MachOYAML::LoadCommand &LoadCommand) {
224  IO.mapOptional("Sections", LoadCommand.Sections);
225 }
226 
227 template <>
228 void mapLoadCommandData<MachO::segment_command_64>(
229  IO &IO, MachOYAML::LoadCommand &LoadCommand) {
230  IO.mapOptional("Sections", LoadCommand.Sections);
231 }
232 
233 template <>
234 void mapLoadCommandData<MachO::dylib_command>(
235  IO &IO, MachOYAML::LoadCommand &LoadCommand) {
236  IO.mapOptional("Content", LoadCommand.Content);
237 }
238 
239 template <>
240 void mapLoadCommandData<MachO::rpath_command>(
241  IO &IO, MachOYAML::LoadCommand &LoadCommand) {
242  IO.mapOptional("Content", LoadCommand.Content);
243 }
244 
245 template <>
246 void mapLoadCommandData<MachO::dylinker_command>(
247  IO &IO, MachOYAML::LoadCommand &LoadCommand) {
248  IO.mapOptional("Content", LoadCommand.Content);
249 }
250 
251 template <>
252 void mapLoadCommandData<MachO::sub_framework_command>(
253  IO &IO, MachOYAML::LoadCommand &LoadCommand) {
254  IO.mapOptional("Content", LoadCommand.Content);
255 }
256 
257 template <>
258 void mapLoadCommandData<MachO::sub_umbrella_command>(
259  IO &IO, MachOYAML::LoadCommand &LoadCommand) {
260  IO.mapOptional("Content", LoadCommand.Content);
261 }
262 
263 template <>
264 void mapLoadCommandData<MachO::sub_client_command>(
265  IO &IO, MachOYAML::LoadCommand &LoadCommand) {
266  IO.mapOptional("Content", LoadCommand.Content);
267 }
268 
269 template <>
270 void mapLoadCommandData<MachO::sub_library_command>(
271  IO &IO, MachOYAML::LoadCommand &LoadCommand) {
272  IO.mapOptional("Content", LoadCommand.Content);
273 }
274 
275 template <>
276 void mapLoadCommandData<MachO::build_version_command>(
277  IO &IO, MachOYAML::LoadCommand &LoadCommand) {
278  IO.mapOptional("Tools", LoadCommand.Tools);
279 }
280 
282  IO &IO, MachOYAML::LoadCommand &LoadCommand) {
283  MachO::LoadCommandType TempCmd = static_cast<MachO::LoadCommandType>(
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);
288 
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); \
294  break;
295 
296  switch (LoadCommand.Data.load_command_data.cmd) {
297 #include "llvm/BinaryFormat/MachO.def"
298  }
299  IO.mapOptional("PayloadBytes", LoadCommand.PayloadBytes);
300  IO.mapOptional("ZeroPadBytes", LoadCommand.ZeroPadBytes, (uint64_t)0ull);
301 }
302 
304  IO &IO, MachO::dyld_info_command &LoadCommand) {
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);
309  IO.mapRequired("weak_bind_off", LoadCommand.weak_bind_off);
310  IO.mapRequired("weak_bind_size", LoadCommand.weak_bind_size);
311  IO.mapRequired("lazy_bind_off", LoadCommand.lazy_bind_off);
312  IO.mapRequired("lazy_bind_size", LoadCommand.lazy_bind_size);
313  IO.mapRequired("export_off", LoadCommand.export_off);
314  IO.mapRequired("export_size", LoadCommand.export_size);
315 }
316 
318  IO &IO, MachOYAML::Relocation &Relocation) {
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);
325  IO.mapRequired("scattered", Relocation.is_scattered);
326  IO.mapRequired("value", Relocation.value);
327 }
328 
330  MachOYAML::Section &Section) {
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);
345 }
346 
347 std::string
349  MachOYAML::Section &Section) {
350  if (Section.content && Section.size < Section.content->binary_size())
351  return "Section size must be greater than or equal to the content size";
352  return "";
353 }
354 
356  IO &IO, MachO::build_tool_version &tool) {
357  IO.mapRequired("tool", tool.tool);
358  IO.mapRequired("version", tool.version);
359 }
360 
362  IO.mapRequired("name", DylibStruct.name);
363  IO.mapRequired("timestamp", DylibStruct.timestamp);
364  IO.mapRequired("current_version", DylibStruct.current_version);
365  IO.mapRequired("compatibility_version", DylibStruct.compatibility_version);
366 }
367 
369  IO &IO, MachO::dylib_command &LoadCommand) {
370  IO.mapRequired("dylib", LoadCommand.dylib);
371 }
372 
373 void MappingTraits<MachO::dylinker_command>::mapping(
374  IO &IO, MachO::dylinker_command &LoadCommand) {
375  IO.mapRequired("name", LoadCommand.name);
376 }
377 
378 void 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);
398 }
399 
400 void 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);
405 }
406 
407 void 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);
413 }
414 
415 void 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);
419 }
420 
421 void 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);
425 }
426 
428  IO.mapRequired("name", FVMLib.name);
429  IO.mapRequired("minor_version", FVMLib.minor_version);
430  IO.mapRequired("header_addr", FVMLib.header_addr);
431 }
432 
434  IO &IO, MachO::fvmlib_command &LoadCommand) {
435  IO.mapRequired("fvmlib", LoadCommand.fvmlib);
436 }
437 
438 void MappingTraits<MachO::ident_command>::mapping(
439  IO &IO, MachO::ident_command &LoadCommand) {}
440 
441 void 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);
445 }
446 
447 void MappingTraits<MachO::linker_option_command>::mapping(
448  IO &IO, MachO::linker_option_command &LoadCommand) {
449  IO.mapRequired("count", LoadCommand.count);
450 }
451 
452 void MappingTraits<MachO::prebind_cksum_command>::mapping(
453  IO &IO, MachO::prebind_cksum_command &LoadCommand) {
454  IO.mapRequired("cksum", LoadCommand.cksum);
455 }
456 
457 void MappingTraits<MachO::load_command>::mapping(
458  IO &IO, MachO::load_command &LoadCommand) {}
459 
460 void 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);
465 }
466 
467 void 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);
477 }
478 
479 void 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);
489 }
490 
491 void MappingTraits<MachO::rpath_command>::mapping(
492  IO &IO, MachO::rpath_command &LoadCommand) {
493  IO.mapRequired("path", LoadCommand.path);
494 }
495 
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);
508 }
509 
511  MachO::section_64 &Section) {
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);
524 }
525 
527  IO &IO, MachO::segment_command &LoadCommand) {
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);
537 }
538 
539 void MappingTraits<MachO::segment_command_64>::mapping(
540  IO &IO, MachO::segment_command_64 &LoadCommand) {
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);
550 }
551 
552 void MappingTraits<MachO::source_version_command>::mapping(
553  IO &IO, MachO::source_version_command &LoadCommand) {
554  IO.mapRequired("version", LoadCommand.version);
555 }
556 
557 void MappingTraits<MachO::sub_client_command>::mapping(
558  IO &IO, MachO::sub_client_command &LoadCommand) {
559  IO.mapRequired("client", LoadCommand.client);
560 }
561 
562 void MappingTraits<MachO::sub_framework_command>::mapping(
563  IO &IO, MachO::sub_framework_command &LoadCommand) {
564  IO.mapRequired("umbrella", LoadCommand.umbrella);
565 }
566 
567 void MappingTraits<MachO::sub_library_command>::mapping(
568  IO &IO, MachO::sub_library_command &LoadCommand) {
569  IO.mapRequired("sub_library", LoadCommand.sub_library);
570 }
571 
572 void MappingTraits<MachO::sub_umbrella_command>::mapping(
573  IO &IO, MachO::sub_umbrella_command &LoadCommand) {
574  IO.mapRequired("sub_umbrella", LoadCommand.sub_umbrella);
575 }
576 
577 void MappingTraits<MachO::symseg_command>::mapping(
578  IO &IO, MachO::symseg_command &LoadCommand) {
579  IO.mapRequired("offset", LoadCommand.offset);
580  IO.mapRequired("size", LoadCommand.size);
581 }
582 
583 void 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);
589 }
590 
591 void MappingTraits<MachO::thread_command>::mapping(
592  IO &IO, MachO::thread_command &LoadCommand) {}
593 
594 void 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);
598 }
599 
600 void MappingTraits<MachO::uuid_command>::mapping(
601  IO &IO, MachO::uuid_command &LoadCommand) {
602  IO.mapRequired("uuid", LoadCommand.uuid);
603 }
604 
605 void 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);
609 }
610 
611 void 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);
616 }
617 
618 void 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);
624 }
625 
626 void 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);
631 }
632 
633 } // end namespace yaml
634 
635 } // end namespace llvm
llvm::MachO::dylib
Definition: MachO.h:617
llvm::MachOYAML::ExportEntry
Definition: MachOYAML.h:106
llvm::MachO::segment_command_64::flags
uint32_t flags
Definition: MachO.h:567
llvm::MachO::build_tool_version::tool
uint32_t tool
Definition: MachO.h:858
llvm::MachOYAML::FatArch::offset
llvm::yaml::Hex64 offset
Definition: MachOYAML.h:157
llvm::MachO::segment_command_64::initprot
uint32_t initprot
Definition: MachO.h:565
llvm::MachOYAML::LoadCommand::Sections
std::vector< Section > Sections
Definition: MachOYAML.h:77
llvm::MachO::section
Definition: MachO.h:570
llvm::MachOYAML::NListEntry::n_desc
uint16_t n_desc
Definition: MachOYAML.h:88
llvm::MachO::dylib::compatibility_version
uint32_t compatibility_version
Definition: MachO.h:621
llvm::MachOYAML::DataInCodeEntry::Length
uint16_t Length
Definition: MachOYAML.h:119
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::MachOYAML::Object
Definition: MachOYAML.h:139
llvm::MachOYAML::Relocation::is_scattered
bool is_scattered
Definition: MachOYAML.h:41
llvm::MachOYAML::Section
Definition: MachOYAML.h:45
llvm::MachOYAML::LinkEditData::DataInCode
std::vector< DataInCodeEntry > DataInCode
Definition: MachOYAML.h:133
llvm::MachOYAML::Relocation::is_pcrel
bool is_pcrel
Definition: MachOYAML.h:36
llvm::yaml::char_16
char[16] char_16
Definition: MachOYAML.h:298
StringRef.h
llvm::MachO::segment_command_64::nsects
uint32_t nsects
Definition: MachO.h:566
llvm::MachOYAML::ExportEntry::Address
llvm::yaml::Hex64 Address
Definition: MachOYAML.h:111
llvm::MachOYAML::LinkEditData::ExportTrie
MachOYAML::ExportEntry ExportTrie
Definition: MachOYAML.h:128
llvm::MachO::fvmlib::header_addr
uint32_t header_addr
Definition: MachO.h:607
output
Current output
Definition: README.txt:1350
llvm::MachOYAML::LoadCommand::ZeroPadBytes
uint64_t ZeroPadBytes
Definition: MachOYAML.h:81
llvm::MachO::segment_command::filesize
uint32_t filesize
Definition: MachO.h:549
llvm::MachOYAML::FatHeader::nfat_arch
uint32_t nfat_arch
Definition: MachOYAML.h:151
llvm::MachO::dylib::name
uint32_t name
Definition: MachO.h:618
llvm::MachO::segment_command::fileoff
uint32_t fileoff
Definition: MachO.h:548
llvm::MachO::segment_command::vmsize
uint32_t vmsize
Definition: MachO.h:547
llvm::MachO::fvmlib
Definition: MachO.h:604
llvm::MachOYAML::UniversalBinary::FatArchs
std::vector< FatArch > FatArchs
Definition: MachOYAML.h:165
llvm::MachOYAML::ExportEntry::Flags
llvm::yaml::Hex64 Flags
Definition: MachOYAML.h:110
llvm::MachOYAML::LinkEditData::LazyBindOpcodes
std::vector< MachOYAML::BindOpcode > LazyBindOpcodes
Definition: MachOYAML.h:127
llvm::MachOYAML::NListEntry
Definition: MachOYAML.h:84
llvm::MachOYAML::LoadCommand::PayloadBytes
std::vector< llvm::yaml::Hex8 > PayloadBytes
Definition: MachOYAML.h:79
llvm::MachO::LoadCommandType
LoadCommandType
Definition: MachO.h:98
llvm::MachO::dyld_info_command::export_off
uint32_t export_off
Definition: MachO.h:889
llvm::MachO::fvmlib::minor_version
uint32_t minor_version
Definition: MachO.h:606
llvm::MachOYAML::ExportEntry::NodeOffset
uint64_t NodeOffset
Definition: MachOYAML.h:108
llvm::MachOYAML::DataInCodeEntry::Offset
llvm::yaml::Hex32 Offset
Definition: MachOYAML.h:118
llvm::MachOYAML::LinkEditData::FunctionStarts
std::vector< yaml::Hex64 > FunctionStarts
Definition: MachOYAML.h:132
llvm::MachO::MH_MAGIC_64
@ MH_MAGIC_64
Definition: MachO.h:32
llvm::yaml::MappingTraits
Definition: ModuleSummaryIndex.h:53
llvm::RISCVFeatures::validate
void validate(const Triple &TT, const FeatureBitset &FeatureBits)
Definition: RISCVBaseInfo.cpp:99
Format.h
llvm::MachOYAML::LinkEditData::RebaseOpcodes
std::vector< MachOYAML::RebaseOpcode > RebaseOpcodes
Definition: MachOYAML.h:124
llvm::MachO::build_tool_version::version
uint32_t version
Definition: MachO.h:859
llvm::yaml::uuid_t
raw_ostream::uuid_t uuid_t
Definition: MachOYAML.h:308
llvm::MachOYAML::Relocation::address
llvm::yaml::Hex32 address
Definition: MachOYAML.h:33
llvm::MachOYAML::RebaseOpcode
Definition: MachOYAML.h:92
llvm::MachOYAML::LoadCommand::Content
std::string Content
Definition: MachOYAML.h:80
llvm::MachOYAML::FileHeader::sizeofcmds
uint32_t sizeofcmds
Definition: MachOYAML.h:68
llvm::MachO::dyld_info_command
Definition: MachO.h:878
llvm::MachOYAML::ExportEntry::Other
llvm::yaml::Hex64 Other
Definition: MachOYAML.h:112
llvm::MachOYAML::LinkEditData::IndirectSymbols
std::vector< yaml::Hex32 > IndirectSymbols
Definition: MachOYAML.h:131
llvm::MachOYAML::DataInCodeEntry::Kind
llvm::yaml::Hex16 Kind
Definition: MachOYAML.h:120
llvm::MachO::fvmlib::name
uint32_t name
Definition: MachO.h:605
llvm::MachOYAML::LinkEditData::isEmpty
bool isEmpty() const
Definition: MachOYAML.cpp:28
llvm::MachOYAML::Relocation::is_extern
bool is_extern
Definition: MachOYAML.h:39
llvm::MachOYAML::BindOpcode
Definition: MachOYAML.h:98
llvm::getAsUnsignedInteger
bool getAsUnsignedInteger(StringRef Str, unsigned Radix, unsigned long long &Result)
Helper functions for StringRef::getAsInteger.
Definition: StringRef.cpp:492
llvm::MachOYAML::ExportEntry::Name
std::string Name
Definition: MachOYAML.h:109
llvm::MachO::segment_command_64::segname
char segname[16]
Definition: MachO.h:559
llvm::MachOYAML::FatArch::align
uint32_t align
Definition: MachOYAML.h:159
llvm::MachOYAML::NListEntry::n_value
uint64_t n_value
Definition: MachOYAML.h:89
llvm::MachOYAML::FatArch::cputype
llvm::yaml::Hex32 cputype
Definition: MachOYAML.h:155
llvm::MachOYAML::UniversalBinary
Definition: MachOYAML.h:163
Host.h
llvm::MachO::segment_command::segname
char segname[16]
Definition: MachO.h:545
llvm::MachOYAML::UniversalBinary::Slices
std::vector< Object > Slices
Definition: MachOYAML.h:166
llvm::MachO::dylib_command::dylib
struct dylib dylib
Definition: MachO.h:627
llvm::MachOYAML::FileHeader::filetype
llvm::yaml::Hex32 filetype
Definition: MachOYAML.h:66
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
llvm::MachOYAML::LoadCommand::Data
llvm::MachO::macho_load_command Data
Definition: MachOYAML.h:76
llvm::MachO::ident_command
Definition: MachO.h:916
llvm::MachO::segment_command::initprot
uint32_t initprot
Definition: MachO.h:551
input
The initial backend is deliberately restricted to z10 We should add support for later architectures at some point If an asm ties an i32 r result to an i64 input
Definition: README.txt:10
llvm::MachOYAML::LoadCommand
Definition: MachOYAML.h:73
llvm::MachOYAML::LinkEditData::NameList
std::vector< NListEntry > NameList
Definition: MachOYAML.h:129
llvm::MachO::fvmlib_command
Definition: MachO.h:611
llvm::OutputFileType::Object
@ Object
llvm::MachOYAML::FatArch::cpusubtype
llvm::yaml::Hex32 cpusubtype
Definition: MachOYAML.h:156
llvm::MachOYAML::FileHeader::reserved
llvm::yaml::Hex32 reserved
Definition: MachOYAML.h:70
llvm::MachO::dylib_command
Definition: MachO.h:624
llvm::MachO::dylinker_command::name
uint32_t name
Definition: MachO.h:666
llvm::MachOYAML::UniversalBinary::Header
FatHeader Header
Definition: MachOYAML.h:164
uint64_t
llvm::MachOYAML::ExportEntry::ImportName
std::string ImportName
Definition: MachOYAML.h:113
llvm::MachOYAML::FileHeader::flags
llvm::yaml::Hex32 flags
Definition: MachOYAML.h:69
llvm::MachO::build_tool_version
Definition: MachO.h:857
llvm::MachOYAML::Relocation::value
int32_t value
Definition: MachOYAML.h:42
llvm::MachOYAML::Relocation::type
uint8_t type
Definition: MachOYAML.h:40
MachOYAML.h
llvm::MachO::dyld_info_command::weak_bind_size
uint32_t weak_bind_size
Definition: MachO.h:886
llvm::MachOYAML::NListEntry::n_sect
uint8_t n_sect
Definition: MachOYAML.h:87
llvm::MachO::dyld_info_command::lazy_bind_off
uint32_t lazy_bind_off
Definition: MachO.h:887
llvm::MachOYAML::FatArch::size
uint64_t size
Definition: MachOYAML.h:158
llvm::MachOYAML::LinkEditData::ChainedFixups
std::vector< yaml::Hex8 > ChainedFixups
Definition: MachOYAML.h:134
llvm::MachO::segment_command_64::fileoff
uint64_t fileoff
Definition: MachO.h:562
llvm::MachO::dyld_info_command::bind_size
uint32_t bind_size
Definition: MachO.h:884
llvm::MachOYAML::FileHeader
Definition: MachOYAML.h:62
llvm::MachOYAML::NListEntry::n_type
llvm::yaml::Hex8 n_type
Definition: MachOYAML.h:86
memcpy
<%struct.s * > cast struct s *S to sbyte *< sbyte * > sbyte uint cast struct s *agg result to sbyte *< sbyte * > sbyte uint cast struct s *memtmp to sbyte *< sbyte * > sbyte uint ret void llc ends up issuing two memcpy or custom lower memcpy(of small size) to be ldmia/stmia. I think option 2 is better but the current register allocator cannot allocate a chunk of registers at a time. A feasible temporary solution is to use specific physical registers at the lowering time for small(<
llvm::MachO::segment_command
Definition: MachO.h:542
llvm::MachO::dylinker_command
Definition: MachO.h:663
llvm::MachO::RebaseOpcode
RebaseOpcode
Definition: MachO.h:242
llvm::MachOYAML::NListEntry::n_strx
uint32_t n_strx
Definition: MachOYAML.h:85
llvm::MachO::segment_command::vmaddr
uint32_t vmaddr
Definition: MachO.h:546
YAMLTraits.h
llvm::MachOYAML::LinkEditData
Definition: MachOYAML.h:123
llvm::MachOYAML::LoadCommand::~LoadCommand
virtual ~LoadCommand()
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::MachOYAML::ExportEntry::TerminalSize
uint64_t TerminalSize
Definition: MachOYAML.h:107
llvm::MachOYAML::FileHeader::cputype
llvm::yaml::Hex32 cputype
Definition: MachOYAML.h:64
llvm::MachO::dyld_info_command::rebase_size
uint32_t rebase_size
Definition: MachO.h:882
llvm::MachOYAML::LinkEditData::WeakBindOpcodes
std::vector< MachOYAML::BindOpcode > WeakBindOpcodes
Definition: MachOYAML.h:126
llvm::MachOYAML::FileHeader::magic
llvm::yaml::Hex32 magic
Definition: MachOYAML.h:63
llvm::MachO::segment_command_64
Definition: MachO.h:556
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::MachO::dyld_info_command::weak_bind_off
uint32_t weak_bind_off
Definition: MachO.h:885
llvm::MachO::MH_CIGAM_64
@ MH_CIGAM_64
Definition: MachO.h:33
llvm::MachOYAML::LinkEditData::BindOpcodes
std::vector< MachOYAML::BindOpcode > BindOpcodes
Definition: MachOYAML.h:125
llvm::MachOYAML::LoadCommand::Tools
std::vector< MachO::build_tool_version > Tools
Definition: MachOYAML.h:78
llvm::MachO::segment_command::maxprot
uint32_t maxprot
Definition: MachO.h:550
llvm::MachO::dylib::timestamp
uint32_t timestamp
Definition: MachO.h:619
llvm::MachO::section_64
Definition: MachO.h:584
llvm::MachOYAML::FileHeader::cpusubtype
llvm::yaml::Hex32 cpusubtype
Definition: MachOYAML.h:65
llvm::MachO::segment_command::nsects
uint32_t nsects
Definition: MachO.h:552
llvm::MachO::segment_command_64::filesize
uint64_t filesize
Definition: MachO.h:563
llvm::MachOYAML::FatArch
Definition: MachOYAML.h:154
llvm::MachO::segment_command_64::vmaddr
uint64_t vmaddr
Definition: MachO.h:560
llvm::MachOYAML::Relocation::symbolnum
uint32_t symbolnum
Definition: MachOYAML.h:35
llvm::MachOYAML::FatArch::reserved
llvm::yaml::Hex32 reserved
Definition: MachOYAML.h:160
llvm::MachO::dylib::current_version
uint32_t current_version
Definition: MachO.h:620
llvm::MachO::segment_command::flags
uint32_t flags
Definition: MachO.h:553
llvm::sys::IsLittleEndianHost
static const bool IsLittleEndianHost
Definition: SwapByteOrder.h:67
llvm::MachOYAML::LinkEditData::StringTable
std::vector< StringRef > StringTable
Definition: MachOYAML.h:130
llvm::MachOYAML::FileHeader::ncmds
uint32_t ncmds
Definition: MachOYAML.h:67
llvm::MachO::dyld_info_command::bind_off
uint32_t bind_off
Definition: MachO.h:883
llvm::MachOYAML::FatHeader::magic
llvm::yaml::Hex32 magic
Definition: MachOYAML.h:150
llvm::MachO::dyld_info_command::rebase_off
uint32_t rebase_off
Definition: MachO.h:881
llvm::MachO::dyld_info_command::lazy_bind_size
uint32_t lazy_bind_size
Definition: MachO.h:888
llvm::MachOYAML::ExportEntry::Children
std::vector< MachOYAML::ExportEntry > Children
Definition: MachOYAML.h:114
llvm::MachO::segment_command_64::maxprot
uint32_t maxprot
Definition: MachO.h:564
MachO.h
llvm::MachO::dyld_info_command::export_size
uint32_t export_size
Definition: MachO.h:890
llvm::MachOYAML::DataInCodeEntry
Definition: MachOYAML.h:117
raw_ostream.h
llvm::MachO::fvmlib_command::fvmlib
struct fvmlib fvmlib
Definition: MachO.h:614
llvm::MachO::segment_command_64::vmsize
uint64_t vmsize
Definition: MachO.h:561
llvm::raw_ostream::write_uuid
raw_ostream & write_uuid(const uuid_t UUID)
Definition: raw_ostream.cpp:151
llvm::MachOYAML::Relocation
Definition: MachOYAML.h:31
llvm::MachOYAML::Relocation::length
uint8_t length
Definition: MachOYAML.h:38
llvm::yaml::mapLoadCommandData
void mapLoadCommandData(IO &IO, MachOYAML::LoadCommand &LoadCommand)
Definition: MachOYAML.cpp:219
llvm::MachO::BindOpcode
BindOpcode
Definition: MachO.h:275
llvm::MachOYAML::FatHeader
Definition: MachOYAML.h:149