14 #ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDCOFF86_64_H 15 #define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDCOFF86_64_H 17 #include "../RuntimeDyldCOFF.h" 21 #define DEBUG_TYPE "dyld" 36 uint64_t getImageBase() {
45 if (
Section.getLoadAddress() != 0)
46 ImageBase = std::min(ImageBase,
Section.getLoadAddress());
51 void write32BitOffset(uint8_t *
Target, int64_t Addend, uint64_t Delta) {
52 uint64_t Result = Addend + Delta;
53 assert(Result <= UINT32_MAX &&
"Relocation overflow");
103 Value -= FinalAddress + Delta;
104 uint64_t Result = Value + RE.
Addend;
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)) {
117 llvm::errs() <<
"IMAGE_REL_AMD64_ADDR32NB relocation requires an" 118 <<
"ordered section layout.\n";
119 write32BitOffset(Target, 0, 0);
121 write32BitOffset(Target, RE.
Addend, Value - ImageBase);
132 assert(static_cast<int64_t>(RE.
Addend) <= INT32_MAX &&
"Relocation overflow");
133 assert(static_cast<int64_t>(RE.
Addend) >= INT32_MIN &&
"Relocation underflow");
144 std::tuple<uint64_t, uint64_t, uint64_t>
146 uint64_t
Offset, uint64_t RelType, uint64_t Addend,
148 uintptr_t StubOffset;
152 OriginalRelValueRef.
SectionID = SectionID;
154 OriginalRelValueRef.
Addend = Addend;
157 auto Stub = Stubs.find(OriginalRelValueRef);
158 if (Stub == Stubs.end()) {
160 << TargetName.
data() <<
"\n");
163 Stubs[OriginalRelValueRef] = StubOffset;
169 StubOffset = Stub->second;
184 Offset = StubOffset + 6;
187 return std::make_tuple(Offset, RelType, Addend);
203 return SectionOrError.takeError();
209 uint64_t RelType = RelI->getType();
210 uint64_t
Offset = RelI->getOffset();
216 if (!TargetNameOrErr)
229 uint8_t *Displacement = (uint8_t *)ObjTarget;
234 SectionID, TargetName, Offset, RelType, Addend, Stubs);
240 uint8_t *Displacement = (uint8_t *)ObjTarget;
249 LLVM_DEBUG(
dbgs() <<
"\t\tIn Section " << SectionID <<
" Offset " << Offset
250 <<
" RelType: " << RelType <<
" TargetName: " 251 << TargetName <<
" Addend " << Addend <<
"\n");
257 bool IsCode = SecI->isText();
258 unsigned TargetSectionID;
259 if (
auto TargetSectionIDOrErr =
261 TargetSectionID = *TargetSectionIDOrErr;
263 return TargetSectionIDOrErr.takeError();
273 for (
auto const &EHFrameSID : UnregisteredEHFrameSections) {
274 uint8_t *EHFrameAddr =
Sections[EHFrameSID].getAddress();
275 uint64_t EHFrameLoadAddr =
Sections[EHFrameSID].getLoadAddress();
276 size_t EHFrameSize =
Sections[EHFrameSID].getSize();
278 RegisteredEHFrameSections.
push_back(EHFrameSID);
280 UnregisteredEHFrameSections.clear();
286 for (
const auto &SectionPair : SectionMap) {
289 if (
auto EC = Section.
getName(Name))
295 if (Name ==
".pdata")
296 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
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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
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.
amdgpu Simplify well known AMD library false Value Value const Twine & Name
std::map< RelocationValueRef, uintptr_t > StubMap
Tagged union holding either a T or a Error.
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.
virtual basic_symbol_iterator symbol_end() const =0
uintptr_t getObjAddress() const
Error finalizeLoad(const ObjectFile &Obj, ObjSectionToIDMap &SectionMap) override
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)
Expected< relocation_iterator > processRelocationRef(unsigned SectionID, relocation_iterator RelI, const 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 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.
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