[ELF] - Make IR symbols be visible when doing relocatable link.

This is PR33097.
Previously when doing relocatable link, all IR symbols were absent
in result object file. Patch makes external symbols to be exported.

Differential revision: https://reviews.llvm.org/D36957

llvm-svn: 311431
diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index deb10ac..751062a 100644
--- a/lld/ELF/LTO.cpp
+++ b/lld/ELF/LTO.cpp
@@ -144,7 +144,13 @@
     // be removed.
     R.Prevailing = !ObjSym.isUndefined() && B->getFile() == &F;
 
-    R.VisibleToRegularObj = Sym->IsUsedInRegularObj ||
+    // We ask LTO to preserve following global symbols:
+    // 1) All symbols when doing relocatable link, so that them can be used
+    //    for doing final link.
+    // 2) Symbols that are used in regular objects.
+    // 3) C named sections if we have corresponding __start_/__stop_ symbol.
+    // 4) Symbols that are defined in bitcode files and used for dynamic linking.
+    R.VisibleToRegularObj = Config->Relocatable || Sym->IsUsedInRegularObj ||
                             (R.Prevailing && Sym->includeInDynsym()) ||
                             UsedStartStop.count(ObjSym.getSectionName());
     if (R.Prevailing)