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" 35 uint64_t getImageBase() {
44 if (
Section.getLoadAddress() != 0)
45 ImageBase = std::min(ImageBase,
Section.getLoadAddress());
50 void write32BitOffset(uint8_t *
Target, int64_t Addend, uint64_t Delta) {
51 uint64_t Result = Addend + Delta;
52 assert(Result <= UINT32_MAX &&
"Relocation overflow");
102 Value -= FinalAddress + Delta;
103 uint64_t Result = Value + RE.
Addend;
104 assert(((int64_t)Result <= INT32_MAX) &&
"Relocation overflow");
105 assert(((int64_t)Result >= INT32_MIN) &&
"Relocation underflow");
114 const uint64_t ImageBase = getImageBase();
115 if (Value < ImageBase || ((Value - ImageBase) > UINT32_MAX)) {
116 llvm::errs() <<
"IMAGE_REL_AMD64_ADDR32NB relocation requires an" 117 <<
"ordered section layout.\n";
118 write32BitOffset(Target, 0, 0);
120 write32BitOffset(Target, RE.
Addend, Value - ImageBase);
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>
145 uint64_t
Offset, uint64_t RelType, uint64_t Addend,
147 uintptr_t StubOffset;
151 OriginalRelValueRef.
SectionID = SectionID;
153 OriginalRelValueRef.
Addend = Addend;
156 auto Stub = Stubs.find(OriginalRelValueRef);
157 if (Stub == Stubs.end()) {
159 << TargetName.
data() <<
"\n");
162 Stubs[OriginalRelValueRef] = StubOffset;
168 StubOffset = Stub->second;
183 Offset = StubOffset + 6;
186 return std::make_tuple(Offset, RelType, Addend);
202 return SectionOrError.takeError();
208 uint64_t RelType = RelI->getType();
209 uint64_t
Offset = RelI->getOffset();
215 if (!TargetNameOrErr)
228 uint8_t *Displacement = (uint8_t *)ObjTarget;
233 SectionID, TargetName, Offset, RelType, Addend, Stubs);
239 uint8_t *Displacement = (uint8_t *)ObjTarget;
248 LLVM_DEBUG(
dbgs() <<
"\t\tIn Section " << SectionID <<
" Offset " << Offset
249 <<
" RelType: " << RelType <<
" TargetName: " 250 << TargetName <<
" Addend " << Addend <<
"\n");
256 bool IsCode = SecI->isText();
257 unsigned TargetSectionID;
258 if (
auto TargetSectionIDOrErr =
260 TargetSectionID = *TargetSectionIDOrErr;
262 return TargetSectionIDOrErr.takeError();
272 for (
auto const &EHFrameSID : UnregisteredEHFrameSections) {
273 uint8_t *EHFrameAddr =
Sections[EHFrameSID].getAddress();
274 uint64_t EHFrameLoadAddr =
Sections[EHFrameSID].getLoadAddress();
275 size_t EHFrameSize =
Sections[EHFrameSID].getSize();
277 RegisteredEHFrameSections.
push_back(EHFrameSID);
279 UnregisteredEHFrameSections.clear();
285 for (
const auto &SectionPair : SectionMap) {
288 if (
auto EC = Section.
getName(Name))
294 if (Name ==
".pdata")
295 UnregisteredEHFrameSections.
push_back(SectionPair.second);
RelocationEntry - used to represent relocations internally in the dynamic linker. ...
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
Expected< StringRef > getName() const
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
void push_back(const T &Elt)
uint64_t readBytesUnaligned(uint8_t *Src, unsigned Size) const
Endian-aware read Read the least significant Size bytes from Src.
uint64_t getLoadAddressWithOffset(unsigned OffsetBytes) const
Return the load address of this section with an offset.
RuntimeDyld::MemoryManager & MemMgr
This class is the base class for all object file types.
uint64_t getSymbolOffset(const SymbolRef &Sym)
Error takeError()
Take ownership of the stored error.
void writeBytesUnaligned(uint64_t Value, uint8_t *Dst, unsigned Size) const
Endian-aware write.
unsigned getStubAlignment() override
unsigned SectionID
SectionID - the section this relocation points to.
std::map< RelocationValueRef, uintptr_t > StubMap
Tagged union holding either a T or a Error.
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 ...
RuntimeDyldCOFFX86_64(RuntimeDyld::MemoryManager &MM, JITSymbolResolver &Resolver)
Expected< section_iterator > getSection() const
Get section this symbol is defined in reference to.
void addRelocationForSymbol(const RelocationEntry &RE, StringRef SymbolName)
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
void addRelocationForSection(const RelocationEntry &RE, unsigned SectionID)
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override
A object file specific relocation resolver.
Symbol resolution interface.
Error finalizeLoad(const object::ObjectFile &Obj, ObjSectionToIDMap &SectionMap) override
virtual basic_symbol_iterator symbol_end() const =0
uintptr_t getObjAddress() const
Expected< unsigned > findOrEmitSection(const ObjectFile &Obj, const SectionRef &Section, bool IsCode, ObjSectionToIDMap &LocalSections)
Find Section in LocalSections.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static ErrorSuccess success()
Create a success value.
int64_t Addend
Addend - the relocation addend encoded in the instruction itself.
std::error_code getName(StringRef &Result) const
uint32_t RelType
RelType - relocation type.
uint8_t * createStubFunction(uint8_t *Addr, unsigned AbiVariant=0)
Emits long jump instruction to Addr.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Target - Wrapper for Target specific information.
uintptr_t getStubOffset() const
std::tuple< uint64_t, uint64_t, uint64_t > generateRelocationStub(unsigned SectionID, StringRef TargetName, uint64_t Offset, uint64_t RelType, uint64_t Addend, StubMap &Stubs)
uint64_t Offset
Offset - offset into the section.
virtual section_iterator section_end() const =0
std::map< SectionRef, unsigned > ObjSectionToIDMap
uint8_t * getAddressWithOffset(unsigned OffsetBytes) const
Return the address of this section with an offset.
SectionEntry - represents a section emitted into memory by the dynamic linker.
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Lightweight error class with error context and mandatory checking.
void advanceStubOffset(unsigned StubSize)
StringRef - Represent a constant reference to a string, i.e.
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.
void registerEHFrames() override
This is a value type class that represents a single section in the list of sections in the object fil...
unsigned getMaxStubSize() override