llvm.org GIT mirror llvm / d69c1ef
LTO: Link non-prevailing weak_odr or linkonce_odr globals into the combined module with available_externally linkage. These linkages mean that the ultimately prevailing symbol will have the same semantics as any non-prevailing copy of the symbol, so we are free to ignore the linker's resolution. Differential Revision: https://reviews.llvm.org/D29367 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293865 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 3 years ago
3 changed file(s) with 36 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
445445 if (GV.hasAppendingLinkage())
446446 Keep.push_back(&GV);
447447
448 DenseSet AliasedGlobals;
449 for (auto &GA : M.aliases())
450 if (GlobalObject *GO = GA.getBaseObject())
451 AliasedGlobals.insert(GO);
452
448453 for (const InputFile::Symbol &Sym :
449454 make_range(InputFile::symbol_iterator(SymTab.symbols().begin(), SymTab,
450455 nullptr),
470475 GV->setLinkage(GlobalValue::WeakODRLinkage);
471476 break;
472477 }
473 } else if (GV->hasAvailableExternallyLinkage()) {
474 // We can link available_externally symbols even if they are
475 // non-prevailing.
478 } else if (isa(GV) &&
479 (GV->hasLinkOnceODRLinkage() || GV->hasWeakODRLinkage() ||
480 GV->hasAvailableExternallyLinkage()) &&
481 !AliasedGlobals.count(cast(GV))) {
482 // Either of the above three types of linkage indicates that the
483 // chosen prevailing symbol will have the same semantics as this copy of
484 // the symbol, so we can link it with available_externally linkage. We
485 // only need to do this if the symbol is undefined.
476486 GlobalValue *CombinedGV =
477487 RegularLTO.CombinedModule->getNamedValue(GV->getName());
478 if (!CombinedGV || CombinedGV->isDeclaration())
488 if (!CombinedGV || CombinedGV->isDeclaration()) {
479489 Keep.push_back(GV);
490 GV->setLinkage(GlobalValue::AvailableExternallyLinkage);
491 cast(GV)->setComdat(nullptr);
492 }
480493 }
481494 }
482495 // Common resolution: collect the maximum size/alignment over all commons.
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 linkonce_odr i32 @f() {
4 ret i32 2
5 }
22
33 ; RUN: llvm-as %s -o %t1
44 ; RUN: llvm-as %S/Inputs/link-odr-availextern-ae.ll -o %t2ae
5 ; RUN: llvm-as %S/Inputs/link-odr-availextern-odr.ll -o %t2odr
56
67 ; RUN: llvm-lto2 -o %t3 %t1 %t2ae -r %t1,f,p -r %t2ae,f, -save-temps
8 ; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=PREVAILING %s
9
10 ; RUN: llvm-lto2 -o %t3 %t1 %t2odr -r %t1,f,p -r %t2odr,f, -save-temps
711 ; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=PREVAILING %s
812
913 ; RUN: llvm-lto2 -o %t3 %t2ae %t1 -r %t1,f,p -r %t2ae,f, -save-temps
1014 ; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=PREVAILING %s
1115
16 ; RUN: llvm-lto2 -o %t3 %t2odr %t1 -r %t1,f,p -r %t2odr,f, -save-temps
17 ; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=PREVAILING %s
18
1219 ; RUN: llvm-lto2 -o %t3 %t2ae -r %t2ae,f, -save-temps
20 ; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=NONPREVAILING %s
21
22 ; RUN: llvm-lto2 -o %t3 %t2odr -r %t2odr,f, -save-temps
23 ; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=NONPREVAILING %s
24
25 ; RUN: llvm-lto2 -o %t3 %t2odr %t1 -r %t1,f, -r %t2odr,f, -save-temps
1326 ; RUN: llvm-dis < %t3.0.0.preopt.bc -o - | FileCheck --check-prefix=NONPREVAILING %s
1427
1528 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"