[lld] r243014 - Use the getSymbol with an explicit symbol table. NFC.

Rafael Espindola rafael.espindola at gmail.com
Thu Jul 23 06:41:26 PDT 2015


Author: rafael
Date: Thu Jul 23 08:41:25 2015
New Revision: 243014

URL: http://llvm.org/viewvc/llvm-project?rev=243014&view=rev
Log:
Use the getSymbol with an explicit symbol table. NFC.

Modified:
    lld/trunk/lib/ReaderWriter/ELF/ELFFile.cpp
    lld/trunk/lib/ReaderWriter/ELF/ELFFile.h
    lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.cpp
    lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h

Modified: lld/trunk/lib/ReaderWriter/ELF/ELFFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFFile.cpp?rev=243014&r1=243013&r2=243014&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFFile.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFFile.cpp Thu Jul 23 08:41:25 2015
@@ -149,7 +149,7 @@ std::error_code ELFFile<ELFT>::createAto
       auto sHdr = *sHdrOrErr;
       auto ri = _objFile->rel_begin(&section);
       auto re = _objFile->rel_end(&section);
-      _relocationReferences[sHdr] = make_range(ri, re);
+      _relocationReferences[sHdr] = §ion;
       totalRelocs += std::distance(ri, re);
     } else {
       auto sectionName = _objFile->getSectionName(&section);
@@ -501,10 +501,10 @@ std::error_code ELFFile<ELFT>::handleSec
       return ec;
     sectionNames.push_back(*sectionName);
   }
-  const Elf_Sym *symbol = _objFile->getSymbol(section->sh_info);
   ErrorOr<const Elf_Shdr *> symtab = _objFile->getSection(section->sh_link);
   if (std::error_code ec = symtab.getError())
     return ec;
+  const Elf_Sym *symbol = _objFile->getSymbol(*symtab, section->sh_info);
   ErrorOr<const Elf_Shdr *> strtab_sec =
       _objFile->getSection((*symtab)->sh_link);
   if (std::error_code ec = strtab_sec.getError())
@@ -616,7 +616,8 @@ template <class ELFT>
 void ELFFile<ELFT>::createRelocationReferences(const Elf_Sym *symbol,
                                                ArrayRef<uint8_t> symContent,
                                                ArrayRef<uint8_t> secContent,
-                                               range<const Elf_Rel *> rels) {
+                                               const Elf_Shdr *relSec) {
+  auto rels = _objFile->rels(relSec);
   bool isMips64EL = _objFile->isMips64EL();
   const auto symValue = getSymbolValue(symbol);
   for (const auto &rel : rels) {
@@ -662,10 +663,12 @@ void ELFFile<ELFT>::updateReferenceForMe
 }
 
 template <class ELFT> void ELFFile<ELFT>::updateReferences() {
+  const Elf_Shdr *symtab = _objFile->getDotSymtabSec();
   for (auto &ri : _references) {
     if (ri->kindNamespace() != Reference::KindNamespace::ELF)
       continue;
-    const Elf_Sym *symbol = _objFile->getSymbol(ri->targetSymbolIndex());
+    const Elf_Sym *symbol =
+        _objFile->getSymbol(symtab, ri->targetSymbolIndex());
     ErrorOr<const Elf_Shdr *> shdr = _objFile->getSection(symbol);
 
     // If the atom is not in mergeable string section, the target atom is

Modified: lld/trunk/lib/ReaderWriter/ELF/ELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFFile.h?rev=243014&r1=243013&r2=243014&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/ELFFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/ELFFile.h Thu Jul 23 08:41:25 2015
@@ -141,7 +141,7 @@ protected:
   virtual void createRelocationReferences(const Elf_Sym *symbol,
                                           ArrayRef<uint8_t> symContent,
                                           ArrayRef<uint8_t> secContent,
-                                          range<const Elf_Rel *> rels);
+                                          const Elf_Shdr *relSec);
 
   /// \brief After all the Atoms and References are created, update each
   /// Reference's target with the Atom pointer it refers to.
@@ -328,8 +328,7 @@ protected:
   std::unordered_map<const Elf_Shdr *, range<const Elf_Rela *>>
       _relocationAddendReferences;
   MergedSectionMapT _mergedSectionMap;
-  std::unordered_map<const Elf_Shdr *, range<const Elf_Rel *>>
-      _relocationReferences;
+  std::unordered_map<const Elf_Shdr *, const Elf_Shdr *> _relocationReferences;
   std::vector<ELFReference<ELFT> *> _references;
   llvm::DenseMap<const Elf_Sym *, Atom *> _symbolToAtomMapping;
   llvm::DenseMap<const ELFReference<ELFT> *, const Elf_Sym *>

Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.cpp?rev=243014&r1=243013&r2=243014&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.cpp Thu Jul 23 08:41:25 2015
@@ -236,9 +236,12 @@ void MipsELFFile<ELFT>::createRelocation
 }
 
 template <class ELFT>
-void MipsELFFile<ELFT>::createRelocationReferences(
-    const Elf_Sym *symbol, ArrayRef<uint8_t> symContent,
-    ArrayRef<uint8_t> secContent, range<const Elf_Rel *> rels) {
+void MipsELFFile<ELFT>::createRelocationReferences(const Elf_Sym *symbol,
+                                                   ArrayRef<uint8_t> symContent,
+                                                   ArrayRef<uint8_t> secContent,
+                                                   const Elf_Shdr *relSec) {
+  const Elf_Shdr *symtab = *this->_objFile->getSection(relSec->sh_link);
+  auto rels = this->_objFile->rels(relSec);
   const auto value = this->getSymbolValue(symbol);
   for (const Elf_Rel *rit = rels.begin(), *eit = rels.end(); rit != eit;
        ++rit) {
@@ -250,7 +253,7 @@ void MipsELFFile<ELFT>::createRelocation
     this->_references.push_back(r);
 
     auto addend = readAddend(*rit, secContent);
-    auto pairRelType = getPairRelocation(*rit);
+    auto pairRelType = getPairRelocation(symtab, *rit);
     if (pairRelType != llvm::ELF::R_MIPS_NONE) {
       addend <<= 16;
       auto mit = findMatchingRelocation(pairRelType, rit, eit);
@@ -279,20 +282,21 @@ MipsELFFile<ELFT>::readAddend(const Elf_
 }
 
 template <class ELFT>
-uint32_t MipsELFFile<ELFT>::getPairRelocation(const Elf_Rel &rel) const {
+uint32_t MipsELFFile<ELFT>::getPairRelocation(const Elf_Shdr *symtab,
+                                              const Elf_Rel &rel) const {
   switch (getPrimaryType(rel)) {
   case llvm::ELF::R_MIPS_HI16:
     return llvm::ELF::R_MIPS_LO16;
   case llvm::ELF::R_MIPS_PCHI16:
     return llvm::ELF::R_MIPS_PCLO16;
   case llvm::ELF::R_MIPS_GOT16:
-    if (isLocalBinding(rel))
+    if (isLocalBinding(symtab, rel))
       return llvm::ELF::R_MIPS_LO16;
     break;
   case llvm::ELF::R_MICROMIPS_HI16:
     return llvm::ELF::R_MICROMIPS_LO16;
   case llvm::ELF::R_MICROMIPS_GOT16:
-    if (isLocalBinding(rel))
+    if (isLocalBinding(symtab, rel))
       return llvm::ELF::R_MICROMIPS_LO16;
     break;
   default:
@@ -315,8 +319,9 @@ MipsELFFile<ELFT>::findMatchingRelocatio
 }
 
 template <class ELFT>
-bool MipsELFFile<ELFT>::isLocalBinding(const Elf_Rel &rel) const {
-  return this->_objFile->getSymbol(rel.getSymbol(isMips64EL<ELFT>()))
+bool MipsELFFile<ELFT>::isLocalBinding(const Elf_Shdr *symtab,
+                                       const Elf_Rel &rel) const {
+  return this->_objFile->getSymbol(symtab, rel.getSymbol(isMips64EL<ELFT>()))
              ->getBinding() == llvm::ELF::STB_LOCAL;
 }
 

Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h?rev=243014&r1=243013&r2=243014&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsELFFile.h Thu Jul 23 08:41:25 2015
@@ -93,7 +93,7 @@ private:
   void createRelocationReferences(const Elf_Sym *symbol,
                                   ArrayRef<uint8_t> symContent,
                                   ArrayRef<uint8_t> secContent,
-                                  range<const Elf_Rel *> rels) override;
+                                  const Elf_Shdr *RelSec) override;
 
   const Elf_Shdr *findSectionByType(uint64_t type) const;
   const Elf_Shdr *findSectionByFlags(uint64_t flags) const;
@@ -111,13 +111,13 @@ private:
   Reference::Addend readAddend(const Elf_Rel &ri,
                                const ArrayRef<uint8_t> content) const;
 
-  uint32_t getPairRelocation(const Elf_Rel &rel) const;
+  uint32_t getPairRelocation(const Elf_Shdr *Symtab, const Elf_Rel &rel) const;
 
   const Elf_Rel *findMatchingRelocation(uint32_t pairRelType,
                                         const Elf_Rel *rit,
                                         const Elf_Rel *eit) const;
 
-  bool isLocalBinding(const Elf_Rel &rel) const;
+  bool isLocalBinding(const Elf_Shdr *Symtab, const Elf_Rel &rel) const;
 };
 
 } // elf





More information about the llvm-commits mailing list