LLVM  10.0.0svn
MachOEmitter.cpp
Go to the documentation of this file.
1 //===- yaml2macho - Convert YAML to a Mach object file --------------------===//
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 /// \file
10 /// The Mach component of yaml2obj.
11 ///
12 //===----------------------------------------------------------------------===//
13 
18 #include "llvm/Support/LEB128.h"
21 
22 #include "llvm/Support/Format.h"
23 
24 using namespace llvm;
25 
26 namespace {
27 
28 class MachOWriter {
29 public:
30  MachOWriter(MachOYAML::Object &Obj) : Obj(Obj), is64Bit(true), fileStart(0) {
33  memset(reinterpret_cast<void *>(&Header), 0, sizeof(MachO::mach_header_64));
34  }
35 
36  void writeMachO(raw_ostream &OS);
37 
38 private:
39  void writeHeader(raw_ostream &OS);
40  void writeLoadCommands(raw_ostream &OS);
41  void writeSectionData(raw_ostream &OS);
42  void writeLinkEditData(raw_ostream &OS);
43 
44  void writeBindOpcodes(raw_ostream &OS,
45  std::vector<MachOYAML::BindOpcode> &BindOpcodes);
46  // LinkEdit writers
47  void writeRebaseOpcodes(raw_ostream &OS);
48  void writeBasicBindOpcodes(raw_ostream &OS);
49  void writeWeakBindOpcodes(raw_ostream &OS);
50  void writeLazyBindOpcodes(raw_ostream &OS);
51  void writeNameList(raw_ostream &OS);
52  void writeStringTable(raw_ostream &OS);
53  void writeExportTrie(raw_ostream &OS);
54 
55  void dumpExportEntry(raw_ostream &OS, MachOYAML::ExportEntry &Entry);
56  void ZeroToOffset(raw_ostream &OS, size_t offset);
57 
58  MachOYAML::Object &Obj;
59  bool is64Bit;
60  uint64_t fileStart;
61 
62  MachO::mach_header_64 Header;
63 };
64 
65 void MachOWriter::writeMachO(raw_ostream &OS) {
66  fileStart = OS.tell();
67  writeHeader(OS);
68  writeLoadCommands(OS);
69  writeSectionData(OS);
70 }
71 
72 void MachOWriter::writeHeader(raw_ostream &OS) {
73  Header.magic = Obj.Header.magic;
74  Header.cputype = Obj.Header.cputype;
75  Header.cpusubtype = Obj.Header.cpusubtype;
76  Header.filetype = Obj.Header.filetype;
77  Header.ncmds = Obj.Header.ncmds;
78  Header.sizeofcmds = Obj.Header.sizeofcmds;
79  Header.flags = Obj.Header.flags;
80  Header.reserved = Obj.Header.reserved;
81 
83  MachO::swapStruct(Header);
84 
85  auto header_size =
87  OS.write((const char *)&Header, header_size);
88 }
89 
90 template <typename SectionType>
91 SectionType constructSection(MachOYAML::Section Sec) {
92  SectionType TempSec;
93  memcpy(reinterpret_cast<void *>(&TempSec.sectname[0]), &Sec.sectname[0], 16);
94  memcpy(reinterpret_cast<void *>(&TempSec.segname[0]), &Sec.segname[0], 16);
95  TempSec.addr = Sec.addr;
96  TempSec.size = Sec.size;
97  TempSec.offset = Sec.offset;
98  TempSec.align = Sec.align;
99  TempSec.reloff = Sec.reloff;
100  TempSec.nreloc = Sec.nreloc;
101  TempSec.flags = Sec.flags;
102  TempSec.reserved1 = Sec.reserved1;
103  TempSec.reserved2 = Sec.reserved2;
104  return TempSec;
105 }
106 
107 template <typename StructType>
108 size_t writeLoadCommandData(MachOYAML::LoadCommand &LC, raw_ostream &OS,
109  bool IsLittleEndian) {
110  return 0;
111 }
112 
113 template <>
114 size_t writeLoadCommandData<MachO::segment_command>(MachOYAML::LoadCommand &LC,
115  raw_ostream &OS,
116  bool IsLittleEndian) {
117  size_t BytesWritten = 0;
118  for (const auto &Sec : LC.Sections) {
119  auto TempSec = constructSection<MachO::section>(Sec);
120  if (IsLittleEndian != sys::IsLittleEndianHost)
121  MachO::swapStruct(TempSec);
122  OS.write(reinterpret_cast<const char *>(&(TempSec)),
123  sizeof(MachO::section));
124  BytesWritten += sizeof(MachO::section);
125  }
126  return BytesWritten;
127 }
128 
129 template <>
130 size_t writeLoadCommandData<MachO::segment_command_64>(
131  MachOYAML::LoadCommand &LC, raw_ostream &OS, bool IsLittleEndian) {
132  size_t BytesWritten = 0;
133  for (const auto &Sec : LC.Sections) {
134  auto TempSec = constructSection<MachO::section_64>(Sec);
135  TempSec.reserved3 = Sec.reserved3;
136  if (IsLittleEndian != sys::IsLittleEndianHost)
137  MachO::swapStruct(TempSec);
138  OS.write(reinterpret_cast<const char *>(&(TempSec)),
139  sizeof(MachO::section_64));
140  BytesWritten += sizeof(MachO::section_64);
141  }
142  return BytesWritten;
143 }
144 
145 size_t writePayloadString(MachOYAML::LoadCommand &LC, raw_ostream &OS) {
146  size_t BytesWritten = 0;
147  if (!LC.PayloadString.empty()) {
148  OS.write(LC.PayloadString.c_str(), LC.PayloadString.length());
149  BytesWritten = LC.PayloadString.length();
150  }
151  return BytesWritten;
152 }
153 
154 template <>
155 size_t writeLoadCommandData<MachO::dylib_command>(MachOYAML::LoadCommand &LC,
156  raw_ostream &OS,
157  bool IsLittleEndian) {
158  return writePayloadString(LC, OS);
159 }
160 
161 template <>
162 size_t writeLoadCommandData<MachO::dylinker_command>(MachOYAML::LoadCommand &LC,
163  raw_ostream &OS,
164  bool IsLittleEndian) {
165  return writePayloadString(LC, OS);
166 }
167 
168 template <>
169 size_t writeLoadCommandData<MachO::rpath_command>(MachOYAML::LoadCommand &LC,
170  raw_ostream &OS,
171  bool IsLittleEndian) {
172  return writePayloadString(LC, OS);
173 }
174 
175 template <>
176 size_t writeLoadCommandData<MachO::build_version_command>(
177  MachOYAML::LoadCommand &LC, raw_ostream &OS, bool IsLittleEndian) {
178  size_t BytesWritten = 0;
179  for (const auto &T : LC.Tools) {
180  struct MachO::build_tool_version tool = T;
181  if (IsLittleEndian != sys::IsLittleEndianHost)
182  MachO::swapStruct(tool);
183  OS.write(reinterpret_cast<const char *>(&tool),
184  sizeof(MachO::build_tool_version));
185  BytesWritten += sizeof(MachO::build_tool_version);
186  }
187  return BytesWritten;
188 }
189 
190 void ZeroFillBytes(raw_ostream &OS, size_t Size) {
191  std::vector<uint8_t> FillData;
192  FillData.insert(FillData.begin(), Size, 0);
193  OS.write(reinterpret_cast<char *>(FillData.data()), Size);
194 }
195 
196 void Fill(raw_ostream &OS, size_t Size, uint32_t Data) {
197  std::vector<uint32_t> FillData;
198  FillData.insert(FillData.begin(), (Size / 4) + 1, Data);
199  OS.write(reinterpret_cast<char *>(FillData.data()), Size);
200 }
201 
202 void MachOWriter::ZeroToOffset(raw_ostream &OS, size_t Offset) {
203  auto currOffset = OS.tell() - fileStart;
204  if (currOffset < Offset)
205  ZeroFillBytes(OS, Offset - currOffset);
206 }
207 
208 void MachOWriter::writeLoadCommands(raw_ostream &OS) {
209  for (auto &LC : Obj.LoadCommands) {
210  size_t BytesWritten = 0;
211  llvm::MachO::macho_load_command Data = LC.Data;
212 
213 #define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \
214  case MachO::LCName: \
215  if (Obj.IsLittleEndian != sys::IsLittleEndianHost) \
216  MachO::swapStruct(Data.LCStruct##_data); \
217  OS.write(reinterpret_cast<const char *>(&(Data.LCStruct##_data)), \
218  sizeof(MachO::LCStruct)); \
219  BytesWritten = sizeof(MachO::LCStruct); \
220  BytesWritten += \
221  writeLoadCommandData<MachO::LCStruct>(LC, OS, Obj.IsLittleEndian); \
222  break;
223 
224  switch (LC.Data.load_command_data.cmd) {
225  default:
227  MachO::swapStruct(Data.load_command_data);
228  OS.write(reinterpret_cast<const char *>(&(Data.load_command_data)),
229  sizeof(MachO::load_command));
230  BytesWritten = sizeof(MachO::load_command);
231  BytesWritten +=
232  writeLoadCommandData<MachO::load_command>(LC, OS, Obj.IsLittleEndian);
233  break;
234 #include "llvm/BinaryFormat/MachO.def"
235  }
236 
237  if (LC.PayloadBytes.size() > 0) {
238  OS.write(reinterpret_cast<const char *>(LC.PayloadBytes.data()),
239  LC.PayloadBytes.size());
240  BytesWritten += LC.PayloadBytes.size();
241  }
242 
243  if (LC.ZeroPadBytes > 0) {
244  ZeroFillBytes(OS, LC.ZeroPadBytes);
245  BytesWritten += LC.ZeroPadBytes;
246  }
247 
248  // Fill remaining bytes with 0. This will only get hit in partially
249  // specified test cases.
250  auto BytesRemaining = LC.Data.load_command_data.cmdsize - BytesWritten;
251  if (BytesRemaining > 0) {
252  ZeroFillBytes(OS, BytesRemaining);
253  }
254  }
255 }
256 
257 void MachOWriter::writeSectionData(raw_ostream &OS) {
258  bool FoundLinkEditSeg = false;
259  for (auto &LC : Obj.LoadCommands) {
260  switch (LC.Data.load_command_data.cmd) {
261  case MachO::LC_SEGMENT:
262  case MachO::LC_SEGMENT_64:
263  uint64_t segOff = is64Bit ? LC.Data.segment_command_64_data.fileoff
264  : LC.Data.segment_command_data.fileoff;
265  if (0 ==
266  strncmp(&LC.Data.segment_command_data.segname[0], "__LINKEDIT", 16)) {
267  FoundLinkEditSeg = true;
268  writeLinkEditData(OS);
269  }
270  for (auto &Sec : LC.Sections) {
271  ZeroToOffset(OS, Sec.offset);
272  // Zero Fill any data between the end of the last thing we wrote and the
273  // start of this section.
274  assert((OS.tell() - fileStart <= Sec.offset ||
275  Sec.offset == (uint32_t)0) &&
276  "Wrote too much data somewhere, section offsets don't line up.");
277  if (0 == strncmp(&Sec.segname[0], "__DWARF", 16)) {
278  if (0 == strncmp(&Sec.sectname[0], "__debug_str", 16)) {
280  } else if (0 == strncmp(&Sec.sectname[0], "__debug_abbrev", 16)) {
282  } else if (0 == strncmp(&Sec.sectname[0], "__debug_aranges", 16)) {
284  } else if (0 == strncmp(&Sec.sectname[0], "__debug_pubnames", 16)) {
286  Obj.IsLittleEndian);
287  } else if (0 == strncmp(&Sec.sectname[0], "__debug_pubtypes", 16)) {
289  Obj.IsLittleEndian);
290  } else if (0 == strncmp(&Sec.sectname[0], "__debug_info", 16)) {
292  } else if (0 == strncmp(&Sec.sectname[0], "__debug_line", 16)) {
294  }
295 
296  continue;
297  }
298 
299  // Skip if it's a virtual section.
301  continue;
302 
303  if (Sec.content) {
304  yaml::BinaryRef Content = *Sec.content;
305  Content.writeAsBinary(OS);
306  ZeroFillBytes(OS, Sec.size - Content.binary_size());
307  } else {
308  // Fill section data with 0xDEADBEEF.
309  Fill(OS, Sec.size, 0xDEADBEEFu);
310  }
311  }
312  uint64_t segSize = is64Bit ? LC.Data.segment_command_64_data.filesize
313  : LC.Data.segment_command_data.filesize;
314  ZeroToOffset(OS, segOff + segSize);
315  break;
316  }
317  }
318  // Old PPC Object Files didn't have __LINKEDIT segments, the data was just
319  // stuck at the end of the file.
320  if (!FoundLinkEditSeg)
321  writeLinkEditData(OS);
322 }
323 
324 void MachOWriter::writeBindOpcodes(
325  raw_ostream &OS, std::vector<MachOYAML::BindOpcode> &BindOpcodes) {
326 
327  for (auto Opcode : BindOpcodes) {
328  uint8_t OpByte = Opcode.Opcode | Opcode.Imm;
329  OS.write(reinterpret_cast<char *>(&OpByte), 1);
330  for (auto Data : Opcode.ULEBExtraData) {
331  encodeULEB128(Data, OS);
332  }
333  for (auto Data : Opcode.SLEBExtraData) {
334  encodeSLEB128(Data, OS);
335  }
336  if (!Opcode.Symbol.empty()) {
337  OS.write(Opcode.Symbol.data(), Opcode.Symbol.size());
338  OS.write('\0');
339  }
340  }
341 }
342 
343 void MachOWriter::dumpExportEntry(raw_ostream &OS,
345  encodeSLEB128(Entry.TerminalSize, OS);
346  if (Entry.TerminalSize > 0) {
347  encodeSLEB128(Entry.Flags, OS);
349  encodeSLEB128(Entry.Other, OS);
350  OS << Entry.ImportName;
351  OS.write('\0');
352  } else {
353  encodeSLEB128(Entry.Address, OS);
355  encodeSLEB128(Entry.Other, OS);
356  }
357  }
358  OS.write(static_cast<uint8_t>(Entry.Children.size()));
359  for (auto EE : Entry.Children) {
360  OS << EE.Name;
361  OS.write('\0');
362  encodeSLEB128(EE.NodeOffset, OS);
363  }
364  for (auto EE : Entry.Children)
365  dumpExportEntry(OS, EE);
366 }
367 
368 void MachOWriter::writeExportTrie(raw_ostream &OS) {
369  dumpExportEntry(OS, Obj.LinkEdit.ExportTrie);
370 }
371 
372 template <typename NListType>
373 void writeNListEntry(MachOYAML::NListEntry &NLE, raw_ostream &OS,
374  bool IsLittleEndian) {
375  NListType ListEntry;
376  ListEntry.n_strx = NLE.n_strx;
377  ListEntry.n_type = NLE.n_type;
378  ListEntry.n_sect = NLE.n_sect;
379  ListEntry.n_desc = NLE.n_desc;
380  ListEntry.n_value = NLE.n_value;
381 
382  if (IsLittleEndian != sys::IsLittleEndianHost)
383  MachO::swapStruct(ListEntry);
384  OS.write(reinterpret_cast<const char *>(&ListEntry), sizeof(NListType));
385 }
386 
387 void MachOWriter::writeLinkEditData(raw_ostream &OS) {
388  typedef void (MachOWriter::*writeHandler)(raw_ostream &);
389  typedef std::pair<uint64_t, writeHandler> writeOperation;
390  std::vector<writeOperation> WriteQueue;
391 
392  MachO::dyld_info_command *DyldInfoOnlyCmd = 0;
393  MachO::symtab_command *SymtabCmd = 0;
394  for (auto &LC : Obj.LoadCommands) {
395  switch (LC.Data.load_command_data.cmd) {
396  case MachO::LC_SYMTAB:
397  SymtabCmd = &LC.Data.symtab_command_data;
398  WriteQueue.push_back(
399  std::make_pair(SymtabCmd->symoff, &MachOWriter::writeNameList));
400  WriteQueue.push_back(
401  std::make_pair(SymtabCmd->stroff, &MachOWriter::writeStringTable));
402  break;
403  case MachO::LC_DYLD_INFO_ONLY:
404  DyldInfoOnlyCmd = &LC.Data.dyld_info_command_data;
405  WriteQueue.push_back(std::make_pair(DyldInfoOnlyCmd->rebase_off,
406  &MachOWriter::writeRebaseOpcodes));
407  WriteQueue.push_back(std::make_pair(DyldInfoOnlyCmd->bind_off,
408  &MachOWriter::writeBasicBindOpcodes));
409  WriteQueue.push_back(std::make_pair(DyldInfoOnlyCmd->weak_bind_off,
410  &MachOWriter::writeWeakBindOpcodes));
411  WriteQueue.push_back(std::make_pair(DyldInfoOnlyCmd->lazy_bind_off,
412  &MachOWriter::writeLazyBindOpcodes));
413  WriteQueue.push_back(std::make_pair(DyldInfoOnlyCmd->export_off,
414  &MachOWriter::writeExportTrie));
415  break;
416  }
417  }
418 
419  llvm::sort(WriteQueue, [](const writeOperation &a, const writeOperation &b) {
420  return a.first < b.first;
421  });
422 
423  for (auto writeOp : WriteQueue) {
424  ZeroToOffset(OS, writeOp.first);
425  (this->*writeOp.second)(OS);
426  }
427 }
428 
429 void MachOWriter::writeRebaseOpcodes(raw_ostream &OS) {
430  MachOYAML::LinkEditData &LinkEdit = Obj.LinkEdit;
431 
432  for (auto Opcode : LinkEdit.RebaseOpcodes) {
433  uint8_t OpByte = Opcode.Opcode | Opcode.Imm;
434  OS.write(reinterpret_cast<char *>(&OpByte), 1);
435  for (auto Data : Opcode.ExtraData)
436  encodeULEB128(Data, OS);
437  }
438 }
439 
440 void MachOWriter::writeBasicBindOpcodes(raw_ostream &OS) {
441  writeBindOpcodes(OS, Obj.LinkEdit.BindOpcodes);
442 }
443 
444 void MachOWriter::writeWeakBindOpcodes(raw_ostream &OS) {
445  writeBindOpcodes(OS, Obj.LinkEdit.WeakBindOpcodes);
446 }
447 
448 void MachOWriter::writeLazyBindOpcodes(raw_ostream &OS) {
449  writeBindOpcodes(OS, Obj.LinkEdit.LazyBindOpcodes);
450 }
451 
452 void MachOWriter::writeNameList(raw_ostream &OS) {
453  for (auto NLE : Obj.LinkEdit.NameList) {
454  if (is64Bit)
455  writeNListEntry<MachO::nlist_64>(NLE, OS, Obj.IsLittleEndian);
456  else
457  writeNListEntry<MachO::nlist>(NLE, OS, Obj.IsLittleEndian);
458  }
459 }
460 
462  for (auto Str : Obj.LinkEdit.StringTable) {
463  OS.write(Str.data(), Str.size());
464  OS.write('\0');
465  }
466 }
467 
468 class UniversalWriter {
469 public:
470  UniversalWriter(yaml::YamlObjectFile &ObjectFile)
471  : ObjectFile(ObjectFile), fileStart(0) {}
472 
473  void writeMachO(raw_ostream &OS);
474 
475 private:
476  void writeFatHeader(raw_ostream &OS);
477  void writeFatArchs(raw_ostream &OS);
478 
479  void ZeroToOffset(raw_ostream &OS, size_t offset);
480 
482  uint64_t fileStart;
483 };
484 
485 void UniversalWriter::writeMachO(raw_ostream &OS) {
486  fileStart = OS.tell();
487  if (ObjectFile.MachO) {
488  MachOWriter Writer(*ObjectFile.MachO);
489  Writer.writeMachO(OS);
490  return;
491  }
492 
493  writeFatHeader(OS);
494  writeFatArchs(OS);
495 
496  auto &FatFile = *ObjectFile.FatMachO;
497  assert(FatFile.FatArchs.size() == FatFile.Slices.size());
498  for (size_t i = 0; i < FatFile.Slices.size(); i++) {
499  ZeroToOffset(OS, FatFile.FatArchs[i].offset);
500  MachOWriter Writer(FatFile.Slices[i]);
501  Writer.writeMachO(OS);
502 
503  auto SliceEnd = FatFile.FatArchs[i].offset + FatFile.FatArchs[i].size;
504  ZeroToOffset(OS, SliceEnd);
505  }
506 }
507 
508 void UniversalWriter::writeFatHeader(raw_ostream &OS) {
509  auto &FatFile = *ObjectFile.FatMachO;
510  MachO::fat_header header;
511  header.magic = FatFile.Header.magic;
512  header.nfat_arch = FatFile.Header.nfat_arch;
514  swapStruct(header);
515  OS.write(reinterpret_cast<const char *>(&header), sizeof(MachO::fat_header));
516 }
517 
518 template <typename FatArchType>
519 FatArchType constructFatArch(MachOYAML::FatArch &Arch) {
520  FatArchType FatArch;
521  FatArch.cputype = Arch.cputype;
522  FatArch.cpusubtype = Arch.cpusubtype;
523  FatArch.offset = Arch.offset;
524  FatArch.size = Arch.size;
525  FatArch.align = Arch.align;
526  return FatArch;
527 }
528 
529 template <typename StructType>
530 void writeFatArch(MachOYAML::FatArch &LC, raw_ostream &OS) {}
531 
532 template <>
533 void writeFatArch<MachO::fat_arch>(MachOYAML::FatArch &Arch, raw_ostream &OS) {
534  auto FatArch = constructFatArch<MachO::fat_arch>(Arch);
536  swapStruct(FatArch);
537  OS.write(reinterpret_cast<const char *>(&FatArch), sizeof(MachO::fat_arch));
538 }
539 
540 template <>
541 void writeFatArch<MachO::fat_arch_64>(MachOYAML::FatArch &Arch,
542  raw_ostream &OS) {
543  auto FatArch = constructFatArch<MachO::fat_arch_64>(Arch);
544  FatArch.reserved = Arch.reserved;
546  swapStruct(FatArch);
547  OS.write(reinterpret_cast<const char *>(&FatArch),
548  sizeof(MachO::fat_arch_64));
549 }
550 
551 void UniversalWriter::writeFatArchs(raw_ostream &OS) {
552  auto &FatFile = *ObjectFile.FatMachO;
553  bool is64Bit = FatFile.Header.magic == MachO::FAT_MAGIC_64;
554  for (auto Arch : FatFile.FatArchs) {
555  if (is64Bit)
556  writeFatArch<MachO::fat_arch_64>(Arch, OS);
557  else
558  writeFatArch<MachO::fat_arch>(Arch, OS);
559  }
560 }
561 
562 void UniversalWriter::ZeroToOffset(raw_ostream &OS, size_t Offset) {
563  auto currOffset = OS.tell() - fileStart;
564  if (currOffset < Offset)
565  ZeroFillBytes(OS, Offset - currOffset);
566 }
567 
568 } // end anonymous namespace
569 
570 namespace llvm {
571 namespace yaml {
572 
574  UniversalWriter Writer(Doc);
575  Writer.writeMachO(Out);
576  return true;
577 }
578 
579 } // namespace yaml
580 } // namespace llvm
void swapStruct(fat_header &mh)
Definition: MachO.h:1002
bool yaml2macho(YamlObjectFile &Doc, raw_ostream &Out, ErrorHandler EH)
PubSection PubNames
Definition: DWARFYAML.h:148
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void EmitDebugInfo(raw_ostream &OS, const Data &DI)
bool isVirtualSection(uint8_t type)
Definition: MachO.h:584
llvm::yaml::Hex64 addr
Definition: MachOYAML.h:33
std::vector< MachOYAML::ExportEntry > Children
Definition: MachOYAML.h:98
void EmitDebugAranges(raw_ostream &OS, const Data &DI)
uint32_t nfat_arch
Definition: MachO.h:928
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:104
llvm::yaml::Hex64 offset
Definition: MachOYAML.h:130
block Block Frequency true
static void ZeroFillBytes(raw_ostream &OS, size_t Size)
DWARFYAML::Data DWARF
Definition: MachOYAML.h:119
llvm::yaml::Hex32 cputype
Definition: MachOYAML.h:48
llvm::yaml::Hex32 flags
Definition: MachOYAML.h:53
std::vector< MachOYAML::RebaseOpcode > RebaseOpcodes
Definition: MachOYAML.h:102
void EmitDebugAbbrev(raw_ostream &OS, const Data &DI)
llvm::yaml::Hex32 cputype
Definition: MachOYAML.h:128
static const bool IsLittleEndianHost
Definition: SwapByteOrder.h:54
llvm::yaml::Hex32 cpusubtype
Definition: MachOYAML.h:129
LinkEditData LinkEdit
Definition: MachOYAML.h:118
std::vector< LoadCommand > LoadCommands
Definition: MachOYAML.h:116
llvm::yaml::Hex64 Address
Definition: MachOYAML.h:95
llvm::yaml::Hex64 Flags
Definition: MachOYAML.h:94
std::vector< MachOYAML::BindOpcode > WeakBindOpcodes
Definition: MachOYAML.h:104
MachOYAML::ExportEntry ExportTrie
Definition: MachOYAML.h:106
llvm::yaml::Hex32 offset
Definition: MachOYAML.h:35
void writeAsBinary(raw_ostream &OS) const
Write the contents (regardless of whether it is binary or a hex string) as binary to the given raw_os...
Definition: YAML.cpp:40
static bool is64Bit(const char *name)
std::vector< MachOYAML::BindOpcode > BindOpcodes
Definition: MachOYAML.h:103
raw_ostream & write(unsigned char C)
ArrayRef< uint8_t >::size_type binary_size() const
The number of bytes that are represented by this BinaryRef.
Definition: YAML.h:80
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1095
void EmitPubSection(raw_ostream &OS, const PubSection &Sect, bool IsLittleEndian)
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
Definition: LEB128.h:80
Optional< llvm::yaml::BinaryRef > content
Definition: MachOYAML.h:43
llvm::yaml::Hex32 reserved
Definition: MachOYAML.h:54
unsigned encodeSLEB128(int64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a SLEB128 value to an output stream.
Definition: LEB128.h:23
llvm::yaml::Hex64 Other
Definition: MachOYAML.h:96
Common declarations for yaml2obj.
PubSection PubTypes
Definition: DWARFYAML.h:149
llvm::yaml::Hex32 reserved3
Definition: MachOYAML.h:42
Specialized YAMLIO scalar type for representing a binary blob.
Definition: YAML.h:63
llvm::yaml::Hex32 cpusubtype
Definition: MachOYAML.h:49
llvm::yaml::Hex32 reloff
Definition: MachOYAML.h:37
static void writeStringTable(std::vector< uint8_t > &B, ArrayRef< const std::string > Strings)
std::vector< NListEntry > NameList
Definition: MachOYAML.h:107
uint32_t Size
Definition: Profile.cpp:46
Common declarations for yaml2obj.
llvm::yaml::Hex32 reserved2
Definition: MachOYAML.h:41
void EmitDebugStr(raw_ostream &OS, const Data &DI)
llvm::yaml::Hex8 n_type
Definition: MachOYAML.h:70
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::yaml::Hex32 flags
Definition: MachOYAML.h:39
uint64_t tell() const
tell - Return the current offset with the file.
Definition: raw_ostream.h:111
llvm::yaml::Hex32 filetype
Definition: MachOYAML.h:50
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
std::vector< StringRef > StringTable
Definition: MachOYAML.h:108
SectionType
These are the section type and attributes fields.
Definition: MachO.h:114
std::vector< MachOYAML::BindOpcode > LazyBindOpcodes
Definition: MachOYAML.h:105
llvm::yaml::Hex32 reserved1
Definition: MachOYAML.h:40
llvm::yaml::Hex32 magic
Definition: MachOYAML.h:47
void EmitDebugLine(raw_ostream &OS, const Data &DI)