Bug 7995 – regression(2.059): D runtime initialization from C fails on OSX in 2.059, worked in 2.058
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
Mac OS X
Creation time
2012-04-26T19:25:00Z
Last change time
2012-06-03T10:23:07Z
Assigned to
nobody
Creator
thelastmammoth
Comments
Comment #0 by thelastmammoth — 2012-04-26T19:25:16Z
[note: this was also mentioned in http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=35199 but I didn't see a bug report; I'm also adding that the code worked fine in 2.058 ]
calling D runtime initialization from C fails on OSX in 2.059, but it worked in 2.058. This is a critical bug as it makes it now impossible to call D from C on OSX.
//main.c
extern void mylib_init();
extern void mylib_free();
int main() {
mylib_init(); //crashes here
mylib_free();
return 0;
}
//mylib.d
module mylib;
import core.runtime;
extern(C) {
bool mylib_init() { return Runtime.initialize();}
bool mylib_free() { return Runtime.terminate();}
}
//Makefile
all:
dmd -c -lib mylib.d -oflibmylib.a
gcc -o main main.c -L. -lmylib -L/usr/share/dmd/lib -lphobos2
//output: (through gdb):
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 13 at address: 0x0000000000000000
0x0000000100009dac in __tls_get_addr ()
(gdb) where
#0 0x0000000100009dac in __tls_get_addr ()
#1 0x0000000100008d80 in thread_attachThis ()
#2 0x0000000100008c3c in thread_init ()
#3 0x000000010000a296 in gc_init ()
#4 0x0000000100010f79 in rt_init ()
#5 0x00000001000075bb in D4core7runtime7Runtime10initializeFDFC6object9ThrowableZvZb ()
#6 0x0000000100000e5d in mylib_init ()
#7 0x0000000100000e2f in main ()
Comment #1 by doob — 2012-05-04T14:33:46Z
I would guess the reason for this is "_d_osx_image_init2" is not called in "rt_init". "main" should really call "rt_init" do avoid code duplication.
Comment #5 by thelastmammoth — 2012-05-23T13:58:33Z
(In reply to comment #4)
> (In reply to comment #3)
> > Commits pushed to master at https://github.com/D-Programming-Language/druntime
> >
> > https://github.com/D-Programming-Language/druntime/commit/714e86fb88459807f35fe7270da592ee06e40e31
> > Fix issue 7995: D runtime initialization from C fails on OSX in 2.059, worked
> > in 2.058.
> >
> > I also refactored the startup code to remove duplicated code.
> > This will hopefully reduce this kind of bugs in the future.
> >
> > https://github.com/D-Programming-Language/druntime/commit/6467f87e1a6b4696b9929c459b38477df1cf0522
> > Merge pull request #205 from jacob-carlborg/7995
> >
> > Fix issue 7995: D runtime initialization from C fails on OSX in 2.059, w...
>
>
> Great, thanks, that appears to solve THAT bug, however I filed a new regression
> bug for a related problem (with dylib instead of lib): see Issue 8133.
Actually the pull request seems to fix Issue 8133 (but master had reverted it in the meantime). It would be nice to have this pull request back in master ...