Prefer common over weak linkage when linking.

This matches the behavior of ELF linkers.

llvm-svn: 217443
This commit is contained in:
Rafael Espindola 2014-09-09 14:27:09 +00:00
parent 91ea478d7c
commit 7fc29546f9
3 changed files with 10 additions and 2 deletions

View File

@ -721,8 +721,9 @@ bool ModuleLinker::getLinkageResult(GlobalValue *Dest, const GlobalValue *Src,
} else if (Src->isWeakForLinker()) {
assert(!Dest->hasExternalWeakLinkage());
assert(!Dest->hasAvailableExternallyLinkage());
if (Dest->hasLinkOnceLinkage() &&
(Src->hasWeakLinkage() || Src->hasCommonLinkage())) {
if ((Dest->hasLinkOnceLinkage() && Src->hasWeakLinkage()) ||
((Dest->hasLinkOnceLinkage() || Dest->hasWeakLinkage()) &&
Src->hasCommonLinkage())) {
LinkFromSrc = true;
LT = Src->getLinkage();
} else {

View File

@ -0,0 +1 @@
@test1_a = weak global i8 1

View File

@ -0,0 +1,6 @@
; RUN: llvm-link %s %p/Inputs/linkage2.ll -S | FileCheck %s
; RUN: llvm-link %p/Inputs/linkage2.ll %s -S | FileCheck %s
@test1_a = common global i8 0
; CHECK: @test1_a = common global i8 0