summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Linker/LinkModules.cpp
diff options
context:
space:
mode:
authorBenoit Belley <benoit.belley@autodesk.com>2017-08-09 20:58:39 +0000
committerBenoit Belley <benoit.belley@autodesk.com>2017-08-09 20:58:39 +0000
commitb1a9ad81c5d4850acd5429b03f59c4e7b6fe3466 (patch)
tree166e140d804538b791921b7dab8799a32d9003f7 /llvm/lib/Linker/LinkModules.cpp
parent0284a20fbafae760a21aca9fde47efbec9f6afcb (diff)
downloadbcm5719-llvm-b1a9ad81c5d4850acd5429b03f59c4e7b6fe3466.tar.gz
bcm5719-llvm-b1a9ad81c5d4850acd5429b03f59c4e7b6fe3466.zip
[Linker] PR33527 - Linker::LinkOnlyNeeded should import AppendingLinkage globals
Linker::LinkOnlyNeeded should always import globals with AppendingLinkage. This resolves PR33527. Differential Revision: https://reviews.llvm.org/D34448 llvm-svn: 310522
Diffstat (limited to 'llvm/lib/Linker/LinkModules.cpp')
-rw-r--r--llvm/lib/Linker/LinkModules.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp
index c0ce4bf76b9..25f31a3401a 100644
--- a/llvm/lib/Linker/LinkModules.cpp
+++ b/llvm/lib/Linker/LinkModules.cpp
@@ -329,8 +329,18 @@ bool ModuleLinker::shouldLinkFromSource(bool &LinkFromSrc,
bool ModuleLinker::linkIfNeeded(GlobalValue &GV) {
GlobalValue *DGV = getLinkedToGlobal(&GV);
- if (shouldLinkOnlyNeeded() && !(DGV && DGV->isDeclaration()))
- return false;
+ if (shouldLinkOnlyNeeded()) {
+ // Always import variables with appending linkage.
+ if (!GV.hasAppendingLinkage()) {
+ // Don't import globals unless they are referenced by the destination
+ // module.
+ if (!DGV)
+ return false;
+ // Don't import globals that are already defined in the destination module
+ if (!DGV->isDeclaration())
+ return false;
+ }
+ }
if (DGV && !GV.hasLocalLinkage() && !GV.hasAppendingLinkage()) {
auto *DGVar = dyn_cast<GlobalVariable>(DGV);
OpenPOWER on IntegriCloud