10 #ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDMACHOARM_H 11 #define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDMACHOARM_H 13 #include "../RuntimeDyldMachO.h" 16 #define DEBUG_TYPE "dyld" 40 return Flags.takeError();
55 auto &Entry = KV.second;
57 Sections[Entry.getSectionID()].getObjAddress() + Entry.getOffset();
58 if (TargetObjAddr == SymbolObjAddr)
75 return SignExtend32<26>(Temp << 2);
84 if ((HighInsn & 0xf800) != 0xf000)
85 return make_error<StringError>(
"Unrecognized thumb branch encoding " 90 if ((LowInsn & 0xf800) != 0xf800)
91 return make_error<StringError>(
"Unrecognized thumb branch encoding " 95 return SignExtend64<23>(((HighInsn & 0x7ff) << 12) |
96 ((LowInsn & 0x7ff) << 1));
114 bool TargetIsLocalThumbFunc =
false;
116 auto Symbol = RelI->getSymbol();
118 if (
auto TargetNameOrErr =
Symbol->getName())
119 TargetName = *TargetNameOrErr;
121 return TargetNameOrErr.takeError();
128 TargetIsLocalThumbFunc =
129 EntryItr->second.getFlags().getTargetFlags() &
136 return processHALFSECTDIFFRelocation(SectionID, RelI, Obj,
140 TargetIsLocalThumbFunc);
155 return make_error<RuntimeDyldError>((
"MachO ARM relocation type " +
157 " is out of range").str());
165 return AddendOrErr.takeError();
172 return ValueOrErr.takeError();
192 processBranchRelocation(RE, Value, Stubs);
213 Value -= FinalAddress;
223 assert((HighInsn & 0xf800) == 0xf000 &&
224 "Unrecognized thumb branch encoding (BR22 high bits)");
225 HighInsn = (HighInsn & 0xf800) | ((Value >> 12) & 0x7ff);
228 assert((LowInsn & 0xf800) != 0xf8000 &&
229 "Unrecognized thumb branch encoding (BR22 low bits)");
230 LowInsn = (LowInsn & 0xf800) | ((Value >> 1) & 0x7ff);
249 uint64_t FinalValue = Value & 0xffffff;
263 assert((Value == SectionABase || Value == SectionBBase) &&
264 "Unexpected HALFSECTDIFF relocation value.");
265 Value = SectionABase - SectionBBase + RE.
Addend;
267 Value = (Value >> 16);
269 bool IsThumb = RE.
Size & 0x2;
276 Insn = (Insn & 0x8f00fbf0) | ((Value & 0xf000) >> 12) |
277 ((Value & 0x0800) >> 1) | ((Value & 0x0700) << 20) |
278 ((Value & 0x00ff) << 16);
280 Insn = (Insn & 0xfff0f000) | ((Value & 0xf000) << 4) | (Value & 0x0fff);
295 if (Name ==
"__nl_symbol_ptr")
309 RuntimeDyldMachO::StubMap::const_iterator i = Stubs.find(Value);
311 if (i != Stubs.end()) {
319 StubOpcode = 0xe51ff004;
321 StubOpcode = 0xf000f8df;
326 uint8_t *StubTargetAddr = Addr + 4;
356 bool IsThumb = HalfDiffKindBits & 0x2;
361 uint64_t
Offset = RelI->getOffset();
366 Immediate = ((Immediate & 0x0000000f) << 12) |
367 ((Immediate & 0x00000400) << 1) |
368 ((Immediate & 0x70000000) >> 20) |
369 ((Immediate & 0x00ff0000) >> 16);
371 Immediate = ((Immediate >> 4) & 0xf000) | (Immediate & 0xfff);
379 uint64_t SectionABase = SAI->getAddress();
380 uint64_t SectionAOffset = AddrA - SectionABase;
382 bool IsCode = SectionA.
isText();
384 if (
auto SectionAIDOrErr =
386 SectionAID = *SectionAIDOrErr;
388 return SectionAIDOrErr.takeError();
393 uint64_t SectionBBase = SBI->getAddress();
394 uint64_t SectionBOffset = AddrB - SectionBBase;
397 if (
auto SectionBIDOrErr =
399 SectionBID = *SectionBIDOrErr;
401 return SectionBIDOrErr.takeError();
404 unsigned Shift = (HalfDiffKindBits & 0x1) ? 16 : 0;
405 uint32_t FullImmVal = (Immediate << Shift) | (OtherHalf << (16 - Shift));
406 int64_t Addend = FullImmVal - (AddrA - AddrB);
412 <<
", AddrB: " << AddrB <<
", Addend: " << Addend
413 <<
", SectionA ID: " << SectionAID <<
", SectionAOffset: " 414 << SectionAOffset <<
", SectionB ID: " << SectionBID
415 <<
", SectionBOffset: " << SectionBOffset <<
"\n");
417 SectionAOffset, SectionBID, SectionBOffset, IsPCRel,
unsigned getStubAlignment() override
RelocationEntry - used to represent relocations internally in the dynamic linker. ...
unsigned getAnyRelocationAddress(const MachO::any_relocation_info &RE) const
This class represents lattice values for constants.
unsigned getAnyRelocationPCRel(const MachO::any_relocation_info &RE) const
uint64_t readBytesUnaligned(uint8_t *Src, unsigned Size) const
Endian-aware read Read the least significant Size bytes from Src.
uint64_t getLoadAddressWithOffset(unsigned OffsetBytes) const
Return the load address of this section with an offset.
bool getPlainRelocationExternal(const MachO::any_relocation_info &RE) const
iterator find(StringRef Key)
void dumpRelocationToResolve(const RelocationEntry &RE, uint64_t Value) const
Dump information about the relocation entry (RE) and resolved value.
This class is the base class for all object file types.
unsigned getMaxStubSize() override
uint8_t * getAddress() const
void writeBytesUnaligned(uint64_t Value, uint8_t *Dst, unsigned Size) const
Endian-aware write.
bool IsPCRel
True if this is a PCRel relocation (MachO specific).
unsigned SectionID
SectionID - the section this relocation points to.
amdgpu Simplify well known AMD library false Value Value const Twine & Name
uint64_t modifyAddressBasedOnFlags(uint64_t Addr, JITSymbolFlags Flags) const override
Modify the given target address based on the given symbol flags.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Expected< relocation_iterator > processRelocationRef(unsigned SectionID, relocation_iterator RelI, const ObjectFile &BaseObjT, ObjSectionToIDMap &ObjSectionToID, StubMap &Stubs) override
Parses one or more object file relocations (some object files use relocation pairs) and stores it to ...
bool isText() const
Whether this section contains instructions.
std::map< RelocationValueRef, uintptr_t > StubMap
Tagged union holding either a T or a Error.
int64_t memcpyAddend(const RelocationEntry &RE) const
This convenience method uses memcpy to extract a contiguous addend (the addend size and offset are ta...
virtual Expected< JITSymbolFlags > getJITSymbolFlags(const SymbolRef &Sym)
Generate JITSymbolFlags from a libObject symbol.
RuntimeDyldMachOARM(RuntimeDyld::MemoryManager &MM, JITSymbolResolver &Resolver)
unsigned getAnyRelocationType(const MachO::any_relocation_info &RE) const
RuntimeDyldMachOTarget - Templated base class for generic MachO linker algorithms and data structures...
Error finalizeSection(const ObjectFile &Obj, unsigned SectionID, const SectionRef &Section)
Expected< RelocationValueRef > getRelocationValueRef(const ObjectFile &BaseTObj, const relocation_iterator &RI, const RelocationEntry &RE, ObjSectionToIDMap &ObjSectionToID)
Construct a RelocationValueRef representing the relocation target.
void addRelocationForSymbol(const RelocationEntry &RE, StringRef SymbolName)
RelocationEntry getRelocationEntry(unsigned SectionID, const ObjectFile &BaseTObj, const relocation_iterator &RI) const
Given a relocation_iterator for a non-scattered relocation, construct a RelocationEntry and fill in t...
void addRelocationForSection(const RelocationEntry &RE, unsigned SectionID)
MachO::any_relocation_info getRelocation(DataRefImpl Rel) const
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Expected< JITSymbolFlags > getJITSymbolFlags(const SymbolRef &SR) override
Generate JITSymbolFlags from a libObject symbol.
Flags for symbols in the JIT.
Symbol resolution interface.
Expected< unsigned > findOrEmitSection(const ObjectFile &Obj, const SectionRef &Section, bool IsCode, ObjSectionToIDMap &LocalSections)
Find Section in LocalSections.
static section_iterator getSectionByAddress(const MachOObjectFile &Obj, uint64_t Addr)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool isRelocationScattered(const MachO::any_relocation_info &RE) const
Expected< int64_t > decodeAddend(const RelocationEntry &RE) const
static ErrorSuccess success()
Create a success value.
int64_t Addend
Addend - the relocation addend encoded in the instruction itself.
std::error_code getName(StringRef &Result) const
uint32_t RelType
RelType - relocation type.
Expected< relocation_iterator > processScatteredVANILLA(unsigned SectionID, relocation_iterator RelI, const ObjectFile &BaseObjT, RuntimeDyldMachO::ObjSectionToIDMap &ObjSectionToID, bool TargetIsLocalThumbFunc=false)
Process a scattered vanilla relocation.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
uintptr_t getStubOffset() const
bool isAddrTargetThumb(unsigned SectionID, uint64_t Offset)
This is a value type class that represents a single symbol in the list of symbols in the object file...
unsigned getAnyRelocationLength(const MachO::any_relocation_info &RE) const
uint64_t Offset
Offset - offset into the section.
std::map< SectionRef, unsigned > ObjSectionToIDMap
uint8_t * getAddressWithOffset(unsigned OffsetBytes) const
Return the address of this section with an offset.
TargetFlagsType & getTargetFlags()
Return a reference to the target-specific flags.
SectionEntry - represents a section emitted into memory by the dynamic linker.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override
A object file specific relocation resolver.
RTDyldSymbolTable GlobalSymbolTable
Lightweight error class with error context and mandatory checking.
unsigned Size
The size of this relocation (MachO specific).
section_iterator section_end() const override
static ARMJITSymbolFlags fromObjectSymbol(const object::SymbolRef &Symbol)
#define UNIMPLEMENTED_RELOC(RelType)
Error populateIndirectSymbolPointersSection(const MachOObjectFile &Obj, const SectionRef &PTSection, unsigned PTSectionID)
void advanceStubOffset(unsigned StubSize)
StringRef - Represent a constant reference to a string, i.e.
void makeValueAddendPCRel(RelocationValueRef &Value, const relocation_iterator &RI, unsigned OffsetToNextPC)
Make the RelocationValueRef addend PC-relative.
uint32_t getScatteredRelocationValue(const MachO::any_relocation_info &RE) const
This is a value type class that represents a single section in the list of sections in the object fil...
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...