[lld] r285904 - Pass the section table around instead of recomputing it.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 3 06:24:29 PDT 2016


Author: rafael
Date: Thu Nov  3 08:24:29 2016
New Revision: 285904

URL: http://llvm.org/viewvc/llvm-project?rev=285904&view=rev
Log:
Pass the section table around instead of recomputing it.

Modified:
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/ELF/InputFiles.h

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=285904&r1=285903&r2=285904&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Thu Nov  3 08:24:29 2016
@@ -150,10 +150,11 @@ uint32_t ELFFileBase<ELFT>::getSectionIn
   return I;
 }
 
-template <class ELFT> void ELFFileBase<ELFT>::initStringTable() {
+template <class ELFT>
+void ELFFileBase<ELFT>::initStringTable(ArrayRef<Elf_Shdr> Sections) {
   if (!Symtab)
     return;
-  StringTable = check(ELFObj.getStringTableForSymtab(*Symtab));
+  StringTable = check(ELFObj.getStringTableForSymtab(*Symtab, Sections));
 }
 
 template <class ELFT>
@@ -194,8 +195,9 @@ template <class ELFT> uint32_t elf::Obje
 template <class ELFT>
 void elf::ObjectFile<ELFT>::parse(DenseSet<CachedHashStringRef> &ComdatGroups) {
   // Read section and symbol tables.
-  initializeSections(ComdatGroups);
-  initializeSymbols();
+  ArrayRef<Elf_Shdr> ObjSections = check(this->ELFObj.sections());
+  initializeSections(ComdatGroups, ObjSections);
+  initializeSymbols(ObjSections);
 }
 
 // Sections with SHT_GROUP and comdat bits define comdat section groups.
@@ -209,7 +211,7 @@ elf::ObjectFile<ELFT>::getShtGroupSignat
   const Elf_Shdr *Symtab =
       check(object::getSection<ELFT>(Sections, Sec.sh_link));
   const Elf_Sym *Sym = check(Obj.getSymbol(Symtab, Sec.sh_info));
-  StringRef Strtab = check(Obj.getStringTableForSymtab(*Symtab));
+  StringRef Strtab = check(Obj.getStringTableForSymtab(*Symtab, Sections));
   return check(Sym->getName(Strtab));
 }
 
@@ -279,9 +281,9 @@ bool elf::ObjectFile<ELFT>::shouldMerge(
 
 template <class ELFT>
 void elf::ObjectFile<ELFT>::initializeSections(
-    DenseSet<CachedHashStringRef> &ComdatGroups) {
+    DenseSet<CachedHashStringRef> &ComdatGroups,
+    ArrayRef<Elf_Shdr> ObjSections) {
   const ELFFile<ELFT> &Obj = this->ELFObj;
-  ArrayRef<Elf_Shdr> ObjSections = check(Obj.sections());
   uint64_t Size = ObjSections.size();
   Sections.resize(Size);
   unsigned I = -1;
@@ -443,8 +445,9 @@ elf::ObjectFile<ELFT>::createInputSectio
   return make<InputSection<ELFT>>(this, &Sec, Name);
 }
 
-template <class ELFT> void elf::ObjectFile<ELFT>::initializeSymbols() {
-  this->initStringTable();
+template <class ELFT>
+void elf::ObjectFile<ELFT>::initializeSymbols(ArrayRef<Elf_Shdr> Sections) {
+  this->initStringTable(Sections);
   Elf_Sym_Range Syms = this->getElfSymbols(false);
   uint32_t NumSymbols = std::distance(Syms.begin(), Syms.end());
   SymbolBodies.reserve(NumSymbols);
@@ -601,7 +604,7 @@ template <class ELFT> void SharedFile<EL
   if (this->VersymSec && !this->Symtab)
     error("SHT_GNU_versym should be associated with symbol table");
 
-  this->initStringTable();
+  this->initStringTable(Sections);
 
   // DSOs are identified by soname, and they usually contain
   // DT_SONAME tag in their header. But if they are missing,
@@ -889,12 +892,13 @@ template <class ELFT> std::vector<String
   typedef typename ELFT::SymRange Elf_Sym_Range;
 
   const ELFFile<ELFT> Obj = createELFObj<ELFT>(this->MB);
-  for (const Elf_Shdr &Sec : check(Obj.sections())) {
+  ArrayRef<Elf_Shdr> Sections = check(Obj.sections());
+  for (const Elf_Shdr &Sec : Sections) {
     if (Sec.sh_type != SHT_SYMTAB)
       continue;
     Elf_Sym_Range Syms = Obj.symbols(&Sec);
     uint32_t FirstNonLocal = Sec.sh_info;
-    StringRef StringTable = check(Obj.getStringTableForSymtab(Sec));
+    StringRef StringTable = check(Obj.getStringTableForSymtab(Sec, Sections));
     std::vector<StringRef> V;
     for (const Elf_Sym &Sym : Syms.slice(FirstNonLocal))
       if (Sym.st_shndx != SHN_UNDEF)

Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=285904&r1=285903&r2=285904&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Thu Nov  3 08:24:29 2016
@@ -114,7 +114,7 @@ protected:
   const Elf_Shdr *Symtab = nullptr;
   ArrayRef<Elf_Word> SymtabSHNDX;
   StringRef StringTable;
-  void initStringTable();
+  void initStringTable(ArrayRef<Elf_Shdr> Sections);
 };
 
 // .o file.
@@ -179,8 +179,9 @@ public:
 
 private:
   void
-  initializeSections(llvm::DenseSet<llvm::CachedHashStringRef> &ComdatGroups);
-  void initializeSymbols();
+  initializeSections(llvm::DenseSet<llvm::CachedHashStringRef> &ComdatGroups,
+                     ArrayRef<Elf_Shdr> ObjSections);
+  void initializeSymbols(ArrayRef<Elf_Shdr> Sections);
   void initializeDwarfLine();
   InputSectionBase<ELFT> *getRelocTarget(const Elf_Shdr &Sec);
   InputSectionBase<ELFT> *createInputSection(const Elf_Shdr &Sec,




More information about the llvm-commits mailing list