-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Linker] Do not keep a private member of a non-prevailing comdat group #69143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -462,6 +462,7 @@ void ModuleLinker::dropReplacedComdat( | |
bool ModuleLinker::run() { | ||
Module &DstM = Mover.getModule(); | ||
DenseSet<const Comdat *> ReplacedDstComdats; | ||
DenseSet<const Comdat *> NonPrevailingComdats; | ||
|
||
for (const auto &SMEC : SrcM->getComdatSymbolTable()) { | ||
const Comdat &C = SMEC.getValue(); | ||
|
@@ -473,6 +474,9 @@ bool ModuleLinker::run() { | |
return true; | ||
ComdatsChosen[&C] = std::make_pair(SK, From); | ||
|
||
if (From == LinkFrom::Dst) | ||
NonPrevailingComdats.insert(&C); | ||
|
||
if (From != LinkFrom::Src) | ||
continue; | ||
|
||
|
@@ -497,6 +501,23 @@ bool ModuleLinker::run() { | |
for (Function &GV : llvm::make_early_inc_range(DstM)) | ||
dropReplacedComdat(GV, ReplacedDstComdats); | ||
|
||
if (!NonPrevailingComdats.empty()) { | ||
DenseSet<GlobalObject *> AliasedGlobals; | ||
for (auto &GA : SrcM->aliases()) | ||
if (GlobalObject *GO = GA.getAliaseeObject(); GO && GO->getComdat()) | ||
AliasedGlobals.insert(GO); | ||
for (const Comdat *C : NonPrevailingComdats) { | ||
SmallVector<GlobalObject *> ToUpdate; | ||
for (GlobalObject *GO : C->getUsers()) | ||
if (GO->hasPrivateLinkage() && !AliasedGlobals.contains(GO)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's more correct to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change would break the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the test and the history, it is still valid. I think the bug here is that these comdats referring to COFF internal linkage entities are considered There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should go ahead and land this as is. I'll file an issue about the logic bug I think I see. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is covered by |
||
ToUpdate.push_back(GO); | ||
for (GlobalObject *GO : ToUpdate) { | ||
GO->setLinkage(GlobalValue::AvailableExternallyLinkage); | ||
GO->setComdat(nullptr); | ||
} | ||
} | ||
} | ||
|
||
for (GlobalVariable &GV : SrcM->globals()) | ||
if (GV.hasLinkOnceLinkage()) | ||
if (const Comdat *SC = GV.getComdat()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for COFF (not for ELF) in the comdat-refer-to-discarded.ll test case we should get a result of
LinkFrom::Both
here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I remember it right,
LinkFrom::Both
corresponds tocomdat nodeduplicate
, whilecomdat-refer-to-discarded.ll
usescomdat any
. Do you think the interpretation of a comdat selection type should depend on the target platform (COFF vs ELF)?