Fix recursive -only-needed.

We were assuming that only linkonce_odr GVs were lazy linked.

llvm-svn: 266995
This commit is contained in:
Rafael Espindola 2016-04-21 14:56:33 +00:00
parent 173f170236
commit 7e0cfdf745
4 changed files with 23 additions and 2 deletions

View File

@ -849,9 +849,11 @@ bool IRLinker::shouldLink(GlobalValue *DGV, GlobalValue &SGV) {
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.

View File

@ -423,7 +423,7 @@ void ModuleLinker::addLazyFor(GlobalValue &GV, IRMover::ValueAdder Add) {
return;
// Add these to the internalize list
if (!GV.hasLinkOnceLinkage())
if (!GV.hasLinkOnceLinkage() && !shouldLinkOnlyNeeded())
return;
if (shouldInternalizeLinkedSymbols())

View File

@ -0,0 +1,8 @@
define void @f2() {
call void @f3()
ret void
}
define void @f3() {
ret void
}

View File

@ -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