Go to the documentation of this file.
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");
58 uint32_t ImmHi = (Imm & 0x1FFFFC) << 3;
83 if (Section.getLoadAddress() != 0)
84 ImageBase =
std::min(ImageBase, Section.getLoadAddress());
99 std::tuple<uint64_t, uint64_t, uint64_t>
103 uintptr_t StubOffset;
107 OriginalRelValueRef.
SectionID = SectionID;
108 OriginalRelValueRef.
Offset = Offset;
109 OriginalRelValueRef.
Addend = Addend;
112 auto Stub = Stubs.find(OriginalRelValueRef);
113 if (Stub == Stubs.end()) {
115 << TargetName.
data() <<
"\n");
117 StubOffset = Section.getStubOffset();
118 Stubs[OriginalRelValueRef] = StubOffset;
119 createStubFunction(Section.getAddressWithOffset(StubOffset));
120 Section.advanceStubOffset(getMaxStubSize());
124 StubOffset = Stub->second;
138 return std::make_tuple(Offset, RelType, Addend);
147 auto Symbol = RelI->getSymbol();
152 if (!TargetNameOrErr)
156 auto SectionOrErr =
Symbol->getSection();
158 return SectionOrErr.takeError();
159 auto Section = *SectionOrErr;
162 uint64_t Offset = RelI->getOffset();
170 uintptr_t ObjTarget = AddendSection.
getObjAddress() + Offset;
171 uint8_t *Displacement = (uint8_t *)ObjTarget;
173 unsigned TargetSectionID = -1;
176 if (TargetName.
startswith(getImportSymbolPrefix())) {
177 TargetSectionID = SectionID;
178 TargetOffset = getDLLImportOffset(SectionID, Stubs, TargetName);
181 }
else if (!IsExtern) {
182 if (
auto TargetSectionIDOrErr = findOrEmitSection(
183 Obj, *Section, Section->isText(), ObjSectionToID))
184 TargetSectionID = *TargetSectionIDOrErr;
186 return TargetSectionIDOrErr.takeError();
188 TargetOffset = getSymbolOffset(*
Symbol);
200 Addend = (orig & 0x03FFFFFF) << 2;
203 std::tie(Offset, RelType, Addend) = generateRelocationStub(
204 SectionID, TargetName, Offset, RelType, Addend, Stubs);
209 Addend = (orig & 0x00FFFFE0) >> 3;
214 Addend = (orig & 0x000FFFE0) >> 3;
220 Addend = ((orig >> 29) & 0
x3) | ((orig >> 3) & 0x1FFFFC);
226 Addend = ((orig >> 10) & 0xFFF);
239 RelI->getTypeName(RelTypeName);
241 LLVM_DEBUG(
dbgs() <<
"\t\tIn Section " << SectionID <<
" Offset " << Offset
242 <<
" RelType: " << RelTypeName <<
" TargetName: "
243 << TargetName <<
" Addend " << Addend <<
"\n");
248 addRelocationForSymbol(RE, TargetName);
251 addRelocationForSection(RE, TargetSectionID);
257 const auto Section = Sections[RE.
SectionID];
258 uint8_t *
Target = Section.getAddressWithOffset(RE.
Offset);
259 uint64_t FinalAddress = Section.getLoadAddressWithOffset(RE.
Offset);
318 assert(isInt<28>(PCRelVal) &&
"Branch target is out of range.");
320 (PCRelVal & 0x0FFFFFFC) >> 2);
327 assert(isInt<21>(PCRelVal) &&
"Branch target is out of range.");
329 (PCRelVal & 0x001FFFFC) << 3);
338 (PCRelVal & 0x0000FFFC) << 3);
349 "relocation overflow");
356 "Relocation overflow");
358 "Relocation underflow");
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
This is an optimization pass for GlobalISel generic memory operations.
@ IMAGE_REL_ARM64_ADDR32NB
unsigned getMaxStubSize() const override
@ IMAGE_REL_ARM64_PAGEBASE_REL21
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
void registerEHFrames() override
Target - Wrapper for Target specific information.
@ IMAGE_REL_ARM64_PAGEOFFSET_12L
uint16_t read16le(const void *P)
void write32le(void *P, uint32_t V)
void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override
A object file specific relocation resolver.
void write16le(void *P, uint16_t V)
Tagged union holding either a T or a Error.
@ IMAGE_REL_ARM64_BRANCH26
the resulting code requires compare and branches when and if * p
@ IMAGE_REL_ARM64_ABSOLUTE
unsigned SectionID
SectionID - the section this relocation points to.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
virtual basic_symbol_iterator symbol_end() const =0
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
uint64_t Offset
Offset - offset into the section.
In x86 we generate this spiffy xmm0 xmm0 ret in x86 we generate this which could be xmm1 movss xmm1 xmm0 ret In sse4 we could use insertps to make both better Here s another testcase that could use x3
virtual section_iterator section_end() const =0
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
uintptr_t getObjAddress() const
int64_t Addend
Addend - the relocation addend encoded in the instruction itself.
RelocationEntry - used to represent relocations internally in the dynamic linker.
multiplies can be turned into SHL s
unsigned getStubAlignment() override
static void or32le(void *P, int32_t V)
SectionEntry - represents a section emitted into memory by the dynamic linker.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::tuple< uint64_t, uint64_t, uint64_t > generateRelocationStub(unsigned SectionID, StringRef TargetName, uint64_t Offset, uint64_t RelType, uint64_t Addend, StubMap &Stubs)
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
StringRef - Represent a constant reference to a string, i.e.
This class is the base class for all object file types.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ IMAGE_REL_ARM64_PAGEOFFSET_12A
@ INTERNAL_REL_ARM64_LONG_BRANCH26
static void write32AArch64Imm(uint8_t *T, uint64_t imm, uint32_t rangeLimit)
constexpr bool isInt< 16 >(int64_t x)
Symbol resolution interface.
@ IMAGE_REL_ARM64_BRANCH14
Error takeError()
Take ownership of the stored error.
uint64_t read64le(const void *P)
void write64le(void *P, uint64_t V)
uint32_t read32le(const void *P)
@ IMAGE_REL_ARM64_BRANCH19
Align max(MaybeAlign Lhs, Align Rhs)
http eax xorl edx cl sete al setne dl sall eax sall edx But that requires good bit subreg support this might be better It s an extra shift
static void write32AArch64Ldr(uint8_t *T, uint64_t imm)
const LLVM_NODISCARD char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
static void add16(uint8_t *p, int16_t v)
std::map< RelocationValueRef, uintptr_t > StubMap
RuntimeDyldCOFFAArch64(RuntimeDyld::MemoryManager &MM, JITSymbolResolver &Resolver)
static void write32AArch64Addr(void *T, uint64_t s, uint64_t p, int shift)
LLVM Value Representation.
uint32_t RelType
RelType - relocation type.
std::map< SectionRef, unsigned > ObjSectionToIDMap
uint64_t resolveRelocation(RelocationResolver Resolver, const RelocationRef &R, uint64_t S, uint64_t LocData)
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 ...
@ IMAGE_REL_ARM64_SECTION