[lld] r368536 - [ELF] Remove redundant isDefined() in Symbol::computeBinding() and delete one redundant call site

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 11 10:03:01 PDT 2019


Author: maskray
Date: Sun Aug 11 10:03:00 2019
New Revision: 368536

URL: http://llvm.org/viewvc/llvm-project?rev=368536&view=rev
Log:
[ELF] Remove redundant isDefined() in Symbol::computeBinding() and delete one redundant call site

After r367869, VER_NDX_LOCAL can only be assigned to Defined and
CommonSymbol.  CommonSymbol becomes Defined after replaceCommonSymbols(),
thus `versionId == VER_NDX_LOCAL` will imply `isDefined()`.

In maybeReportUndefined(), computeBinding() is called when the symbol is
unknown to be Undefined. computeBinding() != STB_LOCAL will always be
true.

Modified:
    lld/trunk/ELF/Relocations.cpp
    lld/trunk/ELF/Symbols.cpp

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=368536&r1=368535&r2=368536&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Sun Aug 11 10:03:00 2019
@@ -770,8 +770,7 @@ static bool maybeReportUndefined(Symbol
   if (!sym.isUndefined() || sym.isWeak())
     return false;
 
-  bool canBeExternal = !sym.isLocal() && sym.computeBinding() != STB_LOCAL &&
-                       sym.visibility == STV_DEFAULT;
+  bool canBeExternal = !sym.isLocal() && sym.visibility == STV_DEFAULT;
   if (config->unresolvedSymbols == UnresolvedPolicy::Ignore && canBeExternal)
     return false;
 

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=368536&r1=368535&r2=368536&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Sun Aug 11 10:03:00 2019
@@ -276,9 +276,8 @@ MemoryBufferRef LazyArchive::getMemberBu
 uint8_t Symbol::computeBinding() const {
   if (config->relocatable)
     return binding;
-  if (visibility != STV_DEFAULT && visibility != STV_PROTECTED)
-    return STB_LOCAL;
-  if (versionId == VER_NDX_LOCAL && isDefined())
+  if ((visibility != STV_DEFAULT && visibility != STV_PROTECTED) ||
+      versionId == VER_NDX_LOCAL)
     return STB_LOCAL;
   if (!config->gnuUnique && binding == STB_GNU_UNIQUE)
     return STB_GLOBAL;




More information about the llvm-commits mailing list