Go to the documentation of this file.
14 #ifndef LLVM_OBJECT_MACHO_H
15 #define LLVM_OBJECT_MACHO_H
37 #include <system_error>
94 void pushDownUntilBottom();
99 NodeState(
const uint8_t *Ptr);
101 const uint8_t *Start;
102 const uint8_t *Current;
106 const char *ImportName =
nullptr;
107 unsigned ChildCount = 0;
108 unsigned NextChildIndex = 0;
109 unsigned ParentStringLength = 0;
110 bool IsExportNode =
false;
123 return make_range(Stack.begin(), Stack.end());
153 int32_t SegmentIndex;
155 const SectionInfo &findSection(int32_t SegIndex,
uint64_t SegOffset);
196 int32_t SegmentIndex = -1;
241 int64_t readSLEB128(
const char **
error);
248 int32_t SegmentIndex = -1;
250 bool LibraryOrdinalSet =
false;
279 : LibOrdinal(LibOrdinal), SymbolName(
Symbol), Addend(Addend),
280 WeakImport(WeakImport) {}
376 std::vector<ChainedFixupTarget> FixupTargets;
550 return BindRebaseSectionTable->checkSegAndOffsets(SegIndex, SegOffset,
565 return BindRebaseSectionTable->checkSegAndOffsets(SegIndex, SegOffset,
572 return BindRebaseSectionTable->segmentName(SegIndex);
578 return BindRebaseSectionTable->sectionName(SegIndex, SegOffset);
584 return BindRebaseSectionTable->address(SegIndex, SegOffset);
677 unsigned Index)
const;
679 unsigned Index)
const;
705 const char **McpuDefault =
nullptr,
706 const char **ArchFlag =
nullptr);
726 uint32_t VersionOrSDK = (SDK) ?
C.sdk :
C.version;
727 return (VersionOrSDK >> 16) & 0xffff;
732 uint32_t VersionOrSDK = (SDK) ?
C.sdk :
C.version;
733 return (VersionOrSDK >> 8) & 0xff;
738 uint32_t VersionOrSDK = (SDK) ?
C.sdk :
C.version;
739 return VersionOrSDK & 0xff;
776 uint32_t major = (version >> 16) & 0xffff;
777 uint32_t minor = (version >> 8) & 0xff;
781 Version = utostr(major) +
"." + utostr(minor);
783 Version +=
"." + utostr(update);
784 return std::string(std::string(
Version.str()));
806 SectionList Sections;
808 LibraryList Libraries;
812 BuildToolList BuildTools;
813 mutable LibraryShortName LibrariesShortNames;
814 std::unique_ptr<BindRebaseSegInfo> BindRebaseSectionTable;
815 const char *SymtabLoadCmd =
nullptr;
816 const char *DysymtabLoadCmd =
nullptr;
817 const char *DataInCodeLoadCmd =
nullptr;
818 const char *LinkOptHintsLoadCmd =
nullptr;
819 const char *DyldInfoLoadCmd =
nullptr;
820 const char *FuncStartsLoadCmd =
nullptr;
821 const char *DyldChainedFixupsLoadCmd =
nullptr;
822 const char *UuidLoadCmd =
nullptr;
823 bool HasPageZeroSegment =
false;
828 : DicePimpl(DiceP) , OwningObject(Owner) {}
831 return DicePimpl ==
Other.DicePimpl;
835 return DicePimpl <
Other.DicePimpl;
841 DicePimpl.
p =
reinterpret_cast<uintptr_t
>(
P + 1);
853 return std::error_code();
861 return std::error_code();
869 return std::error_code();
883 #endif // LLVM_OBJECT_MACHO_H
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override
MachO::sub_umbrella_command getSubUmbrellaCommand(const LoadCommandInfo &L) const
bool getPlainRelocationExternal(const MachO::any_relocation_info &RE) const
static std::string getVersionString(uint32_t version)
uint64_t segmentAddress() const
uint32_t nodeOffset() const
StringRef getStringTableData() const
This is an optimization pass for GlobalISel generic memory operations.
@ PLATFORM_WATCHOSSIMULATOR
static uint32_t getVersionMinMajor(MachO::version_min_command &C, bool SDK)
MachOAbstractFixupEntry is an abstract class representing a fixup in a MH_DYLDLINK file.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
MachO::uuid_command getUuidCommand(const LoadCommandInfo &L) const
MachO::source_version_command getSourceVersionCommand(const LoadCommandInfo &L) const
iterator_range< fixup_iterator > fixupTable(Error &Err)
For iterating over all chained fixups.
uint8_t getRelocationLength(DataRefImpl Rel) const
MachOChainedFixupEntry(Error *Err, const MachOObjectFile *O, bool Parse)
static Expected< std::vector< std::string > > findDsymObjectMembers(StringRef Path)
If the input path is a .dSYM bundle (as created by the dsymutil tool), return the paths to the object...
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
static bool is64Bit(const char *name)
void ReadULEB128s(uint64_t Index, SmallVectorImpl< uint64_t > &Out) const
section_iterator getRelocationRelocatedSection(relocation_iterator Rel) const
ChainedFixupTarget(int LibOrdinal, StringRef Symbol, uint64_t Addend, bool WeakImport)
A raw_ostream that writes to an std::string.
uint64_t getSectionIndex(DataRefImpl Sec) const override
uint64_t getSectionSize(DataRefImpl Sec) const override
StringRef typeName() const
StringRef typeName() const
StringRef sectionName(int32_t SegIndex, uint64_t SegOffset)
The object format emitted by the WebAssembly backed is documented see the home tools
StringRef segmentName() const
MachOAbstractFixupEntry(Error *Err, const MachOObjectFile *O)
bool isSectionText(DataRefImpl Sec) const override
MachO::segment_command getSegmentLoadCommand(const LoadCommandInfo &L) const
MachO::routines_command getRoutinesCommand(const LoadCommandInfo &L) const
iterator_range< bind_iterator > weakBindTable(Error &Err)
For use iterating over all weak bind table entries.
Triple - Helper class for working with autoconf configuration names.
llvm::binaryformat::Swift5ReflectionSectionKind mapReflectionSectionNameToEnumValue(StringRef SectionName) const override
static bool isValidArch(StringRef ArchFlag)
relocation_iterator locrel_begin() const
bool operator==(const MachORebaseEntry &) const
@ BIND_SPECIAL_DYLIB_WEAK_LOOKUP
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.
unsigned getAnyRelocationAddress(const MachO::any_relocation_info &RE) const
uint64_t segmentOffset() const
Error checkSymbolTable() const
SmallVector< uint64_t > getFunctionStarts() const
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.
ArrayRef< char > getSectionRawName(DataRefImpl Sec) const
MachO::dyld_info_command getDyldInfoLoadCommand(const LoadCommandInfo &L) const
unsigned getAnyRelocationPCRel(const MachO::any_relocation_info &RE) const
static std::string getBuildPlatform(uint32_t platform)
to esp esp setne al movzbw ax esp setg cl movzbw cx cmove cx cl jne LBB1_2 esp ret(also really horrible code on ppc). This is due to the expand code for 64-bit compares. GCC produces multiple branches
ChainedFixupTarget holds all the information about an external symbol necessary to bind this binary t...
LoadCommandList::const_iterator load_command_iterator
bool isSectionStripped(DataRefImpl Sec) const override
When dsymutil generates the companion file, it strips all unnecessary sections (e....
StringRef mapDebugSectionName(StringRef Name) const override
Maps a debug section name to a standard DWARF section name.
ArrayRef< uint8_t > getSegmentContents(StringRef SegmentName) const
Return the raw contents of an entire segment.
Tagged union holding either a T or a Error.
MachO::build_version_command getBuildVersionLoadCommand(const LoadCommandInfo &L) const
section_iterator getRelocationSection(DataRefImpl Rel) const
ExportEntry encapsulates the current-state-of-the-walk used when doing a non-recursive walk of the tr...
symbol_iterator getSymbolByIndex(unsigned Index) const
iterator_range< rebase_iterator > rebaseTable(Error &Err)
For use iterating over all rebase table entries.
static bool classof(const Binary *v)
bool operator==(const DiceRef &Other) const
the resulting code requires compare and branches when and if * p
uint64_t getSymbolIndex(DataRefImpl Symb) const
int32_t segmentIndex() const
Expected< SectionRef > getSection(unsigned SectionIndex) const
MachO::dylib_command getDylibIDLoadCommand(const LoadCommandInfo &L) const
basic_symbol_iterator symbol_end() const override
uint32_t getIndirectSymbolTableEntry(const MachO::dysymtab_command &DLC, unsigned Index) const
ArrayRef< uint8_t > getSectionContents(uint32_t Offset, uint64_t Size) const
StringRef sectionName() const
static uint64_t readULEB128(WasmObjectFile::ReadContext &Ctx)
uint64_t getSectionAlignment(DataRefImpl Sec) const override
MachO::linkedit_data_command getLinkOptHintsLoadCommand() const
MachO::sub_framework_command getSubFrameworkCommand(const LoadCommandInfo &L) const
uint32_t getScatteredRelocationType(const MachO::any_relocation_info &RE) const
Expected< uint64_t > getSymbolAddress(DataRefImpl Symb) const override
MachO::dysymtab_command getDysymtabLoadCommand() const
MachO::rpath_command getRpathCommand(const LoadCommandInfo &L) const
MachO::version_min_command getVersionMinLoadCommand(const LoadCommandInfo &L) const
const char * checkSegAndOffsets(int32_t SegIndex, uint64_t SegOffset, uint8_t PointerSize, uint32_t Count=1, uint32_t Skip=0)
uint64_t textAddress() const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
bool isSectionCompressed(DataRefImpl Sec) const override
StringRef sectionName() const
MachO::linkedit_data_command getLinkeditDataLoadCommand(const LoadCommandInfo &L) const
(vector float) vec_cmpeq(*A, *B) C
uint64_t rawValue() const
static std::string getBuildTool(uint32_t tools)
const MachOObjectFile * O
MachO::build_tool_version getBuildToolVersion(unsigned index) const
ArrayRef< uint8_t > getUuid() const
ArrayRef< uint8_t > getDyldInfoLazyBindOpcodes() const
Manages the enabling and disabling of subtarget specific features.
MachO::any_relocation_info getRelocation(DataRefImpl Rel) const
std::error_code getLength(uint16_t &Result) const
uint64_t getRelocationOffset(DataRefImpl Rel) const override
bool operator==(const MachOBindEntry &) const
const ObjectFile * getObjectFile() const
unsigned getSymbolSectionID(SymbolRef Symb) const
bool isSectionVirtual(DataRefImpl Sec) const override
uint64_t address(uint32_t SegIndex, uint64_t SegOffset)
void moveRelocationNext(DataRefImpl &Rel) const override
MachO::linkedit_data_command getDataInCodeLoadCommand() const
StringRef sectionName() const
static Expected< std::unique_ptr< MachOObjectFile > > create(MemoryBufferRef Object, bool IsLittleEndian, bool Is64Bits, uint32_t UniversalCputype=0, uint32_t UniversalIndex=0)
StringRef segmentName() const
uint64_t pointerValue() const
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override
ArrayRef< char > getSectionRawFinalSegmentName(DataRefImpl Sec) const
MachO::section_64 getSection64(DataRefImpl DRI) const
bool operator==(const ExportEntry &) const
This is a value type class that represents a single section in the list of sections in the object fil...
ArrayRef< uint8_t > getDyldInfoWeakBindOpcodes() const
unsigned getSectionType(SectionRef Sec) const
MachO::entry_point_command getEntryPointCommand(const LoadCommandInfo &L) const
unsigned getSectionID(SectionRef Sec) const
SmallVector< LoadCommandInfo, 4 > LoadCommandList
SubtargetFeatures getFeatures() const override
unsigned getPlainRelocationSymbolNum(const MachO::any_relocation_info &RE) const
MachO::dylinker_command getDylinkerCommand(const LoadCommandInfo &L) const
bar al al movzbl eax ret Missed when stored in a memory object
MachO::note_command getNoteLoadCommand(const LoadCommandInfo &L) const
MachO::nlist_64 getSymbol64TableEntry(DataRefImpl DRI) const
iterator_range< relocation_iterator > external_relocations() const
bool isSectionBitcode(DataRefImpl Sec) const override
const char * BindEntryCheckSegAndOffsets(int32_t SegIndex, uint64_t SegOffset, uint8_t PointerSize, uint32_t Count=1, uint32_t Skip=0) const
Expected< SymbolRef::Type > getSymbolType(DataRefImpl Symb) const override
basic_symbol_iterator symbol_begin() const override
Expected< std::vector< ChainedFixupTarget > > getDyldChainedFixupTargets() const
MachORebaseEntry(Error *Err, const MachOObjectFile *O, ArrayRef< uint8_t > opcodes, bool is64Bit)
MachO::routines_command_64 getRoutinesCommand64(const LoadCommandInfo &L) const
MachO::data_in_code_entry getDice(DataRefImpl Rel) const
load_command_iterator end_load_commands() const
static uint32_t getVersionMinMinor(MachO::version_min_command &C, bool SDK)
Triple getArchTriple(const char **McpuDefault=nullptr) const
constexpr uint64_t PointerSize
x86_64 pointer size.
typename SuperClass::const_iterator const_iterator
section_iterator section_end() const override
std::error_code getLibraryShortNameByIndex(unsigned Index, StringRef &) const
ArrayRef< uint8_t > getDyldInfoRebaseOpcodes() const
DiceRef - This is a value type class that represents a single data in code entry in the table in a Ma...
DataRefImpl getRawDataRefImpl() const
StringRef segmentName() const
bool getScatteredRelocationScattered(const MachO::any_relocation_info &RE) const
ArrayRef< uint8_t > getDyldInfoBindOpcodes() const
MachO::data_in_code_entry getDataInCodeTableEntry(uint32_t DataOffset, unsigned Index) const
Triple::ArchType getArch() const override
std::error_code getKind(uint16_t &Result) const
load_command_iterator begin_load_commands() const
StringRef segmentName(int32_t SegIndex)
relocation_iterator extrel_begin() const
StringRef symbolName() const
SectionRef getAnyRelocationSection(const MachO::any_relocation_info &RE) const
Expected< section_iterator > getSymbolSection(DataRefImpl Symb) const override
StringRef - Represent a constant reference to a string, i.e.
This class is the base class for all object file types.
static Constant * SegmentOffset(IRBuilderBase &IRB, int Offset, unsigned AddressSpace)
std::error_code getOffset(uint32_t &Result) const
static bool isMachOPairedReloc(uint64_t RelocType, uint64_t Arch)
iterator_range< export_iterator > exports(Error &Err) const
For use iterating over all exported symbols.
void getRelocationTypeName(DataRefImpl Rel, SmallVectorImpl< char > &Result) const override
MachO::encryption_info_command_64 getEncryptionInfoCommand64(const LoadCommandInfo &L) const
relocation_iterator locrel_end() const
int32_t segmentIndex() const
bool isRelocationScattered(const MachO::any_relocation_info &RE) const
section_iterator section_begin() const override
static uint32_t getVersionMinUpdate(MachO::version_min_command &C, bool SDK)
Expected< uint32_t > getSymbolFlags(DataRefImpl Symb) const override
MachO::mach_header Header
MachO::symtab_command getSymtabLoadCommand() const
void moveSectionNext(DataRefImpl &Sec) const override
relocation_iterator extrel_end() const
unsigned getAnyRelocationType(const MachO::any_relocation_info &RE) const
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
MachO::nlist getSymbolTableEntry(DataRefImpl DRI) const
iterator_range< load_command_iterator > load_commands() const
uint64_t segmentOffset() const
MachO::segment_command_64 getSegment64LoadCommand(const LoadCommandInfo &L) const
int32_t segmentIndex() const
Lightweight error class with error context and mandatory checking.
const MachO::mach_header_64 & getHeader64() const
StringRef symbolName() const
MachOBindEntry encapsulates the current state in the decompression of binding opcodes.
uint64_t getNValue(DataRefImpl Sym) const
bool isDebugSection(DataRefImpl Sec) const override
uint32_t getLibraryCount() const
bool operator<(const DiceRef &Other) const
bool hasPageZeroSegment() const
MachO::sub_client_command getSubClientCommand(const LoadCommandInfo &L) const
std::error_code getIndirectName(DataRefImpl Symb, StringRef &Res) const
uint64_t getRelocationType(DataRefImpl Rel) const override
static Triple getHostArch()
uint8_t getBytesInAddress() const override
The number of bytes used to represent an address in this object file format.
ArrayRef< uint8_t > getDyldInfoExportsTrie() const
uint32_t getScatteredRelocationValue(const MachO::any_relocation_info &RE) const
const char * RebaseEntryCheckSegAndOffsets(int32_t SegIndex, uint64_t SegOffset, uint8_t PointerSize, uint32_t Count=1, uint32_t Skip=0) const
iterator_range< bind_iterator > bindTable(Error &Err)
For use iterating over all bind table entries.
relocation_iterator section_rel_begin(DataRefImpl Sec) const override
StringRef getSectionFinalSegmentName(DataRefImpl Sec) const
MachORebaseEntry encapsulates the current state in the decompression of rebasing opcodes.
StringRef typeName() const
MachO::mach_header_64 Header64
A range adaptor for a pair of iterators.
dice_iterator begin_dices() const
unsigned getAnyRelocationLength(const MachO::any_relocation_info &RE) const
dice_iterator end_dices() const
static ArrayRef< StringRef > getValidArchs()
This is a value type class that represents a single symbol in the list of symbols in the object file.
ExportEntry(Error *Err, const MachOObjectFile *O, ArrayRef< uint8_t > Trie)
static StringRef guessLibraryShortName(StringRef Name, bool &isFramework, StringRef &Suffix)
bool isSectionBSS(DataRefImpl Sec) const override
uint64_t getSectionAddress(DataRefImpl Sec) const override
MachO::thread_command getThreadCommand(const LoadCommandInfo &L) const
const MachO::mach_header & getHeader() const
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 ...
void moveSymbolNext(DataRefImpl &Symb) const override
MachO::encryption_info_command getEncryptionInfoCommand(const LoadCommandInfo &L) const
Expected< Optional< MachO::dyld_chained_fixups_header > > getChainedFixupsHeader() const
If the optional is None, no header was found, but the object was well-formed.
StringRef getFileFormatName() const override
Expected< StringRef > getSymbolName(DataRefImpl Symb) const override
std::string & str()
Returns the string's reference.
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
bool operator==(const MachOChainedFixupEntry &) const
bool isSectionData(DataRefImpl Sec) const override
iterator_range< bind_iterator > lazyBindTable(Error &Err)
For use iterating over all lazy bind table entries.
BindRebaseSegInfo(const MachOObjectFile *Obj)
Expected< StringRef > getSectionName(DataRefImpl Sec) const override
relocation_iterator section_rel_end(DataRefImpl Sec) const override
MachO::sub_library_command getSubLibraryCommand(const LoadCommandInfo &L) const
uint64_t segmentOffset() const
MachO::linker_option_command getLinkerOptionLoadCommand(const LoadCommandInfo &L) const
Optional< std::vector< StOtherPiece > > Other
bool isRelocatableObject() const override
True if this is a relocatable object (.o/.obj).
StringRef otherName() const
uint32_t getSymbolAlignment(DataRefImpl Symb) const override
MachOBindEntry(Error *Err, const MachOObjectFile *O, ArrayRef< uint8_t > Opcodes, bool is64Bit, MachOBindEntry::Kind)