summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-09-09 14:27:09 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-09-09 14:27:09 +0000
commit7fc29546f93e1c4ca579be76c69245e7521cce4b (patch)
tree26e4174c5b4363ceaa7bdd3b0f2f5b53bdab6c91
parent91ea478d7c69853866125e8a01add7f44922c147 (diff)
downloadbcm5719-llvm-7fc29546f93e1c4ca579be76c69245e7521cce4b.tar.gz
bcm5719-llvm-7fc29546f93e1c4ca579be76c69245e7521cce4b.zip
Prefer common over weak linkage when linking.
This matches the behavior of ELF linkers. llvm-svn: 217443
-rw-r--r--llvm/lib/Linker/LinkModules.cpp5
-rw-r--r--llvm/test/Linker/Inputs/linkage2.ll1
-rw-r--r--llvm/test/Linker/linkage2.ll6
3 files changed, 10 insertions, 2 deletions
diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp
index d02d590ca10..14c6a10c339 100644
--- a/llvm/lib/Linker/LinkModules.cpp
+++ b/llvm/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/llvm/test/Linker/Inputs/linkage2.ll b/llvm/test/Linker/Inputs/linkage2.ll
new file mode 100644
index 00000000000..3f6963ec4c7
--- /dev/null
+++ b/llvm/test/Linker/Inputs/linkage2.ll
@@ -0,0 +1 @@
+@test1_a = weak global i8 1
diff --git a/llvm/test/Linker/linkage2.ll b/llvm/test/Linker/linkage2.ll
new file mode 100644
index 00000000000..2ecdc1ff30a
--- /dev/null
+++ b/llvm/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
OpenPOWER on IntegriCloud