14 #define DEBUG_TYPE "dyld"
20 using namespace llvm::object;
25 uint32_t Length = *((uint32_t*)P);
27 unsigned char *
Ret = P + Length;
28 uint32_t Offset = *((uint32_t*)P);
34 intptr_t NewLocation = FDELocation - DeltaForText;
41 uint8_t Augmentationsize = *
P;
43 if (Augmentationsize != 0) {
45 intptr_t NewLSDA = LSDA - DeltaForEH;
55 return ObjDistance - MemDistance;
62 for (
int i = 0, e = UnregisteredEHFrameSections.size(); i != e; ++i) {
63 EHFrameRelatedSections &SectionInfo = UnregisteredEHFrameSections[i];
68 SectionEntry *EHFrame = &Sections[SectionInfo.EHFrameSID];
71 ExceptTab = &Sections[SectionInfo.ExceptTabSID];
79 unsigned char *End = P + EHFrame->
Size;
84 MemMgr->registerEHFrames(EHFrame->
Address,
88 UnregisteredEHFrameSections.clear();
95 ObjSectionToIDMap::iterator i, e;
96 for (i = SectionMap.begin(), e = SectionMap.end(); i != e; ++i) {
100 if (Name ==
"__eh_frame")
101 EHFrameSID = i->second;
102 else if (Name ==
"__text")
104 else if (Name ==
"__gcc_except_tab")
105 ExceptTabSID = i->second;
107 UnregisteredEHFrameSections.push_back(EHFrameRelatedSections(EHFrameSID,
146 uint8_t *LocalAddress = Section.
Address + Offset;
147 uint64_t FinalAddress = Section.
LoadAddress + Offset;
148 unsigned MachoType =
Type;
149 unsigned Size = 1 << LogSize;
151 DEBUG(
dbgs() <<
"resolveRelocation LocalAddress: "
152 <<
format(
"%p", LocalAddress)
153 <<
" FinalAddress: " <<
format(
"%p", FinalAddress)
154 <<
" Value: " <<
format(
"%p", Value)
155 <<
" Addend: " << Addend
156 <<
" isPCRel: " << isPCRel
157 <<
" MachoType: " << MachoType
165 resolveX86_64Relocation(LocalAddress,
174 resolveI386Relocation(LocalAddress,
184 resolveARMRelocation(LocalAddress,
195 bool RuntimeDyldMachO::resolveI386Relocation(uint8_t *LocalAddress,
196 uint64_t FinalAddress,
203 Value -= FinalAddress + 4;
209 uint8_t *p = LocalAddress;
210 uint64_t ValueToWrite = Value + Addend;
211 for (
unsigned i = 0; i < Size; ++i) {
212 *p++ = (uint8_t)(ValueToWrite & 0xff);
220 return Error(
"Relocation type not implemented yet!");
224 bool RuntimeDyldMachO::resolveX86_64Relocation(uint8_t *LocalAddress,
225 uint64_t FinalAddress,
236 Value -= FinalAddress + 4;
250 uint8_t *p = (uint8_t*)LocalAddress;
251 for (
unsigned i = 0; i < Size; ++i) {
252 *p++ = (uint8_t)Value;
261 return Error(
"Relocation type not implemented yet!");
265 bool RuntimeDyldMachO::resolveARMRelocation(uint8_t *LocalAddress,
266 uint64_t FinalAddress,
275 Value -= FinalAddress;
288 uint8_t *p = (uint8_t*)LocalAddress;
289 for (
unsigned i = 0; i < Size; ++i) {
290 *p++ = (uint8_t)Value;
298 uint32_t *p = (uint32_t*)LocalAddress;
308 *p = (*p & ~0xffffff) | Value;
319 return Error(
"Relocation type not implemented yet!");
353 uint8_t *LocalAddress = Section.
Address + Offset;
354 unsigned NumBytes = 1 << Size;
356 memcpy(&Addend, LocalAddress, NumBytes);
362 Symbol->getName(TargetName);
365 if (lsi != Symbols.
end()) {
371 if (gsi != GlobalSymbolTable.end()) {
381 Value.
SectionID = findOrEmitSection(Obj, Sec,
true, ObjSectionToID);
384 Value.
Addend = Addend - Addr;
391 StubMap::const_iterator i = Stubs.find(Value);
393 if (i != Stubs.end()) {
394 Addr = Section.
Address + i->second;
403 addRelocationForSection(RE, Value.
SectionID);
407 resolveRelocation(Section, Offset, (uint64_t)Addr,
414 StubMap::const_iterator i = Stubs.find(Value);
415 if (i != Stubs.end())
416 resolveRelocation(Section, Offset,
417 (uint64_t)Section.
Address + i->second,
418 RelType, 0, IsPCRel, Size);
422 uint8_t *StubTargetAddr = createStubFunction(Section.
Address +
429 addRelocationForSection(RE, Value.
SectionID);
430 resolveRelocation(Section, Offset,
432 RelType, 0, IsPCRel, Size);
441 addRelocationForSection(RE, Value.
SectionID);
451 if (
Magic ==
"\xFE\xED\xFA\xCE")
return true;
452 if (
Magic ==
"\xCE\xFA\xED\xFE")
return true;
453 if (
Magic ==
"\xFE\xED\xFA\xCF")
return true;
454 if (
Magic ==
"\xCF\xFA\xED\xFE")
return true;
COFF::RelocationTypeX86 Type
static intptr_t computeDelta(SectionEntry *A, SectionEntry *B)
size_t Size
Size - section size. Doesn't include the stubs.
size_t getBufferSize() const
iterator find(StringRef Key)
uint8_t * Address
Address - address in the linker's memory where the section resides.
virtual bool isCompatibleFormat(const ObjectBuffer *Buffer) const
virtual void finalizeLoad(ObjSectionToIDMap &SectionMap)
MachO::any_relocation_info getRelocation(DataRefImpl Rel) const
bool IsPCRel
True if this is a PCRel relocation (MachO specific).
unsigned SectionID
SectionID - the section this relocation points to.
const char * getBufferStart() const
#define llvm_unreachable(msg)
std::map< RelocationValueRef, uintptr_t > StubMap
format_object1< T > format(const char *Fmt, const T &Val)
SectionRef getRelocationSection(const MachO::any_relocation_info &RE) const
const char * data() const
error_code getName(StringRef &Result) const
virtual void registerEHFrames()
unsigned getAnyRelocationLength(const MachO::any_relocation_info &RE) const
error_code getAddress(uint64_t &Result) const
symbol_iterator getSymbol() const
static unsigned char * processFDE(unsigned char *P, intptr_t DeltaForText, intptr_t DeltaForEH)
bool isRelocationScattered(const MachO::any_relocation_info &RE) const
static const char *const Magic
uint32_t RelType
RelType - relocation type.
unsigned getAnyRelocationPCRel(const MachO::any_relocation_info &RE) const
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
virtual object::ObjectFile * getObjectFile() const =0
#define RTDYLD_INVALID_SECTION_ID
uint64_t Offset
Offset - offset into the section.
std::map< SectionRef, unsigned > ObjSectionToIDMap
virtual void processRelocationRef(unsigned SectionID, RelocationRef RelI, ObjectImage &Obj, ObjSectionToIDMap &ObjSectionToID, const SymbolTableMap &Symbols, StubMap &Stubs)
Parses the object file relocation and stores it to Relocations or SymbolRelocations (this depends on ...
unsigned getAnyRelocationType(const MachO::any_relocation_info &RE) const
LLVM Value Representation.
unsigned Size
The size of this relocation (MachO specific).
bool getPlainRelocationExternal(const MachO::any_relocation_info &RE) const
error_code getOffset(uint64_t &Result) const
DataRefImpl getRawDataRefImpl() const