13#ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDCOFFTHUMB_H
14#define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDCOFFTHUMB_H
16#include "../RuntimeDyldCOFF.h"
21#define DEBUG_TYPE "dyld"
41 return cast<object::COFFObjectFile>(Obj)
42 .getCOFFSection(*Section)
62 return Flags.takeError();
65 if (!SectionIterOrErr) {
66 return SectionIterOrErr.takeError();
70 cast<object::COFFObjectFile>(Sec.
getObject());
74 Flags->getTargetFlags() =
isThumb;
87 auto Symbol = RelI->getSymbol();
96 auto SectionOrErr = Symbol->getSection();
98 return SectionOrErr.takeError();
99 auto Section = *SectionOrErr;
108 uint8_t *Displacement = (uint8_t *)ObjTarget;
122 RelI->getTypeName(RelTypeName);
125 <<
" RelType: " << RelTypeName <<
" TargetName: "
126 << TargetName <<
" Addend " << Addend <<
"\n");
129 unsigned TargetSectionID = -1;
133 TargetSectionID = SectionID;
137 }
else if (!IsExtern) {
138 if (
auto TargetSectionIDOrErr =
140 TargetSectionID = *TargetSectionIDOrErr;
142 return TargetSectionIDOrErr.takeError();
154 bool IsTargetThumbFunc =
isThumbFunc(Symbol, Obj, Section);
164 TargetOffset, 0, 0,
false, 0, IsTargetThumbFunc);
171 TargetOffset, 0, 0,
false, 0);
190 TargetOffset, 0, 0,
false, 0, IsTargetThumbFunc);
198 TargetOffset + Addend,
true, 0);
210 uint8_t *
Target = Section.getAddressWithOffset(RE.
Offset);
224 Result |= ISASelectionBit;
225 assert(Result <= UINT32_MAX &&
"relocation overflow");
227 <<
" RelType: IMAGE_REL_ARM_ADDR32"
229 <<
" Value: " <<
format(
"0x%08" PRIx32, Result)
239 assert(Result <= UINT32_MAX &&
"relocation overflow");
241 <<
" RelType: IMAGE_REL_ARM_ADDR32NB"
243 <<
" Value: " <<
format(
"0x%08" PRIx32, Result)
245 Result |= ISASelectionBit;
252 "relocation overflow");
254 <<
" RelType: IMAGE_REL_ARM_SECTION Value: "
261 "relocation overflow");
263 <<
" RelType: IMAGE_REL_ARM_SECREL Value: " << RE.
Addend
271 assert(Result <= UINT32_MAX &&
"relocation overflow");
273 <<
" RelType: IMAGE_REL_ARM_MOV32T"
275 <<
" Value: " <<
format(
"0x%08" PRIx32, Result)
283 auto EncodeImmediate = [](uint8_t *Bytes,
uint16_t Immediate) {
284 Bytes[0] |= ((Immediate & 0xf000) >> 12);
285 Bytes[1] |= ((Immediate & 0x0800) >> 11);
286 Bytes[2] |= ((Immediate & 0x00ff) >> 0);
287 Bytes[3] |= (((Immediate & 0x0700) >> 8) << 4);
290 EncodeImmediate(&
Target[0],
291 (
static_cast<uint32_t>(Result) >> 00) | ISASelectionBit);
300 "relocation overflow");
302 "relocation underflow");
304 <<
" RelType: IMAGE_REL_ARM_BRANCH20T"
305 <<
" Value: " <<
static_cast<int32_t
>(
Value) <<
'\n');
306 static_cast<void>(
Value);
315 "relocation overflow");
317 "relocation underflow");
319 <<
" RelType: IMAGE_REL_ARM_BRANCH24T"
320 <<
" Value: " <<
static_cast<int32_t
>(
Value) <<
'\n');
321 static_cast<void>(
Value);
330 "relocation overflow");
332 "relocation underflow");
334 <<
" RelType: IMAGE_REL_ARM_BLX23T"
335 <<
" Value: " <<
static_cast<int32_t
>(
Value) <<
'\n');
336 static_cast<void>(
Value);
static bool isThumb(const MCSubtargetInfo &STI)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallString class.
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
Expected< JITSymbolFlags > getJITSymbolFlags(const SymbolRef &SR) override
Generate JITSymbolFlags from a libObject symbol.
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.
virtual Expected< JITSymbolFlags > getJITSymbolFlags(const SymbolRef &Sym)
Generate JITSymbolFlags from a libObject symbol.
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 starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Target - Wrapper for Target specific information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
const coff_section * getCOFFSection(const SectionRef &Section) const
This class is the base class for all object file types.
virtual section_iterator section_end() const =0
This is a value type class that represents a single section in the list of sections in the object fil...
const ObjectFile * getObject() const
This is a value type class that represents a single symbol in the list of symbols in the object file.
Expected< section_iterator > getSection() const
Get section this symbol is defined in reference to.
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.
support::ulittle32_t Characteristics