[lld] r328401 - Do not add a dummy entry to SharedFile::Verdefs. NFC.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 23 17:25:25 PDT 2018


Author: ruiu
Date: Fri Mar 23 17:25:24 2018
New Revision: 328401

URL: http://llvm.org/viewvc/llvm-project?rev=328401&view=rev
Log:
Do not add a dummy entry to SharedFile::Verdefs. NFC.

Previously, we used 0 as an alias for VER_NDX_GLOBAL and had a dummy
entry in SharedFile::Verdefs so that the access to the array is within
its boundary. But that's not straightforwad. We can just stop doing both.

Modified:
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/ELF/SyntheticSections.cpp

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=328401&r1=328400&r2=328401&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Fri Mar 23 17:25:24 2018
@@ -784,17 +784,15 @@ template <class ELFT> void SharedFile<EL
 
 // Parse the version definitions in the object file if present. Returns a vector
 // whose nth element contains a pointer to the Elf_Verdef for version identifier
-// n. Version identifiers that are not definitions map to nullptr. The array
-// always has at least length 1.
+// n. Version identifiers that are not definitions map to nullptr.
 template <class ELFT>
 std::vector<const typename ELFT::Verdef *>
 SharedFile<ELFT>::parseVerdefs(const Elf_Versym *&Versym) {
-  std::vector<const Elf_Verdef *> Verdefs(1);
   // We only need to process symbol versions for this DSO if it has both a
   // versym and a verdef section, which indicates that the DSO contains symbol
   // version definitions.
   if (!VersymSec || !VerdefSec)
-    return Verdefs;
+    return {};
 
   // The location of the first global versym entry.
   const char *Base = this->MB.getBuffer().data();
@@ -806,7 +804,7 @@ SharedFile<ELFT>::parseVerdefs(const Elf
   // sequentially starting from 1, so we predict that the largest identifier
   // will be VerdefCount.
   unsigned VerdefCount = VerdefSec->sh_info;
-  Verdefs.resize(VerdefCount + 1);
+  std::vector<const Elf_Verdef *> Verdefs(VerdefCount + 1);
 
   // Build the Verdefs array by following the chain of Elf_Verdef objects
   // from the start of the .gnu.version_d section.
@@ -864,7 +862,7 @@ template <class ELFT> void SharedFile<EL
     // MIPS BFD linker puts _gp_disp symbol into DSO files and incorrectly
     // assigns VER_NDX_LOCAL to this section global symbol. Here is a
     // workaround for this bug.
-    if (Config->EMachine == EM_MIPS && Versym && VersymIndex == VER_NDX_LOCAL &&
+    if (Config->EMachine == EM_MIPS && VersymIndex == VER_NDX_LOCAL &&
         Name == "_gp_disp")
       continue;
 
@@ -877,8 +875,6 @@ 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

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=328401&r1=328400&r2=328401&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Fri Mar 23 17:25:24 2018
@@ -2329,8 +2329,7 @@ VersionNeedSection<ELFT>::VersionNeedSec
 template <class ELFT>
 void VersionNeedSection<ELFT>::addSymbol(SharedSymbol *SS) {
   SharedFile<ELFT> &File = SS->getFile<ELFT>();
-  const typename ELFT::Verdef *Ver = File.Verdefs[SS->VerdefIndex];
-  if (!Ver) {
+  if (SS->VerdefIndex == VER_NDX_GLOBAL) {
     SS->VersionId = VER_NDX_GLOBAL;
     return;
   }
@@ -2340,7 +2339,9 @@ void VersionNeedSection<ELFT>::addSymbol
   // for the soname.
   if (File.VerdefMap.empty())
     Needed.push_back({&File, InX::DynStrTab->addString(File.SoName)});
+  const typename ELFT::Verdef *Ver = File.Verdefs[SS->VerdefIndex];
   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
   // dynstr entry for the version name.




More information about the llvm-commits mailing list