14 #ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDCOFFTHUMB_H 15 #define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDCOFFTHUMB_H 17 #include "../RuntimeDyldCOFF.h" 21 #define DEBUG_TYPE "dyld" 36 if (*SymTypeOrErr != SymbolRef::ST_Function)
41 return cast<COFFObjectFile>(Obj).getCOFFSection(*Section)->Characteristics &
63 auto Symbol = RelI->getSymbol();
72 auto SectionOrErr =
Symbol->getSection();
74 return SectionOrErr.takeError();
77 uint64_t RelType = RelI->getType();
78 uint64_t
Offset = RelI->getOffset();
84 uint8_t *Displacement = (uint8_t *)ObjTarget;
98 RelI->getTypeName(RelTypeName);
100 LLVM_DEBUG(
dbgs() <<
"\t\tIn Section " << SectionID <<
" Offset " << Offset
101 <<
" RelType: " << RelTypeName <<
" TargetName: " 102 << TargetName <<
" Addend " << Addend <<
"\n");
104 unsigned TargetSectionID = -1;
106 RelocationEntry RE(SectionID, Offset, RelType, 0, -1, 0, 0, 0,
false, 0);
109 if (
auto TargetSectionIDOrErr =
111 TargetSectionID = *TargetSectionIDOrErr;
113 return TargetSectionIDOrErr.takeError();
126 SectionID, Offset, RelType, Addend, TargetSectionID,
152 SectionID, Offset, RelType, Addend, TargetSectionID,
188 Result |= ISASelectionBit;
189 assert(Result <= UINT32_MAX &&
"relocation overflow");
191 <<
" RelType: IMAGE_REL_ARM_ADDR32" 193 <<
" Value: " <<
format(
"0x%08" PRIx32, Result)
203 assert(Result <= UINT32_MAX &&
"relocation overflow");
205 <<
" RelType: IMAGE_REL_ARM_ADDR32NB" 207 <<
" Value: " <<
format(
"0x%08" PRIx32, Result)
209 Result |= ISASelectionBit;
216 "relocation overflow");
218 <<
" RelType: IMAGE_REL_ARM_SECTION Value: " 224 assert(static_cast<uint64_t>(RE.
Addend) <= UINT32_MAX &&
225 "relocation overflow");
227 <<
" RelType: IMAGE_REL_ARM_SECREL Value: " << RE.
Addend 235 assert(Result <= UINT32_MAX &&
"relocation overflow");
237 <<
" RelType: IMAGE_REL_ARM_MOV32T" 239 <<
" Value: " <<
format(
"0x%08" PRIx32, Result)
247 auto EncodeImmediate = [](uint8_t *Bytes, uint16_t Immediate) {
248 Bytes[0] |= ((Immediate & 0xf000) >> 12);
249 Bytes[1] |= ((Immediate & 0x0800) >> 11);
250 Bytes[2] |= ((Immediate & 0x00ff) >> 0);
251 Bytes[3] |= (((Immediate & 0x0700) >> 8) << 4);
254 EncodeImmediate(&Target[0],
255 (static_cast<uint32_t>(Result) >> 00) | ISASelectionBit);
256 EncodeImmediate(&Target[4], static_cast<uint32_t>(Result) >> 16);
265 "relocation overflow");
267 "relocation underflow");
269 <<
" RelType: IMAGE_REL_ARM_BRANCH20T" 270 <<
" Value: " << static_cast<int32_t>(Value) <<
'\n');
271 static_cast<void>(Value);
280 "relocation overflow");
282 "relocation underflow");
284 <<
" RelType: IMAGE_REL_ARM_BRANCH24T" 285 <<
" Value: " << static_cast<int32_t>(Value) <<
'\n');
286 static_cast<void>(Value);
295 "relocation overflow");
297 "relocation underflow");
299 <<
" RelType: IMAGE_REL_ARM_BLX23T" 300 <<
" Value: " << static_cast<int32_t>(Value) <<
'\n');
301 static_cast<void>(Value);
RelocationEntry - used to represent relocations internally in the dynamic linker. ...
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 readBytesUnaligned(uint8_t *Src, unsigned Size) const
Endian-aware read Read the least significant Size bytes from Src.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
This class is the base class for all object file types.
Expected< relocation_iterator > processRelocationRef(unsigned SectionID, relocation_iterator RelI, const ObjectFile &Obj, ObjSectionToIDMap &ObjSectionToID, StubMap &Stubs) override
Parses one or more object file relocations (some object files use relocation pairs) and stores it to ...
uint64_t getSymbolOffset(const SymbolRef &Sym)
Error takeError()
Take ownership of the stored error.
void registerEHFrames() override
void writeBytesUnaligned(uint64_t Value, uint8_t *Dst, unsigned Size) const
Endian-aware write.
unsigned SectionID
SectionID - the section this relocation points to.
std::map< RelocationValueRef, uintptr_t > StubMap
Tagged union holding either a T or a Error.
RuntimeDyldCOFFThumb(RuntimeDyld::MemoryManager &MM, JITSymbolResolver &Resolver)
void addRelocationForSymbol(const RelocationEntry &RE, StringRef SymbolName)
void addRelocationForSection(const RelocationEntry &RE, unsigned SectionID)
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
Expected< unsigned > findOrEmitSection(const ObjectFile &Obj, const SectionRef &Section, bool IsCode, ObjSectionToIDMap &LocalSections)
Find Section in LocalSections.
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned getMaxStubSize() override
static bool isThumbFunc(symbol_iterator Symbol, const ObjectFile &Obj, section_iterator Section)
Expected< SymbolRef::Type > getType() const
int64_t Addend
Addend - the relocation addend encoded in the instruction itself.
uint32_t RelType
RelType - relocation type.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Target - Wrapper for Target specific information.
uint64_t Offset
Offset - offset into the section.
virtual section_iterator section_end() const =0
std::map< SectionRef, unsigned > ObjSectionToIDMap
unsigned getStubAlignment() override
SectionEntry - represents a section emitted into memory by the dynamic linker.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A raw_ostream that writes to an std::string.
LLVM Value Representation.
void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override
A object file specific relocation resolver.
StringRef - Represent a constant reference to a string, i.e.