14#ifndef LLVM_OBJECT_MACHO_H
15#define LLVM_OBJECT_MACHO_H
38#include <system_error>
96 void pushDownUntilBottom();
108 const char *ImportName =
nullptr;
109 unsigned ChildCount = 0;
110 unsigned NextChildIndex = 0;
111 unsigned ParentStringLength = 0;
112 bool IsExportNode =
false;
125 return make_range(Stack.begin(), Stack.end());
156 int32_t SegmentIndex;
158 const SectionInfo &findSection(int32_t SegIndex,
uint64_t SegOffset);
199 int32_t SegmentIndex = -1;
245 int64_t readSLEB128(
const char **
error);
252 int32_t SegmentIndex = -1;
254 bool LibraryOrdinalSet =
false;
283 : LibOrdinal(LibOrdinal), NameOffset(NameOffset), SymbolName(Symbol),
284 Addend(Addend), WeakImport(WeakImport) {}
399 void findNextPageWithFixups();
401 std::vector<ChainedFixupTarget> FixupTargets;
402 std::vector<ChainedFixupsSegment> Segments;
423 size_t MachOFilesetEntryOffset = 0);
491 void moveRelocationNext(
DataRefImpl &Rel)
const override;
501 std::error_code getLibraryShortNameByIndex(
unsigned Index,
StringRef &)
const;
521 uint8_t getBytesInAddress()
const override;
523 StringRef getFileFormatName()
const override;
528 Triple getArchTriple(
const char **McpuDefault =
nullptr)
const;
536 load_command_iterator begin_load_commands()
const;
537 load_command_iterator end_load_commands()
const;
587 return BindRebaseSectionTable->checkSegAndOffsets(SegIndex, SegOffset,
588 PointerSize,
Count, Skip);
602 return BindRebaseSectionTable->checkSegAndOffsets(SegIndex, SegOffset,
603 PointerSize,
Count, Skip);
609 return BindRebaseSectionTable->segmentName(SegIndex);
615 return BindRebaseSectionTable->sectionName(SegIndex, SegOffset);
621 return BindRebaseSectionTable->address(SegIndex, SegOffset);
636 unsigned getPlainRelocationSymbolNum(
639 bool getScatteredRelocationScattered(
641 uint32_t getScatteredRelocationValue(
643 uint32_t getScatteredRelocationType(
660 getLinkeditDataLoadCommand(
const LoadCommandInfo &L)
const;
662 getSegmentLoadCommand(
const LoadCommandInfo &L)
const;
664 getSegment64LoadCommand(
const LoadCommandInfo &L)
const;
666 getLinkerOptionLoadCommand(
const LoadCommandInfo &L)
const;
668 getVersionMinLoadCommand(
const LoadCommandInfo &L)
const;
670 getNoteLoadCommand(
const LoadCommandInfo &L)
const;
672 getBuildVersionLoadCommand(
const LoadCommandInfo &L)
const;
674 getBuildToolVersion(
unsigned index)
const;
676 getDylibIDLoadCommand(
const LoadCommandInfo &L)
const;
678 getDyldInfoLoadCommand(
const LoadCommandInfo &L)
const;
680 getDylinkerCommand(
const LoadCommandInfo &L)
const;
682 getUuidCommand(
const LoadCommandInfo &L)
const;
684 getRpathCommand(
const LoadCommandInfo &L)
const;
686 getSourceVersionCommand(
const LoadCommandInfo &L)
const;
688 getEntryPointCommand(
const LoadCommandInfo &L)
const;
690 getEncryptionInfoCommand(
const LoadCommandInfo &L)
const;
692 getEncryptionInfoCommand64(
const LoadCommandInfo &L)
const;
694 getSubFrameworkCommand(
const LoadCommandInfo &L)
const;
696 getSubUmbrellaCommand(
const LoadCommandInfo &L)
const;
698 getSubLibraryCommand(
const LoadCommandInfo &L)
const;
700 getSubClientCommand(
const LoadCommandInfo &L)
const;
702 getRoutinesCommand(
const LoadCommandInfo &L)
const;
704 getRoutinesCommand64(
const LoadCommandInfo &L)
const;
706 getThreadCommand(
const LoadCommandInfo &L)
const;
708 getFilesetEntryLoadCommand(
const LoadCommandInfo &L)
const;
716 unsigned Index)
const;
718 unsigned Index)
const;
732 getChainedFixupsHeader()
const;
738 getChainedFixupsLoadCommand()
const;
742 getChainedFixupsSegments()
const;
757 const char **McpuDefault =
nullptr,
758 const char **ArchFlag =
nullptr);
759 static bool isValidArch(
StringRef ArchFlag);
761 static Triple getHostArch();
763 bool isRelocatableObject()
const override;
780 uint32_t VersionOrSDK = (SDK) ?
C.sdk :
C.version;
781 return (VersionOrSDK >> 16) & 0xffff;
786 uint32_t VersionOrSDK = (SDK) ?
C.sdk :
C.version;
787 return (VersionOrSDK >> 8) & 0xff;
792 uint32_t VersionOrSDK = (SDK) ?
C.sdk :
C.version;
793 return VersionOrSDK & 0xff;
798#define PLATFORM(platform, id, name, build_name, target, tapi_target, \
800 case MachO::PLATFORM_##platform: \
802#include "llvm/BinaryFormat/MachO.def"
827 uint32_t major = (version >> 16) & 0xffff;
828 uint32_t minor = (version >> 8) & 0xff;
835 return std::string(std::string(
Version));
849 size_t MachOFilesetEntryOffset = 0);
858 SectionList Sections;
860 LibraryList Libraries;
861 LoadCommandList LoadCommands;
864 BuildToolList BuildTools;
865 mutable LibraryShortName LibrariesShortNames;
866 std::unique_ptr<BindRebaseSegInfo> BindRebaseSectionTable;
867 const char *SymtabLoadCmd =
nullptr;
868 const char *DysymtabLoadCmd =
nullptr;
869 const char *DataInCodeLoadCmd =
nullptr;
870 const char *LinkOptHintsLoadCmd =
nullptr;
871 const char *DyldInfoLoadCmd =
nullptr;
872 const char *FuncStartsLoadCmd =
nullptr;
873 const char *DyldChainedFixupsLoadCmd =
nullptr;
874 const char *DyldExportsTrieLoadCmd =
nullptr;
875 const char *UuidLoadCmd =
nullptr;
876 bool HasPageZeroSegment =
false;
877 size_t MachOFilesetEntryOffset = 0;
882 : DicePimpl(DiceP) , OwningObject(Owner) {}
885 return DicePimpl ==
Other.DicePimpl;
889 return DicePimpl <
Other.DicePimpl;
895 DicePimpl.p =
reinterpret_cast<uintptr_t
>(
P + 1);
907 return std::error_code();
915 return std::error_code();
923 return std::error_code();
Unify divergent function exit nodes
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static StringRef getSymbolName(SymbolKind SymKind)
static bool isDebugSection(const SectionBase &Sec)
This file defines the SmallString class.
This file defines the SmallVector class.
static unsigned getSymbolSectionID(const ObjectFile &O, SymbolRef Sym)
static unsigned getSectionID(const ObjectFile &O, SectionRef Sec)
static std::unique_ptr< PDBSymbol > getSymbolType(const PDBSymbol &Symbol)
static uint64_t readULEB128(WasmObjectFile::ReadContext &Ctx)
static bool is64Bit(const char *name)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Manages the enabling and disabling of subtarget specific features.
Triple - Helper class for working with autoconf configuration names.
A range adaptor for a pair of iterators.
LLVM_ABI StringRef segmentName(int32_t SegIndex)
LLVM_ABI StringRef sectionName(int32_t SegIndex, uint64_t SegOffset)
LLVM_ABI BindRebaseSegInfo(const MachOObjectFile *Obj)
LLVM_ABI const char * checkSegAndOffsets(int32_t SegIndex, uint64_t SegOffset, uint8_t PointerSize, uint64_t Count=1, uint64_t Skip=0)
LLVM_ABI uint64_t address(uint32_t SegIndex, uint64_t SegOffset)
bool operator==(const DiceRef &Other) const
std::error_code getOffset(uint32_t &Result) const
std::error_code getLength(uint16_t &Result) const
bool operator<(const DiceRef &Other) const
DataRefImpl getRawDataRefImpl() const
std::error_code getKind(uint16_t &Result) const
const ObjectFile * getObjectFile() const
LLVM_ABI StringRef name() const
LLVM_ABI ExportEntry(Error *Err, const MachOObjectFile *O, ArrayRef< uint8_t > Trie)
LLVM_ABI bool operator==(const ExportEntry &) const
LLVM_ABI StringRef otherName() const
LLVM_ABI uint64_t address() const
LLVM_ABI uint64_t flags() const
LLVM_ABI uint32_t nodeOffset() const
friend class MachOObjectFile
LLVM_ABI uint64_t other() const
LLVM_ABI StringRef sectionName() const
LLVM_ABI uint64_t segmentAddress() const
LLVM_ABI int32_t segmentIndex() const
LLVM_ABI uint64_t address() const
LLVM_ABI StringRef typeName() const
LLVM_ABI int64_t addend() const
LLVM_ABI MachOAbstractFixupEntry(Error *Err, const MachOObjectFile *O)
uint64_t textAddress() const
LLVM_ABI uint32_t flags() const
uint64_t pointerValue() const
uint64_t rawValue() const
LLVM_ABI StringRef symbolName() const
LLVM_ABI void moveToFirst()
LLVM_ABI int ordinal() const
LLVM_ABI StringRef segmentName() const
LLVM_ABI void moveToEnd()
const MachOObjectFile * O
LLVM_ABI uint64_t segmentOffset() const
MachOBindEntry encapsulates the current state in the decompression of binding opcodes.
LLVM_ABI uint32_t flags() const
LLVM_ABI bool operator==(const MachOBindEntry &) const
LLVM_ABI StringRef symbolName() const
LLVM_ABI int ordinal() const
LLVM_ABI StringRef sectionName() const
LLVM_ABI MachOBindEntry(Error *Err, const MachOObjectFile *O, ArrayRef< uint8_t > Opcodes, bool is64Bit, MachOBindEntry::Kind)
LLVM_ABI StringRef segmentName() const
LLVM_ABI uint64_t segmentOffset() const
LLVM_ABI int64_t addend() const
LLVM_ABI uint64_t address() const
friend class MachOObjectFile
LLVM_ABI int32_t segmentIndex() const
LLVM_ABI StringRef typeName() const
LLVM_ABI bool operator==(const MachOChainedFixupEntry &) const
LLVM_ABI MachOChainedFixupEntry(Error *Err, const MachOObjectFile *O, bool Parse)
LLVM_ABI void moveToEnd()
LLVM_ABI void moveToFirst()
void moveSectionNext(DataRefImpl &Sec) const override
static std::string getVersionString(uint32_t version)
MachO::mach_header_64 Header64
bool isSectionData(DataRefImpl Sec) const override
uint64_t getSectionAlignment(DataRefImpl Sec) const override
Expected< SectionRef > getSection(unsigned SectionIndex) const
std::error_code getIndirectName(DataRefImpl Symb, StringRef &Res) const
Expected< section_iterator > getSymbolSection(DataRefImpl Symb) const override
const char * RebaseEntryCheckSegAndOffsets(int32_t SegIndex, uint64_t SegOffset, uint8_t PointerSize, uint64_t Count=1, uint64_t Skip=0) const
void moveSymbolNext(DataRefImpl &Symb) const override
MachO::mach_header Header
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override
relocation_iterator section_rel_begin(DataRefImpl Sec) const override
static std::string getBuildTool(uint32_t tools)
ArrayRef< uint8_t > getSectionContents(uint32_t Offset, uint64_t Size) const
const char * BindEntryCheckSegAndOffsets(int32_t SegIndex, uint64_t SegOffset, uint8_t PointerSize, uint64_t Count=1, uint64_t Skip=0) const
Error checkSymbolTable() const
static std::string getBuildPlatform(uint32_t platform)
relocation_iterator section_rel_end(DataRefImpl Sec) const override
static bool classof(const Binary *v)
unsigned getSectionType(SectionRef Sec) const
static Expected< std::unique_ptr< MachOObjectFile > > create(MemoryBufferRef Object, bool IsLittleEndian, bool Is64Bits, uint32_t UniversalCputype=0, uint32_t UniversalIndex=0, size_t MachOFilesetEntryOffset=0)
Expected< uint32_t > getSymbolFlags(DataRefImpl Symb) const override
bool isSectionBSS(DataRefImpl Sec) const override
bool isSectionVirtual(DataRefImpl Sec) const override
LoadCommandList::const_iterator load_command_iterator
iterator_range< relocation_iterator > external_relocations() const
static bool isMachOPairedReloc(uint64_t RelocType, uint64_t Arch)
static uint32_t getVersionMinUpdate(MachO::version_min_command &C, bool SDK)
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 BindRebaseSegmentName(int32_t SegIndex) const
For use with the SegIndex of a checked Mach-O Bind or Rebase entry to get the segment name.
relocation_iterator extrel_begin() const
SmallVector< LoadCommandInfo, 4 > LoadCommandList
MachO::data_in_code_entry getDice(DataRefImpl Rel) const
bool isSectionStripped(DataRefImpl Sec) const override
When dsymutil generates the companion file, it strips all unnecessary sections (e....
uint64_t getSectionIndex(DataRefImpl Sec) 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 ...
static uint32_t getVersionMinMajor(MachO::version_min_command &C, bool SDK)
uint64_t getSectionAddress(DataRefImpl Sec) const override
bool hasPageZeroSegment() const
Expected< StringRef > getSectionName(DataRefImpl Sec) const override
bool isSectionText(DataRefImpl Sec) const override
bool isSectionCompressed(DataRefImpl Sec) const override
bool isSectionBitcode(DataRefImpl Sec) const override
Expected< SubtargetFeatures > getFeatures() const override
uint32_t getSymbolAlignment(DataRefImpl Symb) const override
uint64_t getNValue(DataRefImpl Sym) const
ArrayRef< uint8_t > getSegmentContents(StringRef SegmentName) const
Return the raw contents of an entire segment.
static uint32_t getVersionMinMinor(MachO::version_min_command &C, bool SDK)
Expected< uint64_t > getSymbolAddress(DataRefImpl Symb) const override
size_t getMachOFilesetEntryOffset() const
uint64_t getSectionSize(DataRefImpl Sec) const override
relocation_iterator extrel_end() const
LLVM_ABI int32_t segmentIndex() const
LLVM_ABI StringRef segmentName() const
LLVM_ABI MachORebaseEntry(Error *Err, const MachOObjectFile *O, ArrayRef< uint8_t > opcodes, bool is64Bit)
LLVM_ABI bool operator==(const MachORebaseEntry &) const
LLVM_ABI uint64_t address() const
LLVM_ABI StringRef sectionName() const
friend class MachOObjectFile
LLVM_ABI uint64_t segmentOffset() const
LLVM_ABI StringRef typeName() const
This class is the base class for all object file types.
ObjectFile(unsigned int Type, MemoryBufferRef Source)
This is a value type class that represents a single section in the list of sections in the object fil...
A raw_ostream that writes to an std::string.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
@ C
The default llvm calling convention, compatible with C.
@ BIND_SPECIAL_DYLIB_WEAK_LOOKUP
Expected< const typename ELFT::Shdr * > getSection(typename ELFT::ShdrRange Sections, uint32_t Index)
content_iterator< SectionRef > section_iterator
content_iterator< MachOBindEntry > bind_iterator
content_iterator< MachOChainedFixupEntry > fixup_iterator
content_iterator< MachORebaseEntry > rebase_iterator
content_iterator< BasicSymbolRef > basic_symbol_iterator
content_iterator< ExportEntry > export_iterator
content_iterator< RelocationRef > relocation_iterator
content_iterator< DiceRef > dice_iterator
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
std::string utostr(uint64_t X, bool isNeg=false)
FunctionAddr VTableAddr uintptr_t uintptr_t Version
static Lanai::Fixups FixupKind(const MCExpr *Expr)
FunctionAddr VTableAddr Count
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
ChainedFixupTarget(int LibOrdinal, uint32_t NameOffset, StringRef Symbol, uint64_t Addend, bool WeakImport)
MachO::dyld_chained_starts_in_segment Header
std::vector< uint16_t > PageStarts
ChainedFixupsSegment(uint8_t SegIdx, uint32_t Offset, const MachO::dyld_chained_starts_in_segment &Header, std::vector< uint16_t > &&PageStarts)