10 #ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDMACHOI386_H
11 #define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_TARGETS_RUNTIMEDYLDMACHOI386_H
13 #include "../RuntimeDyldMachO.h"
15 #define DEBUG_TYPE "dyld"
47 return processSECTDIFFRelocation(SectionID, RelI, Obj,
50 return processI386ScatteredVANILLA(SectionID, RelI, Obj,
91 Value -= FinalAddress + 4;
104 assert((Value == SectionABase || Value == SectionBBase) &&
105 "Unexpected SECTDIFF relocation value.");
106 Value = SectionABase - SectionBBase + RE.
Addend;
111 Error(
"Relocation type not implemented yet!");
120 if (Name ==
"__jump_table")
121 populateJumpTable(cast<MachOObjectFile>(Obj), Section, SectionID);
122 else if (Name ==
"__pointers")
141 uint64_t Offset = RelI->getOffset();
142 uint8_t *LocalAddress = Section.
Address + Offset;
143 unsigned NumBytes = 1 << Size;
152 assert(SAI != Obj.
section_end() &&
"Can't find section for address A");
153 uint64_t SectionABase = SAI->getAddress();
154 uint64_t SectionAOffset = AddrA - SectionABase;
156 bool IsCode = SectionA.
isText();
157 uint32_t SectionAID =
162 assert(SBI != Obj.
section_end() &&
"Can't find section for address B");
163 uint64_t SectionBBase = SBI->getAddress();
164 uint64_t SectionBOffset = AddrB - SectionBBase;
166 uint32_t SectionBID =
170 Addend -= AddrA - AddrB;
172 DEBUG(
dbgs() <<
"Found SECTDIFF: AddrA: " << AddrA <<
", AddrB: " << AddrB
173 <<
", Addend: " << Addend <<
", SectionA ID: " << SectionAID
174 <<
", SectionAOffset: " << SectionAOffset
175 <<
", SectionB ID: " << SectionBID
176 <<
", SectionBOffset: " << SectionBOffset <<
"\n");
178 SectionAOffset, SectionBID, SectionBOffset,
199 uint64_t Offset = RelI->getOffset();
200 uint8_t *LocalAddress = Section.
Address + Offset;
201 unsigned NumBytes = 1 << Size;
206 assert(TargetSI != Obj.
section_end() &&
"Can't find section for symbol");
207 uint64_t SectionBaseAddr = TargetSI->getAddress();
209 bool IsCode = TargetSection.
isText();
210 uint32_t TargetSectionID =
213 Addend -= SectionBaseAddr;
214 RelocationEntry R(SectionID, Offset, RelocType, Addend, IsPCRel, Size);
223 unsigned JTSectionID) {
225 "__jump_table section not supported in 64-bit MachO.");
229 uint32_t JTSectionSize = Sec32.
size;
230 unsigned FirstIndirectSymbol = Sec32.
reserved1;
232 unsigned NumJTEntries = JTSectionSize / JTEntrySize;
234 unsigned JTEntryOffset = 0;
236 assert((JTSectionSize % JTEntrySize) == 0 &&
237 "Jump-table section does not contain a whole number of stubs?");
239 for (
unsigned i = 0; i < NumJTEntries; ++i) {
240 unsigned SymbolIndex =
244 if (std::error_code EC = IndirectSymbolName.
getError())
246 uint8_t *JTEntryAddr = JTSectionAddr + JTEntryOffset;
251 JTEntryOffset += JTEntrySize;
RelocationEntry - used to represent relocations internally in the dynamic linker. ...
std::error_code getError() const
void writeBytesUnaligned(uint64_t Value, uint8_t *Dst, unsigned Size) const
Endian-aware write.
Represents either an error or a value T.
void finalizeSection(const ObjectFile &Obj, unsigned SectionID, const SectionRef &Section)
unsigned getAnyRelocationType(const MachO::any_relocation_info &RE) const
void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override
A object file specific relocation resolver.
This class is the base class for all object file types.
uint8_t * Address
Address - address in the linker's memory where the section resides.
unsigned findOrEmitSection(const ObjectFile &Obj, const SectionRef &Section, bool IsCode, ObjSectionToIDMap &LocalSections)
Find Section in LocalSections.
DataRefImpl getRawDataRefImpl() const
void populateIndirectSymbolPointersSection(const MachOObjectFile &Obj, const SectionRef &PTSection, unsigned PTSectionID)
uint32_t getIndirectSymbolTableEntry(const MachO::dysymtab_command &DLC, unsigned Index) const
unsigned getMaxStubSize() override
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
Reports a serious error, calling any installed error handler.
bool IsPCRel
True if this is a PCRel relocation (MachO specific).
unsigned SectionID
SectionID - the section this relocation points to.
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...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
int64_t memcpyAddend(const RelocationEntry &RE) const
This convenience method uses memcpy to extract a contiguous addend (the addend size and offset are ta...
std::map< RelocationValueRef, uintptr_t > StubMap
uint32_t getScatteredRelocationValue(const MachO::any_relocation_info &RE) const
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 ...
std::error_code getName(StringRef &Result) const
void dumpRelocationToResolve(const RelocationEntry &RE, uint64_t Value) const
Dump information about the relocation entry (RE) and resolved value.
RuntimeDyldMachOTarget - Templated base class for generic MachO linker algorithms and data structures...
bool Error(const Twine &Msg)
void addRelocationForSymbol(const RelocationEntry &RE, StringRef SymbolName)
MachO::any_relocation_info getRelocation(DataRefImpl Rel) const
RuntimeDyld::SymbolResolver & Resolver
MachO::section getSection(DataRefImpl DRI) const
void addRelocationForSection(const RelocationEntry &RE, unsigned SectionID)
uint64_t readBytesUnaligned(uint8_t *Src, unsigned Size) const
Endian-aware read Read the least significant Size bytes from Src.
unsigned getAnyRelocationPCRel(const MachO::any_relocation_info &RE) const
uint8_t * getSectionAddress(unsigned SectionID) const
static section_iterator getSectionByAddress(const MachOObjectFile &Obj, uint64_t Addr)
unsigned getAnyRelocationLength(const MachO::any_relocation_info &RE) const
int64_t Addend
Addend - the relocation addend encoded in the instruction itself.
uint32_t RelType
RelType - relocation type.
RuntimeDyldMachOI386(RuntimeDyld::MemoryManager &MM, RuntimeDyld::SymbolResolver &Resolver)
uint8_t * createStubFunction(uint8_t *Addr, unsigned AbiVariant=0)
Emits long jump instruction to Addr.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
ErrorOr< StringRef > getName() const
uint64_t Offset
Offset - offset into the section.
std::map< SectionRef, unsigned > ObjSectionToIDMap
RelocationValueRef getRelocationValueRef(const ObjectFile &BaseTObj, const relocation_iterator &RI, const RelocationEntry &RE, ObjSectionToIDMap &ObjSectionToID)
Construct a RelocationValueRef representing the relocation target.
uint64_t LoadAddress
LoadAddress - the address of the section in the target process's memory.
basic_symbol_iterator getSymbolByIndex(unsigned Index) const
unsigned getStubAlignment() override
MachO::dysymtab_command getDysymtabLoadCommand() const
SectionEntry - represents a section emitted into memory by the dynamic linker.
LLVM Value Representation.
unsigned Size
The size of this relocation (MachO specific).
section_iterator section_end() const override
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.
bool isRelocationScattered(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...