[lld] r301259 - Remove DefaultSoName.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 24 14:44:20 PDT 2017


Author: rafael
Date: Mon Apr 24 16:44:20 2017
New Revision: 301259

URL: http://llvm.org/viewvc/llvm-project?rev=301259&view=rev
Log:
Remove DefaultSoName.

We can just use the existing SoName member variable. It now initially
contains what was in DefaultSoName and is modified if the .so has an
actual soname.

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

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=301259&r1=301258&r2=301259&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Mon Apr 24 16:44:20 2017
@@ -184,8 +184,6 @@ void LinkerDriver::addFile(StringRef Pat
       error("attempted static link of dynamic object " + Path);
       return;
     }
-    Files.push_back(createSharedFile(MBRef));
-
     // DSOs usually have DT_SONAME tags in their ELF headers, and the
     // sonames are used to identify DSOs. But if they are missing,
     // they are identified by filenames. We don't know whether the new
@@ -196,8 +194,8 @@ void LinkerDriver::addFile(StringRef Pat
     // If a file was specified by -lfoo, the directory part is not
     // significant, as a user did not specify it. This behavior is
     // compatible with GNU.
-    Files.back()->DefaultSoName =
-        WithLOption ? sys::path::filename(Path) : Path;
+    Files.push_back(createSharedFile(
+        MBRef, WithLOption ? sys::path::filename(Path) : Path));
     return;
   default:
     if (InLib)

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=301259&r1=301258&r2=301259&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Mon Apr 24 16:44:20 2017
@@ -608,8 +608,9 @@ ArchiveFile::getMember(const Archive::Sy
 }
 
 template <class ELFT>
-SharedFile<ELFT>::SharedFile(MemoryBufferRef M)
-    : ELFFileBase<ELFT>(Base::SharedKind, M), AsNeeded(Config->AsNeeded) {}
+SharedFile<ELFT>::SharedFile(MemoryBufferRef M, StringRef DefaultSoName)
+    : ELFFileBase<ELFT>(Base::SharedKind, M), SoName(DefaultSoName),
+      AsNeeded(Config->AsNeeded) {}
 
 template <class ELFT>
 const typename ELFT::Shdr *
@@ -619,12 +620,6 @@ SharedFile<ELFT>::getSection(const Elf_S
       toString(this));
 }
 
-template <class ELFT> StringRef SharedFile<ELFT>::getSoName() const {
-  if (SoName.empty())
-    return this->DefaultSoName;
-  return SoName;
-}
-
 // Partially parse the shared object file so that we can call
 // getSoName on this object.
 template <class ELFT> void SharedFile<ELFT>::parseSoName() {
@@ -867,8 +862,23 @@ void BitcodeFile::parse(DenseSet<CachedH
     Symbols.push_back(createBitcodeSymbol<ELFT>(KeptComdats, ObjSym, this));
 }
 
+// Small bit of template meta programming to handle the SharedFile constructor
+// being the only one with a DefaultSoName parameter.
+template <template <class> class T, class E>
+typename std::enable_if<std::is_same<T<E>, SharedFile<E>>::value,
+                        InputFile *>::type
+createELFAux(MemoryBufferRef MB, StringRef DefaultSoName) {
+  return make<T<E>>(MB, DefaultSoName);
+}
+template <template <class> class T, class E>
+typename std::enable_if<!std::is_same<T<E>, SharedFile<E>>::value,
+                        InputFile *>::type
+createELFAux(MemoryBufferRef MB, StringRef DefaultSoName) {
+  return make<T<E>>(MB);
+}
+
 template <template <class> class T>
-static InputFile *createELFFile(MemoryBufferRef MB) {
+static InputFile *createELFFile(MemoryBufferRef MB, StringRef DefaultSoName) {
   unsigned char Size;
   unsigned char Endian;
   std::tie(Size, Endian) = getElfArchType(MB.getBuffer());
@@ -882,13 +892,13 @@ static InputFile *createELFFile(MemoryBu
 
   InputFile *Obj;
   if (Size == ELFCLASS32 && Endian == ELFDATA2LSB)
-    Obj = make<T<ELF32LE>>(MB);
+    Obj = createELFAux<T, ELF32LE>(MB, DefaultSoName);
   else if (Size == ELFCLASS32 && Endian == ELFDATA2MSB)
-    Obj = make<T<ELF32BE>>(MB);
+    Obj = createELFAux<T, ELF32BE>(MB, DefaultSoName);
   else if (Size == ELFCLASS64 && Endian == ELFDATA2LSB)
-    Obj = make<T<ELF64LE>>(MB);
+    Obj = createELFAux<T, ELF64LE>(MB, DefaultSoName);
   else if (Size == ELFCLASS64 && Endian == ELFDATA2MSB)
-    Obj = make<T<ELF64BE>>(MB);
+    Obj = createELFAux<T, ELF64BE>(MB, DefaultSoName);
   else
     fatal(MB.getBufferIdentifier() + ": invalid file class");
 
@@ -933,13 +943,13 @@ InputFile *elf::createObjectFile(MemoryB
                                  uint64_t OffsetInArchive) {
   InputFile *F = isBitcode(MB)
                      ? make<BitcodeFile>(MB, ArchiveName, OffsetInArchive)
-                     : createELFFile<ObjectFile>(MB);
+                     : createELFFile<ObjectFile>(MB, "");
   F->ArchiveName = ArchiveName;
   return F;
 }
 
-InputFile *elf::createSharedFile(MemoryBufferRef MB) {
-  return createELFFile<SharedFile>(MB);
+InputFile *elf::createSharedFile(MemoryBufferRef MB, StringRef DefaultSoName) {
+  return createELFFile<SharedFile>(MB, DefaultSoName);
 }
 
 MemoryBufferRef LazyObjectFile::getBuffer() {

Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=301259&r1=301258&r2=301259&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Mon Apr 24 16:44:20 2017
@@ -93,10 +93,6 @@ public:
   uint16_t EMachine = llvm::ELF::EM_NONE;
   uint8_t OSABI = 0;
 
-  // For SharedKind inputs, the string to use in DT_NEEDED when the library
-  // has no soname.
-  std::string DefaultSoName;
-
   // Cache for toString(). Only toString() should use this member.
   mutable std::string ToStringCache;
 
@@ -283,12 +279,12 @@ template <class ELFT> class SharedFile :
   typedef typename ELFT::Versym Elf_Versym;
 
   std::vector<StringRef> Undefs;
-  StringRef SoName;
   const Elf_Shdr *VersymSec = nullptr;
   const Elf_Shdr *VerdefSec = nullptr;
 
 public:
-  StringRef getSoName() const;
+  std::string SoName;
+
   const Elf_Shdr *getSection(const Elf_Sym &Sym) const;
   llvm::ArrayRef<StringRef> getUndefinedSymbols() { return Undefs; }
 
@@ -296,7 +292,7 @@ public:
     return F->kind() == Base::SharedKind;
   }
 
-  explicit SharedFile(MemoryBufferRef M);
+  SharedFile(MemoryBufferRef M, StringRef DefaultSoName);
 
   void parseSoName();
   void parseRest();
@@ -329,7 +325,7 @@ public:
 
 InputFile *createObjectFile(MemoryBufferRef MB, StringRef ArchiveName = "",
                             uint64_t OffsetInArchive = 0);
-InputFile *createSharedFile(MemoryBufferRef MB);
+InputFile *createSharedFile(MemoryBufferRef MB, StringRef DefaultSoName);
 
 } // namespace elf
 } // namespace lld

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=301259&r1=301258&r2=301259&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Mon Apr 24 16:44:20 2017
@@ -81,7 +81,7 @@ template <class ELFT> void SymbolTable<E
   if (auto *F = dyn_cast<SharedFile<ELFT>>(File)) {
     // DSOs are uniquified not by filename but by soname.
     F->parseSoName();
-    if (ErrorCount || !SoNames.insert(F->getSoName()).second)
+    if (ErrorCount || !SoNames.insert(F->SoName).second)
       return;
     SharedFiles.push_back(F);
     F->parseRest();

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=301259&r1=301258&r2=301259&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Mon Apr 24 16:44:20 2017
@@ -1027,7 +1027,7 @@ template <class ELFT> void DynamicSectio
          In<ELFT>::DynStrTab->addString(Config->RPath)});
   for (SharedFile<ELFT> *F : Symtab<ELFT>::X->getSharedFiles())
     if (F->isNeeded())
-      add({DT_NEEDED, In<ELFT>::DynStrTab->addString(F->getSoName())});
+      add({DT_NEEDED, In<ELFT>::DynStrTab->addString(F->SoName)});
   if (!Config->SoName.empty())
     add({DT_SONAME, In<ELFT>::DynStrTab->addString(Config->SoName)});
 
@@ -2042,7 +2042,7 @@ void VersionNeedSection<ELFT>::addSymbol
   // to create one by adding it to our needed list and creating a dynstr entry
   // for the soname.
   if (File->VerdefMap.empty())
-    Needed.push_back({File, In<ELFT>::DynStrTab->addString(File->getSoName())});
+    Needed.push_back({File, In<ELFT>::DynStrTab->addString(File->SoName)});
   typename SharedFile<ELFT>::NeededVer &NV = File->VerdefMap[Ver];
   // If we don't already know that we need an Elf_Vernaux for this Elf_Verdef,
   // prepare to create one by allocating a version identifier and creating a




More information about the llvm-commits mailing list