[lld] r322590 - Inline foot gun into only valid use.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 16 11:28:29 PST 2018


Author: rafael
Date: Tue Jan 16 11:28:28 2018
New Revision: 322590

URL: http://llvm.org/viewvc/llvm-project?rev=322590&view=rev
Log:
Inline foot gun into only valid use.

Symbol had both Visibility and getVisibility() and they had different
meanings. That is just too easy to get wrong.

getVisibility() would compute the visibility of a particular symbol
(foo in bar.o), and Visibility stores the computed value we will put
in the output.

There is only one case when we want what getVisibility() provides, so
inline it.

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

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=322590&r1=322589&r2=322590&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Tue Jan 16 11:28:28 2018
@@ -744,7 +744,10 @@ template <class ELFT> static void addGot
 static bool canDefineSymbolInExecutable(Symbol &Sym) {
   // If the symbol has default visibility the symbol defined in the
   // executable will preempt it.
-  if (Sym.getVisibility() == STV_DEFAULT)
+  // Note that we want the visibility of the shared symbol itself, not
+  // the visibility of the symbol in the output file we are producing. That is
+  // why we use Sym.StOther.
+  if ((Sym.StOther & 0x3) == STV_DEFAULT)
     return true;
 
   // If we are allowed to break address equality of functions, defining

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=322590&r1=322589&r2=322590&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Tue Jan 16 11:28:28 2018
@@ -108,7 +108,6 @@ public:
   }
 
   StringRef getName() const { return Name; }
-  uint8_t getVisibility() const { return StOther & 0x3; }
   void parseSymbolVersion();
 
   bool isInGot() const { return GotIndex != -1U; }




More information about the llvm-commits mailing list