Skip to content

Commit

Permalink
Merge pull request #6718 from MartinNowak/fix17338
Browse files Browse the repository at this point in the history
fixup for - #6717 [Reg 2.075] link failure unsupported symbol section
  • Loading branch information
WalterBright committed Apr 22, 2017
2 parents e84e711 + b21f445 commit 39c3abb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/ddmd/backend/elfobj.c
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
@@ -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);
}
}

0 comments on commit 39c3abb

Please sign in to comment.