From: Rafael Espindola Date: Thu, 24 Mar 2016 15:23:01 +0000 (+0000) Subject: Fix another case where we were unconditionally linking linkonce GVs. X-Git-Tag: llvmorg-3.9.0-rc1~11031 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e1c42ac12b29462944af83719c92fa5546da6a90;p=platform%2Fupstream%2Fllvm.git Fix another case where we were unconditionally linking linkonce GVs. With this I think that now llvm-link, lld and the gold plugin should agree on which symbol is kept. llvm-svn: 264292 --- diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp index f6e0f06..c07c47e 100644 --- a/llvm/lib/Linker/LinkModules.cpp +++ b/llvm/lib/Linker/LinkModules.cpp @@ -447,6 +447,12 @@ void ModuleLinker::addLazyFor(GlobalValue &GV, IRMover::ValueAdder Add) { if (!SC) return; for (GlobalValue *GV2 : LazyComdatMembers[SC]) { + GlobalValue *DGV = getLinkedToGlobal(GV2); + bool LinkFromSrc = true; + if (DGV && shouldLinkFromSource(LinkFromSrc, *DGV, *GV2)) + return; + if (!LinkFromSrc) + continue; if (shouldInternalizeLinkedSymbols()) Internalize.insert(GV2->getName()); Add(*GV2); diff --git a/llvm/test/Linker/Inputs/pr27044.ll b/llvm/test/Linker/Inputs/pr27044.ll index 907643c..c949a93 100644 --- a/llvm/test/Linker/Inputs/pr27044.ll +++ b/llvm/test/Linker/Inputs/pr27044.ll @@ -1,7 +1,19 @@ $foo = comdat any +$bar = comdat any + define linkonce_odr i32 @f1() comdat($foo) { ret i32 1 } + define void @f2() comdat($foo) { + call i32 @g2() ret void } + +define linkonce_odr i32 @g1() comdat($bar) { + ret i32 1 +} + +define linkonce_odr i32 @g2() comdat($bar) { + ret i32 1 +} diff --git a/llvm/test/Linker/pr27044.ll b/llvm/test/Linker/pr27044.ll index 58d2165..59e6c50 100644 --- a/llvm/test/Linker/pr27044.ll +++ b/llvm/test/Linker/pr27044.ll @@ -1,8 +1,14 @@ ; RUN: llvm-link -S %s %p/Inputs/pr27044.ll -o - | FileCheck %s ; CHECK: define i32 @f1() { +; CHECK: define i32 @g1() { ; CHECK: define void @f2() comdat($foo) { +; CHECK: define linkonce_odr i32 @g2() comdat($bar) { define i32 @f1() { ret i32 0 } + +define i32 @g1() { + ret i32 0 +}