1 //===- MachO.h - MachO object file implementation ---------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the MachOObjectFile class, which implement the ObjectFile
11 // interface for MachO files.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_OBJECT_MACHO_H
16 #define LLVM_OBJECT_MACHO_H
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"
24 #include "llvm/ADT/iterator_range.h"
25 #include "llvm/BinaryFormat/MachO.h"
26 #include "llvm/MC/SubtargetFeature.h"
27 #include "llvm/Object/Binary.h"
28 #include "llvm/Object/ObjectFile.h"
29 #include "llvm/Object/SymbolicFile.h"
30 #include "llvm/Support/Error.h"
31 #include "llvm/Support/Format.h"
32 #include "llvm/Support/MemoryBuffer.h"
33 #include "llvm/Support/raw_ostream.h"
37 #include <system_error>
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.
45 DataRefImpl DicePimpl;
46 const ObjectFile *OwningObject = nullptr;
50 DiceRef(DataRefImpl DiceP, const ObjectFile *Owner);
52 bool operator==(const DiceRef &Other) const;
53 bool operator<(const DiceRef &Other) const;
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;
61 DataRefImpl getRawDataRefImpl() const;
62 const ObjectFile *getObjectFile() const;
64 using dice_iterator = content_iterator<DiceRef>;
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()) {
73 ExportEntry(ArrayRef<uint8_t> Trie);
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;
82 bool operator==(const ExportEntry &) const;
87 friend class MachOObjectFile;
91 uint64_t readULEB128(const uint8_t *&p);
92 void pushDownUntilBottom();
93 void pushNode(uint64_t Offset);
95 // Represents a node in the mach-o exports trie.
97 NodeState(const uint8_t *Ptr);
100 const uint8_t *Current;
102 uint64_t Address = 0;
104 const char *ImportName = nullptr;
105 unsigned ChildCount = 0;
106 unsigned NextChildIndex = 0;
107 unsigned ParentStringLength = 0;
108 bool IsExportNode = false;
111 ArrayRef<uint8_t> Trie;
112 SmallString<256> CumulativeString;
113 SmallVector<NodeState, 16> Stack;
114 bool Malformed = false;
117 using export_iterator = content_iterator<ExportEntry>;
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.
123 class BindRebaseSegInfo {
125 BindRebaseSegInfo(const MachOObjectFile *Obj);
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,
130 const char *checkCountAndSkip(uint32_t Count, uint32_t Skip,
131 uint8_t PointerSize, int32_t SegIndex,
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);
142 StringRef SectionName;
143 StringRef SegmentName;
144 uint64_t OffsetInSegment;
145 uint64_t SegmentStartAddress;
146 int32_t SegmentIndex;
148 const SectionInfo &findSection(int32_t SegIndex, uint64_t SegOffset);
150 SmallVector<SectionInfo, 32> Sections;
154 /// MachORebaseEntry encapsulates the current state in the decompression of
155 /// rebasing opcodes. This allows you to iterate through the compressed table of
158 /// for (const llvm::object::MachORebaseEntry &Entry : Obj->rebaseTable(&Err)) {
160 /// if (Err) { report error ...
161 class MachORebaseEntry {
163 MachORebaseEntry(Error *Err, const MachOObjectFile *O,
164 ArrayRef<uint8_t> opcodes, bool is64Bit);
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;
173 bool operator==(const MachORebaseEntry &) const;
178 friend class MachOObjectFile;
182 uint64_t readULEB128(const char **error);
185 const MachOObjectFile *O;
186 ArrayRef<uint8_t> Opcodes;
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;
196 using rebase_iterator = content_iterator<MachORebaseEntry>;
198 /// MachOBindEntry encapsulates the current state in the decompression of
199 /// binding opcodes. This allows you to iterate through the compressed table of
202 /// for (const llvm::object::MachOBindEntry &Entry : Obj->bindTable(&Err)) {
204 /// if (Err) { report error ...
205 class MachOBindEntry {
207 enum class Kind { Regular, Lazy, Weak };
209 MachOBindEntry(Error *Err, const MachOObjectFile *O,
210 ArrayRef<uint8_t> Opcodes, bool is64Bit, MachOBindEntry::Kind);
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;
220 StringRef segmentName() const;
221 StringRef sectionName() const;
222 uint64_t address() const;
224 bool operator==(const MachOBindEntry &) const;
229 friend class MachOObjectFile;
233 uint64_t readULEB128(const char **error);
234 int64_t readSLEB128(const char **error);
237 const MachOObjectFile *O;
238 ArrayRef<uint8_t> Opcodes;
240 uint64_t SegmentOffset = 0;
241 int32_t SegmentIndex = -1;
242 StringRef SymbolName;
243 bool LibraryOrdinalSet = false;
247 uint64_t RemainingLoopCount = 0;
248 uint64_t AdvanceAmount = 0;
249 uint8_t BindType = 0;
254 using bind_iterator = content_iterator<MachOBindEntry>;
256 class MachOObjectFile : public ObjectFile {
258 struct LoadCommandInfo {
259 const char *Ptr; // Where in memory the load command is.
260 MachO::load_command C; // The command itself.
262 using LoadCommandList = SmallVector<LoadCommandInfo, 4>;
263 using load_command_iterator = LoadCommandList::const_iterator;
265 static Expected<std::unique_ptr<MachOObjectFile>>
266 create(MemoryBufferRef Object, bool IsLittleEndian, bool Is64Bits,
267 uint32_t UniversalCputype = 0, uint32_t UniversalIndex = 0);
269 void moveSymbolNext(DataRefImpl &Symb) const override;
271 uint64_t getNValue(DataRefImpl Sym) const;
272 Expected<StringRef> getSymbolName(DataRefImpl Symb) const override;
275 Error checkSymbolTable() const;
277 std::error_code getIndirectName(DataRefImpl Symb, StringRef &Res) const;
278 unsigned getSectionType(SectionRef Sec) const;
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;
283 Expected<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const override;
284 uint32_t getSymbolFlags(DataRefImpl Symb) const override;
285 Expected<section_iterator> getSymbolSection(DataRefImpl Symb) const override;
286 unsigned getSymbolSectionID(SymbolRef Symb) const;
287 unsigned getSectionID(SectionRef Sec) const;
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;
304 relocation_iterator section_rel_begin(DataRefImpl Sec) const override;
305 relocation_iterator section_rel_end(DataRefImpl Sec) const override;
307 relocation_iterator extrel_begin() const;
308 relocation_iterator extrel_end() const;
309 iterator_range<relocation_iterator> external_relocations() const {
310 return make_range(extrel_begin(), extrel_end());
313 void moveRelocationNext(DataRefImpl &Rel) const override;
314 uint64_t getRelocationOffset(DataRefImpl Rel) const override;
315 symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
316 section_iterator getRelocationSection(DataRefImpl Rel) const;
317 uint64_t getRelocationType(DataRefImpl Rel) const override;
318 void getRelocationTypeName(DataRefImpl Rel,
319 SmallVectorImpl<char> &Result) const override;
320 uint8_t getRelocationLength(DataRefImpl Rel) const;
323 std::error_code getLibraryShortNameByIndex(unsigned Index, StringRef &) const;
324 uint32_t getLibraryCount() const;
326 section_iterator getRelocationRelocatedSection(relocation_iterator Rel) const;
328 // TODO: Would be useful to have an iterator based version
329 // of the load command interface too.
331 basic_symbol_iterator symbol_begin() const override;
332 basic_symbol_iterator symbol_end() const override;
335 basic_symbol_iterator getSymbolByIndex(unsigned Index) const;
336 uint64_t getSymbolIndex(DataRefImpl Symb) const;
338 section_iterator section_begin() const override;
339 section_iterator section_end() const override;
341 uint8_t getBytesInAddress() const override;
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;
348 relocation_iterator section_rel_begin(unsigned Index) const;
349 relocation_iterator section_rel_end(unsigned Index) const;
351 dice_iterator begin_dices() const;
352 dice_iterator end_dices() const;
354 load_command_iterator begin_load_commands() const;
355 load_command_iterator end_load_commands() const;
356 iterator_range<load_command_iterator> load_commands() const;
358 /// For use iterating over all exported symbols.
359 iterator_range<export_iterator> exports() const;
361 /// For use examining a trie not in a MachOObjectFile.
362 static iterator_range<export_iterator> exports(ArrayRef<uint8_t> Trie);
364 /// For use iterating over all rebase table entries.
365 iterator_range<rebase_iterator> rebaseTable(Error &Err);
367 /// For use examining rebase opcodes in a MachOObjectFile.
368 static iterator_range<rebase_iterator> rebaseTable(Error &Err,
370 ArrayRef<uint8_t> Opcodes,
373 /// For use iterating over all bind table entries.
374 iterator_range<bind_iterator> bindTable(Error &Err);
376 /// For use iterating over all lazy bind table entries.
377 iterator_range<bind_iterator> lazyBindTable(Error &Err);
379 /// For use iterating over all weak bind table entries.
380 iterator_range<bind_iterator> weakBindTable(Error &Err);
382 /// For use examining bind opcodes in a MachOObjectFile.
383 static iterator_range<bind_iterator> bindTable(Error &Err,
385 ArrayRef<uint8_t> Opcodes,
387 MachOBindEntry::Kind);
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,
396 /// For use in MachOBindEntry::moveNext() to validate a MachOBindEntry for
397 /// the BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB opcode.
398 const char *BindEntryCheckCountAndSkip(uint32_t Count, uint32_t Skip,
399 uint8_t PointerSize, int32_t SegIndex,
400 uint64_t SegOffset) const {
401 return BindRebaseSectionTable->checkCountAndSkip(Count, Skip, PointerSize,
402 SegIndex, SegOffset);
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,
412 /// For use in MachORebaseEntry::moveNext() to validate a MachORebaseEntry for
413 /// the REBASE_OPCODE_DO_*_TIMES* opcodes.
414 const char *RebaseEntryCheckCountAndSkip(uint32_t Count, uint32_t Skip,
415 uint8_t PointerSize, int32_t SegIndex,
416 uint64_t SegOffset) const {
417 return BindRebaseSectionTable->checkCountAndSkip(Count, Skip, PointerSize,
418 SegIndex, SegOffset);
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);
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);
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);
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.
442 StringRef getSectionFinalSegmentName(DataRefImpl Sec) const;
444 // Names are stored as 16 bytes. These returns the raw 16 bytes without
445 // interpreting them as a C string.
446 ArrayRef<char> getSectionRawName(DataRefImpl Sec) const;
447 ArrayRef<char> getSectionRawFinalSegmentName(DataRefImpl Sec) const;
449 // MachO specific Info about relocations.
450 bool isRelocationScattered(const MachO::any_relocation_info &RE) const;
451 unsigned getPlainRelocationSymbolNum(
452 const MachO::any_relocation_info &RE) const;
453 bool getPlainRelocationExternal(const MachO::any_relocation_info &RE) const;
454 bool getScatteredRelocationScattered(
455 const MachO::any_relocation_info &RE) const;
456 uint32_t getScatteredRelocationValue(
457 const MachO::any_relocation_info &RE) const;
458 uint32_t getScatteredRelocationType(
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;
464 SectionRef getAnyRelocationSection(const MachO::any_relocation_info &RE) const;
466 // MachO specific structures.
467 MachO::section getSection(DataRefImpl DRI) const;
468 MachO::section_64 getSection64(DataRefImpl DRI) const;
469 MachO::section getSection(const LoadCommandInfo &L, unsigned Index) const;
470 MachO::section_64 getSection64(const LoadCommandInfo &L,unsigned Index) const;
471 MachO::nlist getSymbolTableEntry(DataRefImpl DRI) const;
472 MachO::nlist_64 getSymbol64TableEntry(DataRefImpl DRI) const;
474 MachO::linkedit_data_command
475 getLinkeditDataLoadCommand(const LoadCommandInfo &L) const;
476 MachO::segment_command
477 getSegmentLoadCommand(const LoadCommandInfo &L) const;
478 MachO::segment_command_64
479 getSegment64LoadCommand(const LoadCommandInfo &L) const;
480 MachO::linker_option_command
481 getLinkerOptionLoadCommand(const LoadCommandInfo &L) const;
482 MachO::version_min_command
483 getVersionMinLoadCommand(const LoadCommandInfo &L) const;
485 getNoteLoadCommand(const LoadCommandInfo &L) const;
486 MachO::build_version_command
487 getBuildVersionLoadCommand(const LoadCommandInfo &L) const;
488 MachO::build_tool_version
489 getBuildToolVersion(unsigned index) const;
491 getDylibIDLoadCommand(const LoadCommandInfo &L) const;
492 MachO::dyld_info_command
493 getDyldInfoLoadCommand(const LoadCommandInfo &L) const;
494 MachO::dylinker_command
495 getDylinkerCommand(const LoadCommandInfo &L) const;
497 getUuidCommand(const LoadCommandInfo &L) const;
499 getRpathCommand(const LoadCommandInfo &L) const;
500 MachO::source_version_command
501 getSourceVersionCommand(const LoadCommandInfo &L) const;
502 MachO::entry_point_command
503 getEntryPointCommand(const LoadCommandInfo &L) const;
504 MachO::encryption_info_command
505 getEncryptionInfoCommand(const LoadCommandInfo &L) const;
506 MachO::encryption_info_command_64
507 getEncryptionInfoCommand64(const LoadCommandInfo &L) const;
508 MachO::sub_framework_command
509 getSubFrameworkCommand(const LoadCommandInfo &L) const;
510 MachO::sub_umbrella_command
511 getSubUmbrellaCommand(const LoadCommandInfo &L) const;
512 MachO::sub_library_command
513 getSubLibraryCommand(const LoadCommandInfo &L) const;
514 MachO::sub_client_command
515 getSubClientCommand(const LoadCommandInfo &L) const;
516 MachO::routines_command
517 getRoutinesCommand(const LoadCommandInfo &L) const;
518 MachO::routines_command_64
519 getRoutinesCommand64(const LoadCommandInfo &L) const;
520 MachO::thread_command
521 getThreadCommand(const LoadCommandInfo &L) const;
523 MachO::any_relocation_info getRelocation(DataRefImpl Rel) const;
524 MachO::data_in_code_entry getDice(DataRefImpl Rel) const;
525 const MachO::mach_header &getHeader() const;
526 const MachO::mach_header_64 &getHeader64() const;
528 getIndirectSymbolTableEntry(const MachO::dysymtab_command &DLC,
529 unsigned Index) const;
530 MachO::data_in_code_entry getDataInCodeTableEntry(uint32_t DataOffset,
531 unsigned Index) const;
532 MachO::symtab_command getSymtabLoadCommand() const;
533 MachO::dysymtab_command getDysymtabLoadCommand() const;
534 MachO::linkedit_data_command getDataInCodeLoadCommand() const;
535 MachO::linkedit_data_command getLinkOptHintsLoadCommand() const;
536 ArrayRef<uint8_t> getDyldInfoRebaseOpcodes() const;
537 ArrayRef<uint8_t> getDyldInfoBindOpcodes() const;
538 ArrayRef<uint8_t> getDyldInfoWeakBindOpcodes() const;
539 ArrayRef<uint8_t> getDyldInfoLazyBindOpcodes() const;
540 ArrayRef<uint8_t> getDyldInfoExportsTrie() const;
541 ArrayRef<uint8_t> getUuid() const;
543 StringRef getStringTableData() const;
544 bool is64Bit() const;
545 void ReadULEB128s(uint64_t Index, SmallVectorImpl<uint64_t> &Out) const;
547 static StringRef guessLibraryShortName(StringRef Name, bool &isFramework,
550 static Triple::ArchType getArch(uint32_t CPUType);
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();
557 bool isRelocatableObject() const override;
559 StringRef mapDebugSectionName(StringRef Name) const override;
561 bool hasPageZeroSegment() const { return HasPageZeroSegment; }
563 static bool classof(const Binary *v) {
568 getVersionMinMajor(MachO::version_min_command &C, bool SDK) {
569 uint32_t VersionOrSDK = (SDK) ? C.sdk : C.version;
570 return (VersionOrSDK >> 16) & 0xffff;
574 getVersionMinMinor(MachO::version_min_command &C, bool SDK) {
575 uint32_t VersionOrSDK = (SDK) ? C.sdk : C.version;
576 return (VersionOrSDK >> 8) & 0xff;
580 getVersionMinUpdate(MachO::version_min_command &C, bool SDK) {
581 uint32_t VersionOrSDK = (SDK) ? C.sdk : C.version;
582 return VersionOrSDK & 0xff;
585 static std::string getBuildPlatform(uint32_t 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";
594 raw_string_ostream ss(ret);
595 ss << format_hex(platform, 8, true);
600 static std::string getBuildTool(uint32_t tools) {
602 case MachO::TOOL_CLANG: return "clang";
603 case MachO::TOOL_SWIFT: return "swift";
604 case MachO::TOOL_LD: return "ld";
607 raw_string_ostream ss(ret);
608 ss << format_hex(tools, 8, true);
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;
618 SmallString<32> Version;
619 Version = utostr(major) + "." + utostr(minor);
621 Version += "." + utostr(update);
622 return Version.str();
626 MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian, bool Is64Bits,
627 Error &Err, uint32_t UniversalCputype = 0,
628 uint32_t UniversalIndex = 0);
630 uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
633 MachO::mach_header_64 Header64;
634 MachO::mach_header Header;
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;
656 inline DiceRef::DiceRef(DataRefImpl DiceP, const ObjectFile *Owner)
657 : DicePimpl(DiceP) , OwningObject(Owner) {}
659 inline bool DiceRef::operator==(const DiceRef &Other) const {
660 return DicePimpl == Other.DicePimpl;
663 inline bool DiceRef::operator<(const DiceRef &Other) const {
664 return DicePimpl < Other.DicePimpl;
667 inline void DiceRef::moveNext() {
668 const MachO::data_in_code_entry *P =
669 reinterpret_cast<const MachO::data_in_code_entry *>(DicePimpl.p);
670 DicePimpl.p = reinterpret_cast<uintptr_t>(P + 1);
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.
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();
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();
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);
698 return std::error_code();
701 inline DataRefImpl DiceRef::getRawDataRefImpl() const {
705 inline const ObjectFile *DiceRef::getObjectFile() const {
709 } // end namespace object
710 } // end namespace llvm
712 #endif // LLVM_OBJECT_MACHO_H