14 #ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_RUNTIMEDYLDIMPL_H 15 #define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_RUNTIMEDYLDIMPL_H 31 #include <system_error> 32 #include <unordered_map> 41 #define UNIMPLEMENTED_RELOC(RelType) \ 43 return make_error<RuntimeDyldError>("Unimplemented relocation: " #RelType) 69 size_t AllocationSize;
77 size_t allocationSize, uintptr_t objAddress)
78 : Name(name), Address(address), Size(size),
79 LoadAddress(reinterpret_cast<uintptr_t>(address)), StubOffset(size),
80 AllocationSize(allocationSize), ObjAddress(objAddress) {
92 assert(OffsetBytes <= AllocationSize &&
"Offset out of bounds!");
93 return Address + OffsetBytes;
103 assert(OffsetBytes <= AllocationSize &&
"Offset out of bounds!");
104 return LoadAddress + OffsetBytes;
110 StubOffset += StubSize;
111 assert(StubOffset <= AllocationSize &&
"Not enough space allocated!");
153 bool IsTargetThumbFunc =
false;
156 : SectionID(id), Offset(offset), RelType(type), Addend(addend),
157 SymOffset(0), IsPCRel(
false), Size(0), IsTargetThumbFunc(
false) {}
161 : SectionID(id), Offset(offset), RelType(type), Addend(addend),
162 SymOffset(symoffset), IsPCRel(
false), Size(0),
163 IsTargetThumbFunc(
false) {}
166 bool IsPCRel,
unsigned Size)
167 : SectionID(id), Offset(offset), RelType(type), Addend(addend),
168 SymOffset(0), IsPCRel(IsPCRel), Size(Size), IsTargetThumbFunc(
false) {}
171 unsigned SectionA, uint64_t SectionAOffset,
unsigned SectionB,
172 uint64_t SectionBOffset,
bool IsPCRel,
unsigned Size)
173 : SectionID(id), Offset(offset), RelType(type),
174 Addend(SectionAOffset - SectionBOffset + addend), IsPCRel(IsPCRel),
175 Size(Size), IsTargetThumbFunc(
false) {
176 Sections.SectionA = SectionA;
177 Sections.SectionB = SectionB;
181 unsigned SectionA, uint64_t SectionAOffset,
unsigned SectionB,
182 uint64_t SectionBOffset,
bool IsPCRel,
unsigned Size,
183 bool IsTargetThumbFunc)
184 : SectionID(id), Offset(offset), RelType(type),
185 Addend(SectionAOffset - SectionBOffset + addend), IsPCRel(IsPCRel),
186 Size(Size), IsTargetThumbFunc(IsTargetThumbFunc) {
187 Sections.SectionA = SectionA;
188 Sections.SectionB = SectionB;
198 bool IsStubThumb =
false;
200 SymbolName(nullptr) {}
210 if (Offset != Other.
Offset)
211 return Offset < Other.
Offset;
212 if (Addend != Other.
Addend)
213 return Addend < Other.
Addend;
226 : Offset(Offset), SectionID(SectionID), Flags(Flags) {}
236 unsigned SectionID = 0;
246 static const unsigned AbsoluteSymbolSection = ~0U;
263 #define RTDYLD_INVALID_SECTION_ID ((RuntimeDyldImpl::SID)(-1)) 292 typedef std::map<RelocationValueRef, uintptr_t>
StubMap;
316 virtual unsigned getMaxStubSize() = 0;
317 virtual unsigned getStubAlignment() = 0;
323 return Sections[SectionID].getLoadAddress();
327 return Sections[SectionID].getAddress();
331 if (IsTargetLittleEndian)
333 *Addr = (Value >> 8) & 0xFF;
334 *(Addr + 1) = Value & 0xFF;
338 if (IsTargetLittleEndian)
340 *Addr = (Value >> 24) & 0xFF;
341 *(Addr + 1) = (Value >> 16) & 0xFF;
342 *(Addr + 2) = (Value >> 8) & 0xFF;
343 *(Addr + 3) = Value & 0xFF;
347 if (IsTargetLittleEndian)
349 *Addr = (Value >> 56) & 0xFF;
350 *(Addr + 1) = (Value >> 48) & 0xFF;
351 *(Addr + 2) = (Value >> 40) & 0xFF;
352 *(Addr + 3) = (Value >> 32) & 0xFF;
353 *(Addr + 4) = (Value >> 24) & 0xFF;
354 *(Addr + 5) = (Value >> 16) & 0xFF;
355 *(Addr + 6) = (Value >> 8) & 0xFF;
356 *(Addr + 7) = Value & 0xFF;
360 IsMipsO32ABI =
false;
361 IsMipsN32ABI =
false;
362 IsMipsN64ABI =
false;
366 uint64_t readBytesUnaligned(uint8_t *Src,
unsigned Size)
const;
370 void writeBytesUnaligned(uint64_t
Value, uint8_t *Dst,
unsigned Size)
const;
388 CommonSymbolList &CommonSymbols, uint64_t CommonSize,
406 ObjSectionToIDMap &LocalSections);
409 void addRelocationForSection(
const RelocationEntry &RE,
unsigned SectionID);
417 uint8_t *createStubFunction(uint8_t *Addr,
unsigned AbiVariant = 0);
420 void resolveRelocationList(
const RelocationList &Relocs, uint64_t Value);
425 virtual void resolveRelocation(
const RelocationEntry &RE, uint64_t Value) = 0;
433 const ObjectFile &Obj, ObjSectionToIDMap &ObjSectionToID,
436 void applyExternalSymbolRelocations(
440 Error resolveExternalSymbols();
445 uint64_t &CodeSize,
uint32_t &CodeAlign,
446 uint64_t &RODataSize,
uint32_t &RODataAlign,
447 uint64_t &RWDataSize,
uint32_t &RWDataAlign);
450 unsigned computeGOTSize(
const ObjectFile &Obj);
453 unsigned computeSectionStubBufSize(
const ObjectFile &Obj,
475 : MemMgr(MemMgr), Resolver(Resolver), Checker(nullptr),
482 this->ProcessAllSections = ProcessAllSections;
486 this->Checker = Checker;
489 virtual std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
496 if (pos == GlobalSymbolTable.
end())
498 const auto &
SymInfo = pos->second;
500 if (
SymInfo.getSectionID() == AbsoluteSymbolSection)
502 return getSectionAddress(
SymInfo.getSectionID()) +
SymInfo.getOffset();
509 if (pos == GlobalSymbolTable.
end())
512 uint64_t SectionAddr = 0;
513 if (
SymEntry.getSectionID() != AbsoluteSymbolSection)
514 SectionAddr = getSectionLoadAddress(
SymEntry.getSectionID());
515 uint64_t TargetAddr = SectionAddr +
SymEntry.getOffset();
521 TargetAddr = modifyAddressBasedOnFlags(TargetAddr,
SymEntry.getFlags());
526 std::map<StringRef, JITEvaluatedSymbol> Result;
528 for (
auto &KV : GlobalSymbolTable) {
529 auto SectionID = KV.second.getSectionID();
530 uint64_t SectionAddr = 0;
531 if (SectionID != AbsoluteSymbolSection)
532 SectionAddr = getSectionLoadAddress(SectionID);
540 void resolveRelocations();
542 void resolveLocalRelocations();
544 static void finalizeAsync(std::unique_ptr<RuntimeDyldImpl> This,
546 std::unique_ptr<MemoryBuffer> UnderlyingBuffer);
548 void reassignSectionAddress(
unsigned SectionID, uint64_t Addr);
550 void mapSectionAddress(
const void *LocalAddress, uint64_t TargetAddress);
561 virtual bool isCompatibleFile(
const ObjectFile &Obj)
const = 0;
563 virtual void registerEHFrames();
565 void deregisterEHFrames();
568 ObjSectionToIDMap &SectionMap) {
Information about the loaded object.
RelocationEntry - used to represent relocations internally in the dynamic linker. ...
JITEvaluatedSymbol getSymbol(StringRef Name) const
uint8_t * getSymbolLocalAddress(StringRef Name) const
void swapByteOrder(T &Value)
virtual void setMipsABI(const ObjectFile &Obj)
This class represents lattice values for constants.
void writeInt16BE(uint8_t *Addr, uint16_t Value)
uint64_t getLoadAddressWithOffset(unsigned OffsetBytes) const
Return the load address of this section with an offset.
virtual uint64_t modifyAddressBasedOnFlags(uint64_t Addr, JITSymbolFlags Flags) const
Modify the given target address based on the given symbol flags.
bool operator==(const RelocationValueRef &Other) const
RuntimeDyld::MemoryManager & MemMgr
RuntimeDyldImpl(RuntimeDyld::MemoryManager &MemMgr, JITSymbolResolver &Resolver)
iterator find(StringRef Key)
This class is the base class for all object file types.
RuntimeDyldCheckerImpl * Checker
RelocationEntry(unsigned id, uint64_t offset, uint32_t type, int64_t addend, uint64_t symoffset)
uint8_t * getAddress() const
JITSymbolFlags getFlags() const
bool IsPCRel
True if this is a PCRel relocation (MachO specific).
SectionEntry(StringRef name, uint8_t *address, size_t size, size_t allocationSize, uintptr_t objAddress)
unsigned SectionID
SectionID - the section this relocation points to.
bool IsTargetLittleEndian
virtual bool relocationNeedsStub(const RelocationRef &R) const
amdgpu Simplify well known AMD library false Value Value const Twine & Name
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
This is a value type class that represents a single relocation in the list of relocations in the obje...
std::map< RelocationValueRef, uintptr_t > StubMap
Tagged union holding either a T or a Error.
virtual size_t getGOTEntrySize()
StringRef getErrorString()
virtual Error finalizeLoad(const ObjectFile &ObjImg, ObjSectionToIDMap &SectionMap)
void setLoadAddress(uint64_t LA)
RelocationEntry(unsigned id, uint64_t offset, uint32_t type, int64_t addend)
void setRuntimeDyldChecker(RuntimeDyldCheckerImpl *Checker)
virtual bool relocationNeedsGot(const RelocationRef &R) const
void setOffset(uint64_t NewOffset)
SmallVector< SectionEntry, 64 > SectionList
RelocationEntry(unsigned id, uint64_t offset, uint32_t type, int64_t addend, unsigned SectionA, uint64_t SectionAOffset, unsigned SectionB, uint64_t SectionBOffset, bool IsPCRel, unsigned Size, bool IsTargetThumbFunc)
Flags for symbols in the JIT.
Symbol resolution interface.
std::vector< SymbolRef > CommonSymbolList
bool operator<(const RelocationValueRef &Other) const
uintptr_t getObjAddress() const
void writeInt32BE(uint8_t *Addr, uint32_t Value)
uint8_t * getSectionAddress(unsigned SectionID) const
uint64_t getOffset() const
static ErrorSuccess success()
Create a success value.
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
unsigned getSectionID() const
StringMap< SymbolTableEntry > RTDyldSymbolTable
int64_t Addend
Addend - the relocation addend encoded in the instruction itself.
uint32_t RelType
RelType - relocation type.
uint64_t getSectionLoadAddress(unsigned SectionID) const
JITSymbolResolver & Resolver
RelocationEntry(unsigned id, uint64_t offset, uint32_t type, int64_t addend, bool IsPCRel, unsigned Size)
Symbol info for RuntimeDyld.
Represents a symbol that has been evaluated to an address already.
uintptr_t getStubOffset() const
void setProcessAllSections(bool ProcessAllSections)
This is a value type class that represents a single symbol in the list of symbols in the object file...
std::map< StringRef, JITEvaluatedSymbol > getSymbolTable() const
uint64_t Offset
Offset - offset into the section.
std::map< SectionRef, unsigned > ObjSectionToIDMap
uint8_t * getAddressWithOffset(unsigned OffsetBytes) const
Return the address of this section with an offset.
void writeInt64BE(uint8_t *Addr, uint64_t Value)
uint64_t getLoadAddress() const
RelocationEntry(unsigned id, uint64_t offset, uint32_t type, int64_t addend, unsigned SectionA, uint64_t SectionAOffset, unsigned SectionB, uint64_t SectionBOffset, bool IsPCRel, unsigned Size)
StringRef getName() const
SymInfo contains information about symbol: it's address and section index which is -1LL for absolute ...
SectionEntry - represents a section emitted into memory by the dynamic linker.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SymbolTableEntry(unsigned SectionID, uint64_t Offset, JITSymbolFlags Flags)
LLVM Value Representation.
RTDyldSymbolTable GlobalSymbolTable
Lightweight error class with error context and mandatory checking.
std::unordered_map< unsigned, RelocationList > Relocations
unsigned Size
The size of this relocation (MachO specific).
void advanceStubOffset(unsigned StubSize)
print Print MemDeps of function
StringRef - Represent a constant reference to a string, i.e.
StringMap< RelocationList > ExternalSymbolRelocations
SmallVector< RelocationEntry, 64 > RelocationList
This is a value type class that represents a single section in the list of sections in the object fil...