[lld] r320449 - Compact symbols from 96 to 88 bytes.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 11 17:45:50 PST 2017


Author: rafael
Date: Mon Dec 11 17:45:49 2017
New Revision: 320449

URL: http://llvm.org/viewvc/llvm-project?rev=320449&view=rev
Log:
Compact symbols from 96 to 88 bytes.

By using an index instead of a pointer for verdef we can put the index
next to the alignment field. This uses the otherwise wasted area and
reduces the shared symbol size.

By itself the performance change of this is in the noise, but I have a
followup patch to remove another 8 bytes that improves performance
when combined with this.

Modified:
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/ELF/InputFiles.h
    lld/trunk/ELF/SymbolTable.cpp
    lld/trunk/ELF/SymbolTable.h
    lld/trunk/ELF/Symbols.h
    lld/trunk/ELF/SyntheticSections.cpp

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=320449&r1=320448&r2=320449&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Mon Dec 11 17:45:49 2017
@@ -794,7 +794,7 @@ SharedFile<ELFT>::parseVerdefs(const Elf
 template <class ELFT> void SharedFile<ELFT>::parseRest() {
   // Create mapping from version identifiers to Elf_Verdef entries.
   const Elf_Versym *Versym = nullptr;
-  std::vector<const Elf_Verdef *> Verdefs = parseVerdefs(Versym);
+  Verdefs = parseVerdefs(Versym);
 
   ArrayRef<Elf_Shdr> Sections = CHECK(this->getObj().sections(), this);
 
@@ -827,6 +827,8 @@ template <class ELFT> void SharedFile<EL
         continue;
       }
       Ver = Verdefs[VersymIndex];
+    } else {
+      VersymIndex = 0;
     }
 
     // We do not usually care about alignments of data in shared object
@@ -844,14 +846,14 @@ template <class ELFT> void SharedFile<EL
       error(toString(this) + ": alignment too large: " + Name);
 
     if (!Hidden)
-      Symtab->addShared(Name, this, Sym, Alignment, Ver);
+      Symtab->addShared(Name, this, Sym, Alignment, VersymIndex);
 
     // Also add the symbol with the versioned name to handle undefined symbols
     // with explicit versions.
     if (Ver) {
       StringRef VerName = this->StringTable.data() + Ver->getAux()->vda_name;
       Name = Saver.save(Name + "@" + VerName);
-      Symtab->addShared(Name, this, Sym, Alignment, Ver);
+      Symtab->addShared(Name, this, Sym, Alignment, VersymIndex);
     }
   }
 }

Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=320449&r1=320448&r2=320449&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Mon Dec 11 17:45:49 2017
@@ -292,6 +292,7 @@ template <class ELFT> class SharedFile :
   const Elf_Shdr *VerdefSec = nullptr;
 
 public:
+  std::vector<const Elf_Verdef *> Verdefs;
   std::string SoName;
 
   llvm::ArrayRef<StringRef> getUndefinedSymbols() { return Undefs; }

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=320449&r1=320448&r2=320449&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Mon Dec 11 17:45:49 2017
@@ -478,7 +478,7 @@ Symbol *SymbolTable::addRegular(StringRe
 template <typename ELFT>
 void SymbolTable::addShared(StringRef Name, SharedFile<ELFT> *File,
                             const typename ELFT::Sym &Sym, uint32_t Alignment,
-                            const typename ELFT::Verdef *Verdef) {
+                            uint32_t VerdefIndex) {
   // DSO symbols do not affect visibility in the output, so we pass STV_DEFAULT
   // as the visibility, which will leave the visibility in the symbol table
   // unchanged.
@@ -497,7 +497,7 @@ void SymbolTable::addShared(StringRef Na
     uint8_t Binding = S->Binding;
     replaceSymbol<SharedSymbol>(S, File, Name, Sym.getBinding(), Sym.st_other,
                                 Sym.getType(), Sym.st_value, Sym.st_size,
-                                Alignment, Verdef);
+                                Alignment, VerdefIndex);
     if (!WasInserted) {
       S->Binding = Binding;
       if (!S->isWeak() && !Config->GcSections)
@@ -839,20 +839,16 @@ template void SymbolTable::addLazyObject
 
 template void SymbolTable::addShared<ELF32LE>(StringRef, SharedFile<ELF32LE> *,
                                               const typename ELF32LE::Sym &,
-                                              uint32_t Alignment,
-                                              const typename ELF32LE::Verdef *);
+                                              uint32_t Alignment, uint32_t);
 template void SymbolTable::addShared<ELF32BE>(StringRef, SharedFile<ELF32BE> *,
                                               const typename ELF32BE::Sym &,
-                                              uint32_t Alignment,
-                                              const typename ELF32BE::Verdef *);
+                                              uint32_t Alignment, uint32_t);
 template void SymbolTable::addShared<ELF64LE>(StringRef, SharedFile<ELF64LE> *,
                                               const typename ELF64LE::Sym &,
-                                              uint32_t Alignment,
-                                              const typename ELF64LE::Verdef *);
+                                              uint32_t Alignment, uint32_t);
 template void SymbolTable::addShared<ELF64BE>(StringRef, SharedFile<ELF64BE> *,
                                               const typename ELF64BE::Sym &,
-                                              uint32_t Alignment,
-                                              const typename ELF64BE::Verdef *);
+                                              uint32_t Alignment, uint32_t);
 
 template void SymbolTable::fetchIfLazy<ELF32LE>(StringRef);
 template void SymbolTable::fetchIfLazy<ELF32BE>(StringRef);

Modified: lld/trunk/ELF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=320449&r1=320448&r2=320449&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.h (original)
+++ lld/trunk/ELF/SymbolTable.h Mon Dec 11 17:45:49 2017
@@ -59,7 +59,7 @@ public:
   template <class ELFT>
   void addShared(StringRef Name, SharedFile<ELFT> *F,
                  const typename ELFT::Sym &Sym, uint32_t Alignment,
-                 const typename ELFT::Verdef *Verdef);
+                 uint32_t VerdefIndex);
 
   template <class ELFT>
   Symbol *addLazyArchive(StringRef Name, ArchiveFile *F,

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=320449&r1=320448&r2=320449&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Mon Dec 11 17:45:49 2017
@@ -210,9 +210,9 @@ public:
 
   SharedSymbol(InputFile *File, StringRef Name, uint8_t Binding,
                uint8_t StOther, uint8_t Type, uint64_t Value, uint64_t Size,
-               uint32_t Alignment, const void *Verdef)
-      : Symbol(SharedKind, File, Name, Binding, StOther, Type), Verdef(Verdef),
-        Value(Value), Size(Size), Alignment(Alignment) {
+               uint32_t Alignment, uint32_t VerdefIndex)
+      : Symbol(SharedKind, File, Name, Binding, StOther, Type), Value(Value),
+        Size(Size), VerdefIndex(VerdefIndex), Alignment(Alignment) {
     // GNU ifunc is a mechanism to allow user-supplied functions to
     // resolve PLT slot values at load-time. This is contrary to the
     // regualr symbol resolution scheme in which symbols are resolved just
@@ -237,14 +237,15 @@ public:
     return cast<SharedFile<ELFT>>(File);
   }
 
-  // This field is a pointer to the symbol's version definition.
-  const void *Verdef;
-
   // If not null, there is a copy relocation to this section.
   InputSection *CopyRelSec = nullptr;
 
   uint64_t Value; // st_value
   uint64_t Size;  // st_size
+
+  // This field is a index to the symbol's version definition.
+  uint32_t VerdefIndex;
+
   uint32_t Alignment;
 };
 

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=320449&r1=320448&r2=320449&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Mon Dec 11 17:45:49 2017
@@ -2305,14 +2305,13 @@ VersionNeedSection<ELFT>::VersionNeedSec
 
 template <class ELFT>
 void VersionNeedSection<ELFT>::addSymbol(SharedSymbol *SS) {
-  auto *Ver = reinterpret_cast<const typename ELFT::Verdef *>(SS->Verdef);
+  SharedFile<ELFT> *File = SS->getFile<ELFT>();
+  const typename ELFT::Verdef *Ver = File->Verdefs[SS->VerdefIndex];
   if (!Ver) {
     SS->VersionId = VER_NDX_GLOBAL;
     return;
   }
 
-  SharedFile<ELFT> *File = SS->getFile<ELFT>();
-
   // If we don't already know that we need an Elf_Verneed for this DSO, prepare
   // to create one by adding it to our needed list and creating a dynstr entry
   // for the soname.




More information about the llvm-commits mailing list