Go to the documentation of this file.
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"
44 if (Section.getLoadAddress() != 0)
45 ImageBase =
std::min(ImageBase, Section.getLoadAddress());
50 void write32BitOffset(uint8_t *
Target, int64_t Addend,
uint64_t Delta) {
52 assert(Result <= UINT32_MAX &&
"Relocation overflow");
89 uint8_t *
Target = Section.getAddressWithOffset(RE.
Offset);
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");
143 std::tuple<uint64_t, uint64_t, uint64_t>
147 uintptr_t StubOffset;
151 OriginalRelValueRef.
SectionID = SectionID;
152 OriginalRelValueRef.
Offset = Offset;
153 OriginalRelValueRef.
Addend = Addend;
156 auto Stub = Stubs.find(OriginalRelValueRef);
157 if (Stub == Stubs.end()) {
159 << TargetName.
data() <<
"\n");
161 StubOffset = Section.getStubOffset();
162 Stubs[OriginalRelValueRef] = StubOffset;
168 StubOffset = Stub->second;
183 Offset = StubOffset + 6;
186 return std::make_tuple(Offset, RelType, Addend);
200 auto SectionOrError =
Symbol->getSection();
202 return SectionOrError.takeError();
209 uint64_t Offset = RelI->getOffset();
212 uintptr_t ObjTarget = Section.getObjAddress() + Offset;
215 if (!TargetNameOrErr)
219 unsigned TargetSectionID = 0;
223 assert(IsExtern &&
"DLLImport not marked extern?");
224 TargetSectionID = SectionID;
228 }
else if (!IsExtern) {
229 if (
auto TargetSectionIDOrErr =
231 TargetSectionID = *TargetSectionIDOrErr;
233 return TargetSectionIDOrErr.takeError();
246 uint8_t *Displacement = (uint8_t *)ObjTarget;
251 SectionID, TargetName, Offset, RelType, Addend, Stubs);
257 uint8_t *Displacement = (uint8_t *)ObjTarget;
266 LLVM_DEBUG(
dbgs() <<
"\t\tIn Section " << SectionID <<
" Offset " << Offset
267 <<
" RelType: " << RelType <<
" TargetName: "
268 << TargetName <<
" Addend " << Addend <<
"\n");
282 for (
auto const &EHFrameSID : UnregisteredEHFrameSections) {
283 uint8_t *EHFrameAddr =
Sections[EHFrameSID].getAddress();
285 size_t EHFrameSize =
Sections[EHFrameSID].getSize();
287 RegisteredEHFrameSections.push_back(EHFrameSID);
289 UnregisteredEHFrameSections.
clear();
295 for (
const auto &SectionPair : SectionMap) {
304 if ((*NameOrErr) ==
".pdata")
305 UnregisteredEHFrameSections.push_back(SectionPair.second);
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
RuntimeDyldCOFFX86_64(RuntimeDyld::MemoryManager &MM, JITSymbolResolver &Resolver)
This is an optimization pass for GlobalISel generic memory operations.
RuntimeDyld::MemoryManager & MemMgr
void registerEHFrames() override
Target - Wrapper for Target specific information.
std::tuple< uint64_t, uint64_t, uint64_t > generateRelocationStub(unsigned SectionID, StringRef TargetName, uint64_t Offset, uint64_t RelType, uint64_t Addend, StubMap &Stubs)
static ErrorSuccess success()
Create a success value.
void addRelocationForSection(const RelocationEntry &RE, unsigned SectionID)
unsigned getMaxStubSize() const override
Tagged union holding either a T or a Error.
void addRelocationForSymbol(const RelocationEntry &RE, StringRef SymbolName)
unsigned SectionID
SectionID - the section this relocation points to.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
virtual basic_symbol_iterator symbol_end() const =0
unsigned getStubAlignment() override
uint64_t Offset
Offset - offset into the section.
virtual section_iterator section_end() const =0
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
void writeBytesUnaligned(uint64_t Value, uint8_t *Dst, unsigned Size) const
Endian-aware write.
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.
int64_t Addend
Addend - the relocation addend encoded in the instruction itself.
This is a value type class that represents a single section in the list of sections in the object fil...
RelocationEntry - used to represent relocations internally in the dynamic linker.
@ IMAGE_REL_AMD64_REL32_4
@ IMAGE_REL_AMD64_REL32_5
SectionEntry - represents a section emitted into memory by the dynamic linker.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
uint64_t getDLLImportOffset(unsigned SectionID, StubMap &Stubs, StringRef Name, bool SetSectionIDMinus1=false)
static constexpr StringRef getImportSymbolPrefix()
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
uint64_t getSymbolOffset(const SymbolRef &Sym)
StringRef - Represent a constant reference to a string, i.e.
This class is the base class for all object file types.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ IMAGE_REL_AMD64_REL32_2
uint8_t * createStubFunction(uint8_t *Addr, unsigned AbiVariant=0)
Emits long jump instruction to Addr.
Symbol resolution interface.
Expected< unsigned > findOrEmitSection(const ObjectFile &Obj, const SectionRef &Section, bool IsCode, ObjSectionToIDMap &LocalSections)
Find Section in LocalSections.
Lightweight error class with error context and mandatory checking.
@ IMAGE_REL_AMD64_ADDR32NB
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 ...
Error finalizeLoad(const object::ObjectFile &Obj, ObjSectionToIDMap &SectionMap) override
@ IMAGE_REL_AMD64_REL32_1
void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override
A object file specific relocation resolver.
Error takeError()
Take ownership of the stored error.
@ IMAGE_REL_AMD64_REL32_3
Align max(MaybeAlign Lhs, Align Rhs)
uint64_t readBytesUnaligned(uint8_t *Src, unsigned Size) const
Endian-aware read Read the least significant Size bytes from Src.
const LLVM_NODISCARD char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
std::map< RelocationValueRef, uintptr_t > StubMap
LLVM Value Representation.
uint32_t RelType
RelType - relocation type.
std::map< SectionRef, unsigned > ObjSectionToIDMap