[lld] r247051 - Don't treat the string table index specially. NFC.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 8 12:23:30 PDT 2015


Author: rafael
Date: Tue Sep  8 14:23:30 2015
New Revision: 247051

URL: http://llvm.org/viewvc/llvm-project?rev=247051&view=rev
Log:
Don't treat the string table index specially. NFC.

We assign the string table section an index like every other section, we can
use it from there.

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=247051&r1=247050&r2=247051&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue Sep  8 14:23:30 2015
@@ -124,9 +124,10 @@ class SymbolTableSection final : public
 public:
   typedef typename ELFFile<ELFT>::Elf_Sym Elf_Sym;
   typedef typename OutputSectionBase<ELFT::Is64Bits>::uintX_t uintX_t;
-  SymbolTableSection(SymbolTable &Table, llvm::StringTableBuilder &Builder)
+  SymbolTableSection(SymbolTable &Table,
+                     StringTableSection<ELFT::Is64Bits> &StrTabSec)
       : OutputSectionBase<ELFT::Is64Bits>(".symtab", SHT_SYMTAB, 0),
-        Table(Table), Builder(Builder) {
+        Table(Table), Builder(StrTabSec.StrTabBuilder), StrTabSec(StrTabSec) {
     typedef OutputSectionBase<ELFT::Is64Bits> Base;
     typename Base::HeaderT &Header = this->Header;
 
@@ -139,10 +140,9 @@ public:
 
   void finalize() override {
     this->Header.sh_size = (NumVisible + 1) * sizeof(Elf_Sym);
+    this->Header.sh_link = StrTabSec.getSectionIndex();
   }
 
-  void setStringTableIndex(uint32_t Index) { this->Header.sh_link = Index; }
-
   void writeTo(uint8_t *Buf) override;
 
   const SymbolTable &getSymTable() { return Table; }
@@ -153,6 +153,7 @@ public:
 private:
   SymbolTable &Table;
   llvm::StringTableBuilder &Builder;
+  const StringTableSection<ELFT::Is64Bits> &StrTabSec;
 };
 
 // The writer writes a SymbolTable result to a file.
@@ -161,7 +162,7 @@ public:
   typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
   typedef typename llvm::object::ELFFile<ELFT>::Elf_Shdr Elf_Shdr;
   typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
-  Writer(SymbolTable *T) : SymTable(*T, StringTable.StrTabBuilder) {}
+  Writer(SymbolTable *T) : SymTable(*T, StringTable) {}
   void run();
 
 private:
@@ -180,7 +181,6 @@ private:
   uintX_t SizeOfHeaders;
   uintX_t SectionHeaderOff;
 
-  unsigned StringTableIndex;
   StringTableSection<ELFT::Is64Bits> StringTable;
 
   SymbolTableSection<ELFT> SymTable;
@@ -504,9 +504,6 @@ template <class ELFT> void Writer<ELFT>:
   uintX_t VA = 0x1000; // The first page is kept unmapped.
   uintX_t FileOff = SizeOfHeaders;
 
-  StringTableIndex = OutputSections.size();
-  SymTable.setStringTableIndex(StringTableIndex);
-
   for (OutputSectionBase<ELFT::Is64Bits> *Sec : OutputSections) {
     StringTable.add(Sec->getName());
     Sec->finalize();
@@ -557,7 +554,7 @@ template <class ELFT> void Writer<ELFT>:
   EHdr->e_phnum = 1;
   EHdr->e_shentsize = sizeof(Elf_Shdr_Impl<ELFT>);
   EHdr->e_shnum = getNumSections();
-  EHdr->e_shstrndx = StringTableIndex;
+  EHdr->e_shstrndx = StringTable.getSectionIndex();
 
   auto PHdrs = reinterpret_cast<Elf_Phdr_Impl<ELFT> *>(Buf + EHdr->e_phoff);
   PHdrs->p_type = PT_LOAD;




More information about the llvm-commits mailing list