15 #ifndef LLVM_OBJECT_MACHO_H
16 #define LLVM_OBJECT_MACHO_H
37 #include <system_error>
58 std::error_code
getLength(uint16_t &Result)
const;
59 std::error_code
getKind(uint16_t &Result)
const;
76 uint64_t
flags()
const;
78 uint64_t
other()
const;
92 void pushDownUntilBottom();
93 void pushNode(uint64_t
Offset);
97 NodeState(
const uint8_t *
Ptr);
100 const uint8_t *Current;
105 unsigned ChildCount = 0;
106 unsigned NextChildIndex = 0;
107 unsigned ParentStringLength = 0;
108 bool IsExportNode =
false;
114 bool Malformed =
false;
131 uint8_t PointerSize, int32_t SegIndex,
144 uint64_t OffsetInSegment;
145 uint64_t SegmentStartAddress;
146 int32_t SegmentIndex;
148 const SectionInfo &findSection(int32_t SegIndex, uint64_t SegOffset);
189 int32_t SegmentIndex = -1;
190 uint64_t RemainingLoopCount = 0;
191 uint64_t AdvanceAmount = 0;
234 int64_t readSLEB128(
const char **
error);
241 int32_t SegmentIndex = -1;
243 bool LibraryOrdinalSet =
false;
247 uint64_t RemainingLoopCount = 0;
248 uint64_t AdvanceAmount = 0;
344 unsigned getArch()
const override;
392 bool endInvalid)
const {
393 return BindRebaseSectionTable->checkSegAndOffset(SegIndex, SegOffset,
399 uint8_t PointerSize, int32_t SegIndex,
400 uint64_t SegOffset)
const {
401 return BindRebaseSectionTable->checkCountAndSkip(Count, Skip, PointerSize,
402 SegIndex, SegOffset);
408 bool endInvalid)
const {
409 return BindRebaseSectionTable->checkSegAndOffset(SegIndex, SegOffset,
415 uint8_t PointerSize, int32_t SegIndex,
416 uint64_t SegOffset)
const {
417 return BindRebaseSectionTable->checkCountAndSkip(Count, Skip, PointerSize,
418 SegIndex, SegOffset);
424 return BindRebaseSectionTable->segmentName(SegIndex);
430 return BindRebaseSectionTable->sectionName(SegIndex, SegOffset);
436 return BindRebaseSectionTable->address(SegIndex, SegOffset);
529 unsigned Index)
const;
531 unsigned Index)
const;
552 const char **McpuDefault =
nullptr,
553 const char **ArchFlag =
nullptr);
570 return (VersionOrSDK >> 16) & 0xffff;
576 return (VersionOrSDK >> 8) & 0xff;
582 return VersionOrSDK & 0xff;
614 uint32_t major = (version >> 16) & 0xffff;
615 uint32_t minor = (version >> 8) & 0xff;
621 Version +=
"." +
utostr(update);
622 return Version.
str();
630 uint64_t getSymbolValueImpl(
DataRefImpl Symb)
const override;
637 SectionList Sections;
639 LibraryList Libraries;
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;
657 : DicePimpl(DiceP) , OwningObject(Owner) {}
660 return DicePimpl == Other.DicePimpl;
664 return DicePimpl < Other.DicePimpl;
670 DicePimpl.
p =
reinterpret_cast<uintptr_t
>(P + 1);
682 return std::error_code();
690 return std::error_code();
698 return std::error_code();
712 #endif // LLVM_OBJECT_MACHO_H
void getRelocationTypeName(DataRefImpl Rel, SmallVectorImpl< char > &Result) const override
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)
iterator_range< relocation_iterator > external_relocations() const
load_command_iterator end_load_commands() const
typename SuperClass::const_iterator const_iterator
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
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.
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...
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...
StringRef typeName() const
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...
MachORebaseEntry(Error *Err, const MachOObjectFile *O, ArrayRef< uint8_t > opcodes, bool is64Bit)
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)
StringRef segmentName() const
static Triple getHostArch()
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.
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
StringRef otherName() const
MachORebaseEntry encapsulates the current state in the decompression of rebasing opcodes.
uint64_t getSectionAlignment(DataRefImpl Sec) const override
ArrayRef< uint8_t > getDyldInfoLazyBindOpcodes() const
load_command_iterator begin_load_commands() const
int32_t segmentIndex() 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...
bool operator==(const MachORebaseEntry &) const
bool isSectionBitcode(DataRefImpl Sec) const override
static std::string getBuildTool(uint32_t tools)
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
bool isSectionText(DataRefImpl Sec) const override
std::error_code getOffset(uint32_t &Result) const
Expected< StringRef > getSymbolName(DataRefImpl Symb) const override
MachO::segment_command_64 getSegment64LoadCommand(const LoadCommandInfo &L) const
StringRef sectionName() const
MachO::uuid_command getUuidCommand(const LoadCommandInfo &L) const
uint64_t segmentOffset() const
uint64_t getSymbolIndex(DataRefImpl Symb) const
StringRef segmentName() const
Tagged union holding either a T or a Error.
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.
MachO::linker_option_command getLinkerOptionLoadCommand(const LoadCommandInfo &L) const
uint32_t nodeOffset() const
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)
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 ...
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
SmallVector< LoadCommandInfo, 4 > LoadCommandList
static std::string utostr(uint64_t X, bool isNeg=false)
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...
MachO::section_64 getSection64(DataRefImpl DRI) const
relocation_iterator extrel_begin() const
MachO::entry_point_command getEntryPointCommand(const LoadCommandInfo &L) const
StringRef symbolName() const
MachO::routines_command_64 getRoutinesCommand64(const LoadCommandInfo &L) const
void moveSectionNext(DataRefImpl &Sec) const override
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
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...
MachO::source_version_command getSourceVersionCommand(const LoadCommandInfo &L) const
MachO::linkedit_data_command getDataInCodeLoadCommand() const
bool operator==(const DiceRef &Other) const
DiceRef - This is a value type class that represents a single data in code entry in the table in a Ma...
MachO::sub_framework_command getSubFrameworkCommand(const LoadCommandInfo &L) const
bool operator==(const MachOBindEntry &) const
StringRef typeName() 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.
Triple - Helper class for working with autoconf configuration names.
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
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...
static uint64_t readULEB128(const uint8_t *&Ptr)
unsigned getAnyRelocationLength(const MachO::any_relocation_info &RE) const
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
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)
uint64_t segmentOffset() const
static uint32_t getVersionMinMinor(MachO::version_min_command &C, bool SDK)
MachO::nlist getSymbolTableEntry(DataRefImpl DRI) const
std::error_code getLength(uint16_t &Result) const
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.
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...
uint32_t getLibraryCount() const
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
bool operator<(const DiceRef &Other) const
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
static std::vector< std::string > Flags
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)
MachO::symtab_command getSymtabLoadCommand() const
basic_symbol_iterator getSymbolByIndex(unsigned Index) const
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
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.
StringRef mapDebugSectionName(StringRef Name) const override
Maps a debug section name to a standard DWARF section name.
LoadCommandList::const_iterator load_command_iterator
unsigned getSectionType(SectionRef Sec) const
int32_t segmentIndex() const
Lightweight error class with error context and mandatory checking.
section_iterator section_end() const override
const ObjectFile * getObjectFile() const
MachOBindEntry(Error *Err, const MachOObjectFile *O, ArrayRef< uint8_t > Opcodes, bool is64Bit, MachOBindEntry::Kind)
StringRef sectionName() const
static uint32_t getVersionMinMajor(MachO::version_min_command &C, bool SDK)
ArrayRef< uint8_t > getDyldInfoWeakBindOpcodes() const
StringRef - Represent a constant reference to a string, i.e.
static bool classof(const Binary *v)
StringRef sectionName(int32_t SegIndex, uint64_t SegOffset)
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
Expected< section_iterator > getSymbolSection(DataRefImpl Symb) const override
relocation_iterator section_rel_begin(DataRefImpl Sec) const override
Error checkSymbolTable() const
This is a value type class that represents a single section in the list of sections in the object fil...
uint64_t getSectionSize(DataRefImpl Sec) const override
ArrayRef< uint8_t > getDyldInfoBindOpcodes() const