diff options
Diffstat (limited to 'llvm')
-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 | ||||
-rw-r--r-- | llvm/test/LTO/Resolution/X86/Inputs/link-odr-availextern-ae.ll | 6 | ||||
-rw-r--r-- | llvm/test/LTO/Resolution/X86/link-odr-availextern.ll | 25 | ||||
-rw-r--r-- | llvm/test/Linker/available_externally_a.ll | 2 |
6 files changed, 57 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()) diff --git a/llvm/test/LTO/Resolution/X86/Inputs/link-odr-availextern-ae.ll b/llvm/test/LTO/Resolution/X86/Inputs/link-odr-availextern-ae.ll new file mode 100644 index 00000000000..f2d180afc82 --- /dev/null +++ b/llvm/test/LTO/Resolution/X86/Inputs/link-odr-availextern-ae.ll @@ -0,0 +1,6 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define available_externally i32 @f() { + ret i32 2 +} diff --git a/llvm/test/LTO/Resolution/X86/link-odr-availextern.ll b/llvm/test/LTO/Resolution/X86/link-odr-availextern.ll new file mode 100644 index 00000000000..4af79b64b2a --- /dev/null +++ b/llvm/test/LTO/Resolution/X86/link-odr-availextern.ll @@ -0,0 +1,25 @@ +; Tests for correct behavior for non-prevailing resolutions in cases involving +; *_odr and available_externally linkages. + +; RUN: llvm-as %s -o %t1 +; RUN: llvm-as %S/Inputs/link-odr-availextern-ae.ll -o %t2ae + +; RUN: llvm-lto2 -o %t3 %t1 %t2ae -r %t1,f,p -r %t2ae,f, -save-temps +; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=PREVAILING %s + +; RUN: llvm-lto2 -o %t3 %t2ae %t1 -r %t1,f,p -r %t2ae,f, -save-temps +; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=PREVAILING %s + +; RUN: llvm-lto2 -o %t3 %t2ae -r %t2ae,f, -save-temps +; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=NONPREVAILING %s + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; PREVAILING: define weak_odr i32 @f() +; PREVAILING-NEXT: ret i32 1 +; NONPREVAILING: define available_externally i32 @f() +; NONPREVAILING-NEXT: ret i32 2 +define linkonce_odr i32 @f() { + ret i32 1 +} diff --git a/llvm/test/Linker/available_externally_a.ll b/llvm/test/Linker/available_externally_a.ll index 3ae4ce29140..7a000b6a4aa 100644 --- a/llvm/test/Linker/available_externally_a.ll +++ b/llvm/test/Linker/available_externally_a.ll @@ -1,5 +1,7 @@ ; RUN: llvm-link %s %p/available_externally_b.ll -S -o - | FileCheck %s +; RUN: llvm-link %s -S -o - | FileCheck --check-prefix=AE-ONLY %s @foo = available_externally unnamed_addr constant i32 0 ; CHECK: @foo = hidden unnamed_addr constant i32 0 +; AE-ONLY-NOT: @foo |