Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/ddmd/backend/elfobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -1736,8 +1736,13 @@ STATIC void setup_comdat(Symbol *s)
const char *p = cpp_mangle(s);
// Create a section for the comdat symbol with the SHF_GROUP bit set
s->Sseg = ElfObj::getsegment(".text.", p, SHT_PROGBITS, SHF_ALLOC|SHF_EXECINSTR|SHF_GROUP, align);
/* Workaround https://issues.dlang.org/show_bug.cgi?id=17339, there was
* a previous instance with the same mangling. Leave the section group
* empty and reuse the existing one. */
const bool issue17339 = MAP_SEG2SECIDX(s->Sseg) < groupsecidx;
// add to section group
SegData[groupseg]->SDbuf->write32(MAP_SEG2SECIDX(s->Sseg));
if (!issue17339)
SegData[groupseg]->SDbuf->write32(MAP_SEG2SECIDX(s->Sseg));

// Create a weak symbol for the comdat
IDXSTR namidx = Obj::addstr(symtab_strings, p);
Expand All @@ -1752,8 +1757,17 @@ STATIC void setup_comdat(Symbol *s)

if (s->Salignment > align)
SegData[s->Sseg]->SDalignment = s->Salignment;
SegData[s->Sseg]->SDsym = s;
SegData[s->Sseg]->SDassocseg = groupseg;
if (issue17339)
{
// existing section symbol and associated group
assert(SegData[s->Sseg]->SDsym);
assert(SegData[s->Sseg]->SDassocseg);
}
else
{
SegData[s->Sseg]->SDsym = s;
SegData[s->Sseg]->SDassocseg = groupseg;
}
return;
#endif
}
Expand Down
25 changes: 25 additions & 0 deletions test/runnable/test17338.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// PERMUTE_ARGS:
// Generate \sum_{i=0}^{14} 2^i = 32767 template instantiations
// (each with 3 sections) to use more than 64Ki sections in total.
version (Win32)
{
// Apparently omf or optlink does not support more than 32767 symbols.
void main()
{
}
}
else
{
size_t foo(size_t i, size_t mask)()
{
static if (i == 14)
return mask;
else
return foo!(i + 1, mask) + foo!(i + 1, mask | (1UL << i));
}

void main()
{
assert(foo!(0, 0) != 0);
}
}