From ec8b573e549b532b253c752e9d50cfbbc933ab51 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 9 Sep 2014 14:27:09 +0000 Subject: [PATCH] Prefer common over weak linkage when linking. This matches the behavior of ELF linkers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217443 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Linker/LinkModules.cpp | 5 +++-- test/Linker/Inputs/linkage2.ll | 1 + test/Linker/linkage2.ll | 6 ++++++ 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 test/Linker/Inputs/linkage2.ll create mode 100644 test/Linker/linkage2.ll diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index d02d590ca10..14c6a10c339 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -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 { diff --git a/test/Linker/Inputs/linkage2.ll b/test/Linker/Inputs/linkage2.ll new file mode 100644 index 00000000000..3f6963ec4c7 --- /dev/null +++ b/test/Linker/Inputs/linkage2.ll @@ -0,0 +1 @@ +@test1_a = weak global i8 1 diff --git a/test/Linker/linkage2.ll b/test/Linker/linkage2.ll new file mode 100644 index 00000000000..2ecdc1ff30a --- /dev/null +++ b/test/Linker/linkage2.ll @@ -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 -- 2.11.0