[ELF] - Symbols from object files that override symbols in DSO are added to .dynsym table.

Main executable did not export symbols that exist both in the main executable and in DSOs before this patch.
Symbols from object files that override symbols in DSO should be added to .dynsym table.

Differential revision: http://reviews.llvm.org/D16405

llvm-svn: 258672
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index bc0db8a..ad6423f 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -53,6 +53,13 @@
   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<DefinedRegular<ELFT>>(isShared() ? Other : this))
+      IsUsedInDynamicReloc = Other->IsUsedInDynamicReloc = true;
+
   if (L != R)
     return -1;
   if (!std::get<0>(L) || !std::get<1>(L) || !std::get<2>(L))