14 #ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDCOFFAARCH64_H 15 #define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDCOFFAARCH64_H 17 #include "../RuntimeDyldCOFF.h" 22 #define DEBUG_TYPE "dyld" 39 orig &= ~(0xFFF << 10);
40 write32le(T, orig | ((imm & (0xFFF >> rangeLimit)) << 10));
48 if ((orig & 0x04800000) == 0x04800000)
50 if ((imm & ((1 << size) - 1)) != 0)
51 assert(0 &&
"misaligned ldr/str offset");
56 uint64_t Imm = (s >> shift) - (p >> shift);
58 uint32_t ImmHi = (Imm & 0x1FFFFC) << 3;
59 uint64_t
Mask = (0x3 << 29) | (0x1FFFFC << 3);
74 uint64_t getImageBase() {
83 if (
Section.getLoadAddress() != 0)
84 ImageBase = std::min(ImageBase,
Section.getLoadAddress());
98 std::tuple<uint64_t, uint64_t, uint64_t>
100 uint64_t
Offset, uint64_t RelType, uint64_t Addend,
102 uintptr_t StubOffset;
106 OriginalRelValueRef.
SectionID = SectionID;
108 OriginalRelValueRef.
Addend = Addend;
111 auto Stub = Stubs.find(OriginalRelValueRef);
112 if (Stub == Stubs.end()) {
114 << TargetName.
data() <<
"\n");
117 Stubs[OriginalRelValueRef] = StubOffset;
123 StubOffset = Stub->second;
137 return std::make_tuple(Offset, RelType, Addend);
146 auto Symbol = RelI->getSymbol();
151 if (!TargetNameOrErr)
155 auto SectionOrErr =
Symbol->getSection();
157 return SectionOrErr.takeError();
160 uint64_t RelType = RelI->getType();
161 uint64_t
Offset = RelI->getOffset();
170 uint8_t *Displacement = (uint8_t *)ObjTarget;
181 Addend = (orig & 0x03FFFFFF) << 2;
184 std::tie(Offset, RelType, Addend) = generateRelocationStub(
185 SectionID, TargetName, Offset, RelType, Addend, Stubs);
190 Addend = (orig & 0x00FFFFE0) >> 3;
195 Addend = (orig & 0x000FFFE0) >> 3;
201 Addend = ((orig >> 29) & 0x3) | ((orig >> 3) & 0x1FFFFC);
207 Addend = ((orig >> 10) & 0xFFF);
220 RelI->getTypeName(RelTypeName);
222 LLVM_DEBUG(
dbgs() <<
"\t\tIn Section " << SectionID <<
" Offset " << Offset
223 <<
" RelType: " << RelTypeName <<
" TargetName: " 224 << TargetName <<
" Addend " << Addend <<
"\n");
227 unsigned TargetSectionID = -1;
230 addRelocationForSymbol(RE, TargetName);
232 if (
auto TargetSectionIDOrErr = findOrEmitSection(
234 TargetSectionID = *TargetSectionIDOrErr;
236 return TargetSectionIDOrErr.takeError();
238 uint64_t TargetOffset = getSymbolOffset(*
Symbol);
240 addRelocationForSection(RE, TargetSectionID);
248 uint64_t FinalAddress =
Section.getLoadAddressWithOffset(RE.
Offset);
291 uint64_t RVA = Value + RE.
Addend - getImageBase();
297 or32le(Target + 12, ((Value + RE.
Addend) & 0xFFFF) << 5);
298 or32le(Target + 8, ((Value + RE.
Addend) & 0xFFFF0000) >> 11);
299 or32le(Target + 4, ((Value + RE.
Addend) & 0xFFFF00000000) >> 27);
300 or32le(Target + 0, ((Value + RE.
Addend) & 0xFFFF000000000000) >> 43);
306 uint64_t PCRelVal = Value + RE.
Addend - FinalAddress;
307 assert(isInt<28>(PCRelVal) &&
"Branch target is out of range.");
309 (PCRelVal & 0x0FFFFFFC) >> 2);
315 uint64_t PCRelVal = Value + RE.
Addend - FinalAddress;
316 assert(isInt<21>(PCRelVal) &&
"Branch target is out of range.");
318 (PCRelVal & 0x001FFFFC) << 3);
324 uint64_t PCRelVal = Value + RE.
Addend - FinalAddress;
327 (PCRelVal & 0x0000FFFC) << 3);
338 "relocation overflow");
345 "Relocation overflow");
347 "Relocation underflow");
353 uint64_t Result = Value - FinalAddress - 4;
RelocationEntry - used to represent relocations internally in the dynamic linker. ...
static void add16(uint8_t *p, int16_t v)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
uint64_t getLoadAddressWithOffset(unsigned OffsetBytes) const
Return the load address of this section with an offset.
This class is the base class for all object file types.
void write32le(void *P, uint32_t V)
constexpr bool isInt< 16 >(int64_t x)
uint16_t read16le(const void *P)
Error takeError()
Take ownership of the stored error.
unsigned SectionID
SectionID - the section this relocation points to.
void write16le(void *P, uint16_t V)
std::map< RelocationValueRef, uintptr_t > StubMap
Tagged union holding either a T or a Error.
static void or32le(void *P, int32_t V)
std::tuple< uint64_t, uint64_t, uint64_t > generateRelocationStub(unsigned SectionID, StringRef TargetName, uint64_t Offset, uint64_t RelType, uint64_t Addend, StubMap &Stubs)
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Symbol resolution interface.
virtual basic_symbol_iterator symbol_end() const =0
uintptr_t getObjAddress() const
static void write32AArch64Imm(uint8_t *T, uint64_t imm, uint32_t rangeLimit)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned getStubAlignment() override
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
Align max(MaybeAlign Lhs, Align Rhs)
int64_t Addend
Addend - the relocation addend encoded in the instruction itself.
uint32_t RelType
RelType - relocation type.
Expected< object::relocation_iterator > processRelocationRef(unsigned SectionID, object::relocation_iterator RelI, const object::ObjectFile &Obj, ObjSectionToIDMap &ObjSectionToID, StubMap &Stubs) override
Parses one or more object file relocations (some object files use relocation pairs) and stores it to ...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Target - Wrapper for Target specific information.
uintptr_t getStubOffset() const
static void write32AArch64Ldr(uint8_t *T, uint64_t imm)
uint64_t Offset
Offset - offset into the section.
uint64_t read64le(const void *P)
void write64le(void *P, uint64_t V)
virtual section_iterator section_end() const =0
std::map< SectionRef, unsigned > ObjSectionToIDMap
uint8_t * getAddressWithOffset(unsigned OffsetBytes) const
Return the address of this section with an offset.
static void write32AArch64Addr(void *T, uint64_t s, uint64_t p, int shift)
uint32_t read32le(const void *P)
void registerEHFrames() override
SectionEntry - represents a section emitted into memory by the dynamic linker.
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override
A object file specific relocation resolver.
RuntimeDyldCOFFAArch64(RuntimeDyld::MemoryManager &MM, JITSymbolResolver &Resolver)
LLVM Value Representation.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
void advanceStubOffset(unsigned StubSize)
StringRef - Represent a constant reference to a string, i.e.
unsigned getMaxStubSize() const override