Skip to content

Commit

Permalink
fix Issue 17352 - Internal error: ddmd/backend/elfobj.c 1739 on dupli…
Browse files Browse the repository at this point in the history
…cate definition
  • Loading branch information
MartinNowak committed Jun 30, 2017
1 parent 934a423 commit 76affab
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/ddmd/backend/elfobj.c
Expand Up @@ -1736,12 +1736,16 @@ 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;
/* If that text section already existed, we've hit one of the few occurences of different
* symbols with identical mangling. This should not happen, but as a workaround we leave the
* just created section group empty and reuse the existing one. Also see
* https://issues.dlang.org/show_bug.cgi?id=17352,
* https://issues.dlang.org/show_bug.cgi?id=14831, and
* https://issues.dlang.org/show_bug.cgi?id=17339.
*/
const bool collidingSection = MAP_SEG2SECIDX(s->Sseg) < groupsecidx;
// add to section group
if (!issue17339)
if (!collidingSection)
SegData[groupseg]->SDbuf->write32(MAP_SEG2SECIDX(s->Sseg));

// Create a weak symbol for the comdat
Expand All @@ -1757,7 +1761,7 @@ STATIC void setup_comdat(Symbol *s)

if (s->Salignment > align)
SegData[s->Sseg]->SDalignment = s->Salignment;
if (issue17339)
if (collidingSection)
{
// existing section symbol and associated group
assert(SegData[s->Sseg]->SDsym);
Expand Down
18 changes: 18 additions & 0 deletions test/compilable/test17352.d
@@ -0,0 +1,18 @@
// https://issues.dlang.org/show_bug.cgi?id=17352
void bug(Args...)()
{
}

void test(bool coin)
{
if (coin)
{
string foobar;
bug!foobar();
}
else
{
string foobar;
bug!foobar();
}
}

0 comments on commit 76affab

Please sign in to comment.