9#ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDMACHOI386_H
10#define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDMACHOI386_H
12#include "../RuntimeDyldMachO.h"
14#define DEBUG_TYPE "dyld"
46 return processSECTDIFFRelocation(SectionID, RelI, Obj,
50 return make_error<RuntimeDyldError>((
"Unhandled I386 scattered relocation "
51 "type: " +
Twine(RelType)).str());
60 return make_error<RuntimeDyldError>((
"MachO I386 relocation type " +
62 " is out of range").str());
72 return ValueOrErr.takeError();
101 uint8_t *LocalAddress = Section.getAddressWithOffset(RE.
Offset);
104 uint64_t FinalAddress = Section.getLoadAddressWithOffset(RE.
Offset);
105 Value -= FinalAddress + 4;
117 "Unexpected SECTDIFF relocation value.");
135 if (
Name ==
"__jump_table")
136 return populateJumpTable(cast<MachOObjectFile>(Obj), Section, SectionID);
137 else if (
Name ==
"__pointers")
158 uint8_t *LocalAddress = Section.getAddressWithOffset(
Offset);
159 unsigned NumBytes = 1 <<
Size;
170 uint64_t SectionAOffset = AddrA - SectionABase;
172 bool IsCode = SectionA.
isText();
174 if (
auto SectionAIDOrErr =
176 SectionAID = *SectionAIDOrErr;
178 return SectionAIDOrErr.takeError();
184 uint64_t SectionBOffset = AddrB - SectionBBase;
187 if (
auto SectionBIDOrErr =
189 SectionBID = *SectionBIDOrErr;
191 return SectionBIDOrErr.takeError();
194 Addend -= AddrA - AddrB;
197 <<
", AddrB: " << AddrB <<
", Addend: " << Addend
198 <<
", SectionA ID: " << SectionAID <<
", SectionAOffset: "
199 << SectionAOffset <<
", SectionB ID: " << SectionBID
200 <<
", SectionBOffset: " << SectionBOffset <<
"\n");
202 SectionAOffset, SectionBID, SectionBOffset,
213 unsigned JTSectionID) {
217 unsigned FirstIndirectSymbol = Sec32.
reserved1;
219 unsigned NumJTEntries = JTSectionSize / JTEntrySize;
221 unsigned JTEntryOffset = 0;
223 if (JTSectionSize % JTEntrySize != 0)
224 return make_error<RuntimeDyldError>(
"Jump-table section does not contain "
225 "a whole number of stubs?");
227 for (
unsigned i = 0; i < NumJTEntries; ++i) {
228 unsigned SymbolIndex =
232 if (!IndirectSymbolName)
234 uint8_t *JTEntryAddr = JTSectionAddr + JTEntryOffset;
239 JTEntryOffset += JTEntrySize;
#define UNIMPLEMENTED_RELOC(RelType)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
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.
unsigned Size
The size of this relocation (MachO specific).
uint32_t RelType
RelType - relocation type.
uint64_t Offset
Offset - offset into the section.
bool IsPCRel
True if this is a PCRel relocation (MachO specific).
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.
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.
uint8_t * createStubFunction(uint8_t *Addr, unsigned AbiVariant=0)
Emits long jump instruction to Addr.
uint64_t readBytesUnaligned(uint8_t *Src, unsigned Size) const
Endian-aware read Read the least significant Size bytes from Src.
uint8_t * getSectionAddress(unsigned SectionID) const
RuntimeDyldMachOTarget - Templated base class for generic MachO linker algorithms and data structures...
unsigned getMaxStubSize() const override
Error finalizeSection(const ObjectFile &Obj, unsigned SectionID, const SectionRef &Section)
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 ...
Align getStubAlignment() override
RuntimeDyldMachOI386(RuntimeDyld::MemoryManager &MM, JITSymbolResolver &Resolver)
void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override
A object file specific relocation resolver.
static section_iterator getSectionByAddress(const MachOObjectFile &Obj, uint64_t Addr)
int64_t memcpyAddend(const RelocationEntry &RE) const
This convenience method uses memcpy to extract a contiguous addend (the addend size and offset are ta...
Error populateIndirectSymbolPointersSection(const MachOObjectFile &Obj, const SectionRef &PTSection, unsigned PTSectionID)
void makeValueAddendPCRel(RelocationValueRef &Value, const relocation_iterator &RI, unsigned OffsetToNextPC)
Make the RelocationValueRef addend PC-relative.
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...
Expected< RelocationValueRef > getRelocationValueRef(const ObjectFile &BaseTObj, const relocation_iterator &RI, const RelocationEntry &RE, ObjSectionToIDMap &ObjSectionToID)
Construct a RelocationValueRef representing the relocation target.
Expected< relocation_iterator > processScatteredVANILLA(unsigned SectionID, relocation_iterator RelI, const ObjectFile &BaseObjT, RuntimeDyldMachO::ObjSectionToIDMap &ObjSectionToID, bool TargetIsLocalThumbFunc=false)
Process a scattered vanilla relocation.
void dumpRelocationToResolve(const RelocationEntry &RE, uint64_t Value) const
Dump information about the relocation entry (RE) and resolved value.
SectionEntry - represents a section emitted into memory by the dynamic linker.
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
Expected< SectionRef > getSection(unsigned SectionIndex) const
section_iterator section_end() const override
uint32_t getScatteredRelocationValue(const MachO::any_relocation_info &RE) const
MachO::dysymtab_command getDysymtabLoadCommand() const
unsigned getAnyRelocationType(const MachO::any_relocation_info &RE) const
symbol_iterator getSymbolByIndex(unsigned Index) const
unsigned getAnyRelocationPCRel(const MachO::any_relocation_info &RE) const
unsigned getAnyRelocationLength(const MachO::any_relocation_info &RE) const
MachO::any_relocation_info getRelocation(DataRefImpl Rel) const
bool isRelocationScattered(const MachO::any_relocation_info &RE) const
uint32_t getIndirectSymbolTableEntry(const MachO::dysymtab_command &DLC, unsigned Index) const
This class is the base class for all object file types.
This is a value type class that represents a single section in the list of sections in the object fil...
DataRefImpl getRawDataRefImpl() const
uint64_t getAddress() const
bool isText() const
Whether this section contains instructions.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ GENERIC_RELOC_LOCAL_SECTDIFF
@ GENERIC_RELOC_PB_LA_PTR
This is an optimization pass for GlobalISel generic memory operations.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void consumeError(Error Err)
Consume a Error without doing anything.
This struct is a compact representation of a valid (non-zero power of two) alignment.