All functions COMDAT on OSX

Marc Schütz via Digitalmars-d digitalmars-d at puremagic.com
Mon Nov 16 09:09:03 PST 2015


On Monday, 16 November 2015 at 14:37:33 UTC, bitwise wrote:
> 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;
>         }
>     }
> [...]

FWIW, that's been in the source since somewhen between 2.025 and 
2.026:
https://github.com/D-Programming-Language/dmd/commit/00337ef8d8c4c1c08da68f95963e2fe1658a49ec

Unfortunately there are no intermediate commits in the repo, 
because only released versions have been imported during the 
switch to Git.


More information about the Digitalmars-d mailing list