Skip to content

Commit 43f59b1

Browse files
committed
ELF: Emit (most) instantiated symbols in COMDATs
To fix issue #3589.
1 parent 208546b commit 43f59b1

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#### Bug fixes
1212
- Fix potentially corrupt IR layouts for bit fields. (#4646, #4708)
1313
- Fix potentially corrupt IR layouts for explicitly under-aligned aggregates, a regression introduced in LDC v1.31. (#4734, #4736)
14+
- ELF: Emit (most) instantiated symbols in COMDATs for proper link-time culling. (#3589, #4748)
1415

1516
# LDC 1.39.0 (2024-07-04)
1617

gen/tollvm.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,13 @@ LLGlobalValue::LinkageTypes DtoLinkageOnly(Dsymbol *sym) {
259259
}
260260

261261
LinkageWithCOMDAT DtoLinkage(Dsymbol *sym) {
262-
return {DtoLinkageOnly(sym), needsCOMDAT()};
262+
const auto linkage = DtoLinkageOnly(sym);
263+
const bool inCOMDAT = needsCOMDAT() ||
264+
// ELF needs some help for ODR linkages:
265+
// https://github.com/ldc-developers/ldc/issues/3589
266+
(linkage == templateLinkage &&
267+
global.params.targetTriple->isOSBinFormatELF());
268+
return {linkage, inCOMDAT};
263269
}
264270

265271
bool needsCOMDAT() {

0 commit comments

Comments
 (0)