[lld] r355478 - ELF: Extract a non-ELFT base class for VersionNeedSection.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 5 19:07:49 PST 2019


Author: pcc
Date: Tue Mar  5 19:07:48 2019
New Revision: 355478

URL: http://llvm.org/viewvc/llvm-project?rev=355478&view=rev
Log:
ELF: Extract a non-ELFT base class for VersionNeedSection.

We're going to need a separate VersionNeedSection for each partition, and
the partition data structure won't be templated.

With this the VersionTableSection class no longer needs ELFT, so detemplate it.

Differential Revision: https://reviews.llvm.org/D58808

Modified:
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/SyntheticSections.cpp
    lld/trunk/ELF/SyntheticSections.h
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=355478&r1=355477&r2=355478&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Tue Mar  5 19:07:48 2019
@@ -1443,8 +1443,6 @@ static const char *LibcallRoutineNames[]
 // all linker scripts have already been parsed.
 template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
   Target = getTarget();
-  InX<ELFT>::VerSym = nullptr;
-  InX<ELFT>::VerNeed = nullptr;
 
   Config->MaxPageSize = getMaxPageSize(Args);
   Config->ImageBase = getImageBase(Args);

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=355478&r1=355477&r2=355478&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Tue Mar  5 19:07:48 2019
@@ -1405,16 +1405,16 @@ template <class ELFT> void DynamicSectio
     if (B->isDefined())
       addSym(DT_FINI, B);
 
-  bool HasVerNeed = InX<ELFT>::VerNeed->getNeedNum() != 0;
+  bool HasVerNeed = In.VerNeed->getNeedNum() != 0;
   if (HasVerNeed || In.VerDef)
-    addInSec(DT_VERSYM, InX<ELFT>::VerSym);
+    addInSec(DT_VERSYM, In.VerSym);
   if (In.VerDef) {
     addInSec(DT_VERDEF, In.VerDef);
     addInt(DT_VERDEFNUM, getVerDefNum());
   }
   if (HasVerNeed) {
-    addInSec(DT_VERNEED, InX<ELFT>::VerNeed);
-    addInt(DT_VERNEEDNUM, InX<ELFT>::VerNeed->getNeedNum());
+    addInSec(DT_VERNEED, In.VerNeed);
+    addInt(DT_VERNEEDNUM, In.VerNeed->getNeedNum());
   }
 
   if (Config->EMachine == EM_MIPS) {
@@ -2769,24 +2769,23 @@ size_t VersionDefinitionSection::getSize
 }
 
 // .gnu.version is a table where each entry is 2 byte long.
-template <class ELFT>
-VersionTableSection<ELFT>::VersionTableSection()
+VersionTableSection::VersionTableSection()
     : SyntheticSection(SHF_ALLOC, SHT_GNU_versym, sizeof(uint16_t),
                        ".gnu.version") {
   this->Entsize = 2;
 }
 
-template <class ELFT> void VersionTableSection<ELFT>::finalizeContents() {
+void VersionTableSection::finalizeContents() {
   // At the moment of june 2016 GNU docs does not mention that sh_link field
   // should be set, but Sun docs do. Also readelf relies on this field.
   getParent()->Link = In.DynSymTab->getParent()->SectionIndex;
 }
 
-template <class ELFT> size_t VersionTableSection<ELFT>::getSize() const {
+size_t VersionTableSection::getSize() const {
   return (In.DynSymTab->getSymbols().size() + 1) * 2;
 }
 
-template <class ELFT> void VersionTableSection<ELFT>::writeTo(uint8_t *Buf) {
+void VersionTableSection::writeTo(uint8_t *Buf) {
   Buf += 2;
   for (const SymbolTableEntry &S : In.DynSymTab->getSymbols()) {
     write16(Buf, S.Sym->VersionId);
@@ -2794,12 +2793,11 @@ template <class ELFT> void VersionTableS
   }
 }
 
-template <class ELFT> bool VersionTableSection<ELFT>::empty() const {
-  return !In.VerDef && InX<ELFT>::VerNeed->empty();
+bool VersionTableSection::empty() const {
+  return !In.VerDef && In.VerNeed->empty();
 }
 
-template <class ELFT>
-VersionNeedSection<ELFT>::VersionNeedSection()
+VersionNeedBaseSection::VersionNeedBaseSection()
     : SyntheticSection(SHF_ALLOC, SHT_GNU_verneed, sizeof(uint32_t),
                        ".gnu.version_r") {
   // Identifiers in verneed section start at 2 because 0 and 1 are reserved
@@ -3239,11 +3237,6 @@ template class elf::SymbolTableSection<E
 template class elf::SymbolTableSection<ELF64LE>;
 template class elf::SymbolTableSection<ELF64BE>;
 
-template class elf::VersionTableSection<ELF32LE>;
-template class elf::VersionTableSection<ELF32BE>;
-template class elf::VersionTableSection<ELF64LE>;
-template class elf::VersionTableSection<ELF64BE>;
-
 template class elf::VersionNeedSection<ELF32LE>;
 template class elf::VersionNeedSection<ELF32BE>;
 template class elf::VersionNeedSection<ELF64LE>;

Modified: lld/trunk/ELF/SyntheticSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.h?rev=355478&r1=355477&r2=355478&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.h (original)
+++ lld/trunk/ELF/SyntheticSections.h Tue Mar  5 19:07:48 2019
@@ -777,7 +777,6 @@ private:
 // identifier defined in the either .gnu.version_r or .gnu.version_d section.
 // The values 0 and 1 are reserved. All other values are used for versions in
 // the own object or in any of the dependencies.
-template <class ELFT>
 class VersionTableSection final : public SyntheticSection {
 public:
   VersionTableSection();
@@ -787,12 +786,24 @@ public:
   bool empty() const override;
 };
 
+class VersionNeedBaseSection : public SyntheticSection {
+protected:
+  // The next available version identifier.
+  unsigned NextIndex;
+
+public:
+  VersionNeedBaseSection();
+  virtual void addSymbol(Symbol *Sym) = 0;
+  virtual size_t getNeedNum() const = 0;
+};
+
 // The .gnu.version_r section defines the version identifiers used by
 // .gnu.version. It contains a linked list of Elf_Verneed data structures. Each
 // Elf_Verneed specifies the version requirements for a single DSO, and contains
 // a reference to a linked list of Elf_Vernaux data structures which define the
 // mapping from version identifiers to version names.
-template <class ELFT> class VersionNeedSection final : public SyntheticSection {
+template <class ELFT>
+class VersionNeedSection final : public VersionNeedBaseSection {
   typedef typename ELFT::Verneed Elf_Verneed;
   typedef typename ELFT::Vernaux Elf_Vernaux;
 
@@ -800,16 +811,12 @@ template <class ELFT> class VersionNeedS
   // string table offsets of their sonames.
   std::vector<std::pair<SharedFile<ELFT> *, size_t>> Needed;
 
-  // The next available version identifier.
-  unsigned NextIndex;
-
 public:
-  VersionNeedSection();
-  void addSymbol(Symbol *Sym);
+  void addSymbol(Symbol *Sym) override;
   void finalizeContents() override;
   void writeTo(uint8_t *Buf) override;
   size_t getSize() const override;
-  size_t getNeedNum() const { return Needed.size(); }
+  size_t getNeedNum() const override { return Needed.size(); }
   bool empty() const override;
 };
 
@@ -1025,17 +1032,12 @@ struct InStruct {
   SymbolTableBaseSection *SymTab;
   SymtabShndxSection *SymTabShndx;
   VersionDefinitionSection *VerDef;
+  VersionNeedBaseSection *VerNeed;
+  VersionTableSection *VerSym;
 };
 
 extern InStruct In;
 
-template <class ELFT> struct InX {
-  static VersionTableSection<ELFT> *VerSym;
-  static VersionNeedSection<ELFT> *VerNeed;
-};
-
-template <class ELFT> VersionTableSection<ELFT> *InX<ELFT>::VerSym;
-template <class ELFT> VersionNeedSection<ELFT> *InX<ELFT>::VerNeed;
 } // namespace elf
 } // namespace lld
 

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=355478&r1=355477&r2=355478&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue Mar  5 19:07:48 2019
@@ -332,16 +332,16 @@ template <class ELFT> static void create
     In.DynSymTab = make<SymbolTableSection<ELFT>>(*In.DynStrTab);
     Add(In.DynSymTab);
 
-    InX<ELFT>::VerSym = make<VersionTableSection<ELFT>>();
-    Add(InX<ELFT>::VerSym);
+    In.VerSym = make<VersionTableSection>();
+    Add(In.VerSym);
 
     if (!Config->VersionDefinitions.empty()) {
       In.VerDef = make<VersionDefinitionSection>();
       Add(In.VerDef);
     }
 
-    InX<ELFT>::VerNeed = make<VersionNeedSection<ELFT>>();
-    Add(InX<ELFT>::VerNeed);
+    In.VerNeed = make<VersionNeedSection<ELFT>>();
+    Add(In.VerNeed);
 
     if (Config->GnuHash) {
       In.GnuHashTab = make<GnuHashTableSection>();
@@ -1714,7 +1714,7 @@ template <class ELFT> void Writer<ELFT>:
       In.DynSymTab->addSymbol(Sym);
       if (auto *File = dyn_cast_or_null<SharedFile<ELFT>>(Sym->File))
         if (File->IsNeeded && !Sym->isUndefined())
-          InX<ELFT>::VerNeed->addSymbol(Sym);
+          In.VerNeed->addSymbol(Sym);
     }
   }
 
@@ -1804,8 +1804,8 @@ template <class ELFT> void Writer<ELFT>:
   finalizeSynthetic(In.Plt);
   finalizeSynthetic(In.Iplt);
   finalizeSynthetic(In.EhFrameHdr);
-  finalizeSynthetic(InX<ELFT>::VerSym);
-  finalizeSynthetic(InX<ELFT>::VerNeed);
+  finalizeSynthetic(In.VerSym);
+  finalizeSynthetic(In.VerNeed);
   finalizeSynthetic(In.Dynamic);
 
   if (!Script->HasSectionsCommand && !Config->Relocatable)




More information about the llvm-commits mailing list