9#ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDMACHOX86_64_H
10#define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDMACHOX86_64_H
14#define DEBUG_TYPE "dyld"
44 return processSubtractRelocation(SectionID, RelI, Obj, ObjSectionToID);
47 "Scattered relocations not supported on X86_64");
55 return ValueOrErr.takeError();
67 " is out of range").str());
73 processGOTRelocation(RE,
Value, Stubs);
88 uint8_t *LocalAddress = Section.getAddressWithOffset(RE.
Offset);
95 uint64_t FinalAddress = Section.getLoadAddressWithOffset(RE.
Offset);
96 Value -= FinalAddress + 4;
114 "Unexpected SUBTRACTOR relocation value.");
134 RuntimeDyldMachO::StubMap::const_iterator i = Stubs.find(
Value);
136 if (i != Stubs.end()) {
137 Addr = Section.getAddressWithOffset(i->second);
139 Stubs[
Value] = Section.getStubOffset();
140 uint8_t *GOTEntry = Section.getAddressWithOffset(Section.getStubOffset());
144 if (
Value.SymbolName)
148 Section.advanceStubOffset(8);
156 Expected<relocation_iterator>
158 const MachOObjectFile &BaseObj,
160 const MachOObjectFile &Obj = BaseObj;
161 MachO::any_relocation_info RE =
166 uint8_t *LocalAddress =
Sections[SectionID].getAddressWithOffset(
Offset);
167 unsigned NumBytes = 1 <<
Size;
171 unsigned SectionBID = ~0
U;
172 uint64_t SectionBOffset = 0;
174 MachO::any_relocation_info RelInfo =
181 if (!SubtrahendNameOrErr)
184 SectionBID = SubtrahendI->second.getSectionID();
185 SectionBOffset = SubtrahendI->second.getOffset();
188 bool IsCode = SecB.
isText();
189 Expected<unsigned> SectionBIDOrErr =
191 if (!SectionBIDOrErr)
193 SectionBID = *SectionBIDOrErr;
199 unsigned SectionAID = ~0
U;
200 uint64_t SectionAOffset = 0;
207 if (!MinuendNameOrErr)
210 SectionAID = MinuendI->second.getSectionID();
211 SectionAOffset = MinuendI->second.getOffset();
214 bool IsCode = SecA.
isText();
215 Expected<unsigned> SectionAIDOrErr =
217 if (!SectionAIDOrErr)
219 SectionAID = *SectionAIDOrErr;
224 SectionAID, SectionAOffset, SectionBID, SectionBOffset,
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define UNIMPLEMENTED_RELOC(RelType)
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
Symbol resolution interface.
RelocationEntry - used to represent relocations internally in the dynamic linker.
unsigned Size
The size of this relocation (MachO specific).
uint32_t RelType
RelType - relocation type.
uint64_t Offset
Offset - offset into the section.
bool IsPCRel
True if this is a PCRel relocation (MachO specific).
int64_t Addend
Addend - the relocation addend encoded in the instruction itself.
unsigned SectionID
SectionID - the section this relocation points to.
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
std::map< SectionRef, unsigned > ObjSectionToIDMap
std::map< RelocationValueRef, uintptr_t > StubMap
void addRelocationForSymbol(const RelocationEntry &RE, StringRef SymbolName)
void addRelocationForSection(const RelocationEntry &RE, unsigned SectionID)
Expected< unsigned > findOrEmitSection(const ObjectFile &Obj, const SectionRef &Section, bool IsCode, ObjSectionToIDMap &LocalSections)
Find Section in LocalSections.
void writeBytesUnaligned(uint64_t Value, uint8_t *Dst, unsigned Size) const
Endian-aware write.
uint64_t readBytesUnaligned(uint8_t *Src, unsigned Size) const
Endian-aware read Read the least significant Size bytes from Src.
RTDyldSymbolTable GlobalSymbolTable
RuntimeDyldMachOCRTPBase(RuntimeDyld::MemoryManager &MemMgr, JITSymbolResolver &Resolver)
Expected< relocation_iterator > processRelocationRef(unsigned SectionID, relocation_iterator RelI, const ObjectFile &BaseObjT, ObjSectionToIDMap &ObjSectionToID, StubMap &Stubs) override
Parses one or more object file relocations (some object files use relocation pairs) and stores it to ...
unsigned getMaxStubSize() const override
Align getStubAlignment() override
void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override
A object file specific relocation resolver.
Error finalizeSection(const ObjectFile &Obj, unsigned SectionID, const SectionRef &Section)
RuntimeDyldMachOX86_64(RuntimeDyld::MemoryManager &MM, JITSymbolResolver &Resolver)
int64_t memcpyAddend(const RelocationEntry &RE) const
This convenience method uses memcpy to extract a contiguous addend (the addend size and offset are ta...
void makeValueAddendPCRel(RelocationValueRef &Value, const relocation_iterator &RI, unsigned OffsetToNextPC)
Make the RelocationValueRef addend PC-relative.
RelocationEntry getRelocationEntry(unsigned SectionID, const ObjectFile &BaseTObj, const relocation_iterator &RI) const
Given a relocation_iterator for a non-scattered relocation, construct a RelocationEntry and fill in t...
Expected< RelocationValueRef > getRelocationValueRef(const ObjectFile &BaseTObj, const relocation_iterator &RI, const RelocationEntry &RE, ObjSectionToIDMap &ObjSectionToID)
Construct a RelocationValueRef representing the relocation target.
void dumpRelocationToResolve(const RelocationEntry &RE, uint64_t Value) const
Dump information about the relocation entry (RE) and resolved value.
SectionEntry - represents a section emitted into memory by the dynamic linker.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
SectionRef getAnyRelocationSection(const MachO::any_relocation_info &RE) const
unsigned getAnyRelocationType(const MachO::any_relocation_info &RE) const
bool getPlainRelocationExternal(const MachO::any_relocation_info &RE) const
unsigned getAnyRelocationLength(const MachO::any_relocation_info &RE) const
MachO::any_relocation_info getRelocation(DataRefImpl Rel) const
bool isRelocationScattered(const MachO::any_relocation_info &RE) const
This class is the base class for all object file types.
uint64_t getOffset() const
symbol_iterator getSymbol() const
DataRefImpl getRawDataRefImpl() const
This is a value type class that represents a single section in the list of sections in the object fil...
uint64_t getAddress() const
bool isText() const
Whether this section contains instructions.
Expected< StringRef > getName() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ X86_64_RELOC_SUBTRACTOR
content_iterator< RelocationRef > relocation_iterator
This is an optimization pass for GlobalISel generic memory operations.
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
This struct is a compact representation of a valid (non-zero power of two) alignment.