14 #ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_RUNTIMEDYLDIMPL_H
15 #define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_RUNTIMEDYLDIMPL_H
31 #include <unordered_map>
32 #include <system_error>
35 using namespace llvm::object;
41 #define UNIMPLEMENTED_RELOC(RelType) \
43 return make_error<RuntimeDyldError>("Unimplemented relocation: " #RelType)
69 size_t AllocationSize;
77 size_t allocationSize, uintptr_t objAddress)
79 LoadAddress(reinterpret_cast<uintptr_t>(address)), StubOffset(size),
80 AllocationSize(allocationSize), ObjAddress(objAddress) {
92 assert(OffsetBytes <= AllocationSize &&
"Offset out of bounds!");
103 assert(OffsetBytes <= AllocationSize &&
"Offset out of bounds!");
104 return LoadAddress + OffsetBytes;
110 StubOffset += StubSize;
111 assert(StubOffset <= AllocationSize &&
"Not enough space allocated!");
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;
199 SymbolName(nullptr) {}
210 if (Addend != Other.
Addend)
211 return Addend < Other.
Addend;
220 :
Offset(0), SectionID(0) {}
223 : Offset(Offset), SectionID(SectionID), Flags(Flags) {}
242 static const unsigned AbsoluteSymbolSection = ~0U;
259 #define RTDYLD_INVALID_SECTION_ID ((RuntimeDyldImpl::SID)(-1))
288 typedef std::map<RelocationValueRef, uintptr_t>
StubMap;
312 virtual unsigned getMaxStubSize() = 0;
313 virtual unsigned getStubAlignment() = 0;
319 return Sections[SectionID].getLoadAddress();
323 return Sections[SectionID].getAddress();
327 if (IsTargetLittleEndian)
329 *Addr = (Value >> 8) & 0xFF;
330 *(Addr + 1) = Value & 0xFF;
334 if (IsTargetLittleEndian)
336 *Addr = (Value >> 24) & 0xFF;
337 *(Addr + 1) = (Value >> 16) & 0xFF;
338 *(Addr + 2) = (Value >> 8) & 0xFF;
339 *(Addr + 3) = Value & 0xFF;
343 if (IsTargetLittleEndian)
345 *Addr = (Value >> 56) & 0xFF;
346 *(Addr + 1) = (Value >> 48) & 0xFF;
347 *(Addr + 2) = (Value >> 40) & 0xFF;
348 *(Addr + 3) = (Value >> 32) & 0xFF;
349 *(Addr + 4) = (Value >> 24) & 0xFF;
350 *(Addr + 5) = (Value >> 16) & 0xFF;
351 *(Addr + 6) = (Value >> 8) & 0xFF;
352 *(Addr + 7) = Value & 0xFF;
356 IsMipsO32ABI =
false;
357 IsMipsN32ABI =
false;
358 IsMipsN64ABI =
false;
362 uint64_t readBytesUnaligned(uint8_t *Src,
unsigned Size)
const;
366 void writeBytesUnaligned(uint64_t
Value, uint8_t *Dst,
unsigned Size)
const;
372 CommonSymbolList &CommonSymbols);
389 ObjSectionToIDMap &LocalSections);
392 void addRelocationForSection(
const RelocationEntry &RE,
unsigned SectionID);
400 uint8_t *createStubFunction(uint8_t *Addr,
unsigned AbiVariant = 0);
403 void resolveRelocationList(
const RelocationList &Relocs, uint64_t
Value);
416 const ObjectFile &Obj, ObjSectionToIDMap &ObjSectionToID,
420 void resolveExternalSymbols();
425 uint64_t &CodeSize,
uint32_t &CodeAlign,
426 uint64_t &RODataSize,
uint32_t &RODataAlign,
427 uint64_t &RWDataSize,
uint32_t &RWDataAlign);
430 unsigned computeSectionStubBufSize(
const ObjectFile &Obj,
444 : MemMgr(MemMgr), Resolver(Resolver), Checker(nullptr),
451 this->ProcessAllSections = ProcessAllSections;
455 this->Checker = Checker;
458 virtual std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
465 if (pos == GlobalSymbolTable.end())
467 const auto &SymInfo = pos->
second;
469 if (SymInfo.getSectionID() == AbsoluteSymbolSection)
471 return getSectionAddress(SymInfo.getSectionID()) + SymInfo.getOffset();
478 if (pos == GlobalSymbolTable.end())
481 uint64_t SectionAddr = 0;
482 if (
SymEntry.getSectionID() != AbsoluteSymbolSection)
483 SectionAddr = getSectionLoadAddress(
SymEntry.getSectionID());
484 uint64_t TargetAddr = SectionAddr +
SymEntry.getOffset();
488 void resolveRelocations();
490 void reassignSectionAddress(
unsigned SectionID, uint64_t Addr);
492 void mapSectionAddress(
const void *LocalAddress, uint64_t TargetAddress);
503 virtual bool isCompatibleFile(
const ObjectFile &Obj)
const = 0;
505 virtual void registerEHFrames();
507 virtual void deregisterEHFrames();
Information about the loaded object.
RelocationEntry - used to represent relocations internally in the dynamic linker. ...
void swapByteOrder(T &Value)
virtual void setMipsABI(const ObjectFile &Obj)
void writeInt16BE(uint8_t *Addr, uint16_t Value)
RuntimeDyld::MemoryManager & MemMgr
uintptr_t getObjAddress() const
RuntimeDyldImpl(RuntimeDyld::MemoryManager &MemMgr, JITSymbolResolver &Resolver)
uint8_t * getAddress() const
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)
virtual bool relocationNeedsStub(const RelocationRef &R) 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
struct fuzzer::@269 Flags
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
bool operator<(const RelocationValueRef &Other) const
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.
StringRef getErrorString()
virtual Error finalizeLoad(const ObjectFile &ObjImg, ObjSectionToIDMap &SectionMap)
void setLoadAddress(uint64_t LA)
Function Alias Analysis false
uint64_t getLoadAddressWithOffset(unsigned OffsetBytes) const
Return the load address of this section with an offset.
RelocationEntry(unsigned id, uint64_t offset, uint32_t type, int64_t addend)
uint8_t * getAddressWithOffset(unsigned OffsetBytes) const
Return the address of this section with an offset.
void setRuntimeDyldChecker(RuntimeDyldCheckerImpl *Checker)
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.
uint8_t * getSectionAddress(unsigned SectionID) const
std::vector< SymbolRef > CommonSymbolList
uintptr_t getStubOffset() const
void writeInt32BE(uint8_t *Addr, uint32_t Value)
static ErrorSuccess success()
Create a success value.
StringMap< SymbolTableEntry > RTDyldSymbolTable
int64_t Addend
Addend - the relocation addend encoded in the instruction itself.
uint32_t RelType
RelType - relocation type.
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.
void setProcessAllSections(bool ProcessAllSections)
uint64_t Offset
Offset - offset into the section.
std::map< SectionRef, unsigned > ObjSectionToIDMap
void writeInt64BE(uint8_t *Addr, uint64_t Value)
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)
uint64_t getLoadAddress() const
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.
JITSymbolFlags getFlags() const
std::unordered_map< unsigned, RelocationList > Relocations
unsigned Size
The size of this relocation (MachO specific).
uint8_t * getSymbolLocalAddress(StringRef Name) const
void advanceStubOffset(unsigned StubSize)
unsigned getSectionID() const
StringRef - Represent a constant reference to a string, i.e.
uint64_t getSectionLoadAddress(unsigned SectionID) const
StringRef getName() 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...
JITEvaluatedSymbol getSymbol(StringRef Name) const