[llvm] r266995 - Fix recursive -only-needed.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 21 07:56:33 PDT 2016


Author: rafael
Date: Thu Apr 21 09:56:33 2016
New Revision: 266995

URL: http://llvm.org/viewvc/llvm-project?rev=266995&view=rev
Log:
Fix recursive -only-needed.

We were assuming that only linkonce_odr GVs were lazy linked.

Added:
    llvm/trunk/test/Linker/Inputs/only-needed-recurse.ll
    llvm/trunk/test/Linker/only-needed-recurse.ll
Modified:
    llvm/trunk/lib/Linker/IRMover.cpp
    llvm/trunk/lib/Linker/LinkModules.cpp

Modified: llvm/trunk/lib/Linker/IRMover.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/IRMover.cpp?rev=266995&r1=266994&r2=266995&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/IRMover.cpp (original)
+++ llvm/trunk/lib/Linker/IRMover.cpp Thu Apr 21 09:56:33 2016
@@ -849,9 +849,11 @@ bool IRLinker::shouldLink(GlobalValue *D
   if (SGV.hasAvailableExternallyLinkage())
     return true;
 
-  if (DoneLinkingBodies)
+  if (SGV.isDeclaration())
     return false;
 
+  if (DoneLinkingBodies)
+    return false;
 
   // Callback to the client to give a chance to lazily add the Global to the
   // list of value to link.

Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=266995&r1=266994&r2=266995&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Thu Apr 21 09:56:33 2016
@@ -423,7 +423,7 @@ void ModuleLinker::addLazyFor(GlobalValu
     return;
 
   // Add these to the internalize list
-  if (!GV.hasLinkOnceLinkage())
+  if (!GV.hasLinkOnceLinkage() && !shouldLinkOnlyNeeded())
     return;
 
   if (shouldInternalizeLinkedSymbols())

Added: llvm/trunk/test/Linker/Inputs/only-needed-recurse.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/Inputs/only-needed-recurse.ll?rev=266995&view=auto
==============================================================================
--- llvm/trunk/test/Linker/Inputs/only-needed-recurse.ll (added)
+++ llvm/trunk/test/Linker/Inputs/only-needed-recurse.ll Thu Apr 21 09:56:33 2016
@@ -0,0 +1,8 @@
+define void @f2() {
+  call void @f3()
+  ret void
+}
+
+define void @f3() {
+  ret void
+}

Added: llvm/trunk/test/Linker/only-needed-recurse.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/only-needed-recurse.ll?rev=266995&view=auto
==============================================================================
--- llvm/trunk/test/Linker/only-needed-recurse.ll (added)
+++ llvm/trunk/test/Linker/only-needed-recurse.ll Thu Apr 21 09:56:33 2016
@@ -0,0 +1,11 @@
+; RUN: llvm-link -S -only-needed %s %p/Inputs/only-needed-recurse.ll | FileCheck %s
+
+declare void @f2()
+
+define void @f1() {
+  call void @f2()
+  ret void
+}
+
+; CHECK: define void @f3
+




More information about the llvm-commits mailing list