[llvm] r219188 - gold plugin: Handle gold selecting a linkonce GV when a weak is present.

Rafael Espindola rafael.espindola at gmail.com
Mon Oct 6 21:06:13 PDT 2014


Author: rafael
Date: Mon Oct  6 23:06:13 2014
New Revision: 219188

URL: http://llvm.org/viewvc/llvm-project?rev=219188&view=rev
Log:
gold plugin: Handle gold selecting a linkonce GV when a weak is present.

The plugin API doesn't have the notion of linkonce, only weak. It is up to the
plugin to figure out if a symbol used only for the symbol table can be dropped.
In particular, it has to avoid dropping a linkonce_odr selected by gold if there
is also a weak_odr.

Added:
    llvm/trunk/test/tools/gold/Inputs/linkonce-weak.ll
    llvm/trunk/test/tools/gold/linkonce-weak.ll
Modified:
    llvm/trunk/tools/gold/gold-plugin.cpp

Added: llvm/trunk/test/tools/gold/Inputs/linkonce-weak.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/gold/Inputs/linkonce-weak.ll?rev=219188&view=auto
==============================================================================
--- llvm/trunk/test/tools/gold/Inputs/linkonce-weak.ll (added)
+++ llvm/trunk/test/tools/gold/Inputs/linkonce-weak.ll Mon Oct  6 23:06:13 2014
@@ -0,0 +1,3 @@
+define weak_odr void @f() {
+  ret void
+}

Added: llvm/trunk/test/tools/gold/linkonce-weak.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/gold/linkonce-weak.ll?rev=219188&view=auto
==============================================================================
--- llvm/trunk/test/tools/gold/linkonce-weak.ll (added)
+++ llvm/trunk/test/tools/gold/linkonce-weak.ll Mon Oct  6 23:06:13 2014
@@ -0,0 +1,19 @@
+; RUN: llvm-as %s -o %t.o
+; RUN: llvm-as %p/Inputs/linkonce-weak.ll -o %t2.o
+
+; RUN: ld -plugin %llvmshlibdir/LLVMgold.so \
+; RUN:    --plugin-opt=emit-llvm \
+; RUN:    -shared %t.o %t2.o -o %t3.o
+; RUN: llvm-dis %t3.o -o - | FileCheck %s
+
+; RUN: ld -plugin %llvmshlibdir/LLVMgold.so \
+; RUN:    --plugin-opt=emit-llvm \
+; RUN:    -shared %t2.o %t.o -o %t3.o
+; RUN: llvm-dis %t3.o -o - | FileCheck %s
+
+define linkonce_odr void @f() {
+  ret void
+}
+
+; Test that we get a weak_odr regardless of the order of the files
+; CHECK: define weak_odr void @f() {

Modified: llvm/trunk/tools/gold/gold-plugin.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=219188&r1=219187&r2=219188&view=diff
==============================================================================
--- llvm/trunk/tools/gold/gold-plugin.cpp (original)
+++ llvm/trunk/tools/gold/gold-plugin.cpp Mon Oct  6 23:06:13 2014
@@ -637,8 +637,14 @@ getModuleForFile(LLVMContext &Context, c
       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;
 





More information about the llvm-commits mailing list