diff options
Diffstat (limited to 'lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp')
-rw-r--r-- | lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp | 88 |
1 files changed, 63 insertions, 25 deletions
diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp index 24437e0..b7f515d 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp @@ -42,8 +42,7 @@ void RuntimeDyldMachO::resolveRelocation(uint8_t *LocalAddress, // This just dispatches to the proper target specific routine. switch (Arch) { default: llvm_unreachable("Unsupported CPU type!"); - case Triple::x86_64: // Fall through. - case Triple::x86: + case Triple::x86_64: resolveX86_64Relocation(LocalAddress, FinalAddress, (uintptr_t)Value, @@ -52,6 +51,15 @@ void RuntimeDyldMachO::resolveRelocation(uint8_t *LocalAddress, Size, Addend); break; + case Triple::x86: + resolveI386Relocation(LocalAddress, + FinalAddress, + (uintptr_t)Value, + isPCRel, + Type, + Size, + Addend); + break; case Triple::arm: // Fall through. case Triple::thumb: resolveARMRelocation(LocalAddress, @@ -66,6 +74,35 @@ void RuntimeDyldMachO::resolveRelocation(uint8_t *LocalAddress, } bool RuntimeDyldMachO:: +resolveI386Relocation(uint8_t *LocalAddress, + uint64_t FinalAddress, + uint64_t Value, + bool isPCRel, + unsigned Type, + unsigned Size, + int64_t Addend) { + if (isPCRel) + Value -= FinalAddress + 4; // see resolveX86_64Relocation + + switch (Type) { + default: + llvm_unreachable("Invalid relocation type!"); + case macho::RIT_Vanilla: { + uint8_t *p = LocalAddress; + uint64_t ValueToWrite = Value + Addend; + for (unsigned i = 0; i < Size; ++i) { + *p++ = (uint8_t)(ValueToWrite & 0xff); + ValueToWrite >>= 8; + } + } + case macho::RIT_Difference: + case macho::RIT_Generic_LocalDifference: + case macho::RIT_Generic_PreboundLazyPointer: + return Error("Relocation type not implemented yet!"); + } +} + +bool RuntimeDyldMachO:: resolveX86_64Relocation(uint8_t *LocalAddress, uint64_t FinalAddress, uint64_t Value, @@ -167,10 +204,11 @@ resolveARMRelocation(uint8_t *LocalAddress, return false; } -void RuntimeDyldMachO:: -processRelocationRef(const ObjRelocationInfo &Rel, const ObjectFile &Obj, - ObjSectionToIDMap &ObjSectionToID, - LocalSymbolMap &Symbols, StubMap &Stubs) { +void RuntimeDyldMachO::processRelocationRef(const ObjRelocationInfo &Rel, + ObjectImage &Obj, + ObjSectionToIDMap &ObjSectionToID, + LocalSymbolMap &Symbols, + StubMap &Stubs) { uint32_t RelType = (uint32_t) (Rel.Type & 0xffffffffL); RelocationValueRef Value; @@ -183,32 +221,32 @@ processRelocationRef(const ObjRelocationInfo &Rel, const ObjectFile &Obj, const SymbolRef &Symbol = Rel.Symbol; Symbol.getName(TargetName); // First look the symbol in object file symbols. - LocalSymbolMap::iterator it = Symbols.find(TargetName.data()); - if (it != Symbols.end()) { - Value.SectionID = it->second.first; - Value.Addend = it->second.second; + LocalSymbolMap::iterator lsi = Symbols.find(TargetName.data()); + if (lsi != Symbols.end()) { + Value.SectionID = lsi->second.first; + Value.Addend = lsi->second.second; } else { // Second look the symbol in global symbol table. - StringMap<SymbolLoc>::iterator itS = SymbolTable.find(TargetName.data()); - if (itS != SymbolTable.end()) { - Value.SectionID = itS->second.first; - Value.Addend = itS->second.second; + StringMap<SymbolLoc>::iterator gsi = SymbolTable.find(TargetName.data()); + if (gsi != SymbolTable.end()) { + Value.SectionID = gsi->second.first; + Value.Addend = gsi->second.second; } else Value.SymbolName = TargetName.data(); } } else { error_code err; - uint8_t sIdx = static_cast<uint8_t>(RelType & 0xFF); - section_iterator sIt = Obj.begin_sections(), - sItEnd = Obj.end_sections(); - for (uint8_t i = 1; i < sIdx; i++) { + uint8_t sectionIndex = static_cast<uint8_t>(RelType & 0xFF); + section_iterator si = Obj.begin_sections(), + se = Obj.end_sections(); + for (uint8_t i = 1; i < sectionIndex; i++) { error_code err; - sIt.increment(err); - if (sIt == sItEnd) + si.increment(err); + if (si == se) break; } - assert(sIt != sItEnd && "No section containing relocation!"); - Value.SectionID = findOrEmitSection(*sIt, true, ObjSectionToID); + assert(si != se && "No section containing relocation!"); + Value.SectionID = findOrEmitSection(Obj, *si, true, ObjSectionToID); Value.Addend = *(const intptr_t *)Target; if (Value.Addend) { // The MachO addend is offset from the current section, we need set it @@ -221,10 +259,10 @@ processRelocationRef(const ObjRelocationInfo &Rel, const ObjectFile &Obj, // This is an ARM branch relocation, need to use a stub function. // Look up for existing stub. - StubMap::const_iterator stubIt = Stubs.find(Value); - if (stubIt != Stubs.end()) + StubMap::const_iterator i = Stubs.find(Value); + if (i != Stubs.end()) resolveRelocation(Target, (uint64_t)Target, - (uint64_t)Section.Address + stubIt->second, + (uint64_t)Section.Address + i->second, RelType, 0); else { // Create a new stub function. |