On Monday, 16 November 2015 at 08:15:39 UTC, Walter Bright wrote:
On 11/15/2015 8:44 PM, bitwise wrote:
https://issues.dlang.org/show_bug.cgi?id=15342

DMD emits all functions as COMDAT on OSX.

I'm guessing this was originally a workaround of some kind...does anybody know
the story?

Thanks,
     Bit

It enables:

1. the linker to remove duplicates (happens with templates and other things)
2. the linker to remove unreferenced COMDATs

I understand what it's for, but it's incorrect behaviour to have _all_ functions being emitted as comdat. Non-template functions shouldn't be coalesced in this way. If you compile the code example in the bug report with *any* compiler other than DMD/OSX, the example will fail as described, with a linker error. The example compares dmd/osx with gcc/osx, but the code will also fail with ldc/osx. And although I don't have time to check, I'm pretty sure it will fail with dmd/win as well.

If you look at the code I cited, this is obviously a hack:

<glue.c#L866-L870>
[...]
#if TARGET_OSX
    s->Sclass = SCcomdat;
#else
    s->Sclass = SCglobal;
#endif
    for (Dsymbol *p = fd->parent; p; p = p->parent) {
        if (p->isTemplateInstance()) {
            s->Sclass = SCcomdat;
            break;
        }
    }
[...]

    Bit

Reply via email to