www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15342] New: DMD outputs all functions as COMDAT on OSX


          Issue ID: 15342
           Summary: DMD outputs all functions as COMDAT on OSX
           Product: D
           Version: D2
          Hardware: All
                OS: Mac OS X
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: nicolas.jinchereau gmail.com

DMD emits all functions as COMDAT on OSX, even non-template functions.

The offending code in DMD:

To verify the problem:

<a.d> and <b.d> with same code
import std.stdio;
extern(C) void a() { printf("foo"); }

<a.cpp> and <b.cpp> with same code
#include <stdio.h>
extern "C" void a() { printf("foo"); }

Compiling with DMD, this works (it shouldn't)
dmd a.d -c -ofa.o
dmd b.d -c -ofb.o
dmd a.o b.o -shared

Compiling with GCC, this fails (as it should)
gcc a.cpp -c -oa.o
gcc b.cpp -c -ob.o
gcc a.o b.o -shared

duplicate symbol _a in:
ld: 1 duplicate symbol for architecture x86_64


I've tried removed the special case in glue.c(cited above), but when I try to
link an executable, I get this error:

ld: GOT load reloc does not point to a movq instruction in
from built/lib/libphobos2.a(runtime_1f3_792.o) for architecture x86_64

Nov 15 2015