10 #ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDMACHOAARCH64_H
11 #define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDMACHOAARCH64_H
13 #include "../RuntimeDyldMachO.h"
16 #define DEBUG_TYPE "dyld"
38 unsigned NumBytes = 1 << RE.
Size;
45 assert((NumBytes == 4 || NumBytes == 8) &&
"Invalid relocation size.");
52 assert(NumBytes == 4 &&
"Invalid relocation size.");
53 assert((((uintptr_t)LocalAddress & 0x3) == 0) &&
54 "Instruction address is not aligned to 4 bytes.");
71 assert((*p & 0xFC000000) == 0x14000000 &&
"Expected branch instruction.");
76 Addend = (*p & 0x03FFFFFF) << 2;
84 assert((*p & 0x9F000000) == 0x90000000 &&
"Expected adrp instruction.");
89 Addend = ((*p & 0x60000000) >> 29) | ((*p & 0x01FFFFE0) >> 3) << 12;
98 assert((*p & 0x3B000000) == 0x39000000 &&
99 "Only expected load / store instructions.");
105 assert((((*p & 0x3B000000) == 0x39000000) ||
106 ((*p & 0x11C00000) == 0x11000000) ) &&
107 "Expected load / store or add/sub instruction.");
110 Addend = (*p & 0x003FFC00) >> 10;
114 int ImplicitShift = 0;
115 if ((*p & 0x3B000000) == 0x39000000) {
117 ImplicitShift = ((*p >> 30) & 0x3);
118 if (ImplicitShift == 0) {
120 if ((*p & 0x04800000) == 0x04800000)
125 Addend <<= ImplicitShift;
140 assert((NumBytes == 4 || NumBytes == 8) &&
"Invalid relocation size.");
147 assert(NumBytes == 4 &&
"Invalid relocation size.");
148 assert((((uintptr_t)LocalAddress & 0x3) == 0) &&
149 "Instruction address is not aligned to 4 bytes.");
166 assert((*p & 0xFC000000) == 0x14000000 &&
"Expected branch instruction.");
169 assert((Addend & 0x3) == 0 &&
"Branch target is not aligned");
170 assert(isInt<28>(Addend) &&
"Branch target is out of range.");
173 *p = (*p & 0xFC000000) | ((uint32_t)(Addend >> 2) & 0x03FFFFFF);
180 assert((*p & 0x9F000000) == 0x90000000 &&
"Expected adrp instruction.");
183 assert((Addend & 0xFFF) == 0 &&
"ADRP target is not page aligned.");
184 assert(isInt<33>(Addend) &&
"Invalid page reloc value.");
187 uint32_t ImmLoValue = ((uint64_t)Addend << 17) & 0x60000000;
188 uint32_t ImmHiValue = ((uint64_t)Addend >> 9) & 0x00FFFFE0;
189 *p = (*p & 0x9F00001F) | ImmHiValue | ImmLoValue;
196 assert((*p & 0x3B000000) == 0x39000000 &&
197 "Only expected load / store instructions.");
204 assert((((*p & 0x3B000000) == 0x39000000) ||
205 ((*p & 0x11C00000) == 0x11000000) ) &&
206 "Expected load / store or add/sub instruction.");
210 int ImplicitShift = 0;
211 if ((*p & 0x3B000000) == 0x39000000) {
213 ImplicitShift = ((*p >> 30) & 0x3);
214 switch (ImplicitShift) {
217 if ((*p & 0x04800000) == 0x04800000) {
219 assert(((Addend & 0xF) == 0) &&
220 "128-bit LDR/STR not 16-byte aligned.");
224 assert(((Addend & 0x1) == 0) &&
"16-bit LDR/STR not 2-byte aligned.");
227 assert(((Addend & 0x3) == 0) &&
"32-bit LDR/STR not 4-byte aligned.");
230 assert(((Addend & 0x7) == 0) &&
"64-bit LDR/STR not 8-byte aligned.");
235 Addend >>= ImplicitShift;
236 assert(isUInt<12>(Addend) &&
"Addend cannot be encoded.");
239 *p = (*p & 0xFFC003FF) | ((uint32_t)(Addend << 10) & 0x003FFC00);
261 int64_t ExplicitAddend = 0;
278 assert((ExplicitAddend == 0 || RE.
Addend == 0) &&
"Relocation has "\
279 "ARM64_RELOC_ADDEND and embedded addend in the instruction.");
280 if (ExplicitAddend) {
281 RE.
Addend = ExplicitAddend;
282 Value.
Offset = ExplicitAddend;
293 processGOTRelocation(RE, Value, Stubs);
316 assert(!RE.
IsPCRel &&
"PCRel and ARM64_RELOC_UNSIGNED not supported");
326 assert(RE.
IsPCRel &&
"not PCRel and ARM64_RELOC_BRANCH26 not supported");
329 int64_t PCRelVal = Value - FinalAddress + RE.
Addend;
335 assert(RE.
IsPCRel &&
"not PCRel and ARM64_RELOC_PAGE21 not supported");
339 ((Value + RE.
Addend) & (-4096)) - (FinalAddress & (-4096));
345 assert(!RE.
IsPCRel &&
"PCRel and ARM64_RELOC_PAGEOFF21 not supported");
360 "processRelocationRef!");
370 assert(RE.
Size == 2);
372 StubMap::const_iterator i = Stubs.find(Value);
374 if (i != Stubs.end())
375 Offset = static_cast<int64_t>(i->second);
379 uintptr_t BaseAddress = uintptr_t(Section.
Address);
381 uintptr_t StubAddress =
382 (BaseAddress + Section.
StubOffset + StubAlignment - 1) &
384 unsigned StubOffset = StubAddress - BaseAddress;
385 Stubs[Value] = StubOffset;
387 "GOT entry not aligned");
396 Offset =
static_cast<int64_t
>(StubOffset);
RelocationEntry - used to represent relocations internally in the dynamic linker. ...
bool getPlainRelocationExternal(const MachO::any_relocation_info &RE) const
relocation_iterator processRelocationRef(unsigned SectionID, relocation_iterator RelI, const ObjectFile &BaseObjT, ObjSectionToIDMap &ObjSectionToID, StubMap &Stubs) override
Parses one or more object file relocations (some object files use relocation pairs) and stores it to ...
void finalizeSection(const ObjectFile &Obj, unsigned SectionID, const SectionRef &Section)
unsigned getAnyRelocationType(const MachO::any_relocation_info &RE) const
This class is the base class for all object file types.
uint8_t * Address
Address - address in the linker's memory where the section resides.
bool IsPCRel
True if this is a PCRel relocation (MachO specific).
unsigned SectionID
SectionID - the section this relocation points to.
void encodeAddend(uint8_t *LocalAddress, unsigned NumBytes, MachO::RelocationInfoType RelType, int64_t Addend) const
Extract the addend encoded in the instruction.
RelocationEntry getRelocationEntry(unsigned SectionID, const ObjectFile &BaseTObj, const relocation_iterator &RI) const
Given a relocation_iterator for a non-scattered relocation, construct a RelocationEntry and fill in t...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::map< RelocationValueRef, uintptr_t > StubMap
uintptr_t StubOffset
StubOffset - used for architectures with stub functions for far relocations (like ARM)...
RuntimeDyldMachOAArch64(RuntimeDyld::MemoryManager &MM, RuntimeDyld::SymbolResolver &Resolver)
void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override
A object file specific relocation resolver.
int64_t decodeAddend(const RelocationEntry &RE) const
Extract the addend encoded in the instruction / memory location.
unsigned getMaxStubSize() override
void dumpRelocationToResolve(const RelocationEntry &RE, uint64_t Value) const
Dump information about the relocation entry (RE) and resolved value.
RuntimeDyldMachOTarget - Templated base class for generic MachO linker algorithms and data structures...
void addRelocationForSymbol(const RelocationEntry &RE, StringRef SymbolName)
MachO::any_relocation_info getRelocation(DataRefImpl Rel) const
RuntimeDyld::SymbolResolver & Resolver
void addRelocationForSection(const RelocationEntry &RE, unsigned SectionID)
unsigned getAnyRelocationPCRel(const MachO::any_relocation_info &RE) const
unsigned getAnyRelocationLength(const MachO::any_relocation_info &RE) const
int64_t SignExtend64(uint64_t x)
SignExtend64 - Sign extend B-bit number x to 64-bit int.
int64_t Addend
Addend - the relocation addend encoded in the instruction itself.
uint32_t RelType
RelType - relocation type.
uint64_t Offset
Offset - offset into the section.
std::map< SectionRef, unsigned > ObjSectionToIDMap
RelocationValueRef getRelocationValueRef(const ObjectFile &BaseTObj, const relocation_iterator &RI, const RelocationEntry &RE, ObjSectionToIDMap &ObjSectionToID)
Construct a RelocationValueRef representing the relocation target.
uint64_t LoadAddress
LoadAddress - the address of the section in the target process's memory.
SectionEntry - represents a section emitted into memory by the dynamic linker.
unsigned getStubAlignment() override
LLVM Value Representation.
unsigned Size
The size of this relocation (MachO specific).
void makeValueAddendPCRel(RelocationValueRef &Value, const relocation_iterator &RI, unsigned OffsetToNextPC)
Make the RelocationValueRef addend PC-relative.
unsigned getPlainRelocationSymbolNum(const MachO::any_relocation_info &RE) const
bool isRelocationScattered(const MachO::any_relocation_info &RE) const
This is a value type class that represents a single section in the list of sections in the object fil...