gold plugin: Handle gold selecting a linkonce GV when a weak is present.
[oota-llvm.git] / tools / gold / gold-plugin.cpp
index ffee1ff3258b3ab21fe66e2f337c89ef741d6647..d5d58d0e5885884e9cdd9dc49cedb31c01887ed6 100644 (file)
@@ -637,8 +637,14 @@ getModuleForFile(LLVMContext &Context, claimed_file &F, raw_fd_ostream *ApiFile,
       keepGlobalValue(*GV, KeptAliases);
       break;
 
-    case LDPR_PREEMPTED_REG:
     case LDPR_PREEMPTED_IR:
+      // Gold might have selected a linkonce_odr and preempted a weak_odr.
+      // In that case we have to make sure we don't end up internalizing it.
+      if (!GV->isDiscardableIfUnused())
+        Maybe.erase(Sym.name);
+
+      // fall-through
+    case LDPR_PREEMPTED_REG:
       Drop.insert(GV);
       break;