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);
427 void moveSymbolNext(
DataRefImpl &Symb)
const override;
433 Error checkSymbolTable()
const;
436 unsigned getSectionType(
SectionRef Sec)
const;
447 void moveSectionNext(
DataRefImpl &Sec)
const override;
454 getSectionContents(
DataRefImpl Sec)
const override;
458 bool isSectionCompressed(
DataRefImpl Sec)
const override;
459 bool isSectionText(
DataRefImpl Sec)
const override;
460 bool isSectionData(
DataRefImpl Sec)
const override;
462 bool isSectionVirtual(
DataRefImpl Sec)
const override;
463 bool isSectionBitcode(
DataRefImpl Sec)
const override;
477 bool isSectionStripped(
DataRefImpl Sec)
const override;
485 return make_range(extrel_begin(), extrel_end());
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"
813 case MachO::TOOL_CLANG:
return "clang";
814 case MachO::TOOL_SWIFT:
return "swift";
815 case MachO::TOOL_LD:
return "ld";
816 case MachO::TOOL_LLD:
827 uint32_t major = (version >> 16) & 0xffff;
828 uint32_t minor = (version >> 8) & 0xff;
832 Version = utostr(major) +
"." + utostr(minor);
834 Version +=
"." + utostr(update);
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();
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static StringRef getSymbolName(SymbolKind SymKind)
static bool isDebugSection(const SectionBase &Sec)
std::optional< std::vector< StOtherPiece > > Other
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)
static Constant * SegmentOffset(IRBuilderBase &IRB, int Offset, unsigned AddressSpace)
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 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)
DiceRef - This is a value type class that represents a single data in code entry in the table in a Ma...
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
ExportEntry encapsulates the current-state-of-the-walk used when doing a non-recursive walk of the tr...
LLVM_ABI StringRef name() const
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
LLVM_ABI uint64_t other() const
MachOAbstractFixupEntry is an abstract class representing a fixup in a MH_DYLDLINK file.
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
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 StringRef symbolName() const
LLVM_ABI int ordinal() const
LLVM_ABI StringRef sectionName() const
LLVM_ABI StringRef segmentName() const
LLVM_ABI uint64_t segmentOffset() const
LLVM_ABI int64_t addend() const
LLVM_ABI uint64_t address() const
LLVM_ABI int32_t segmentIndex() const
LLVM_ABI StringRef typeName() const
LLVM_ABI void moveToEnd()
LLVM_ABI void moveToFirst()
static std::string getVersionString(uint32_t version)
MachO::mach_header_64 Header64
const char * RebaseEntryCheckSegAndOffsets(int32_t SegIndex, uint64_t SegOffset, uint8_t PointerSize, uint64_t Count=1, uint64_t Skip=0) const
MachO::mach_header Header
static std::string getBuildTool(uint32_t tools)
const char * BindEntryCheckSegAndOffsets(int32_t SegIndex, uint64_t SegOffset, uint8_t PointerSize, uint64_t Count=1, uint64_t Skip=0) const
static std::string getBuildPlatform(uint32_t platform)
static bool classof(const Binary *v)
iterator_range< relocation_iterator > external_relocations() const
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.
MachO::data_in_code_entry getDice(DataRefImpl Rel) 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 ...
static uint32_t getVersionMinMajor(MachO::version_min_command &C, bool SDK)
bool hasPageZeroSegment() const
Expected< SubtargetFeatures > getFeatures() const override
static uint32_t getVersionMinMinor(MachO::version_min_command &C, bool SDK)
size_t getMachOFilesetEntryOffset() const
MachORebaseEntry encapsulates the current state in the decompression of rebasing opcodes.
LLVM_ABI int32_t segmentIndex() const
LLVM_ABI StringRef segmentName() const
LLVM_ABI bool operator==(const MachORebaseEntry &) const
LLVM_ABI uint64_t address() const
LLVM_ABI StringRef sectionName() const
LLVM_ABI uint64_t segmentOffset() const
LLVM_ABI StringRef typeName() const
This class is the base class for all object file types.
This is a value type class that represents a single section in the list of sections in the object fil...
This is a value type class that represents a single symbol in the list of symbols in the object file.
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.
@ BIND_SPECIAL_DYLIB_WEAK_LOOKUP
Expected< const typename ELFT::Shdr * > getSection(typename ELFT::ShdrRange Sections, uint32_t Index)
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.
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
ChainedFixupTarget holds all the information about an external symbol necessary to bind this binary t...
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)