Comment #0 by nicolas.jinchereau — 2015-11-16T04:39:28Z
DMD emits all functions as COMDAT on OSX, even non-template functions.
The offending code in DMD:
https://github.com/D-Programming-Language/dmd/blob/a907543f21590b2ae56eb6c41d61e24cb25a1dc2/src/glue.c#L866-L870
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:
a.o
b.o
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 '_D4core7runtime19defaultTraceHandlerFPvZ16DefaultTraceInfo7fixlineMxFAxaNkKG4096aZAxa' from built/lib/libphobos2.a(runtime_1f3_792.o) for architecture x86_64
Comment #1 by nicolas.jinchereau — 2015-11-16T04:40:44Z
*** Issue 11199 has been marked as a duplicate of this issue. ***
Comment #2 by robert.schadek — 2024-12-13T18:45:49Z