diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/LTO/LTO.cpp | 35 | ||||
-rw-r--r-- | llvm/lib/Linker/IRMover.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/Linker/LinkModules.cpp | 3 |
3 files changed, 24 insertions, 17 deletions
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index e602c64337c..4d0c039891e 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -455,20 +455,29 @@ Error LTO::addRegularLTO(BitcodeModule BM, const SymbolResolution *&ResI, SymbolResolution Res = *ResI++; addSymbolToGlobalRes(Used, Sym, Res, 0); - if (Sym.getFlags() & object::BasicSymbolRef::SF_Undefined) - continue; - if (Res.Prevailing && Sym.isGV()) { + if (Sym.isGV()) { GlobalValue *GV = Sym.getGV(); - Keep.push_back(GV); - switch (GV->getLinkage()) { - default: - break; - case GlobalValue::LinkOnceAnyLinkage: - GV->setLinkage(GlobalValue::WeakAnyLinkage); - break; - case GlobalValue::LinkOnceODRLinkage: - GV->setLinkage(GlobalValue::WeakODRLinkage); - break; + if (Res.Prevailing) { + if (Sym.getFlags() & object::BasicSymbolRef::SF_Undefined) + continue; + Keep.push_back(GV); + switch (GV->getLinkage()) { + default: + break; + case GlobalValue::LinkOnceAnyLinkage: + GV->setLinkage(GlobalValue::WeakAnyLinkage); + break; + case GlobalValue::LinkOnceODRLinkage: + GV->setLinkage(GlobalValue::WeakODRLinkage); + break; + } + } else if (GV->hasAvailableExternallyLinkage()) { + // We can link available_externally symbols even if they are + // non-prevailing. + GlobalValue *CombinedGV = + RegularLTO.CombinedModule->getNamedValue(GV->getName()); + if (!CombinedGV || CombinedGV->isDeclaration()) + Keep.push_back(GV); } } // Common resolution: collect the maximum size/alignment over all commons. diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp index 9f3cfc0eace..468d86d6e0d 100644 --- a/llvm/lib/Linker/IRMover.cpp +++ b/llvm/lib/Linker/IRMover.cpp @@ -870,9 +870,6 @@ bool IRLinker::shouldLink(GlobalValue *DGV, GlobalValue &SGV) { if (DGV && !DGV->isDeclarationForLinker()) return false; - if (SGV.hasAvailableExternallyLinkage()) - return true; - if (SGV.isDeclaration() || DoneLinkingBodies) return false; diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp index cf2c4ccf523..7ff84db0702 100644 --- a/llvm/lib/Linker/LinkModules.cpp +++ b/llvm/lib/Linker/LinkModules.cpp @@ -425,7 +425,8 @@ void ModuleLinker::addLazyFor(GlobalValue &GV, const IRMover::ValueAdder &Add) { return; // Add these to the internalize list - if (!GV.hasLinkOnceLinkage() && !shouldLinkOnlyNeeded()) + if (!GV.hasLinkOnceLinkage() && !GV.hasAvailableExternallyLinkage() && + !shouldLinkOnlyNeeded()) return; if (shouldInternalizeLinkedSymbols()) |