[lld] r300147 - Do not initialize this->SoName with this->DefaultSoName.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 12 17:23:32 PDT 2017


Author: ruiu
Date: Wed Apr 12 19:23:32 2017
New Revision: 300147

URL: http://llvm.org/viewvc/llvm-project?rev=300147&view=rev
Log:
Do not initialize this->SoName with this->DefaultSoName.

This patch uses DefaultSoName in getSoName instead of in parseSoName.
I think this is more readable. This patch also add comments.

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

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=300147&r1=300146&r2=300147&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Wed Apr 12 19:23:32 2017
@@ -184,9 +184,17 @@ void LinkerDriver::addFile(StringRef Pat
       return;
     }
     Files.push_back(createSharedFile(MBRef));
-    // If the library is found at an explicitly given path use the entire path
-    // as he default soname. Such libraries should not require RPATH or
-    // LD_LIBRARY_PATH to run.
+
+    // 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
+    // file has a DT_SONAME or not because we haven't parsed it yet.
+    // Here, we set the default soname for the file because we might
+    // need it later.
+    //
+    // 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;
     return;

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=300147&r1=300146&r2=300147&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Wed Apr 12 19:23:32 2017
@@ -625,13 +625,20 @@ 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() {
   const Elf_Shdr *DynamicSec = nullptr;
-
   const ELFFile<ELFT> Obj = this->getObj();
   ArrayRef<Elf_Shdr> Sections = check(Obj.sections(), toString(this));
+
+  // Search for .dynsym, .dynamic, .symtab, .gnu.version and .gnu.version_d.
   for (const Elf_Shdr &Sec : Sections) {
     switch (Sec.sh_type) {
     default:
@@ -658,14 +665,9 @@ template <class ELFT> void SharedFile<EL
   if (this->VersymSec && this->Symbols.empty())
     error("SHT_GNU_versym should be associated with symbol table");
 
-  // DSOs are identified by soname, and they usually contain
-  // DT_SONAME tag in their header. But if they are missing,
-  // filenames are used as default sonames.
-  SoName = this->DefaultSoName;
-
+  // Search for a DT_SONAME tag to initialize this->SoName.
   if (!DynamicSec)
     return;
-
   ArrayRef<Elf_Dyn> Arr =
       check(Obj.template getSectionContentsAsArray<Elf_Dyn>(DynamicSec),
             toString(this));

Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=300147&r1=300146&r2=300147&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Wed Apr 12 19:23:32 2017
@@ -296,7 +296,7 @@ template <class ELFT> class SharedFile :
   const Elf_Shdr *VerdefSec = nullptr;
 
 public:
-  StringRef getSoName() const { return SoName; }
+  StringRef getSoName() const;
   const Elf_Shdr *getSection(const Elf_Sym &Sym) const;
   llvm::ArrayRef<StringRef> getUndefinedSymbols() { return Undefs; }
 




More information about the llvm-commits mailing list