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/iterator_range.h"
20 #include "llvm/ADT/SmallString.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/StringExtras.h"
23 #include "llvm/ADT/StringRef.h"
24 #include "llvm/ADT/Triple.h"
25 #include "llvm/MC/SubtargetFeature.h"
26 #include "llvm/Object/Binary.h"
27 #include "llvm/Object/ObjectFile.h"
28 #include "llvm/Object/SymbolicFile.h"
29 #include "llvm/Support/Error.h"
30 #include "llvm/Support/Format.h"
31 #include "llvm/Support/MachO.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 void moveRelocationNext(DataRefImpl &Rel) const override;
308 uint64_t getRelocationOffset(DataRefImpl Rel) const override;
309 symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
310 section_iterator getRelocationSection(DataRefImpl Rel) const;
311 uint64_t getRelocationType(DataRefImpl Rel) const override;
312 void getRelocationTypeName(DataRefImpl Rel,
313 SmallVectorImpl<char> &Result) const override;
314 uint8_t getRelocationLength(DataRefImpl Rel) const;
317 std::error_code getLibraryShortNameByIndex(unsigned Index, StringRef &) const;
318 uint32_t getLibraryCount() const;
320 section_iterator getRelocationRelocatedSection(relocation_iterator Rel) const;
322 // TODO: Would be useful to have an iterator based version
323 // of the load command interface too.
325 basic_symbol_iterator symbol_begin() const override;
326 basic_symbol_iterator symbol_end() const override;
329 basic_symbol_iterator getSymbolByIndex(unsigned Index) const;
330 uint64_t getSymbolIndex(DataRefImpl Symb) const;
332 section_iterator section_begin() const override;
333 section_iterator section_end() const override;
335 uint8_t getBytesInAddress() const override;
337 StringRef getFileFormatName() const override;
338 unsigned getArch() const override;
339 SubtargetFeatures getFeatures() const override { return SubtargetFeatures(); }
340 Triple getArchTriple(const char **McpuDefault = nullptr) const;
342 relocation_iterator section_rel_begin(unsigned Index) const;
343 relocation_iterator section_rel_end(unsigned Index) const;
345 dice_iterator begin_dices() const;
346 dice_iterator end_dices() const;
348 load_command_iterator begin_load_commands() const;
349 load_command_iterator end_load_commands() const;
350 iterator_range<load_command_iterator> load_commands() const;
352 /// For use iterating over all exported symbols.
353 iterator_range<export_iterator> exports() const;
355 /// For use examining a trie not in a MachOObjectFile.
356 static iterator_range<export_iterator> exports(ArrayRef<uint8_t> Trie);
358 /// For use iterating over all rebase table entries.
359 iterator_range<rebase_iterator> rebaseTable(Error &Err);
361 /// For use examining rebase opcodes in a MachOObjectFile.
362 static iterator_range<rebase_iterator> rebaseTable(Error &Err,
364 ArrayRef<uint8_t> Opcodes,
367 /// For use iterating over all bind table entries.
368 iterator_range<bind_iterator> bindTable(Error &Err);
370 /// For use iterating over all lazy bind table entries.
371 iterator_range<bind_iterator> lazyBindTable(Error &Err);
373 /// For use iterating over all weak bind table entries.
374 iterator_range<bind_iterator> weakBindTable(Error &Err);
376 /// For use examining bind opcodes in a MachOObjectFile.
377 static iterator_range<bind_iterator> bindTable(Error &Err,
379 ArrayRef<uint8_t> Opcodes,
381 MachOBindEntry::Kind);
383 /// For use with a SegIndex,SegOffset pair in MachOBindEntry::moveNext() to
384 /// validate a MachOBindEntry.
385 const char *BindEntryCheckSegAndOffset(int32_t SegIndex, uint64_t SegOffset,
386 bool endInvalid) const {
387 return BindRebaseSectionTable->checkSegAndOffset(SegIndex, SegOffset,
390 /// For use in MachOBindEntry::moveNext() to validate a MachOBindEntry for
391 /// the BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB opcode.
392 const char *BindEntryCheckCountAndSkip(uint32_t Count, uint32_t Skip,
393 uint8_t PointerSize, int32_t SegIndex,
394 uint64_t SegOffset) const {
395 return BindRebaseSectionTable->checkCountAndSkip(Count, Skip, PointerSize,
396 SegIndex, SegOffset);
399 /// For use with a SegIndex,SegOffset pair in MachORebaseEntry::moveNext() to
400 /// validate a MachORebaseEntry.
401 const char *RebaseEntryCheckSegAndOffset(int32_t SegIndex, uint64_t SegOffset,
402 bool endInvalid) const {
403 return BindRebaseSectionTable->checkSegAndOffset(SegIndex, SegOffset,
406 /// For use in MachORebaseEntry::moveNext() to validate a MachORebaseEntry for
407 /// the REBASE_OPCODE_DO_*_TIMES* opcodes.
408 const char *RebaseEntryCheckCountAndSkip(uint32_t Count, uint32_t Skip,
409 uint8_t PointerSize, int32_t SegIndex,
410 uint64_t SegOffset) const {
411 return BindRebaseSectionTable->checkCountAndSkip(Count, Skip, PointerSize,
412 SegIndex, SegOffset);
415 /// For use with the SegIndex of a checked Mach-O Bind or Rebase entry to
416 /// get the segment name.
417 StringRef BindRebaseSegmentName(int32_t SegIndex) const {
418 return BindRebaseSectionTable->segmentName(SegIndex);
421 /// For use with a SegIndex,SegOffset pair from a checked Mach-O Bind or
422 /// Rebase entry to get the section name.
423 StringRef BindRebaseSectionName(uint32_t SegIndex, uint64_t SegOffset) const {
424 return BindRebaseSectionTable->sectionName(SegIndex, SegOffset);
427 /// For use with a SegIndex,SegOffset pair from a checked Mach-O Bind or
428 /// Rebase entry to get the address.
429 uint64_t BindRebaseAddress(uint32_t SegIndex, uint64_t SegOffset) const {
430 return BindRebaseSectionTable->address(SegIndex, SegOffset);
433 // In a MachO file, sections have a segment name. This is used in the .o
434 // files. They have a single segment, but this field specifies which segment
435 // a section should be put in in the final object.
436 StringRef getSectionFinalSegmentName(DataRefImpl Sec) const;
438 // Names are stored as 16 bytes. These returns the raw 16 bytes without
439 // interpreting them as a C string.
440 ArrayRef<char> getSectionRawName(DataRefImpl Sec) const;
441 ArrayRef<char> getSectionRawFinalSegmentName(DataRefImpl Sec) const;
443 // MachO specific Info about relocations.
444 bool isRelocationScattered(const MachO::any_relocation_info &RE) const;
445 unsigned getPlainRelocationSymbolNum(
446 const MachO::any_relocation_info &RE) const;
447 bool getPlainRelocationExternal(const MachO::any_relocation_info &RE) const;
448 bool getScatteredRelocationScattered(
449 const MachO::any_relocation_info &RE) const;
450 uint32_t getScatteredRelocationValue(
451 const MachO::any_relocation_info &RE) const;
452 uint32_t getScatteredRelocationType(
453 const MachO::any_relocation_info &RE) const;
454 unsigned getAnyRelocationAddress(const MachO::any_relocation_info &RE) const;
455 unsigned getAnyRelocationPCRel(const MachO::any_relocation_info &RE) const;
456 unsigned getAnyRelocationLength(const MachO::any_relocation_info &RE) const;
457 unsigned getAnyRelocationType(const MachO::any_relocation_info &RE) const;
458 SectionRef getAnyRelocationSection(const MachO::any_relocation_info &RE) const;
460 // MachO specific structures.
461 MachO::section getSection(DataRefImpl DRI) const;
462 MachO::section_64 getSection64(DataRefImpl DRI) const;
463 MachO::section getSection(const LoadCommandInfo &L, unsigned Index) const;
464 MachO::section_64 getSection64(const LoadCommandInfo &L,unsigned Index) const;
465 MachO::nlist getSymbolTableEntry(DataRefImpl DRI) const;
466 MachO::nlist_64 getSymbol64TableEntry(DataRefImpl DRI) const;
468 MachO::linkedit_data_command
469 getLinkeditDataLoadCommand(const LoadCommandInfo &L) const;
470 MachO::segment_command
471 getSegmentLoadCommand(const LoadCommandInfo &L) const;
472 MachO::segment_command_64
473 getSegment64LoadCommand(const LoadCommandInfo &L) const;
474 MachO::linker_option_command
475 getLinkerOptionLoadCommand(const LoadCommandInfo &L) const;
476 MachO::version_min_command
477 getVersionMinLoadCommand(const LoadCommandInfo &L) const;
479 getNoteLoadCommand(const LoadCommandInfo &L) const;
480 MachO::build_version_command
481 getBuildVersionLoadCommand(const LoadCommandInfo &L) const;
482 MachO::build_tool_version
483 getBuildToolVersion(unsigned index) const;
485 getDylibIDLoadCommand(const LoadCommandInfo &L) const;
486 MachO::dyld_info_command
487 getDyldInfoLoadCommand(const LoadCommandInfo &L) const;
488 MachO::dylinker_command
489 getDylinkerCommand(const LoadCommandInfo &L) const;
491 getUuidCommand(const LoadCommandInfo &L) const;
493 getRpathCommand(const LoadCommandInfo &L) const;
494 MachO::source_version_command
495 getSourceVersionCommand(const LoadCommandInfo &L) const;
496 MachO::entry_point_command
497 getEntryPointCommand(const LoadCommandInfo &L) const;
498 MachO::encryption_info_command
499 getEncryptionInfoCommand(const LoadCommandInfo &L) const;
500 MachO::encryption_info_command_64
501 getEncryptionInfoCommand64(const LoadCommandInfo &L) const;
502 MachO::sub_framework_command
503 getSubFrameworkCommand(const LoadCommandInfo &L) const;
504 MachO::sub_umbrella_command
505 getSubUmbrellaCommand(const LoadCommandInfo &L) const;
506 MachO::sub_library_command
507 getSubLibraryCommand(const LoadCommandInfo &L) const;
508 MachO::sub_client_command
509 getSubClientCommand(const LoadCommandInfo &L) const;
510 MachO::routines_command
511 getRoutinesCommand(const LoadCommandInfo &L) const;
512 MachO::routines_command_64
513 getRoutinesCommand64(const LoadCommandInfo &L) const;
514 MachO::thread_command
515 getThreadCommand(const LoadCommandInfo &L) const;
517 MachO::any_relocation_info getRelocation(DataRefImpl Rel) const;
518 MachO::data_in_code_entry getDice(DataRefImpl Rel) const;
519 const MachO::mach_header &getHeader() const;
520 const MachO::mach_header_64 &getHeader64() const;
522 getIndirectSymbolTableEntry(const MachO::dysymtab_command &DLC,
523 unsigned Index) const;
524 MachO::data_in_code_entry getDataInCodeTableEntry(uint32_t DataOffset,
525 unsigned Index) const;
526 MachO::symtab_command getSymtabLoadCommand() const;
527 MachO::dysymtab_command getDysymtabLoadCommand() const;
528 MachO::linkedit_data_command getDataInCodeLoadCommand() const;
529 MachO::linkedit_data_command getLinkOptHintsLoadCommand() const;
530 ArrayRef<uint8_t> getDyldInfoRebaseOpcodes() const;
531 ArrayRef<uint8_t> getDyldInfoBindOpcodes() const;
532 ArrayRef<uint8_t> getDyldInfoWeakBindOpcodes() const;
533 ArrayRef<uint8_t> getDyldInfoLazyBindOpcodes() const;
534 ArrayRef<uint8_t> getDyldInfoExportsTrie() const;
535 ArrayRef<uint8_t> getUuid() const;
537 StringRef getStringTableData() const;
538 bool is64Bit() const;
539 void ReadULEB128s(uint64_t Index, SmallVectorImpl<uint64_t> &Out) const;
541 static StringRef guessLibraryShortName(StringRef Name, bool &isFramework,
544 static Triple::ArchType getArch(uint32_t CPUType);
545 static Triple getArchTriple(uint32_t CPUType, uint32_t CPUSubType,
546 const char **McpuDefault = nullptr,
547 const char **ArchFlag = nullptr);
548 static bool isValidArch(StringRef ArchFlag);
549 static Triple getHostArch();
551 bool isRelocatableObject() const override;
553 bool hasPageZeroSegment() const { return HasPageZeroSegment; }
555 static bool classof(const Binary *v) {
560 getVersionMinMajor(MachO::version_min_command &C, bool SDK) {
561 uint32_t VersionOrSDK = (SDK) ? C.sdk : C.version;
562 return (VersionOrSDK >> 16) & 0xffff;
566 getVersionMinMinor(MachO::version_min_command &C, bool SDK) {
567 uint32_t VersionOrSDK = (SDK) ? C.sdk : C.version;
568 return (VersionOrSDK >> 8) & 0xff;
572 getVersionMinUpdate(MachO::version_min_command &C, bool SDK) {
573 uint32_t VersionOrSDK = (SDK) ? C.sdk : C.version;
574 return VersionOrSDK & 0xff;
577 static std::string getBuildPlatform(uint32_t platform) {
579 case MachO::PLATFORM_MACOS: return "macos";
580 case MachO::PLATFORM_IOS: return "ios";
581 case MachO::PLATFORM_TVOS: return "tvos";
582 case MachO::PLATFORM_WATCHOS: return "watchos";
583 case MachO::PLATFORM_BRIDGEOS: return "bridgeos";
586 raw_string_ostream ss(ret);
587 ss << format_hex(platform, 8, true);
592 static std::string getBuildTool(uint32_t tools) {
594 case MachO::TOOL_CLANG: return "clang";
595 case MachO::TOOL_SWIFT: return "swift";
596 case MachO::TOOL_LD: return "ld";
599 raw_string_ostream ss(ret);
600 ss << format_hex(tools, 8, true);
605 static std::string getVersionString(uint32_t version) {
606 uint32_t major = (version >> 16) & 0xffff;
607 uint32_t minor = (version >> 8) & 0xff;
608 uint32_t update = version & 0xff;
610 SmallString<32> Version;
611 Version = utostr(major) + "." + utostr(minor);
613 Version += "." + utostr(update);
614 return Version.str();
618 MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian, bool Is64Bits,
619 Error &Err, uint32_t UniversalCputype = 0,
620 uint32_t UniversalIndex = 0);
622 uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
625 MachO::mach_header_64 Header64;
626 MachO::mach_header Header;
628 using SectionList = SmallVector<const char*, 1>;
629 SectionList Sections;
630 using LibraryList = SmallVector<const char*, 1>;
631 LibraryList Libraries;
632 LoadCommandList LoadCommands;
633 using LibraryShortName = SmallVector<StringRef, 1>;
634 using BuildToolList = SmallVector<const char*, 1>;
635 BuildToolList BuildTools;
636 mutable LibraryShortName LibrariesShortNames;
637 std::unique_ptr<BindRebaseSegInfo> BindRebaseSectionTable;
638 const char *SymtabLoadCmd = nullptr;
639 const char *DysymtabLoadCmd = nullptr;
640 const char *DataInCodeLoadCmd = nullptr;
641 const char *LinkOptHintsLoadCmd = nullptr;
642 const char *DyldInfoLoadCmd = nullptr;
643 const char *UuidLoadCmd = nullptr;
644 bool HasPageZeroSegment = false;
648 inline DiceRef::DiceRef(DataRefImpl DiceP, const ObjectFile *Owner)
649 : DicePimpl(DiceP) , OwningObject(Owner) {}
651 inline bool DiceRef::operator==(const DiceRef &Other) const {
652 return DicePimpl == Other.DicePimpl;
655 inline bool DiceRef::operator<(const DiceRef &Other) const {
656 return DicePimpl < Other.DicePimpl;
659 inline void DiceRef::moveNext() {
660 const MachO::data_in_code_entry *P =
661 reinterpret_cast<const MachO::data_in_code_entry *>(DicePimpl.p);
662 DicePimpl.p = reinterpret_cast<uintptr_t>(P + 1);
665 // Since a Mach-O data in code reference, a DiceRef, can only be created when
666 // the OwningObject ObjectFile is a MachOObjectFile a static_cast<> is used for
667 // the methods that get the values of the fields of the reference.
669 inline std::error_code DiceRef::getOffset(uint32_t &Result) const {
670 const MachOObjectFile *MachOOF =
671 static_cast<const MachOObjectFile *>(OwningObject);
672 MachO::data_in_code_entry Dice = MachOOF->getDice(DicePimpl);
673 Result = Dice.offset;
674 return std::error_code();
677 inline std::error_code DiceRef::getLength(uint16_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.length;
682 return std::error_code();
685 inline std::error_code DiceRef::getKind(uint16_t &Result) const {
686 const MachOObjectFile *MachOOF =
687 static_cast<const MachOObjectFile *>(OwningObject);
688 MachO::data_in_code_entry Dice = MachOOF->getDice(DicePimpl);
690 return std::error_code();
693 inline DataRefImpl DiceRef::getRawDataRefImpl() const {
697 inline const ObjectFile *DiceRef::getObjectFile() const {
701 } // end namespace object
702 } // end namespace llvm
704 #endif // LLVM_OBJECT_MACHO_H