13#ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDCOFF86_64_H
14#define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDCOFF86_64_H
16#include "../RuntimeDyldCOFF.h"
20#define DEBUG_TYPE "dyld"
37 ImageBase = std::numeric_limits<uint64_t>::max();
44 if (Section.getLoadAddress() != 0)
45 ImageBase = std::min(ImageBase, Section.getLoadAddress());
52 assert(Result <= UINT32_MAX &&
"Relocation overflow");
99 uint64_t FinalAddress = Section.getLoadAddressWithOffset(RE.
Offset);
103 Value -= FinalAddress + Delta;
105 assert(((int64_t)Result <= INT32_MAX) &&
"Relocation overflow");
106 assert(((int64_t)Result >= INT32_MIN) &&
"Relocation underflow");
115 const uint64_t ImageBase = getImageBase();
116 if (
Value < ImageBase || ((
Value - ImageBase) > UINT32_MAX))
118 "ordered section layout");
131 assert(
static_cast<int64_t
>(RE.
Addend) <= INT32_MAX &&
"Relocation overflow");
132 assert(
static_cast<int64_t
>(RE.
Addend) >= INT32_MIN &&
"Relocation underflow");
138 assert(
static_cast<int16_t
>(RE.
SectionID) <= INT16_MAX &&
"Relocation overflow");
139 assert(
static_cast<int16_t
>(RE.
SectionID) >= INT16_MIN &&
"Relocation underflow");
150 std::tuple<uint64_t, uint64_t, uint64_t>
154 uintptr_t StubOffset;
158 OriginalRelValueRef.
SectionID = SectionID;
160 OriginalRelValueRef.
Addend = Addend;
163 auto Stub = Stubs.find(OriginalRelValueRef);
164 if (Stub == Stubs.end()) {
166 << TargetName.
data() <<
"\n");
168 StubOffset = Section.getStubOffset();
169 Stubs[OriginalRelValueRef] = StubOffset;
175 StubOffset = Stub->second;
193 return std::make_tuple(
Offset, RelType, Addend);
207 auto SectionOrError = Symbol->getSection();
209 return SectionOrError.takeError();
219 uintptr_t ObjTarget = Section.getObjAddress() +
Offset;
222 if (!TargetNameOrErr)
226 unsigned TargetSectionID = 0;
230 assert(IsExtern &&
"DLLImport not marked extern?");
231 TargetSectionID = SectionID;
235 }
else if (!IsExtern) {
236 if (
auto TargetSectionIDOrErr =
238 TargetSectionID = *TargetSectionIDOrErr;
240 return TargetSectionIDOrErr.takeError();
258 SectionID, TargetName,
Offset, RelType, Addend, Stubs);
274 <<
" RelType: " << RelType <<
" TargetName: "
275 << TargetName <<
" Addend " << Addend <<
"\n");
289 for (
auto const &EHFrameSID : UnregisteredEHFrameSections) {
292 size_t EHFrameSize =
Sections[EHFrameSID].getSize();
294 RegisteredEHFrameSections.
push_back(EHFrameSID);
296 UnregisteredEHFrameSections.clear();
302 for (
const auto &SectionPair : SectionMap) {
311 if ((*NameOrErr) ==
".pdata")
312 UnregisteredEHFrameSections.
push_back(SectionPair.second);
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.
uint32_t RelType
RelType - relocation type.
uint64_t Offset
Offset - offset into the section.
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.
void registerEHFrames() override
void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override
A object file specific relocation resolver.
unsigned getMaxStubSize() const override
RuntimeDyldCOFFX86_64(RuntimeDyld::MemoryManager &MM, JITSymbolResolver &Resolver)
Align getStubAlignment() override
Error finalizeLoad(const object::ObjectFile &Obj, ObjSectionToIDMap &SectionMap) override
std::tuple< uint64_t, uint64_t, uint64_t > generateRelocationStub(unsigned SectionID, StringRef TargetName, uint64_t Offset, uint64_t RelType, uint64_t Addend, StubMap &Stubs)
Expected< object::relocation_iterator > processRelocationRef(unsigned SectionID, object::relocation_iterator RelI, const object::ObjectFile &Obj, ObjSectionToIDMap &ObjSectionToID, StubMap &Stubs) override
Parses one or more object file relocations (some object files use relocation pairs) and stores it to ...
uint64_t getSymbolOffset(const SymbolRef &Sym)
static constexpr StringRef getImportSymbolPrefix()
uint64_t getDLLImportOffset(unsigned SectionID, StubMap &Stubs, StringRef Name, bool SetSectionIDMinus1=false)
std::map< SectionRef, unsigned > ObjSectionToIDMap
std::map< RelocationValueRef, uintptr_t > StubMap
void addRelocationForSymbol(const RelocationEntry &RE, StringRef SymbolName)
RuntimeDyld::MemoryManager & MemMgr
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.
uint8_t * createStubFunction(uint8_t *Addr, unsigned AbiVariant=0)
Emits long jump instruction to Addr.
uint64_t readBytesUnaligned(uint8_t *Src, unsigned Size) const
Endian-aware read Read the least significant Size bytes from Src.
virtual void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size)=0
Register the EH frames with the runtime so that c++ exceptions work.
SectionEntry - represents a section emitted into memory by the dynamic linker.
void push_back(const T &Elt)
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.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Target - Wrapper for Target specific information.
LLVM Value Representation.
This class is the base class for all object file types.
virtual section_iterator section_end() const =0
This is a value type class that represents a single section in the list of sections in the object fil...
bool isText() const
Whether this section contains instructions.
virtual basic_symbol_iterator symbol_end() const =0
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ IMAGE_REL_AMD64_REL32_5
@ IMAGE_REL_AMD64_REL32_3
@ IMAGE_REL_AMD64_ADDR32NB
@ IMAGE_REL_AMD64_SECTION
@ IMAGE_REL_AMD64_REL32_2
@ IMAGE_REL_AMD64_REL32_1
@ IMAGE_REL_AMD64_REL32_4
This is an optimization pass for GlobalISel generic memory operations.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This struct is a compact representation of a valid (non-zero power of two) alignment.