From 4923eea4f6a5c547cfa87e2da7ba788100df4982 Mon Sep 17 00:00:00 2001 From: Juergen Ributzka Date: Fri, 21 Mar 2014 07:26:41 +0000 Subject: [RuntimeDyld] Allow processRelocationRef to process more than one relocation entry at a time. Some targets require more than one relocation entry to perform a relocation. This change allows processRelocationRef to process more than one relocation entry at a time by passing the relocation iterator itself instead of just the relocation entry. Related to git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204439 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp | 23 +++++++++++----------- lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp | 22 +++++++++++---------- lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h | 8 ++++---- lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h | 13 ++++++------ .../RuntimeDyld/RuntimeDyldMachO.cpp | 23 ++++++++++++---------- lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h | 8 ++++---- 6 files changed, 51 insertions(+), 46 deletions(-) (limited to 'lib/ExecutionEngine/RuntimeDyld') diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp index 310b206a06..5c3cc008e3 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp @@ -165,18 +165,19 @@ ObjectImage* RuntimeDyldImpl::loadObject(ObjectImage *InputObject) { StubMap Stubs; section_iterator RelocatedSection = SI->getRelocatedSection(); - if ((SI->relocation_begin() != SI->relocation_end()) || - ProcessAllSections) { - bool IsCode = false; - Check(RelocatedSection->isText(IsCode)); - SectionID = - findOrEmitSection(*Obj, *RelocatedSection, IsCode, LocalSections); - DEBUG(dbgs() << "\tSectionID: " << SectionID << "\n"); - } + if (SI->relocation_empty() && !ProcessAllSections) + continue; + + bool IsCode = false; + Check(RelocatedSection->isText(IsCode)); + SectionID = + findOrEmitSection(*Obj, *RelocatedSection, IsCode, LocalSections); + DEBUG(dbgs() << "\tSectionID: " << SectionID << "\n"); - for (const RelocationRef &Reloc : SI->relocations()) - processRelocationRef(SectionID, Reloc, *Obj, LocalSections, LocalSymbols, - Stubs); + for (relocation_iterator I = SI->relocation_begin(), + E = SI->relocation_end(); I != E;) + I = processRelocationRef(SectionID, I, *Obj, LocalSections, LocalSymbols, + Stubs); } // Give the subclasses a chance to tie-up any loose ends. diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp index 96b4e127aa..6510bd0a2e 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp @@ -919,17 +919,18 @@ void RuntimeDyldELF::resolveRelocation(const SectionEntry &Section, } } -void RuntimeDyldELF::processRelocationRef(unsigned SectionID, - RelocationRef RelI, - ObjectImage &Obj, - ObjSectionToIDMap &ObjSectionToID, - const SymbolTableMap &Symbols, - StubMap &Stubs) { +relocation_iterator +RuntimeDyldELF::processRelocationRef(unsigned SectionID, + relocation_iterator RelI, + ObjectImage &Obj, + ObjSectionToIDMap &ObjSectionToID, + const SymbolTableMap &Symbols, + StubMap &Stubs) { uint64_t RelType; - Check(RelI.getType(RelType)); + Check(RelI->getType(RelType)); int64_t Addend; - Check(getELFRelocationAddend(RelI, Addend)); - symbol_iterator Symbol = RelI.getSymbol(); + Check(getELFRelocationAddend(*RelI, Addend)); + symbol_iterator Symbol = RelI->getSymbol(); // Obtain the symbol name which is referenced in the relocation StringRef TargetName; @@ -1001,7 +1002,7 @@ void RuntimeDyldELF::processRelocationRef(unsigned SectionID, } } uint64_t Offset; - Check(RelI.getOffset(Offset)); + Check(RelI->getOffset(Offset)); DEBUG(dbgs() << "\t\tSectionID: " << SectionID << " Offset: " << Offset @@ -1337,6 +1338,7 @@ void RuntimeDyldELF::processRelocationRef(unsigned SectionID, else addRelocationForSection(RE, Value.SectionID); } + return ++RelI; } void RuntimeDyldELF::updateGOTEntries(StringRef Name, uint64_t Addr) { diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h index f7f43b4069..9c81d071d2 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h @@ -133,10 +133,10 @@ public: {} void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override; - void processRelocationRef(unsigned SectionID, RelocationRef RelI, - ObjectImage &Obj, ObjSectionToIDMap &ObjSectionToID, - const SymbolTableMap &Symbols, - StubMap &Stubs) override; + relocation_iterator + processRelocationRef(unsigned SectionID, relocation_iterator RelI, + ObjectImage &Obj, ObjSectionToIDMap &ObjSectionToID, + const SymbolTableMap &Symbols, StubMap &Stubs) override; bool isCompatibleFormat(const ObjectBuffer *Buffer) const override; bool isCompatibleFile(const object::ObjectFile *Buffer) const override; void registerEHFrames() override; diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h index 0b7de17a6e..504a3ff670 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h @@ -300,12 +300,10 @@ protected: /// \brief Parses the object file relocation and stores it to Relocations /// or SymbolRelocations (this depends on the object file type). - virtual void processRelocationRef(unsigned SectionID, - RelocationRef RelI, - ObjectImage &Obj, - ObjSectionToIDMap &ObjSectionToID, - const SymbolTableMap &Symbols, - StubMap &Stubs) = 0; + virtual relocation_iterator + processRelocationRef(unsigned SectionID, relocation_iterator RelI, + ObjectImage &Obj, ObjSectionToIDMap &ObjSectionToID, + const SymbolTableMap &Symbols, StubMap &Stubs) = 0; /// \brief Resolve relocations to external symbols. void resolveExternalSymbols(); @@ -321,7 +319,8 @@ protected: uint64_t& DataSizeRW); // \brief Compute the stub buffer size required for a section - unsigned computeSectionStubBufSize(ObjectImage &Obj, const SectionRef &Section); + unsigned computeSectionStubBufSize(ObjectImage &Obj, + const SectionRef &Section); public: RuntimeDyldImpl(RTDyldMemoryManager *mm) diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp index 62de7b707c..0f9fc9169d 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp @@ -320,15 +320,17 @@ bool RuntimeDyldMachO::resolveARMRelocation(uint8_t *LocalAddress, return false; } -void RuntimeDyldMachO::processRelocationRef(unsigned SectionID, - RelocationRef RelI, - ObjectImage &Obj, - ObjSectionToIDMap &ObjSectionToID, - const SymbolTableMap &Symbols, - StubMap &Stubs) { +relocation_iterator +RuntimeDyldMachO::processRelocationRef(unsigned SectionID, + relocation_iterator RelI, + ObjectImage &Obj, + ObjSectionToIDMap &ObjSectionToID, + const SymbolTableMap &Symbols, + StubMap &Stubs) { const ObjectFile *OF = Obj.getObjectFile(); const MachOObjectFile *MachO = static_cast(OF); - MachO::any_relocation_info RE= MachO->getRelocation(RelI.getRawDataRefImpl()); + MachO::any_relocation_info RE = + MachO->getRelocation(RelI->getRawDataRefImpl()); uint32_t RelType = MachO->getAnyRelocationType(RE); @@ -339,7 +341,7 @@ void RuntimeDyldMachO::processRelocationRef(unsigned SectionID, // Note: This will fail horribly where the relocations *do* need to be // applied, but that was already the case. if (MachO->isRelocationScattered(RE)) - return; + return ++RelI; RelocationValueRef Value; SectionEntry &Section = Sections[SectionID]; @@ -348,7 +350,7 @@ void RuntimeDyldMachO::processRelocationRef(unsigned SectionID, bool IsPCRel = MachO->getAnyRelocationPCRel(RE); unsigned Size = MachO->getAnyRelocationLength(RE); uint64_t Offset; - RelI.getOffset(Offset); + RelI->getOffset(Offset); uint8_t *LocalAddress = Section.Address + Offset; unsigned NumBytes = 1 << Size; uint64_t Addend = 0; @@ -356,7 +358,7 @@ void RuntimeDyldMachO::processRelocationRef(unsigned SectionID, if (isExtern) { // Obtain the symbol name which is referenced in the relocation - symbol_iterator Symbol = RelI.getSymbol(); + symbol_iterator Symbol = RelI->getSymbol(); StringRef TargetName; Symbol->getName(TargetName); // First search for the symbol in the local symbol table @@ -443,6 +445,7 @@ void RuntimeDyldMachO::processRelocationRef(unsigned SectionID, else addRelocationForSection(RE, Value.SectionID); } + return ++RelI; } diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h index 1a285ffbfb..48b0481ce5 100644 --- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h +++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h @@ -88,10 +88,10 @@ public: RuntimeDyldMachO(RTDyldMemoryManager *mm) : RuntimeDyldImpl(mm) {} void resolveRelocation(const RelocationEntry &RE, uint64_t Value) override; - void processRelocationRef(unsigned SectionID, RelocationRef RelI, - ObjectImage &Obj, ObjSectionToIDMap &ObjSectionToID, - const SymbolTableMap &Symbols, - StubMap &Stubs) override; + relocation_iterator + processRelocationRef(unsigned SectionID, relocation_iterator RelI, + ObjectImage &Obj, ObjSectionToIDMap &ObjSectionToID, + const SymbolTableMap &Symbols, StubMap &Stubs) override; bool isCompatibleFormat(const ObjectBuffer *Buffer) const override; bool isCompatibleFile(const object::ObjectFile *Obj) const override; void registerEHFrames() override; -- cgit v1.2.3