14 #ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_RUNTIMEDYLDIMPL_H
15 #define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_RUNTIMEDYLDIMPL_H
33 #include <system_error>
36 using namespace llvm::object;
41 inline std::error_code
Check(std::error_code Err) {
80 LoadAddress(reinterpret_cast<uintptr_t>(address)), StubOffset(size),
81 ObjAddress(objAddress) {}
120 : SectionID(id), Offset(offset), RelType(type), Addend(addend),
121 SymOffset(0), IsPCRel(
false), Size(0) {}
125 : SectionID(id), Offset(offset), RelType(type), Addend(addend),
126 SymOffset(symoffset), IsPCRel(
false), Size(0) {}
129 bool IsPCRel,
unsigned Size)
130 : SectionID(id), Offset(offset), RelType(type), Addend(addend),
131 SymOffset(0), IsPCRel(IsPCRel), Size(Size) {}
134 unsigned SectionA, uint64_t SectionAOffset,
unsigned SectionB,
135 uint64_t SectionBOffset,
bool IsPCRel,
unsigned Size)
136 : SectionID(id), Offset(offset), RelType(type),
137 Addend(SectionAOffset - SectionBOffset + addend), IsPCRel(IsPCRel),
139 Sections.SectionA = SectionA;
140 Sections.SectionB = SectionB;
151 SymbolName(nullptr) {}
160 if (Offset != Other.
Offset)
161 return Offset < Other.
Offset;
162 if (Addend != Other.
Addend)
163 return Addend < Other.
Addend;
175 :
JITSymbolBase(Flags), Offset(Offset), SectionID(SectionID) {}
206 #define RTDYLD_INVALID_SECTION_ID ((RuntimeDyldImpl::SID)(-1))
235 typedef std::map<RelocationValueRef, uintptr_t>
StubMap;
258 virtual unsigned getMaxStubSize() = 0;
259 virtual unsigned getStubAlignment() = 0;
266 ErrorStr = Msg.
str();
272 return Sections[SectionID].LoadAddress;
276 return (uint8_t *)Sections[SectionID].Address;
280 if (IsTargetLittleEndian)
282 *Addr = (Value >> 8) & 0xFF;
283 *(Addr + 1) = Value & 0xFF;
287 if (IsTargetLittleEndian)
289 *Addr = (Value >> 24) & 0xFF;
290 *(Addr + 1) = (Value >> 16) & 0xFF;
291 *(Addr + 2) = (Value >> 8) & 0xFF;
292 *(Addr + 3) = Value & 0xFF;
296 if (IsTargetLittleEndian)
298 *Addr = (Value >> 56) & 0xFF;
299 *(Addr + 1) = (Value >> 48) & 0xFF;
300 *(Addr + 2) = (Value >> 40) & 0xFF;
301 *(Addr + 3) = (Value >> 32) & 0xFF;
302 *(Addr + 4) = (Value >> 24) & 0xFF;
303 *(Addr + 5) = (Value >> 16) & 0xFF;
304 *(Addr + 6) = (Value >> 8) & 0xFF;
305 *(Addr + 7) = Value & 0xFF;
309 IsMipsO32ABI =
false;
310 IsMipsN64ABI =
false;
314 uint64_t readBytesUnaligned(uint8_t *Src,
unsigned Size)
const;
318 void writeBytesUnaligned(uint64_t
Value, uint8_t *Dst,
unsigned Size)
const;
323 void emitCommonSymbols(
const ObjectFile &Obj, CommonSymbolList &CommonSymbols);
338 bool IsCode, ObjSectionToIDMap &LocalSections);
341 void addRelocationForSection(
const RelocationEntry &RE,
unsigned SectionID);
349 uint8_t *createStubFunction(uint8_t *Addr,
unsigned AbiVariant = 0);
352 void resolveRelocationList(
const RelocationList &Relocs, uint64_t
Value);
365 const ObjectFile &Obj, ObjSectionToIDMap &ObjSectionToID,
369 void resolveExternalSymbols();
373 void computeTotalAllocSize(
const ObjectFile &Obj, uint64_t &CodeSize,
374 uint64_t &DataSizeRO, uint64_t &DataSizeRW);
377 unsigned computeSectionStubBufSize(
const ObjectFile &Obj,
386 : MemMgr(MemMgr), Resolver(Resolver), Checker(nullptr),
393 this->ProcessAllSections = ProcessAllSections;
397 this->Checker = Checker;
400 virtual std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
407 if (pos == GlobalSymbolTable.end())
409 const auto &SymInfo = pos->
second;
410 return getSectionAddress(SymInfo.getSectionID()) + SymInfo.getOffset();
417 if (pos == GlobalSymbolTable.end())
419 const auto &SymEntry = pos->
second;
420 uint64_t TargetAddr =
421 getSectionLoadAddress(SymEntry.getSectionID()) + SymEntry.getOffset();
425 void resolveRelocations();
427 void reassignSectionAddress(
unsigned SectionID, uint64_t Addr);
429 void mapSectionAddress(
const void *LocalAddress, uint64_t
TargetAddress);
440 virtual bool isCompatibleFile(
const ObjectFile &Obj)
const = 0;
442 virtual void registerEHFrames();
444 virtual void deregisterEHFrames();
Information about the loaded object.
RelocationEntry - used to represent relocations internally in the dynamic linker. ...
size_t Size
Size - section size. Doesn't include the stubs.
RuntimeDyldImpl(RuntimeDyld::MemoryManager &MemMgr, RuntimeDyld::SymbolResolver &Resolver)
void swapByteOrder(T &Value)
virtual void setMipsABI(const ObjectFile &Obj)
void writeInt16BE(uint8_t *Addr, uint16_t Value)
std::string Name
Name - section name.
RuntimeDyld::MemoryManager & MemMgr
This class is the base class for all object file types.
RuntimeDyldCheckerImpl * Checker
uint8_t * Address
Address - address in the linker's memory where the section resides.
RelocationEntry(unsigned id, uint64_t offset, uint32_t type, int64_t addend, uint64_t symoffset)
Base class for symbols in the JIT.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
Reports a serious error, calling any installed error handler.
bool IsPCRel
True if this is a PCRel relocation (MachO specific).
unsigned SectionID
SectionID - the section this relocation points to.
bool IsTargetLittleEndian
std::string str() const
Return the twine contents as a std::string.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
bool operator<(const RelocationValueRef &Other) const
std::map< RelocationValueRef, uintptr_t > StubMap
uintptr_t StubOffset
StubOffset - used for architectures with stub functions for far relocations (like ARM)...
StringRef getErrorString()
virtual void finalizeLoad(const ObjectFile &ObjImg, ObjSectionToIDMap &SectionMap)
RelocationEntry(unsigned id, uint64_t offset, uint32_t type, int64_t addend)
bool Error(const Twine &Msg)
JITSymbolFlags
Flags for symbols in the JIT.
RuntimeDyld::SymbolResolver & Resolver
DenseMap< unsigned, RelocationList > Relocations
void setRuntimeDyldChecker(RuntimeDyldCheckerImpl *Checker)
SmallVector< SectionEntry, 64 > SectionList
uint8_t * getSectionAddress(unsigned SectionID) const
std::vector< SymbolRef > CommonSymbolList
void writeInt32BE(uint8_t *Addr, uint32_t Value)
StringMap< SymbolTableEntry > RTDyldSymbolTable
int64_t Addend
Addend - the relocation addend encoded in the instruction itself.
uint32_t RelType
RelType - relocation type.
RelocationEntry(unsigned id, uint64_t offset, uint32_t type, int64_t addend, bool IsPCRel, unsigned Size)
uint64_t TargetAddress
Represents an address in the target process's address space.
uintptr_t ObjAddress
ObjAddress - address of the section in the in-memory object file.
Symbol info for RuntimeDyld.
void setProcessAllSections(bool ProcessAllSections)
SectionEntry(StringRef name, uint8_t *address, size_t size, uintptr_t objAddress)
RuntimeDyld::SymbolInfo getSymbol(StringRef Name) const
uint64_t Offset
Offset - offset into the section.
std::map< SectionRef, unsigned > ObjSectionToIDMap
std::error_code Check(std::error_code Err)
uint64_t LoadAddress
LoadAddress - the address of the section in the target process's memory.
void writeInt64BE(uint8_t *Addr, uint64_t Value)
Information about a named symbol.
uint64_t getOffset() 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)
SectionEntry - represents a section emitted into memory by the dynamic linker.
SymbolTableEntry(unsigned SectionID, uint64_t Offset, JITSymbolFlags Flags)
LLVM Value Representation.
RTDyldSymbolTable GlobalSymbolTable
unsigned Size
The size of this relocation (MachO specific).
uint8_t * getSymbolLocalAddress(StringRef Name) const
unsigned getSectionID() const
StringRef - Represent a constant reference to a string, i.e.
uint64_t getSectionLoadAddress(unsigned SectionID) const
bool operator==(const RelocationValueRef &Other) const
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...