ELF: Move Visibility, IsUsedInRegularObj and MustBeInDynSym flags to Symbol.

These are properties of a symbol name, rather than a particular instance
of a symbol in an object file. We can simplify the code by collecting these
properties in Symbol.

The MustBeInDynSym flag has been renamed ExportDynamic, as its semantics
have been changed to be the same as those of --dynamic-list and
--export-dynamic-symbol, which do not cause hidden symbols to be exported.

Differential Revision: http://reviews.llvm.org/D19400

llvm-svn: 267183
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index e6f8842..43a0cbb 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -80,7 +80,7 @@
     return 0;
   case SymbolBody::LazyArchiveKind:
   case SymbolBody::LazyObjectKind:
-    assert(Body.isUsedInRegularObj() && "lazy symbol reached writer");
+    assert(Body.Backref->IsUsedInRegularObj && "lazy symbol reached writer");
     return 0;
   case SymbolBody::DefinedBitcodeKind:
     llvm_unreachable("should have been replaced");
@@ -104,13 +104,9 @@
 }
 
 void SymbolBody::init() {
-  Kind K = kind();
-  IsUsedInRegularObj = K == DefinedRegularKind || K == DefinedCommonKind ||
-                       K == DefinedSyntheticKind || K == UndefinedElfKind;
   CanKeepUndefined = false;
-  MustBeInDynSym = false;
-  CanOmitFromDynSym = false;
   NeedsCopyOrPltAddr = false;
+  CanOmitFromDynSym = false;
 }
 
 // Returns true if a symbol can be replaced at load-time by a symbol
@@ -122,7 +118,7 @@
   if (isShared())
     return true;
 
-  if (getVisibility() != STV_DEFAULT)
+  if (Backref->Visibility != STV_DEFAULT)
     return false;
 
   if (isUndefined()) {
@@ -193,14 +189,6 @@
   return 0;
 }
 
-static uint8_t getMinVisibility(uint8_t VA, uint8_t VB) {
-  if (VA == STV_DEFAULT)
-    return VB;
-  if (VB == STV_DEFAULT)
-    return VA;
-  return std::min(VA, VB);
-}
-
 static int compareCommons(DefinedCommon *A, DefinedCommon *B) {
   if (Config->WarnCommon)
     warning("multiple common of " + A->getName());
@@ -220,31 +208,6 @@
   if (L > R)
     return -Other->compare(this);
 
-  uint8_t V = getMinVisibility(getVisibility(), Other->getVisibility());
-  if (isShared() != Other->isShared()) {
-    SymbolBody *Shared = isShared() ? this : Other;
-    Shared->MustBeInDynSym = true;
-    if (Shared->getVisibility() == STV_DEFAULT &&
-        (V == STV_DEFAULT || V == STV_PROTECTED)) {
-      // We want to export all symbols that exist in the executable and are
-      // preemptable in DSOs, so that the symbols in the executable can
-      // preempt symbols in the DSO at runtime.
-      SymbolBody *NonShared = isShared() ? Other : this;
-      NonShared->MustBeInDynSym = true;
-    }
-  }
-
-  if (!isShared() && !Other->isShared()) {
-    setVisibility(V);
-    Other->setVisibility(V);
-  }
-
-  if (IsUsedInRegularObj || Other->IsUsedInRegularObj)
-    IsUsedInRegularObj = Other->IsUsedInRegularObj = true;
-
-  if (!CanOmitFromDynSym || !Other->CanOmitFromDynSym)
-    CanOmitFromDynSym = Other->CanOmitFromDynSym = false;
-
   if (L != R)
     return -1;
   if (!isDefined() || isShared() || isWeak())
@@ -358,15 +321,10 @@
 #endif
 }
 
-bool SymbolBody::includeInDynsym() const {
-  if (MustBeInDynSym)
-    return true;
-  uint8_t V = getVisibility();
-  if (V != STV_DEFAULT && V != STV_PROTECTED)
+bool Symbol::includeInDynsym() const {
+  if (Visibility != STV_DEFAULT && Visibility != STV_PROTECTED)
     return false;
-  if (!Config->ExportDynamic && !Config->Shared)
-    return false;
-  return !CanOmitFromDynSym;
+  return ExportDynamic || Body->isShared();
 }
 
 template uint32_t SymbolBody::template getVA<ELF32LE>(uint32_t) const;