Prefer common over weak linkage when linking.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 9 Sep 2014 14:27:09 +0000 (14:27 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 9 Sep 2014 14:27:09 +0000 (14:27 +0000)
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
test/Linker/Inputs/linkage2.ll [new file with mode: 0644]
test/Linker/linkage2.ll [new file with mode: 0644]

index d02d590ca1081fb8c52f93ec8dd64870895cb0dc..14c6a10c3398e70ad607254db556ee051a244d4c 100644 (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 {
diff --git a/test/Linker/Inputs/linkage2.ll b/test/Linker/Inputs/linkage2.ll
new file mode 100644 (file)
index 0000000..3f6963e
--- /dev/null
@@ -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 (file)
index 0000000..2ecdc1f
--- /dev/null
@@ -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