Cleanup the handling of MustBeInDynSym and IsUsedInRegularObj.

Now MustBeInDynSym is only true if the symbol really must be in the
dynamic symbol table.

IsUsedInRegularObj is only true if the symbol is used in a .o or -u. Not
a .so or a .bc.

A benefit is that this is now done almost entirilly during symbol
resolution. The only exception is copy relocations because of aliases.

This includes a small fix in that protected symbols in .so don't force
executable symbols to be exported.

This also opens the way for implementing internalize for -shared.

llvm-svn: 265826
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index 9def17c..a0d0769 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -218,6 +218,18 @@
   if (L > R)
     return -Other->compare(this);
 
+  if (isShared() != Other->isShared()) {
+    SymbolBody *Shared = isShared() ? this : Other;
+    Shared->MustBeInDynSym = true;
+    if (Shared->getVisibility() == STV_DEFAULT) {
+      // 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()) {
     uint8_t V = getMinVisibility(getVisibility(), Other->getVisibility());
     setVisibility(V);
@@ -227,15 +239,6 @@
   if (IsUsedInRegularObj || Other->IsUsedInRegularObj)
     IsUsedInRegularObj = Other->IsUsedInRegularObj = true;
 
-  // We want to export all symbols that exist both in the executable
-  // and in DSOs, so that the symbols in the executable can interrupt
-  // symbols in the DSO at runtime.
-  if (isShared() != Other->isShared())
-    if (isa<Defined>(isShared() ? Other : this)) {
-      IsUsedInRegularObj = Other->IsUsedInRegularObj = true;
-      MustBeInDynSym = Other->MustBeInDynSym = true;
-    }
-
   if (L != R)
     return -1;
   if (!isDefined() || isShared() || isWeak())