diff options
author | Benoit Belley <benoit.belley@autodesk.com> | 2017-08-09 20:58:39 +0000 |
---|---|---|
committer | Benoit Belley <benoit.belley@autodesk.com> | 2017-08-09 20:58:39 +0000 |
commit | bad5f185df2d4a88145025b7ec93c8e008c9cd80 (patch) | |
tree | cf193d56a5db6c262860ed4370059eea71116e5b /lib/Linker | |
parent | fe294dbbe4bdd756357c996e5278cd5d7ff54b23 (diff) |
[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
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310522 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Linker')
-rw-r--r-- | lib/Linker/LinkModules.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index c0ce4bf76b9..25f31a3401a 100644 --- a/lib/Linker/LinkModules.cpp +++ b/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); |