llvm.org GIT mirror llvm / e482a05
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293864 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 3 years ago
6 changed file(s) with 57 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
454454 SymbolResolution Res = *ResI++;
455455 addSymbolToGlobalRes(Used, Sym, Res, 0);
456456
457 if (Sym.getFlags() & object::BasicSymbolRef::SF_Undefined)
458 continue;
459 if (Res.Prevailing && Sym.isGV()) {
457 if (Sym.isGV()) {
460458 GlobalValue *GV = Sym.getGV();
461 Keep.push_back(GV);
462 switch (GV->getLinkage()) {
463 default:
464 break;
465 case GlobalValue::LinkOnceAnyLinkage:
466 GV->setLinkage(GlobalValue::WeakAnyLinkage);
467 break;
468 case GlobalValue::LinkOnceODRLinkage:
469 GV->setLinkage(GlobalValue::WeakODRLinkage);
470 break;
459 if (Res.Prevailing) {
460 if (Sym.getFlags() & object::BasicSymbolRef::SF_Undefined)
461 continue;
462 Keep.push_back(GV);
463 switch (GV->getLinkage()) {
464 default:
465 break;
466 case GlobalValue::LinkOnceAnyLinkage:
467 GV->setLinkage(GlobalValue::WeakAnyLinkage);
468 break;
469 case GlobalValue::LinkOnceODRLinkage:
470 GV->setLinkage(GlobalValue::WeakODRLinkage);
471 break;
472 }
473 } else if (GV->hasAvailableExternallyLinkage()) {
474 // We can link available_externally symbols even if they are
475 // non-prevailing.
476 GlobalValue *CombinedGV =
477 RegularLTO.CombinedModule->getNamedValue(GV->getName());
478 if (!CombinedGV || CombinedGV->isDeclaration())
479 Keep.push_back(GV);
471480 }
472481 }
473482 // Common resolution: collect the maximum size/alignment over all commons.
868868
869869 if (DGV && !DGV->isDeclarationForLinker())
870870 return false;
871
872 if (SGV.hasAvailableExternallyLinkage())
873 return true;
874871
875872 if (SGV.isDeclaration() || DoneLinkingBodies)
876873 return false;
424424 return;
425425
426426 // Add these to the internalize list
427 if (!GV.hasLinkOnceLinkage() && !shouldLinkOnlyNeeded())
427 if (!GV.hasLinkOnceLinkage() && !GV.hasAvailableExternallyLinkage() &&
428 !shouldLinkOnlyNeeded())
428429 return;
429430
430431 if (shouldInternalizeLinkedSymbols())
0 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
1 target triple = "x86_64-unknown-linux-gnu"
2
3 define available_externally i32 @f() {
4 ret i32 2
5 }
0 ; Tests for correct behavior for non-prevailing resolutions in cases involving
1 ; *_odr and available_externally linkages.
2
3 ; RUN: llvm-as %s -o %t1
4 ; RUN: llvm-as %S/Inputs/link-odr-availextern-ae.ll -o %t2ae
5
6 ; RUN: llvm-lto2 -o %t3 %t1 %t2ae -r %t1,f,p -r %t2ae,f, -save-temps
7 ; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=PREVAILING %s
8
9 ; RUN: llvm-lto2 -o %t3 %t2ae %t1 -r %t1,f,p -r %t2ae,f, -save-temps
10 ; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=PREVAILING %s
11
12 ; RUN: llvm-lto2 -o %t3 %t2ae -r %t2ae,f, -save-temps
13 ; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=NONPREVAILING %s
14
15 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
16 target triple = "x86_64-unknown-linux-gnu"
17
18 ; PREVAILING: define weak_odr i32 @f()
19 ; PREVAILING-NEXT: ret i32 1
20 ; NONPREVAILING: define available_externally i32 @f()
21 ; NONPREVAILING-NEXT: ret i32 2
22 define linkonce_odr i32 @f() {
23 ret i32 1
24 }
0 ; RUN: llvm-link %s %p/available_externally_b.ll -S -o - | FileCheck %s
1 ; RUN: llvm-link %s -S -o - | FileCheck --check-prefix=AE-ONLY %s
12
23 @foo = available_externally unnamed_addr constant i32 0
34
45 ; CHECK: @foo = hidden unnamed_addr constant i32 0
6 ; AE-ONLY-NOT: @foo