Linker: Move special casing for available_externally in IRMover to clients. NFCI.

The goal is to simplify the semantic model for clients of IRMover.

Differential Revision: https://reviews.llvm.org/D29435

llvm-svn: 293864
This commit is contained in:
Peter Collingbourne 2017-02-02 05:12:15 +00:00
parent 1116d6915c
commit c387e70c69
6 changed files with 57 additions and 17 deletions

View File

@ -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.

View File

@ -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;

View File

@ -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())

View File

@ -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
}

View File

@ -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
}

View File

@ -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