[lld] r247363 - Cache the bss output section in the writer, not in the symbol table.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 10 17:10:11 PDT 2015


Author: rafael
Date: Thu Sep 10 19:10:11 2015
New Revision: 247363

URL: http://llvm.org/viewvc/llvm-project?rev=247363&view=rev
Log:
Cache the bss output section in the writer, not in the symbol table.

There is soon going to be two symbol tables, but there will still be only one
output bss.

Modified:
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=247363&r1=247362&r2=247363&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Sep 10 19:10:11 2015
@@ -132,15 +132,17 @@ private:
   llvm::StringTableBuilder StrTabBuilder;
 };
 
+template <class ELFT> class Writer;
+
 template <class ELFT>
 class SymbolTableSection final : public OutputSectionBase<ELFT::Is64Bits> {
 public:
   typedef typename ELFFile<ELFT>::Elf_Sym Elf_Sym;
   typedef typename OutputSectionBase<ELFT::Is64Bits>::uintX_t uintX_t;
-  SymbolTableSection(SymbolTable &Table,
+  SymbolTableSection(Writer<ELFT> &W, SymbolTable &Table,
                      StringTableSection<ELFT::Is64Bits> &StrTabSec)
       : OutputSectionBase<ELFT::Is64Bits>(".symtab", SHT_SYMTAB, 0),
-        Table(Table), StrTabSec(StrTabSec) {
+        Table(Table), StrTabSec(StrTabSec), W(W) {
     typedef OutputSectionBase<ELFT::Is64Bits> Base;
     typename Base::HeaderT &Header = this->Header;
 
@@ -165,12 +167,11 @@ public:
     ++NumVisible;
   }
 
-  OutputSection<ELFT> *BSSSec = nullptr;
-
 private:
   SymbolTable &Table;
   StringTableSection<ELFT::Is64Bits> &StrTabSec;
   unsigned NumVisible = 0;
+  const Writer<ELFT> &W;
 };
 
 template <bool Is64Bits>
@@ -246,10 +247,15 @@ public:
   typedef typename ELFFile<ELFT>::Elf_Phdr Elf_Phdr;
   typedef typename ELFFile<ELFT>::Elf_Sym Elf_Sym;
   Writer(SymbolTable *T)
-      : StrTabSec(false), DynStrSec(true), SymTable(*T, StrTabSec),
+      : StrTabSec(false), DynStrSec(true), SymTable(*this, *T, StrTabSec),
         DynamicSec(*T, DynStrSec) {}
   void run();
 
+  const OutputSection<ELFT> &getBSS() const {
+    assert(BSSSec);
+    return *BSSSec;
+  }
+
 private:
   void createSections();
   void assignAddresses();
@@ -273,6 +279,8 @@ private:
   SymbolTableSection<ELFT> SymTable;
 
   DynamicSection<ELFT::Is64Bits> DynamicSec;
+
+  OutputSection<ELFT> *BSSSec = nullptr;
 };
 } // anonymous namespace
 
@@ -406,14 +414,14 @@ template <class ELFT> void SymbolTableSe
     ESym->st_name = StrTabSec.getFileOff(Name);
 
     const SectionChunk<ELFT> *Section = nullptr;
-    OutputSection<ELFT> *Out = nullptr;
+    const OutputSection<ELFT> *Out = nullptr;
 
     switch (Body->kind()) {
     case SymbolBody::DefinedRegularKind:
       Section = &cast<DefinedRegular<ELFT>>(Body)->Section;
       break;
     case SymbolBody::DefinedCommonKind:
-      Out = BSSSec;
+      Out = &W.getBSS();
       break;
     case SymbolBody::UndefinedKind:
       if (!Body->isWeak())
@@ -546,8 +554,7 @@ template <class ELFT> void Writer<ELFT>:
     }
   }
 
-  SymTable.BSSSec = getSection(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE);
-  OutputSection<ELFT> *BSSSec = SymTable.BSSSec;
+  BSSSec = getSection(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE);
   // FIXME: Try to avoid the extra walk over all global symbols.
   std::vector<DefinedCommon<ELFT> *> CommonSymbols;
   for (auto &P : Symtab.getSymbols()) {




More information about the llvm-commits mailing list