Fix an issue that common symbols are not internalized under some condition.

r360841 introduced CommonSymbol class. An unintended behavioral change
introduced by that change was that common symbols are not internalized
by LTO under some condition. This patch fixes that issue.

The issue occurred under the following condition:

  1. There exists a common symbol
  2. At least one DSO is given to lld or -pie is used

If the above conditions are met, Symbol::includeInDynsym() returned a
wrong value for a common symbol.

Fixes https://bugs.llvm.org/show_bug.cgi?id=41978

Differential Revision: https://reviews.llvm.org/D63752

llvm-svn: 364273
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index a5bc49d..9a4de4f 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -275,13 +275,13 @@
     return false;
   if (computeBinding() == STB_LOCAL)
     return false;
+
   // If a PIE binary was not linked against any shared libraries, then we can
   // safely drop weak undef symbols from .dynsym.
   if (isUndefWeak() && Config->Pie && SharedFiles.empty())
     return false;
-  if (!isDefined())
-    return true;
-  return ExportDynamic;
+
+  return isUndefined() || isShared() || ExportDynamic;
 }
 
 // Print out a log message for --trace-symbol.