13#ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDCOFFTHUMB_H
14#define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDCOFFTHUMB_H
16#include "../RuntimeDyldCOFF.h"
20#define DEBUG_TYPE "dyld"
40 return cast<object::COFFObjectFile>(Obj)
41 .getCOFFSection(*Section)
64 auto Symbol = RelI->getSymbol();
73 auto SectionOrErr = Symbol->getSection();
75 return SectionOrErr.takeError();
76 auto Section = *SectionOrErr;
85 uint8_t *Displacement = (uint8_t *)ObjTarget;
99 RelI->getTypeName(RelTypeName);
102 <<
" RelType: " << RelTypeName <<
" TargetName: "
103 << TargetName <<
" Addend " << Addend <<
"\n");
106 unsigned TargetSectionID = -1;
110 TargetSectionID = SectionID;
114 }
else if (!IsExtern) {
115 if (
auto TargetSectionIDOrErr =
117 TargetSectionID = *TargetSectionIDOrErr;
119 return TargetSectionIDOrErr.takeError();
131 bool IsTargetThumbFunc =
isThumbFunc(Symbol, Obj, Section);
141 TargetOffset, 0, 0,
false, 0, IsTargetThumbFunc);
148 TargetOffset, 0, 0,
false, 0);
167 TargetOffset, 0, 0,
false, 0, IsTargetThumbFunc);
175 TargetOffset + Addend,
true, 0);
187 uint8_t *
Target = Section.getAddressWithOffset(RE.
Offset);
201 Result |= ISASelectionBit;
202 assert(Result <= UINT32_MAX &&
"relocation overflow");
204 <<
" RelType: IMAGE_REL_ARM_ADDR32"
206 <<
" Value: " <<
format(
"0x%08" PRIx32, Result)
216 assert(Result <= UINT32_MAX &&
"relocation overflow");
218 <<
" RelType: IMAGE_REL_ARM_ADDR32NB"
220 <<
" Value: " <<
format(
"0x%08" PRIx32, Result)
222 Result |= ISASelectionBit;
229 "relocation overflow");
231 <<
" RelType: IMAGE_REL_ARM_SECTION Value: "
238 "relocation overflow");
240 <<
" RelType: IMAGE_REL_ARM_SECREL Value: " << RE.
Addend
248 assert(Result <= UINT32_MAX &&
"relocation overflow");
250 <<
" RelType: IMAGE_REL_ARM_MOV32T"
252 <<
" Value: " <<
format(
"0x%08" PRIx32, Result)
260 auto EncodeImmediate = [](uint8_t *Bytes,
uint16_t Immediate) {
261 Bytes[0] |= ((Immediate & 0xf000) >> 12);
262 Bytes[1] |= ((Immediate & 0x0800) >> 11);
263 Bytes[2] |= ((Immediate & 0x00ff) >> 0);
264 Bytes[3] |= (((Immediate & 0x0700) >> 8) << 4);
267 EncodeImmediate(&
Target[0],
268 (
static_cast<uint32_t>(Result) >> 00) | ISASelectionBit);
277 "relocation overflow");
279 "relocation underflow");
281 <<
" RelType: IMAGE_REL_ARM_BRANCH20T"
282 <<
" Value: " <<
static_cast<int32_t
>(
Value) <<
'\n');
283 static_cast<void>(
Value);
292 "relocation overflow");
294 "relocation underflow");
296 <<
" RelType: IMAGE_REL_ARM_BRANCH24T"
297 <<
" Value: " <<
static_cast<int32_t
>(
Value) <<
'\n');
298 static_cast<void>(
Value);
307 "relocation overflow");
309 "relocation underflow");
311 <<
" RelType: IMAGE_REL_ARM_BLX23T"
312 <<
" Value: " <<
static_cast<int32_t
>(
Value) <<
'\n');
313 static_cast<void>(
Value);
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
Symbol resolution interface.
RelocationEntry - used to represent relocations internally in the dynamic linker.
uint32_t RelType
RelType - relocation type.
uint64_t Offset
Offset - offset into the section.
int64_t Addend
Addend - the relocation addend encoded in the instruction itself.
unsigned SectionID
SectionID - the section this relocation points to.
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
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 ...
void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override
A object file specific relocation resolver.
Align getStubAlignment() override
unsigned getMaxStubSize() const override
void registerEHFrames() override
RuntimeDyldCOFFThumb(RuntimeDyld::MemoryManager &MM, JITSymbolResolver &Resolver)
uint64_t getSymbolOffset(const SymbolRef &Sym)
static constexpr StringRef getImportSymbolPrefix()
uint64_t getDLLImportOffset(unsigned SectionID, StubMap &Stubs, StringRef Name, bool SetSectionIDMinus1=false)
std::map< SectionRef, unsigned > ObjSectionToIDMap
std::map< RelocationValueRef, uintptr_t > StubMap
void addRelocationForSymbol(const RelocationEntry &RE, StringRef SymbolName)
void addRelocationForSection(const RelocationEntry &RE, unsigned SectionID)
Expected< unsigned > findOrEmitSection(const ObjectFile &Obj, const SectionRef &Section, bool IsCode, ObjSectionToIDMap &LocalSections)
Find Section in LocalSections.
void writeBytesUnaligned(uint64_t Value, uint8_t *Dst, unsigned Size) const
Endian-aware write.
uint64_t readBytesUnaligned(uint8_t *Src, unsigned Size) const
Endian-aware read Read the least significant Size bytes from Src.
SectionEntry - represents a section emitted into memory by the dynamic linker.
uintptr_t getObjAddress() const
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef - Represent a constant reference to a string, i.e.
bool startswith(StringRef Prefix) const
Target - Wrapper for Target specific information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
This class is the base class for all object file types.
virtual section_iterator section_end() const =0
virtual basic_symbol_iterator symbol_end() const =0
A raw_ostream that writes to an std::string.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ IMAGE_REL_ARM_BRANCH20T
@ IMAGE_REL_ARM_BRANCH24T
This is an optimization pass for GlobalISel generic memory operations.
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
static bool isThumbFunc(object::symbol_iterator Symbol, const object::ObjectFile &Obj, object::section_iterator Section)
This struct is a compact representation of a valid (non-zero power of two) alignment.