llvm.org GIT mirror llvm / 6411a79
[LTO] Fix the interaction between linker redefined symbols and ThinLTO This is the same as r304719 but for ThinLTO. The substantial difference is that in this case we don't have whole visibility, just the summary. In the LTO case, when we got the resolution for the input file we could just see if the linker told us whether a symbol was linker redefined (using --wrap or --defsym) and switch the linkage directly for the GV. Here, we have the summary. So, we record that the linkage changed from <whatever it was> to $weakany to prevent IPOs across this symbol boundaries and actually just switch the linkage at FunctionImport time. This patch should also fixes the lld bits (as all the scaffolding for communicating if a symbol is linker redefined should be there & should be the same), but I'll make sure to add some tests there as well. Fixes PR33192. Differential Revision: https://reviews.llvm.org/D35064 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307303 91177308-0d34-0410-b5e6-96231b3b80d8 Davide Italiano 3 years ago
3 changed file(s) with 35 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
664664 auto GUID = GlobalValue::getGUID(GlobalValue::getGlobalIdentifier(
665665 Sym.getIRName(), GlobalValue::ExternalLinkage, ""));
666666 ThinLTO.PrevailingModuleForGUID[GUID] = BM.getModuleIdentifier();
667
668 // For linker redefined symbols (via --wrap or --defsym) we want to
669 // switch the linkage to `weak` to prevent IPOs from happening.
670 // Find the summary in the module for this very GV and record the new
671 // linkage so that we can switch it when we import the GV.
672 if (Res.LinkerRedefined)
673 if (auto S = ThinLTO.CombinedIndex.findSummaryInModule(
674 GUID, BM.getModuleIdentifier()))
675 S->setLinkage(GlobalValue::WeakAnyLinkage);
667676 }
668677 }
669678 }
536536 };
537537
538538 auto updateLinkage = [&](GlobalValue &GV) {
539 if (!GlobalValue::isWeakForLinker(GV.getLinkage()))
540 return;
541539 // See if the global summary analysis computed a new resolved linkage.
542540 const auto &GS = DefinedGlobals.find(GV.getGUID());
543541 if (GS == DefinedGlobals.end())
544542 return;
545543 auto NewLinkage = GS->second->linkage();
546544 if (NewLinkage == GV.getLinkage())
545 return;
546
547 // Switch the linkage to weakany if asked for, e.g. we do this for
548 // linker redefined symbols (via --wrap or --defsym).
549 if (NewLinkage == GlobalValue::WeakAnyLinkage) {
550 GV.setLinkage(NewLinkage);
551 return;
552 }
553
554 if (!GlobalValue::isWeakForLinker(GV.getLinkage()))
547555 return;
548556 // Check for a non-prevailing def that has interposable linkage
549557 // (e.g. non-odr weak or linkonce). In that case we can't simply
0 ; RUN: opt -module-summary %s -o %t.o
1 ; RUN: llvm-lto2 run -o %t1.o %t.o -r %t.o,patatino,pr
2 ; RUN: llvm-readobj -t %t1.o.0 | FileCheck %s
3
4 ; CHECK: Name: patatino
5 ; CHECK-NEXT: Value:
6 ; CHECK-NEXT: Size:
7 ; CHECK-NEXT: Binding: Weak
8 ; CHECK-NEXT: Type: Function
9
10 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
11 target triple = "x86_64-unknown-linux-gnu"
12
13 define void @patatino() {
14 ret void
15 }