9 #ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDMACHOI386_H 10 #define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDMACHOI386_H 12 #include "../RuntimeDyldMachO.h" 15 #define DEBUG_TYPE "dyld" 47 return processSECTDIFFRelocation(SectionID, RelI, Obj,
51 return make_error<RuntimeDyldError>((
"Unhandled I386 scattered relocation " 52 "type: " +
Twine(RelType)).str());
61 return make_error<RuntimeDyldError>((
"MachO I386 relocation type " +
63 " is out of range").str());
73 return ValueOrErr.takeError();
106 Value -= FinalAddress + 4;
117 assert((Value == SectionABase || Value == SectionBBase) &&
118 "Unexpected SECTDIFF relocation value.");
119 Value = SectionABase - SectionBBase + RE.
Addend;
136 if (Name ==
"__jump_table")
137 return populateJumpTable(cast<MachOObjectFile>(Obj), Section, SectionID);
138 else if (Name ==
"__pointers")
158 uint64_t
Offset = RelI->getOffset();
160 unsigned NumBytes = 1 <<
Size;
170 uint64_t SectionABase = SAI->getAddress();
171 uint64_t SectionAOffset = AddrA - SectionABase;
173 bool IsCode = SectionA.
isText();
175 if (
auto SectionAIDOrErr =
177 SectionAID = *SectionAIDOrErr;
179 return SectionAIDOrErr.takeError();
184 uint64_t SectionBBase = SBI->getAddress();
185 uint64_t SectionBOffset = AddrB - SectionBBase;
188 if (
auto SectionBIDOrErr =
190 SectionBID = *SectionBIDOrErr;
192 return SectionBIDOrErr.takeError();
195 Addend -= AddrA - AddrB;
198 <<
", AddrB: " << AddrB <<
", Addend: " << Addend
199 <<
", SectionA ID: " << SectionAID <<
", SectionAOffset: " 200 << SectionAOffset <<
", SectionB ID: " << SectionBID
201 <<
", SectionBOffset: " << SectionBOffset <<
"\n");
203 SectionAOffset, SectionBID, SectionBOffset,
214 unsigned JTSectionID) {
218 unsigned FirstIndirectSymbol = Sec32.
reserved1;
220 unsigned NumJTEntries = JTSectionSize / JTEntrySize;
222 unsigned JTEntryOffset = 0;
224 if (JTSectionSize % JTEntrySize != 0)
225 return make_error<RuntimeDyldError>(
"Jump-table section does not contain " 226 "a whole number of stubs?");
228 for (
unsigned i = 0; i < NumJTEntries; ++i) {
229 unsigned SymbolIndex =
233 if (!IndirectSymbolName)
235 uint8_t *JTEntryAddr = JTSectionAddr + JTEntryOffset;
240 JTEntryOffset += JTEntrySize;
RelocationEntry - used to represent relocations internally in the dynamic linker. ...
This class represents lattice values for constants.
Expected< StringRef > getName() const
unsigned getAnyRelocationPCRel(const MachO::any_relocation_info &RE) const
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
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.
void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override
A object file specific relocation resolver.
Expected< SectionRef > getSection(unsigned SectionIndex) const
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() const override
Error takeError()
Take ownership of the stored error.
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.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
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...
symbol_iterator getSymbolByIndex(unsigned Index) const
unsigned getAnyRelocationType(const MachO::any_relocation_info &RE) const
RuntimeDyldMachOTarget - Templated base class for generic MachO linker algorithms and data structures...
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.
Symbol resolution interface.
Expected< unsigned > findOrEmitSection(const ObjectFile &Obj, const SectionRef &Section, bool IsCode, ObjSectionToIDMap &LocalSections)
Find Section in LocalSections.
uint8_t * getSectionAddress(unsigned SectionID) const
DataRefImpl getRawDataRefImpl() const
void consumeError(Error Err)
Consume a Error without doing anything.
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
static ErrorSuccess success()
Create a success value.
RuntimeDyldMachOI386(RuntimeDyld::MemoryManager &MM, JITSymbolResolver &Resolver)
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 ...
int64_t Addend
Addend - the relocation addend encoded in the instruction itself.
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.
uint8_t * createStubFunction(uint8_t *Addr, unsigned AbiVariant=0)
Emits long jump instruction to Addr.
Expected< StringRef > getName() const
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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.
unsigned getStubAlignment() override
SectionEntry - represents a section emitted into memory by the dynamic linker.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Lightweight error class with error context and mandatory checking.
unsigned Size
The size of this relocation (MachO specific).
section_iterator section_end() const override
#define UNIMPLEMENTED_RELOC(RelType)
Error populateIndirectSymbolPointersSection(const MachOObjectFile &Obj, const SectionRef &PTSection, unsigned PTSectionID)
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 getIndirectSymbolTableEntry(const MachO::dysymtab_command &DLC, unsigned Index) const
uint32_t getScatteredRelocationValue(const MachO::any_relocation_info &RE) const
Error finalizeSection(const ObjectFile &Obj, unsigned SectionID, const SectionRef &Section)
This is a value type class that represents a single section in the list of sections in the object fil...
MachO::dysymtab_command getDysymtabLoadCommand() const