#include "RuntimeDyldELF.h"
#include "RuntimeDyldCheckerImpl.h"
#include "Targets/RuntimeDyldELFMips.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/TargetParser/Triple.h"
usingnamespacellvm;
usingnamespacellvm::object;
usingnamespacellvm::support::endian;
#define DEBUG_TYPE …
static void or32le(void *P, int32_t V) { … }
static void or32AArch64Imm(void *L, uint64_t Imm) { … }
template <class T> static void write(bool isBE, void *P, T V) { … }
static void write32AArch64Addr(void *L, uint64_t Imm) { … }
static uint64_t getBits(uint64_t Val, int Start, int End) { … }
namespace {
template <class ELFT> class DyldELFObject : public ELFObjectFile<ELFT> { … };
template <class ELFT>
DyldELFObject<ELFT>::DyldELFObject(ELFObjectFile<ELFT> &&Obj)
: … { … }
template <class ELFT>
Expected<std::unique_ptr<DyldELFObject<ELFT>>>
DyldELFObject<ELFT>::create(MemoryBufferRef Wrapper) { … }
template <class ELFT>
void DyldELFObject<ELFT>::updateSectionAddress(const SectionRef &Sec,
uint64_t Addr) { … }
template <class ELFT>
void DyldELFObject<ELFT>::updateSymbolAddress(const SymbolRef &SymRef,
uint64_t Addr) { … }
class LoadedELFObjectInfo final
: public LoadedObjectInfoHelper<LoadedELFObjectInfo,
RuntimeDyld::LoadedObjectInfo> { … };
template <typename ELFT>
static Expected<std::unique_ptr<DyldELFObject<ELFT>>>
createRTDyldELFObject(MemoryBufferRef Buffer, const ObjectFile &SourceObject,
const LoadedELFObjectInfo &L) { … }
static OwningBinary<ObjectFile>
createELFDebugObject(const ObjectFile &Obj, const LoadedELFObjectInfo &L) { … }
OwningBinary<ObjectFile>
LoadedELFObjectInfo::getObjectForDebug(const ObjectFile &Obj) const { … }
}
namespace llvm {
RuntimeDyldELF::RuntimeDyldELF(RuntimeDyld::MemoryManager &MemMgr,
JITSymbolResolver &Resolver)
: … { … }
RuntimeDyldELF::~RuntimeDyldELF() = default;
void RuntimeDyldELF::registerEHFrames() { … }
std::unique_ptr<RuntimeDyldELF>
llvm::RuntimeDyldELF::create(Triple::ArchType Arch,
RuntimeDyld::MemoryManager &MemMgr,
JITSymbolResolver &Resolver) { … }
std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
RuntimeDyldELF::loadObject(const object::ObjectFile &O) { … }
void RuntimeDyldELF::resolveX86_64Relocation(const SectionEntry &Section,
uint64_t Offset, uint64_t Value,
uint32_t Type, int64_t Addend,
uint64_t SymOffset) { … }
void RuntimeDyldELF::resolveX86Relocation(const SectionEntry &Section,
uint64_t Offset, uint32_t Value,
uint32_t Type, int32_t Addend) { … }
void RuntimeDyldELF::resolveAArch64Relocation(const SectionEntry &Section,
uint64_t Offset, uint64_t Value,
uint32_t Type, int64_t Addend) { … }
void RuntimeDyldELF::resolveARMRelocation(const SectionEntry &Section,
uint64_t Offset, uint32_t Value,
uint32_t Type, int32_t Addend) { … }
void RuntimeDyldELF::setMipsABI(const ObjectFile &Obj) { … }
Error RuntimeDyldELF::findPPC64TOCSection(const ELFObjectFileBase &Obj,
ObjSectionToIDMap &LocalSections,
RelocationValueRef &Rel) { … }
Error RuntimeDyldELF::findOPDEntrySection(const ELFObjectFileBase &Obj,
ObjSectionToIDMap &LocalSections,
RelocationValueRef &Rel) { … }
static inline uint16_t applyPPClo(uint64_t value) { … }
static inline uint16_t applyPPChi(uint64_t value) { … }
static inline uint16_t applyPPCha (uint64_t value) { … }
static inline uint16_t applyPPChigher(uint64_t value) { … }
static inline uint16_t applyPPChighera (uint64_t value) { … }
static inline uint16_t applyPPChighest(uint64_t value) { … }
static inline uint16_t applyPPChighesta (uint64_t value) { … }
void RuntimeDyldELF::resolvePPC32Relocation(const SectionEntry &Section,
uint64_t Offset, uint64_t Value,
uint32_t Type, int64_t Addend) { … }
void RuntimeDyldELF::resolvePPC64Relocation(const SectionEntry &Section,
uint64_t Offset, uint64_t Value,
uint32_t Type, int64_t Addend) { … }
void RuntimeDyldELF::resolveSystemZRelocation(const SectionEntry &Section,
uint64_t Offset, uint64_t Value,
uint32_t Type, int64_t Addend) { … }
void RuntimeDyldELF::resolveBPFRelocation(const SectionEntry &Section,
uint64_t Offset, uint64_t Value,
uint32_t Type, int64_t Addend) { … }
static void applyUTypeImmRISCV(uint8_t *InstrAddr, uint32_t Imm) { … }
static void applyITypeImmRISCV(uint8_t *InstrAddr, uint32_t Imm) { … }
void RuntimeDyldELF::resolveRISCVRelocation(const SectionEntry &Section,
uint64_t Offset, uint64_t Value,
uint32_t Type, int64_t Addend,
SID SectionID) { … }
void RuntimeDyldELF::resolveRelocation(const RelocationEntry &RE,
uint64_t Value) { … }
void RuntimeDyldELF::resolveRelocation(const SectionEntry &Section,
uint64_t Offset, uint64_t Value,
uint32_t Type, int64_t Addend,
uint64_t SymOffset, SID SectionID) { … }
void *RuntimeDyldELF::computePlaceholderAddress(unsigned SectionID,
uint64_t Offset) const { … }
void RuntimeDyldELF::processSimpleRelocation(unsigned SectionID, uint64_t Offset, unsigned RelType, RelocationValueRef Value) { … }
uint32_t RuntimeDyldELF::getMatchingLoRelocation(uint32_t RelType,
bool IsLocal) const { … }
bool RuntimeDyldELF::resolveAArch64ShortBranch(
unsigned SectionID, relocation_iterator RelI,
const RelocationValueRef &Value) { … }
void RuntimeDyldELF::resolveAArch64Branch(unsigned SectionID,
const RelocationValueRef &Value,
relocation_iterator RelI,
StubMap &Stubs) { … }
Expected<relocation_iterator>
RuntimeDyldELF::processRelocationRef(
unsigned SectionID, relocation_iterator RelI, const ObjectFile &O,
ObjSectionToIDMap &ObjSectionToID, StubMap &Stubs) { … }
void RuntimeDyldELF::processX86_64GOTTPOFFRelocation(unsigned SectionID,
uint64_t Offset,
RelocationValueRef Value,
int64_t Addend) { … }
void RuntimeDyldELF::processX86_64TLSRelocation(
unsigned SectionID, uint64_t Offset, uint64_t RelType,
RelocationValueRef Value, int64_t Addend,
const RelocationRef &GetAddrRelocation) { … }
size_t RuntimeDyldELF::getGOTEntrySize() { … }
uint64_t RuntimeDyldELF::allocateGOTEntries(unsigned no) { … }
uint64_t RuntimeDyldELF::findOrAllocGOTEntry(const RelocationValueRef &Value,
unsigned GOTRelType) { … }
void RuntimeDyldELF::resolveGOTOffsetRelocation(unsigned SectionID,
uint64_t Offset,
uint64_t GOTOffset,
uint32_t Type) { … }
RelocationEntry RuntimeDyldELF::computeGOTOffsetRE(uint64_t GOTOffset,
uint64_t SymbolOffset,
uint32_t Type) { … }
void RuntimeDyldELF::processNewSymbol(const SymbolRef &ObjSymbol, SymbolTableEntry& Symbol) { … }
Error RuntimeDyldELF::finalizeLoad(const ObjectFile &Obj,
ObjSectionToIDMap &SectionMap) { … }
bool RuntimeDyldELF::isCompatibleFile(const object::ObjectFile &Obj) const { … }
void RuntimeDyldELF::createIFuncResolver(uint8_t *Addr) const { … }
void RuntimeDyldELF::createIFuncStub(unsigned IFuncStubSectionID,
uint64_t IFuncResolverOffset,
uint64_t IFuncStubOffset,
unsigned IFuncSectionID,
uint64_t IFuncOffset) { … }
unsigned RuntimeDyldELF::getMaxIFuncStubSize() const { … }
bool RuntimeDyldELF::relocationNeedsGot(const RelocationRef &R) const { … }
bool RuntimeDyldELF::relocationNeedsStub(const RelocationRef &R) const { … }
}