13#ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_RUNTIMEDYLDIMPL_H
14#define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_RUNTIMEDYLDIMPL_H
31#include <system_error>
32#include <unordered_map>
39#define UNIMPLEMENTED_RELOC(RelType) \
41 return make_error<RuntimeDyldError>("Unimplemented relocation: " #RelType)
67 size_t AllocationSize;
75 size_t allocationSize, uintptr_t objAddress)
77 LoadAddress(reinterpret_cast<uintptr_t>(address)), StubOffset(
size),
78 AllocationSize(allocationSize), ObjAddress(objAddress) {
90 assert(OffsetBytes <= AllocationSize &&
"Offset out of bounds!");
91 return Address + OffsetBytes;
101 assert(OffsetBytes <= AllocationSize &&
"Offset out of bounds!");
102 return LoadAddress + OffsetBytes;
108 StubOffset += StubSize;
109 assert(StubOffset <= AllocationSize &&
"Not enough space allocated!");
169 unsigned SectionA,
uint64_t SectionAOffset,
unsigned SectionB,
171 :
Offset(offset),
Addend(SectionAOffset - SectionBOffset + addend),
179 unsigned SectionA,
uint64_t SectionAOffset,
unsigned SectionB,
182 :
Offset(offset),
Addend(SectionAOffset - SectionBOffset + addend),
222 : Offset(Offset), SectionID(SectionID), Flags(Flags) {}
232 unsigned SectionID = 0;
257#define RTDYLD_INVALID_SECTION_ID ((RuntimeDyldImpl::SID)(-1))
286 typedef std::map<RelocationValueRef, uintptr_t>
StubMap;
321 llvm::support::endian::write<uint16_t>(
Addr,
Value,
328 llvm::support::endian::write<uint32_t>(
Addr,
Value,
335 llvm::support::endian::write<uint64_t>(
Addr,
Value,
471 virtual std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
478 return Sections[SectionID].getLoadAddress();
485 return Sections[SectionID].getAddress();
503 const auto &
SymInfo = pos->second;
514 return GSTItr->second.getSectionID();
538 std::map<StringRef, JITEvaluatedSymbol> Result;
541 auto SectionID = KV.second.getSectionID();
555 std::unique_ptr<RuntimeDyldImpl> This,
557 std::unique_ptr<RuntimeDyld::LoadedObjectInfo>,
561 std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
Info);
This file defines the StringMap class.
Analysis containing CSE Info
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const Value * getAddress(const DbgVariableIntrinsic *DVI)
This file defines the SmallVector class.
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.
Represents a symbol that has been evaluated to an address already.
Flags for symbols in the JIT.
Symbol resolution interface.
RelocationEntry - used to represent relocations internally in the dynamic linker.
RelocationEntry(unsigned id, uint64_t offset, uint32_t type, int64_t addend)
unsigned Size
The size of this relocation (MachO specific).
RelocationEntry(unsigned id, uint64_t offset, uint32_t type, int64_t addend, bool IsPCRel, unsigned Size)
uint32_t RelType
RelType - relocation type.
uint64_t Offset
Offset - offset into the section.
RelocationEntry(unsigned id, uint64_t offset, uint32_t type, int64_t addend, uint64_t symoffset)
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)
bool IsPCRel
True if this is a PCRel relocation (MachO specific).
int64_t Addend
Addend - the relocation addend encoded in the instruction itself.
unsigned SectionID
SectionID - the section this relocation points to.
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 operator<(const RelocationValueRef &Other) const
bool operator==(const RelocationValueRef &Other) const
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
virtual bool relocationNeedsGot(const RelocationRef &R) const
void mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress)
virtual void processNewSymbol(const SymbolRef &ObjSymbol, SymbolTableEntry &Entry)
RuntimeDyld::NotifyStubEmittedFunction NotifyStubEmittedFunction
StringMap< RelocationList > ExternalSymbolRelocations
void reassignSectionAddress(unsigned SectionID, uint64_t Addr)
NotifyStubEmittedFunction NotifyStubEmitted
virtual uint64_t modifyAddressBasedOnFlags(uint64_t Addr, JITSymbolFlags Flags) const
Modify the given target address based on the given symbol flags.
virtual Expected< relocation_iterator > processRelocationRef(unsigned SectionID, relocation_iterator RelI, const ObjectFile &Obj, ObjSectionToIDMap &ObjSectionToID, StubMap &Stubs)=0
Parses one or more object file relocations (some object files use relocation pairs) and stores it to ...
std::map< SectionRef, unsigned > ObjSectionToIDMap
virtual void resolveRelocation(const RelocationEntry &RE, uint64_t Value)=0
A object file specific relocation resolver.
virtual Align getStubAlignment()=0
virtual bool isCompatibleFile(const ObjectFile &Obj) const =0
void writeInt32BE(uint8_t *Addr, uint32_t Value)
virtual Error finalizeLoad(const ObjectFile &ObjImg, ObjSectionToIDMap &SectionMap)
RuntimeDyldImpl(RuntimeDyld::MemoryManager &MemMgr, JITSymbolResolver &Resolver)
void applyExternalSymbolRelocations(const StringMap< JITEvaluatedSymbol > ExternalSymbolMap)
void resolveRelocationList(const RelocationList &Relocs, uint64_t Value)
Resolves relocations from Relocs list with address from Value.
void writeInt64BE(uint8_t *Addr, uint64_t Value)
SmallVector< RelocationEntry, 64 > RelocationList
StringRef getErrorString()
std::map< RelocationValueRef, uintptr_t > StubMap
JITEvaluatedSymbol getSymbol(StringRef Name) const
std::map< StringRef, JITEvaluatedSymbol > getSymbolTable() const
void deregisterEHFrames()
void writeInt16BE(uint8_t *Addr, uint16_t Value)
static const unsigned AbsoluteSymbolSection
void addRelocationForSymbol(const RelocationEntry &RE, StringRef SymbolName)
StringRef getSectionContent(unsigned SectionID) const
virtual void registerEHFrames()
bool IsTargetLittleEndian
JITSymbolResolver & Resolver
virtual ~RuntimeDyldImpl()
static void finalizeAsync(std::unique_ptr< RuntimeDyldImpl > This, unique_function< void(object::OwningBinary< object::ObjectFile >, std::unique_ptr< RuntimeDyld::LoadedObjectInfo >, Error)> OnEmitted, object::OwningBinary< object::ObjectFile > O, std::unique_ptr< RuntimeDyld::LoadedObjectInfo > Info)
Error emitCommonSymbols(const ObjectFile &Obj, CommonSymbolList &CommonSymbols, uint64_t CommonSize, uint32_t CommonAlign)
Given the common symbols discovered in the object file, emit a new section for them and update the sy...
virtual std::unique_ptr< RuntimeDyld::LoadedObjectInfo > loadObject(const object::ObjectFile &Obj)=0
Expected< unsigned > emitSection(const ObjectFile &Obj, const SectionRef &Section, bool IsCode)
Emits section data from the object file to the MemoryManager.
std::unordered_map< unsigned, RelocationList > Relocations
std::vector< SymbolRef > CommonSymbolList
RuntimeDyld::MemoryManager & MemMgr
void resolveLocalRelocations()
void addRelocationForSection(const RelocationEntry &RE, unsigned SectionID)
Expected< unsigned > findOrEmitSection(const ObjectFile &Obj, const SectionRef &Section, bool IsCode, ObjSectionToIDMap &LocalSections)
Find Section in LocalSections.
virtual bool relocationNeedsStub(const RelocationRef &R) const
unsigned getSymbolSectionID(StringRef Name) const
void setProcessAllSections(bool ProcessAllSections)
unsigned computeGOTSize(const ObjectFile &Obj)
uint8_t * getSymbolLocalAddress(StringRef Name) const
virtual void setMipsABI(const ObjectFile &Obj)
void writeBytesUnaligned(uint64_t Value, uint8_t *Dst, unsigned Size) const
Endian-aware write.
std::deque< SectionEntry > SectionList
virtual size_t getGOTEntrySize()
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.
uint64_t getSectionLoadAddress(unsigned SectionID) const
virtual unsigned getMaxStubSize() const =0
uint8_t * getSectionAddress(unsigned SectionID) const
void setNotifyStubEmitted(NotifyStubEmittedFunction NotifyStubEmitted)
Error computeTotalAllocSize(const ObjectFile &Obj, uint64_t &CodeSize, Align &CodeAlign, uint64_t &RODataSize, Align &RODataAlign, uint64_t &RWDataSize, Align &RWDataAlign)
unsigned computeSectionStubBufSize(const ObjectFile &Obj, const SectionRef &Section)
void resolveRelocations()
RTDyldSymbolTable GlobalSymbolTable
virtual Expected< JITSymbolFlags > getJITSymbolFlags(const SymbolRef &Sym)
Generate JITSymbolFlags from a libObject symbol.
Expected< ObjSectionToIDMap > loadObjectImpl(const object::ObjectFile &Obj)
Error resolveExternalSymbols()
Resolve relocations to external symbols.
Information about the loaded object.
std::function< void(StringRef FileName, StringRef SectionName, StringRef SymbolName, unsigned SectionID, uint32_t StubOffset)> NotifyStubEmittedFunction
SectionEntry - represents a section emitted into memory by the dynamic linker.
uint8_t * getAddressWithOffset(unsigned OffsetBytes) const
Return the address of this section with an offset.
SectionEntry(StringRef name, uint8_t *address, size_t size, size_t allocationSize, uintptr_t objAddress)
void advanceStubOffset(unsigned StubSize)
void setLoadAddress(uint64_t LA)
uintptr_t getStubOffset() const
uint64_t getLoadAddressWithOffset(unsigned OffsetBytes) const
Return the load address of this section with an offset.
uintptr_t getObjAddress() const
StringRef getName() const
uint8_t * getAddress() const
uint64_t getLoadAddress() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
iterator find(StringRef Key)
StringRef - Represent a constant reference to a string, i.e.
Symbol info for RuntimeDyld.
uint64_t getOffset() const
SymbolTableEntry(unsigned SectionID, uint64_t Offset, JITSymbolFlags Flags)
unsigned getSectionID() const
JITSymbolFlags getFlags() const
void setOffset(uint64_t NewOffset)
SymbolTableEntry()=default
LLVM Value Representation.
This class is the base class for all object file types.
This is a value type class that represents a single relocation in the list of relocations in the obje...
This is a value type class that represents a single section in the list of sections in the object fil...
This is a value type class that represents a single symbol in the list of symbols in the object file.
unique_function is a type-erasing functor similar to std::function.
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
StringMap< SymbolTableEntry > RTDyldSymbolTable
Implement std::hash so that hash_code can be used in STL containers.
SymInfo contains information about symbol: it's address and section index which is -1LL for absolute ...
This struct is a compact representation of a valid (non-zero power of two) alignment.