[llvm] r264223 - Fix lazy linking of comdat members.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 23 17:06:03 PDT 2016
Author: rafael
Date: Wed Mar 23 19:06:03 2016
New Revision: 264223
URL: http://llvm.org/viewvc/llvm-project?rev=264223&view=rev
Log:
Fix lazy linking of comdat members.
If not for lazy linking of linkonce GVs, comdats are just a
preprocessing before symbol resolution.
Lazy linking complicates it since when we pick a visible member of
comdat, we have to make sure the rest of it passes symbol resolution
too.
Modified:
llvm/trunk/lib/Linker/LinkModules.cpp
llvm/trunk/test/Linker/comdat9.ll
Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=264223&r1=264222&r2=264223&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Wed Mar 23 19:06:03 2016
@@ -76,8 +76,8 @@ class ModuleLinker {
ComdatsChosen;
bool getComdatResult(const Comdat *SrcC, Comdat::SelectionKind &SK,
bool &LinkFromSrc);
- // Keep track of the global value members of each comdat in source.
- DenseMap<const Comdat *, std::vector<GlobalValue *>> ComdatMembers;
+ // Keep track of the lazy linked global members of each comdat in source.
+ DenseMap<const Comdat *, std::vector<GlobalValue *>> LazyComdatMembers;
/// Given a global in the source module, return the global in the
/// destination module that is being linked to, if any.
@@ -446,8 +446,8 @@ void ModuleLinker::addLazyFor(GlobalValu
const Comdat *SC = GV.getComdat();
if (!SC)
return;
- for (GlobalValue *GV2 : ComdatMembers[SC]) {
- if (!GV2->hasLocalLinkage() && shouldInternalizeLinkedSymbols())
+ for (GlobalValue *GV2 : LazyComdatMembers[SC]) {
+ if (shouldInternalizeLinkedSymbols())
Internalize.insert(GV2->getName());
Add(*GV2);
}
@@ -533,16 +533,19 @@ bool ModuleLinker::run() {
}
for (GlobalVariable &GV : SrcM->globals())
- if (const Comdat *SC = GV.getComdat())
- ComdatMembers[SC].push_back(&GV);
+ if (GV.hasLinkOnceLinkage())
+ if (const Comdat *SC = GV.getComdat())
+ LazyComdatMembers[SC].push_back(&GV);
for (Function &SF : *SrcM)
- if (const Comdat *SC = SF.getComdat())
- ComdatMembers[SC].push_back(&SF);
+ if (SF.hasLinkOnceLinkage())
+ if (const Comdat *SC = SF.getComdat())
+ LazyComdatMembers[SC].push_back(&SF);
for (GlobalAlias &GA : SrcM->aliases())
- if (const Comdat *SC = GA.getComdat())
- ComdatMembers[SC].push_back(&GA);
+ if (GA.hasLinkOnceLinkage())
+ if (const Comdat *SC = GA.getComdat())
+ LazyComdatMembers[SC].push_back(&GA);
// Insert all of the globals in src into the DstM module... without linking
// initializers (which could refer to functions not yet mapped over).
@@ -563,9 +566,8 @@ bool ModuleLinker::run() {
const Comdat *SC = GV->getComdat();
if (!SC)
continue;
- for (GlobalValue *GV2 : ComdatMembers[SC])
- if (GV2->hasInternalLinkage())
- ValuesToLink.insert(GV2);
+ for (GlobalValue *GV2 : LazyComdatMembers[SC])
+ ValuesToLink.insert(GV2);
}
if (shouldInternalizeLinkedSymbols()) {
Modified: llvm/trunk/test/Linker/comdat9.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/comdat9.ll?rev=264223&r1=264222&r2=264223&view=diff
==============================================================================
--- llvm/trunk/test/Linker/comdat9.ll (original)
+++ llvm/trunk/test/Linker/comdat9.ll Wed Mar 23 19:06:03 2016
@@ -11,7 +11,7 @@ define internal void @f() comdat($c) {
; CHECK-DAG: define internal void @f() comdat($c)
$f2 = comdat largest
-define internal void @f2() comdat($f2) {
+define linkonce_odr void @f2() comdat($f2) {
ret void
}
define void @f3() comdat($f2) {
@@ -19,4 +19,4 @@ define void @f3() comdat($f2) {
}
; CHECK-DAG: $f2 = comdat largest
-; CHECK-DAG: define internal void @f2() comdat {
+; CHECK-DAG: define linkonce_odr void @f2()
More information about the llvm-commits
mailing list