LLVM  5.0.0
MachO.h
Go to the documentation of this file.
1 //===- MachO.h - MachO object file implementation ---------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the MachOObjectFile class, which implement the ObjectFile
11 // interface for MachO files.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_OBJECT_MACHO_H
16 #define LLVM_OBJECT_MACHO_H
17 
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/SmallString.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/StringExtras.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/ADT/Triple.h"
27 #include "llvm/Object/Binary.h"
28 #include "llvm/Object/ObjectFile.h"
30 #include "llvm/Support/Error.h"
31 #include "llvm/Support/Format.h"
34 #include <cstdint>
35 #include <memory>
36 #include <string>
37 #include <system_error>
38 
39 namespace llvm {
40 namespace object {
41 
42 /// DiceRef - This is a value type class that represents a single
43 /// data in code entry in the table in a Mach-O object file.
44 class DiceRef {
45  DataRefImpl DicePimpl;
46  const ObjectFile *OwningObject = nullptr;
47 
48 public:
49  DiceRef() = default;
50  DiceRef(DataRefImpl DiceP, const ObjectFile *Owner);
51 
52  bool operator==(const DiceRef &Other) const;
53  bool operator<(const DiceRef &Other) const;
54 
55  void moveNext();
56 
57  std::error_code getOffset(uint32_t &Result) const;
58  std::error_code getLength(uint16_t &Result) const;
59  std::error_code getKind(uint16_t &Result) const;
60 
62  const ObjectFile *getObjectFile() const;
63 };
65 
66 /// ExportEntry encapsulates the current-state-of-the-walk used when doing a
67 /// non-recursive walk of the trie data structure. This allows you to iterate
68 /// across all exported symbols using:
69 /// for (const llvm::object::ExportEntry &AnExport : Obj->exports()) {
70 /// }
71 class ExportEntry {
72 public:
74 
75  StringRef name() const;
76  uint64_t flags() const;
77  uint64_t address() const;
78  uint64_t other() const;
79  StringRef otherName() const;
80  uint32_t nodeOffset() const;
81 
82  bool operator==(const ExportEntry &) const;
83 
84  void moveNext();
85 
86 private:
87  friend class MachOObjectFile;
88 
89  void moveToFirst();
90  void moveToEnd();
91  uint64_t readULEB128(const uint8_t *&p);
92  void pushDownUntilBottom();
93  void pushNode(uint64_t Offset);
94 
95  // Represents a node in the mach-o exports trie.
96  struct NodeState {
97  NodeState(const uint8_t *Ptr);
98 
99  const uint8_t *Start;
100  const uint8_t *Current;
101  uint64_t Flags = 0;
102  uint64_t Address = 0;
103  uint64_t Other = 0;
104  const char *ImportName = nullptr;
105  unsigned ChildCount = 0;
106  unsigned NextChildIndex = 0;
107  unsigned ParentStringLength = 0;
108  bool IsExportNode = false;
109  };
110 
111  ArrayRef<uint8_t> Trie;
112  SmallString<256> CumulativeString;
114  bool Malformed = false;
115  bool Done = false;
116 };
118 
119 // Segment info so SegIndex/SegOffset pairs in a Mach-O Bind or Rebase entry
120 // can be checked and translated. Only the SegIndex/SegOffset pairs from
121 // checked entries are to be used with the segmentName(), sectionName() and
122 // address() methods below.
124 public:
126 
127  // Used to check a Mach-O Bind or Rebase entry for errors when iterating.
128  const char *checkSegAndOffset(int32_t SegIndex, uint64_t SegOffset,
129  bool endInvalid);
130  const char *checkCountAndSkip(uint32_t Count, uint32_t Skip,
131  uint8_t PointerSize, int32_t SegIndex,
132  uint64_t SegOffset);
133  // Used with valid SegIndex/SegOffset values from checked entries.
134  StringRef segmentName(int32_t SegIndex);
135  StringRef sectionName(int32_t SegIndex, uint64_t SegOffset);
136  uint64_t address(uint32_t SegIndex, uint64_t SegOffset);
137 
138 private:
139  struct SectionInfo {
140  uint64_t Address;
141  uint64_t Size;
143  StringRef SegmentName;
144  uint64_t OffsetInSegment;
145  uint64_t SegmentStartAddress;
146  int32_t SegmentIndex;
147  };
148  const SectionInfo &findSection(int32_t SegIndex, uint64_t SegOffset);
149 
151  int32_t MaxSegIndex;
152 };
153 
154 /// MachORebaseEntry encapsulates the current state in the decompression of
155 /// rebasing opcodes. This allows you to iterate through the compressed table of
156 /// rebasing using:
157 /// Error Err;
158 /// for (const llvm::object::MachORebaseEntry &Entry : Obj->rebaseTable(&Err)) {
159 /// }
160 /// if (Err) { report error ...
162 public:
163  MachORebaseEntry(Error *Err, const MachOObjectFile *O,
164  ArrayRef<uint8_t> opcodes, bool is64Bit);
165 
166  int32_t segmentIndex() const;
167  uint64_t segmentOffset() const;
168  StringRef typeName() const;
169  StringRef segmentName() const;
170  StringRef sectionName() const;
171  uint64_t address() const;
172 
173  bool operator==(const MachORebaseEntry &) const;
174 
175  void moveNext();
176 
177 private:
178  friend class MachOObjectFile;
179 
180  void moveToFirst();
181  void moveToEnd();
182  uint64_t readULEB128(const char **error);
183 
184  Error *E;
185  const MachOObjectFile *O;
186  ArrayRef<uint8_t> Opcodes;
187  const uint8_t *Ptr;
188  uint64_t SegmentOffset = 0;
189  int32_t SegmentIndex = -1;
190  uint64_t RemainingLoopCount = 0;
191  uint64_t AdvanceAmount = 0;
192  uint8_t RebaseType = 0;
193  uint8_t PointerSize;
194  bool Done = false;
195 };
197 
198 /// MachOBindEntry encapsulates the current state in the decompression of
199 /// binding opcodes. This allows you to iterate through the compressed table of
200 /// bindings using:
201 /// Error Err;
202 /// for (const llvm::object::MachOBindEntry &Entry : Obj->bindTable(&Err)) {
203 /// }
204 /// if (Err) { report error ...
206 public:
207  enum class Kind { Regular, Lazy, Weak };
208 
209  MachOBindEntry(Error *Err, const MachOObjectFile *O,
211 
212  int32_t segmentIndex() const;
213  uint64_t segmentOffset() const;
214  StringRef typeName() const;
215  StringRef symbolName() const;
216  uint32_t flags() const;
217  int64_t addend() const;
218  int ordinal() const;
219 
220  StringRef segmentName() const;
221  StringRef sectionName() const;
222  uint64_t address() const;
223 
224  bool operator==(const MachOBindEntry &) const;
225 
226  void moveNext();
227 
228 private:
229  friend class MachOObjectFile;
230 
231  void moveToFirst();
232  void moveToEnd();
233  uint64_t readULEB128(const char **error);
234  int64_t readSLEB128(const char **error);
235 
236  Error *E;
237  const MachOObjectFile *O;
238  ArrayRef<uint8_t> Opcodes;
239  const uint8_t *Ptr;
240  uint64_t SegmentOffset = 0;
241  int32_t SegmentIndex = -1;
242  StringRef SymbolName;
243  bool LibraryOrdinalSet = false;
244  int Ordinal = 0;
245  uint32_t Flags = 0;
246  int64_t Addend = 0;
247  uint64_t RemainingLoopCount = 0;
248  uint64_t AdvanceAmount = 0;
249  uint8_t BindType = 0;
250  uint8_t PointerSize;
251  Kind TableKind;
252  bool Done = false;
253 };
255 
256 class MachOObjectFile : public ObjectFile {
257 public:
259  const char *Ptr; // Where in memory the load command is.
260  MachO::load_command C; // The command itself.
261  };
264 
266  create(MemoryBufferRef Object, bool IsLittleEndian, bool Is64Bits,
267  uint32_t UniversalCputype = 0, uint32_t UniversalIndex = 0);
268 
269  void moveSymbolNext(DataRefImpl &Symb) const override;
270 
271  uint64_t getNValue(DataRefImpl Sym) const;
272  Expected<StringRef> getSymbolName(DataRefImpl Symb) const override;
273 
274  // MachO specific.
275  Error checkSymbolTable() const;
276 
277  std::error_code getIndirectName(DataRefImpl Symb, StringRef &Res) const;
278  unsigned getSectionType(SectionRef Sec) const;
279 
280  Expected<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
281  uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
282  uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
284  uint32_t getSymbolFlags(DataRefImpl Symb) const override;
286  unsigned getSymbolSectionID(SymbolRef Symb) const;
287  unsigned getSectionID(SectionRef Sec) const;
288 
289  void moveSectionNext(DataRefImpl &Sec) const override;
290  std::error_code getSectionName(DataRefImpl Sec,
291  StringRef &Res) const override;
292  uint64_t getSectionAddress(DataRefImpl Sec) const override;
293  uint64_t getSectionIndex(DataRefImpl Sec) const override;
294  uint64_t getSectionSize(DataRefImpl Sec) const override;
295  std::error_code getSectionContents(DataRefImpl Sec,
296  StringRef &Res) const override;
297  uint64_t getSectionAlignment(DataRefImpl Sec) const override;
298  bool isSectionCompressed(DataRefImpl Sec) const override;
299  bool isSectionText(DataRefImpl Sec) const override;
300  bool isSectionData(DataRefImpl Sec) const override;
301  bool isSectionBSS(DataRefImpl Sec) const override;
302  bool isSectionVirtual(DataRefImpl Sec) const override;
303  bool isSectionBitcode(DataRefImpl Sec) const override;
305  relocation_iterator section_rel_end(DataRefImpl Sec) const override;
306 
310  return make_range(extrel_begin(), extrel_end());
311  }
312 
313  void moveRelocationNext(DataRefImpl &Rel) const override;
314  uint64_t getRelocationOffset(DataRefImpl Rel) const override;
315  symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
317  uint64_t getRelocationType(DataRefImpl Rel) const override;
319  SmallVectorImpl<char> &Result) const override;
320  uint8_t getRelocationLength(DataRefImpl Rel) const;
321 
322  // MachO specific.
323  std::error_code getLibraryShortNameByIndex(unsigned Index, StringRef &) const;
324  uint32_t getLibraryCount() const;
325 
327 
328  // TODO: Would be useful to have an iterator based version
329  // of the load command interface too.
330 
331  basic_symbol_iterator symbol_begin() const override;
332  basic_symbol_iterator symbol_end() const override;
333 
334  // MachO specific.
335  basic_symbol_iterator getSymbolByIndex(unsigned Index) const;
336  uint64_t getSymbolIndex(DataRefImpl Symb) const;
337 
338  section_iterator section_begin() const override;
339  section_iterator section_end() const override;
340 
341  uint8_t getBytesInAddress() const override;
342 
343  StringRef getFileFormatName() const override;
344  unsigned getArch() const override;
345  SubtargetFeatures getFeatures() const override { return SubtargetFeatures(); }
346  Triple getArchTriple(const char **McpuDefault = nullptr) const;
347 
348  relocation_iterator section_rel_begin(unsigned Index) const;
349  relocation_iterator section_rel_end(unsigned Index) const;
350 
351  dice_iterator begin_dices() const;
352  dice_iterator end_dices() const;
353 
357 
358  /// For use iterating over all exported symbols.
360 
361  /// For use examining a trie not in a MachOObjectFile.
363 
364  /// For use iterating over all rebase table entries.
366 
367  /// For use examining rebase opcodes in a MachOObjectFile.
369  MachOObjectFile *O,
370  ArrayRef<uint8_t> Opcodes,
371  bool is64);
372 
373  /// For use iterating over all bind table entries.
375 
376  /// For use iterating over all lazy bind table entries.
378 
379  /// For use iterating over all weak bind table entries.
381 
382  /// For use examining bind opcodes in a MachOObjectFile.
384  MachOObjectFile *O,
385  ArrayRef<uint8_t> Opcodes,
386  bool is64,
388 
389  /// For use with a SegIndex,SegOffset pair in MachOBindEntry::moveNext() to
390  /// validate a MachOBindEntry.
391  const char *BindEntryCheckSegAndOffset(int32_t SegIndex, uint64_t SegOffset,
392  bool endInvalid) const {
393  return BindRebaseSectionTable->checkSegAndOffset(SegIndex, SegOffset,
394  endInvalid);
395  }
396  /// For use in MachOBindEntry::moveNext() to validate a MachOBindEntry for
397  /// the BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB opcode.
399  uint8_t PointerSize, int32_t SegIndex,
400  uint64_t SegOffset) const {
401  return BindRebaseSectionTable->checkCountAndSkip(Count, Skip, PointerSize,
402  SegIndex, SegOffset);
403  }
404 
405  /// For use with a SegIndex,SegOffset pair in MachORebaseEntry::moveNext() to
406  /// validate a MachORebaseEntry.
407  const char *RebaseEntryCheckSegAndOffset(int32_t SegIndex, uint64_t SegOffset,
408  bool endInvalid) const {
409  return BindRebaseSectionTable->checkSegAndOffset(SegIndex, SegOffset,
410  endInvalid);
411  }
412  /// For use in MachORebaseEntry::moveNext() to validate a MachORebaseEntry for
413  /// the REBASE_OPCODE_DO_*_TIMES* opcodes.
415  uint8_t PointerSize, int32_t SegIndex,
416  uint64_t SegOffset) const {
417  return BindRebaseSectionTable->checkCountAndSkip(Count, Skip, PointerSize,
418  SegIndex, SegOffset);
419  }
420 
421  /// For use with the SegIndex of a checked Mach-O Bind or Rebase entry to
422  /// get the segment name.
423  StringRef BindRebaseSegmentName(int32_t SegIndex) const {
424  return BindRebaseSectionTable->segmentName(SegIndex);
425  }
426 
427  /// For use with a SegIndex,SegOffset pair from a checked Mach-O Bind or
428  /// Rebase entry to get the section name.
429  StringRef BindRebaseSectionName(uint32_t SegIndex, uint64_t SegOffset) const {
430  return BindRebaseSectionTable->sectionName(SegIndex, SegOffset);
431  }
432 
433  /// For use with a SegIndex,SegOffset pair from a checked Mach-O Bind or
434  /// Rebase entry to get the address.
435  uint64_t BindRebaseAddress(uint32_t SegIndex, uint64_t SegOffset) const {
436  return BindRebaseSectionTable->address(SegIndex, SegOffset);
437  }
438 
439  // In a MachO file, sections have a segment name. This is used in the .o
440  // files. They have a single segment, but this field specifies which segment
441  // a section should be put in in the final object.
443 
444  // Names are stored as 16 bytes. These returns the raw 16 bytes without
445  // interpreting them as a C string.
448 
449  // MachO specific Info about relocations.
452  const MachO::any_relocation_info &RE) const;
455  const MachO::any_relocation_info &RE) const;
457  const MachO::any_relocation_info &RE) const;
459  const MachO::any_relocation_info &RE) const;
460  unsigned getAnyRelocationAddress(const MachO::any_relocation_info &RE) const;
461  unsigned getAnyRelocationPCRel(const MachO::any_relocation_info &RE) const;
462  unsigned getAnyRelocationLength(const MachO::any_relocation_info &RE) const;
463  unsigned getAnyRelocationType(const MachO::any_relocation_info &RE) const;
465 
466  // MachO specific structures.
469  MachO::section getSection(const LoadCommandInfo &L, unsigned Index) const;
470  MachO::section_64 getSection64(const LoadCommandInfo &L,unsigned Index) const;
473 
475  getLinkeditDataLoadCommand(const LoadCommandInfo &L) const;
477  getSegmentLoadCommand(const LoadCommandInfo &L) const;
479  getSegment64LoadCommand(const LoadCommandInfo &L) const;
481  getLinkerOptionLoadCommand(const LoadCommandInfo &L) const;
483  getVersionMinLoadCommand(const LoadCommandInfo &L) const;
485  getNoteLoadCommand(const LoadCommandInfo &L) const;
487  getBuildVersionLoadCommand(const LoadCommandInfo &L) const;
489  getBuildToolVersion(unsigned index) const;
491  getDylibIDLoadCommand(const LoadCommandInfo &L) const;
493  getDyldInfoLoadCommand(const LoadCommandInfo &L) const;
495  getDylinkerCommand(const LoadCommandInfo &L) const;
497  getUuidCommand(const LoadCommandInfo &L) const;
499  getRpathCommand(const LoadCommandInfo &L) const;
501  getSourceVersionCommand(const LoadCommandInfo &L) const;
503  getEntryPointCommand(const LoadCommandInfo &L) const;
505  getEncryptionInfoCommand(const LoadCommandInfo &L) const;
507  getEncryptionInfoCommand64(const LoadCommandInfo &L) const;
509  getSubFrameworkCommand(const LoadCommandInfo &L) const;
511  getSubUmbrellaCommand(const LoadCommandInfo &L) const;
513  getSubLibraryCommand(const LoadCommandInfo &L) const;
515  getSubClientCommand(const LoadCommandInfo &L) const;
517  getRoutinesCommand(const LoadCommandInfo &L) const;
519  getRoutinesCommand64(const LoadCommandInfo &L) const;
521  getThreadCommand(const LoadCommandInfo &L) const;
522 
525  const MachO::mach_header &getHeader() const;
526  const MachO::mach_header_64 &getHeader64() const;
527  uint32_t
529  unsigned Index) const;
531  unsigned Index) const;
541  ArrayRef<uint8_t> getUuid() const;
542 
544  bool is64Bit() const;
545  void ReadULEB128s(uint64_t Index, SmallVectorImpl<uint64_t> &Out) const;
546 
547  static StringRef guessLibraryShortName(StringRef Name, bool &isFramework,
548  StringRef &Suffix);
549 
551  static Triple getArchTriple(uint32_t CPUType, uint32_t CPUSubType,
552  const char **McpuDefault = nullptr,
553  const char **ArchFlag = nullptr);
554  static bool isValidArch(StringRef ArchFlag);
555  static Triple getHostArch();
556 
557  bool isRelocatableObject() const override;
558 
560 
561  bool hasPageZeroSegment() const { return HasPageZeroSegment; }
562 
563  static bool classof(const Binary *v) {
564  return v->isMachO();
565  }
566 
567  static uint32_t
569  uint32_t VersionOrSDK = (SDK) ? C.sdk : C.version;
570  return (VersionOrSDK >> 16) & 0xffff;
571  }
572 
573  static uint32_t
575  uint32_t VersionOrSDK = (SDK) ? C.sdk : C.version;
576  return (VersionOrSDK >> 8) & 0xff;
577  }
578 
579  static uint32_t
581  uint32_t VersionOrSDK = (SDK) ? C.sdk : C.version;
582  return VersionOrSDK & 0xff;
583  }
584 
585  static std::string getBuildPlatform(uint32_t platform) {
586  switch (platform) {
587  case MachO::PLATFORM_MACOS: return "macos";
588  case MachO::PLATFORM_IOS: return "ios";
589  case MachO::PLATFORM_TVOS: return "tvos";
590  case MachO::PLATFORM_WATCHOS: return "watchos";
591  case MachO::PLATFORM_BRIDGEOS: return "bridgeos";
592  default:
593  std::string ret;
594  raw_string_ostream ss(ret);
595  ss << format_hex(platform, 8, true);
596  return ss.str();
597  }
598  }
599 
600  static std::string getBuildTool(uint32_t tools) {
601  switch (tools) {
602  case MachO::TOOL_CLANG: return "clang";
603  case MachO::TOOL_SWIFT: return "swift";
604  case MachO::TOOL_LD: return "ld";
605  default:
606  std::string ret;
607  raw_string_ostream ss(ret);
608  ss << format_hex(tools, 8, true);
609  return ss.str();
610  }
611  }
612 
613  static std::string getVersionString(uint32_t version) {
614  uint32_t major = (version >> 16) & 0xffff;
615  uint32_t minor = (version >> 8) & 0xff;
616  uint32_t update = version & 0xff;
617 
619  Version = utostr(major) + "." + utostr(minor);
620  if (update != 0)
621  Version += "." + utostr(update);
622  return Version.str();
623  }
624 
625 private:
626  MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian, bool Is64Bits,
627  Error &Err, uint32_t UniversalCputype = 0,
628  uint32_t UniversalIndex = 0);
629 
630  uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
631 
632  union {
635  };
636  using SectionList = SmallVector<const char*, 1>;
637  SectionList Sections;
638  using LibraryList = SmallVector<const char*, 1>;
639  LibraryList Libraries;
640  LoadCommandList LoadCommands;
641  using LibraryShortName = SmallVector<StringRef, 1>;
642  using BuildToolList = SmallVector<const char*, 1>;
643  BuildToolList BuildTools;
644  mutable LibraryShortName LibrariesShortNames;
645  std::unique_ptr<BindRebaseSegInfo> BindRebaseSectionTable;
646  const char *SymtabLoadCmd = nullptr;
647  const char *DysymtabLoadCmd = nullptr;
648  const char *DataInCodeLoadCmd = nullptr;
649  const char *LinkOptHintsLoadCmd = nullptr;
650  const char *DyldInfoLoadCmd = nullptr;
651  const char *UuidLoadCmd = nullptr;
652  bool HasPageZeroSegment = false;
653 };
654 
655 /// DiceRef
656 inline DiceRef::DiceRef(DataRefImpl DiceP, const ObjectFile *Owner)
657  : DicePimpl(DiceP) , OwningObject(Owner) {}
658 
659 inline bool DiceRef::operator==(const DiceRef &Other) const {
660  return DicePimpl == Other.DicePimpl;
661 }
662 
663 inline bool DiceRef::operator<(const DiceRef &Other) const {
664  return DicePimpl < Other.DicePimpl;
665 }
666 
667 inline void DiceRef::moveNext() {
669  reinterpret_cast<const MachO::data_in_code_entry *>(DicePimpl.p);
670  DicePimpl.p = reinterpret_cast<uintptr_t>(P + 1);
671 }
672 
673 // Since a Mach-O data in code reference, a DiceRef, can only be created when
674 // the OwningObject ObjectFile is a MachOObjectFile a static_cast<> is used for
675 // the methods that get the values of the fields of the reference.
676 
677 inline std::error_code DiceRef::getOffset(uint32_t &Result) const {
678  const MachOObjectFile *MachOOF =
679  static_cast<const MachOObjectFile *>(OwningObject);
680  MachO::data_in_code_entry Dice = MachOOF->getDice(DicePimpl);
681  Result = Dice.offset;
682  return std::error_code();
683 }
684 
685 inline std::error_code DiceRef::getLength(uint16_t &Result) const {
686  const MachOObjectFile *MachOOF =
687  static_cast<const MachOObjectFile *>(OwningObject);
688  MachO::data_in_code_entry Dice = MachOOF->getDice(DicePimpl);
689  Result = Dice.length;
690  return std::error_code();
691 }
692 
693 inline std::error_code DiceRef::getKind(uint16_t &Result) const {
694  const MachOObjectFile *MachOOF =
695  static_cast<const MachOObjectFile *>(OwningObject);
696  MachO::data_in_code_entry Dice = MachOOF->getDice(DicePimpl);
697  Result = Dice.kind;
698  return std::error_code();
699 }
700 
702  return DicePimpl;
703 }
704 
705 inline const ObjectFile *DiceRef::getObjectFile() const {
706  return OwningObject;
707 }
708 
709 } // end namespace object
710 } // end namespace llvm
711 
712 #endif // LLVM_OBJECT_MACHO_H
void getRelocationTypeName(DataRefImpl Rel, SmallVectorImpl< char > &Result) const override
MachineLoop * L
bool getPlainRelocationExternal(const MachO::any_relocation_info &RE) const
iterator_range< export_iterator > exports() const
For use iterating over all exported symbols.
static uint32_t getVersionMinUpdate(MachO::version_min_command &C, bool SDK)
Definition: MachO.h:580
iterator_range< relocation_iterator > external_relocations() const
Definition: MachO.h:309
load_command_iterator end_load_commands() const
typename SuperClass::const_iterator const_iterator
Definition: SmallVector.h:326
std::error_code getIndirectName(DataRefImpl Symb, StringRef &Res) const
relocation_iterator extrel_end() const
StringRef getStringTableData() const
std::error_code getKind(uint16_t &Result) const
Definition: MachO.h:693
StringRef getFileFormatName() const override
MachO::linkedit_data_command getLinkOptHintsLoadCommand() const
uint64_t getRelocationOffset(DataRefImpl Rel) const override
bool isSectionVirtual(DataRefImpl Sec) const override
ArrayRef< char > getSectionRawFinalSegmentName(DataRefImpl Sec) const
ArrayRef< char > getSectionRawName(DataRefImpl Sec) const
MachO::data_in_code_entry getDataInCodeTableEntry(uint32_t DataOffset, unsigned Index) const
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
Definition: Format.h:186
std::error_code getSectionName(DataRefImpl Sec, StringRef &Res) const override
void moveRelocationNext(DataRefImpl &Rel) const override
ExportEntry encapsulates the current-state-of-the-walk used when doing a non-recursive walk of the tr...
Definition: MachO.h:71
uint64_t BindRebaseAddress(uint32_t SegIndex, uint64_t SegOffset) const
For use with a SegIndex,SegOffset pair from a checked Mach-O Bind or Rebase entry to get the address...
Definition: MachO.h:435
bool isRelocatableObject() const override
True if this is a relocatable object (.o/.obj).
unsigned getAnyRelocationType(const MachO::any_relocation_info &RE) const
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
const char * RebaseEntryCheckSegAndOffset(int32_t SegIndex, uint64_t SegOffset, bool endInvalid) const
For use with a SegIndex,SegOffset pair in MachORebaseEntry::moveNext() to validate a MachORebaseEntry...
Definition: MachO.h:407
MachORebaseEntry(Error *Err, const MachOObjectFile *O, ArrayRef< uint8_t > opcodes, bool is64Bit)
Definition: MachO.h:788
const char * checkCountAndSkip(uint32_t Count, uint32_t Skip, uint8_t PointerSize, int32_t SegIndex, uint64_t SegOffset)
static std::string getVersionString(uint32_t version)
Definition: MachO.h:613
uint32_t getScatteredRelocationType(const MachO::any_relocation_info &RE) const
uint8_t getRelocationLength(DataRefImpl Rel) const
This class is the base class for all object file types.
Definition: ObjectFile.h:189
uint8_t getBytesInAddress() const override
The number of bytes used to represent an address in this object file format.
uint64_t getRelocationType(DataRefImpl Rel) const override
#define error(X)
StringRef otherName() const
MachORebaseEntry encapsulates the current state in the decompression of rebasing opcodes.
Definition: MachO.h:161
uint64_t getSectionAlignment(DataRefImpl Sec) const override
ArrayRef< uint8_t > getDyldInfoLazyBindOpcodes() const
load_command_iterator begin_load_commands() const
uint32_t getIndirectSymbolTableEntry(const MachO::dysymtab_command &DLC, unsigned Index) const
const char * BindEntryCheckSegAndOffset(int32_t SegIndex, uint64_t SegOffset, bool endInvalid) const
For use with a SegIndex,SegOffset pair in MachOBindEntry::moveNext() to validate a MachOBindEntry...
Definition: MachO.h:391
bool operator==(const MachORebaseEntry &) const
bool isSectionBitcode(DataRefImpl Sec) const override
static std::string getBuildTool(uint32_t tools)
Definition: MachO.h:600
uint64_t getSectionAddress(DataRefImpl Sec) const override
basic_symbol_iterator symbol_begin() const override
bool operator==(const ExportEntry &) const
ExportEntry(ArrayRef< uint8_t > Trie)
DataRefImpl getRawDataRefImpl() const
Definition: MachO.h:701
bool isSectionText(DataRefImpl Sec) const override
std::error_code getOffset(uint32_t &Result) const
Definition: MachO.h:677
Expected< StringRef > getSymbolName(DataRefImpl Symb) const override
MachO::segment_command_64 getSegment64LoadCommand(const LoadCommandInfo &L) const
MachO::uuid_command getUuidCommand(const LoadCommandInfo &L) const
uint16_t length
Definition: MachO.h:790
uint64_t getSymbolIndex(DataRefImpl Symb) const
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
uint32_t getSymbolAlignment(DataRefImpl Symb) const override
void ReadULEB128s(uint64_t Index, SmallVectorImpl< uint64_t > &Out) const
MachOBindEntry encapsulates the current state in the decompression of binding opcodes.
Definition: MachO.h:205
MachO::linker_option_command getLinkerOptionLoadCommand(const LoadCommandInfo &L) const
ELFYAML::ELF_STO Other
Definition: ELFYAML.cpp:663
MachO::encryption_info_command_64 getEncryptionInfoCommand64(const LoadCommandInfo &L) const
dice_iterator end_dices() const
uint32_t getScatteredRelocationValue(const MachO::any_relocation_info &RE) const
MachO::dylib_command getDylibIDLoadCommand(const LoadCommandInfo &L) const
static std::string getBuildPlatform(uint32_t platform)
Definition: MachO.h:585
unsigned getArch() const override
StringRef BindRebaseSectionName(uint32_t SegIndex, uint64_t SegOffset) const
For use with a SegIndex,SegOffset pair from a checked Mach-O Bind or Rebase entry to get the section ...
Definition: MachO.h:429
MachO::routines_command getRoutinesCommand(const LoadCommandInfo &L) const
iterator_range< rebase_iterator > rebaseTable(Error &Err)
For use iterating over all rebase table entries.
SubtargetFeatures getFeatures() const override
Definition: MachO.h:345
SmallVector< LoadCommandInfo, 4 > LoadCommandList
Definition: MachO.h:262
static std::string utostr(uint64_t X, bool isNeg=false)
Definition: StringExtras.h:160
MachO::dylinker_command getDylinkerCommand(const LoadCommandInfo &L) const
const MachO::mach_header & getHeader() const
bool getScatteredRelocationScattered(const MachO::any_relocation_info &RE) const
basic_symbol_iterator symbol_end() const override
const char * BindEntryCheckCountAndSkip(uint32_t Count, uint32_t Skip, uint8_t PointerSize, int32_t SegIndex, uint64_t SegOffset) const
For use in MachOBindEntry::moveNext() to validate a MachOBindEntry for the BIND_OPCODE_DO_BIND_ULEB_T...
Definition: MachO.h:398
MachO::section_64 getSection64(DataRefImpl DRI) const
relocation_iterator extrel_begin() const
const char * Name
MachO::entry_point_command getEntryPointCommand(const LoadCommandInfo &L) const
MachO::routines_command_64 getRoutinesCommand64(const LoadCommandInfo &L) const
void moveSectionNext(DataRefImpl &Sec) const override
#define P(N)
bool isSectionCompressed(DataRefImpl Sec) const override
unsigned getSectionID(SectionRef Sec) const
const MachO::mach_header_64 & getHeader64() const
iterator_range< bind_iterator > weakBindTable(Error &Err)
For use iterating over all weak bind table entries.
unsigned getAnyRelocationAddress(const MachO::any_relocation_info &RE) const
static Constant * SegmentOffset(IRBuilder<> &IRB, unsigned Offset, unsigned AddressSpace)
ArrayRef< uint8_t > getUuid() const
iterator_range< load_command_iterator > load_commands() const
MachO::any_relocation_info getRelocation(DataRefImpl Rel) const
MachO::section getSection(DataRefImpl DRI) const
static bool is64Bit(const char *name)
MachO::segment_command getSegmentLoadCommand(const LoadCommandInfo &L) const
uint32_t offset
Definition: MachO.h:789
unsigned getAnyRelocationPCRel(const MachO::any_relocation_info &RE) const
ArrayRef< uint8_t > getDyldInfoRebaseOpcodes() const
const char * RebaseEntryCheckCountAndSkip(uint32_t Count, uint32_t Skip, uint8_t PointerSize, int32_t SegIndex, uint64_t SegOffset) const
For use in MachORebaseEntry::moveNext() to validate a MachORebaseEntry for the REBASE_OPCODE_DO_*_TIM...
Definition: MachO.h:414
MachO::source_version_command getSourceVersionCommand(const LoadCommandInfo &L) const
MachO::linkedit_data_command getDataInCodeLoadCommand() const
bool operator==(const DiceRef &Other) const
Definition: MachO.h:659
DiceRef - This is a value type class that represents a single data in code entry in the table in a Ma...
Definition: MachO.h:44
MachO::sub_framework_command getSubFrameworkCommand(const LoadCommandInfo &L) const
bool operator==(const MachOBindEntry &) const
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override
MachO::thread_command getThreadCommand(const LoadCommandInfo &L) const
uint64_t getNValue(DataRefImpl Sym) const
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
Definition: raw_ostream.h:479
uint16_t kind
Definition: MachO.h:791
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
section_iterator getRelocationSection(DataRefImpl Rel) const
std::error_code getLibraryShortNameByIndex(unsigned Index, StringRef &) const
Triple getArchTriple(const char **McpuDefault=nullptr) const
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
section_iterator getRelocationRelocatedSection(relocation_iterator Rel) const
bool hasPageZeroSegment() const
Definition: MachO.h:561
Expected< uint64_t > getSymbolAddress(DataRefImpl Symb) const override
void moveSymbolNext(DataRefImpl &Symb) const override
StringRef BindRebaseSegmentName(int32_t SegIndex) const
For use with the SegIndex of a checked Mach-O Bind or Rebase entry to get the segment name...
Definition: MachO.h:423
static uint64_t readULEB128(const uint8_t *&Ptr)
unsigned getAnyRelocationLength(const MachO::any_relocation_info &RE) const
#define E
Definition: LargeTest.cpp:27
unsigned getSymbolSectionID(SymbolRef Symb) const
bool isSectionData(DataRefImpl Sec) const override
StringRef getSectionFinalSegmentName(DataRefImpl Sec) const
std::error_code getSectionContents(DataRefImpl Sec, StringRef &Res) const override
bool isMachO() const
Definition: Binary.h:112
MachO::nlist_64 getSymbol64TableEntry(DataRefImpl DRI) const
MachO::build_version_command getBuildVersionLoadCommand(const LoadCommandInfo &L) const
ArrayRef< uint8_t > getDyldInfoExportsTrie() const
BindRebaseSegInfo(const MachOObjectFile *Obj)
static uint32_t getVersionMinMinor(MachO::version_min_command &C, bool SDK)
Definition: MachO.h:574
MachO::nlist getSymbolTableEntry(DataRefImpl DRI) const
std::error_code getLength(uint16_t &Result) const
Definition: MachO.h:685
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override
uint32_t getSymbolFlags(DataRefImpl Symb) const override
MachO::sub_library_command getSubLibraryCommand(const LoadCommandInfo &L) const
SectionRef getAnyRelocationSection(const MachO::any_relocation_info &RE) const
A range adaptor for a pair of iterators.
MachO::build_tool_version getBuildToolVersion(unsigned index) const
Manages the enabling and disabling of subtarget specific features.
MachO::encryption_info_command getEncryptionInfoCommand(const LoadCommandInfo &L) const
StringRef str() const
Explicit conversion to StringRef.
Definition: SmallString.h:267
iterator_range< bind_iterator > bindTable(Error &Err)
For use iterating over all bind table entries.
const char * checkSegAndOffset(int32_t SegIndex, uint64_t SegOffset, bool endInvalid)
This is a value type class that represents a single symbol in the list of symbols in the object file...
Definition: ObjectFile.h:128
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
bool operator<(const DiceRef &Other) const
Definition: MachO.h:663
static Expected< std::unique_ptr< MachOObjectFile > > create(MemoryBufferRef Object, bool IsLittleEndian, bool Is64Bits, uint32_t UniversalCputype=0, uint32_t UniversalIndex=0)
MachO::note_command getNoteLoadCommand(const LoadCommandInfo &L) const
MachO::mach_header_64 Header64
Definition: MachO.h:633
static std::vector< std::string > Flags
Definition: FlagsTest.cpp:8
MachO::linkedit_data_command getLinkeditDataLoadCommand(const LoadCommandInfo &L) const
MachO::version_min_command getVersionMinLoadCommand(const LoadCommandInfo &L) const
static StringRef guessLibraryShortName(StringRef Name, bool &isFramework, StringRef &Suffix)
uint64_t address(uint32_t SegIndex, uint64_t SegOffset)
bool isSectionBSS(DataRefImpl Sec) const override
uint64_t getSectionIndex(DataRefImpl Sec) const override
StringRef segmentName(int32_t SegIndex)
#define C
Definition: LargeTest.cpp:25
MachO::symtab_command getSymtabLoadCommand() const
basic_symbol_iterator getSymbolByIndex(unsigned Index) const
StringRef ImportName
dice_iterator begin_dices() const
section_iterator section_begin() const override
iterator_range< bind_iterator > lazyBindTable(Error &Err)
For use iterating over all lazy bind table entries.
Expected< SymbolRef::Type > getSymbolType(DataRefImpl Symb) const override
static bool isValidArch(StringRef ArchFlag)
relocation_iterator section_rel_end(DataRefImpl Sec) const override
MachO::dysymtab_command getDysymtabLoadCommand() const
MachO::mach_header Header
Definition: MachO.h:634
MachO::rpath_command getRpathCommand(const LoadCommandInfo &L) const
MachO::data_in_code_entry getDice(DataRefImpl Rel) const
MachO::sub_umbrella_command getSubUmbrellaCommand(const LoadCommandInfo &L) const
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:463
StringRef mapDebugSectionName(StringRef Name) const override
Maps a debug section name to a standard DWARF section name.
LoadCommandList::const_iterator load_command_iterator
Definition: MachO.h:263
unsigned getSectionType(SectionRef Sec) const
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
section_iterator section_end() const override
const ObjectFile * getObjectFile() const
Definition: MachO.h:705
const char SectionName[]
Definition: AMDGPUPTNote.h:24
MachOBindEntry(Error *Err, const MachOObjectFile *O, ArrayRef< uint8_t > Opcodes, bool is64Bit, MachOBindEntry::Kind)
static uint32_t getVersionMinMajor(MachO::version_min_command &C, bool SDK)
Definition: MachO.h:568
ArrayRef< uint8_t > getDyldInfoWeakBindOpcodes() const
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
static bool classof(const Binary *v)
Definition: MachO.h:563
StringRef sectionName(int32_t SegIndex, uint64_t SegOffset)
int * Ptr
unsigned getPlainRelocationSymbolNum(const MachO::any_relocation_info &RE) const
MachO::dyld_info_command getDyldInfoLoadCommand(const LoadCommandInfo &L) const
bool isRelocationScattered(const MachO::any_relocation_info &RE) const
MachO::sub_client_command getSubClientCommand(const LoadCommandInfo &L) const
const uint64_t Version
Definition: InstrProf.h:864
Expected< section_iterator > getSymbolSection(DataRefImpl Symb) const override
relocation_iterator section_rel_begin(DataRefImpl Sec) const override
This is a value type class that represents a single section in the list of sections in the object fil...
Definition: ObjectFile.h:81
uint64_t getSectionSize(DataRefImpl Sec) const override
ArrayRef< uint8_t > getDyldInfoBindOpcodes() const