www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - D runtime in os x dylib

reply "John Colvin" <john.loughran.colvin gmail.com> writes:
There seems to be a problem with starting the d runtime in a d 
dylib loaded in a c program. Whenever I call Runtime.initialize() 
i get a segfault.

C code:

     #include <stdio.h>
     #include <dlfcn.h>

     int main() {
         void *library;
         int (*fptr)();
         library = dlopen("testlib.dylib", RTLD_LAZY);
         if(library == NULL)
             puts("couldn't load the library");
         else {
             *(void **)(&fptr) = dlsym(library,"number");
             if(fptr == NULL) {
    	        puts("couldn't load function");
             }
             else {
                 printf("the result is %d\n",(*fptr)());
             }
         }
         return(0);
     }

compiled with gcc, no flags.

d code:

     import core.runtime;

     extern(C) int number() {
     	Runtime.initialize();
     	return(4);
     }

compiled with dmd -shared

Backtrace:

     Program received signal EXC_BAD_ACCESS, Could not access 
memory.
     Reason: 13 at address: 0x0000000000000000
     0x000000010003de28 in __tls_get_addr ()
     (gdb) bt
     #0  0x000000010003de28 in __tls_get_addr ()
     #1  0x000000010003cdfc in thread_attachThis ()
     #2  0x000000010003ccb8 in thread_init ()
     #3  0x000000010003e312 in gc_init ()
     #4  0x0000000100044ff5 in rt_init ()
     #5  0x000000010003b637 in 
D4core7runtime7Runtime10initializeFDFC6object9ThrowableZvZb ()
     #6  0x0000000100034ee9 in number ()
     #7  0x0000000100000e84 in main ()

All compilation and debugging done in OS X 10.7

Note: if the Runtime.initialize(); line is commented out, the 
library is loaded and runs correctly.
Jun 23 2012
next sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2012-06-23 22:54, John Colvin wrote:
 There seems to be a problem with starting the d runtime in a d dylib
 loaded in a c program. Whenever I call Runtime.initialize() i get a
 segfault.

Dynamic libraries aren't properly working yet. It's being worked on. -- /Jacob Carlborg
Jun 24 2012
parent reply Jacob Carlborg <doob me.com> writes:
On 2012-06-24 13:47, John Colvin wrote:

 I see that now, managed to dig up some old bug reports and threads. Is
 there any timeframe for this or is it on the back burner so to speak?

I'm not sure of the time frame for this but Martin Nowak is working on this: https://github.com/dawgfoto/druntime/commits/SharedRuntime -- /Jacob Carlborg
Jun 24 2012
parent reply Jacob Carlborg <doob me.com> writes:
On 2012-06-24 16:39, John Colvin wrote:
 Hmm, nothing in the last 3 months. Looks like i may have to abandon os x
 for development at least for the near future.

I'm not entirely sure but maybe you're having this problem: http://d.puremagic.com/issues/show_bug.cgi?id=7995 Pull the latest source code from github and try that if you're using a release. -- /Jacob Carlborg
Jun 25 2012
parent reply Jacob Carlborg <doob me.com> writes:
On 2012-06-25 18:26, John Colvin wrote:
 On Monday, 25 June 2012 at 12:17:03 UTC, Jacob Carlborg wrote:
 On 2012-06-24 16:39, John Colvin wrote:
 Hmm, nothing in the last 3 months. Looks like i may have to abandon os x
 for development at least for the near future.

I'm not entirely sure but maybe you're having this problem: http://d.puremagic.com/issues/show_bug.cgi?id=7995 Pull the latest source code from github and try that if you're using a release.

I'm having a nightmare getting the runtime to compile, with MODEL=64 I get a load of these: src/core/simd.d(35): Error: base type of __vector must be a 16 byte static array, not void[32LU] src/core/simd.d(52): Error: template instance core.simd.Vector!(void[32LU]) error instantiating src/core/simd.d(35): Error: base type of __vector must be a 16 byte static array, not double[4LU] src/core/simd.d(53): Error: template instance core.simd.Vector!(double[4LU]) error instantiating src/core/simd.d(35): Error: base type of __vector must be a 16 byte static array, not float[8LU] src/core/simd.d(54): Error: template instance core.simd.Vector!(float[8LU]) error instantiating src/core/simd.d(35): Error: base type of __vector must be a 16 byte static array, not byte[32LU] src/core/simd.d(55): Error: template instance core.simd.Vector!(byte[32LU]) error instantiating src/core/simd.d(35): Error: base type of __vector must be a 16 byte static array, not ubyte[32LU] src/core/simd.d(56): Error: template instance core.simd.Vector!(ubyte[32LU]) error instantiating src/core/simd.d(35): Error: base type of __vector must be a 16 byte static array, not short[16LU] src/core/simd.d(57): Error: template instance core.simd.Vector!(short[16LU]) error instantiating src/core/simd.d(35): Error: base type of __vector must be a 16 byte static array, not ushort[16LU] src/core/simd.d(58): Error: template instance core.simd.Vector!(ushort[16LU]) error instantiating src/core/simd.d(35): Error: base type of __vector must be a 16 byte static array, not int[8LU] src/core/simd.d(59): Error: template instance core.simd.Vector!(int[8LU]) error instantiating src/core/simd.d(35): Error: base type of __vector must be a 16 byte static array, not uint[8LU] src/core/simd.d(60): Error: template instance core.simd.Vector!(uint[8LU]) error instantiating src/core/simd.d(35): Error: base type of __vector must be a 16 byte static array, not long[4LU] src/core/simd.d(61): Error: template instance core.simd.Vector!(long[4LU]) error instantiating src/core/simd.d(35): Error: base type of __vector must be a 16 byte static array, not ulong[4LU] src/core/simd.d(62): Error: template instance core.simd.Vector!(ulong[4LU]) error instantiating I tried MODEL=32 just in case and got the same but with "u" insteal of "LU"

Are you using the latest sources of DMD? -- /Jacob Carlborg
Jun 25 2012
parent Jacob Carlborg <doob me.com> writes:
On 2012-06-27 02:35, John Colvin wrote:
 On Tuesday, 26 June 2012 at 18:31:34 UTC, John Colvin wrote:
 On Monday, 25 June 2012 at 18:55:22 UTC, Jacob Carlborg wrote:

 Are you using the latest sources of DMD?

Yes I am.

sorry, my mistake, i replaced the wrong dmd file. It compiles fine with the up to date dmd.

Good, is that working any better ? -- /Jacob Carlborg
Jun 27 2012
prev sibling next sibling parent "John Colvin" <john.loughran.colvin gmail.com> writes:
On Sunday, 24 June 2012 at 09:59:18 UTC, Jacob Carlborg wrote:
 On 2012-06-23 22:54, John Colvin wrote:
 There seems to be a problem with starting the d runtime in a d 
 dylib
 loaded in a c program. Whenever I call Runtime.initialize() i 
 get a
 segfault.

Dynamic libraries aren't properly working yet. It's being worked on.

I see that now, managed to dig up some old bug reports and threads. Is there any timeframe for this or is it on the back burner so to speak?
Jun 24 2012
prev sibling next sibling parent "John Colvin" <john.loughran.colvin gmail.com> writes:
Hmm, nothing in the last 3 months. Looks like i may have to 
abandon os x for development at least for the near future.

On Sunday, 24 June 2012 at 12:41:15 UTC, Jacob Carlborg wrote:
 On 2012-06-24 13:47, John Colvin wrote:

 I see that now, managed to dig up some old bug reports and 
 threads. Is
 there any timeframe for this or is it on the back burner so to 
 speak?

I'm not sure of the time frame for this but Martin Nowak is working on this: https://github.com/dawgfoto/druntime/commits/SharedRuntime

Jun 24 2012
prev sibling next sibling parent "John Colvin" <john.loughran.colvin gmail.com> writes:
On Monday, 25 June 2012 at 12:17:03 UTC, Jacob Carlborg wrote:
 On 2012-06-24 16:39, John Colvin wrote:
 Hmm, nothing in the last 3 months. Looks like i may have to 
 abandon os x
 for development at least for the near future.

I'm not entirely sure but maybe you're having this problem: http://d.puremagic.com/issues/show_bug.cgi?id=7995 Pull the latest source code from github and try that if you're using a release.

I'm having a nightmare getting the runtime to compile, with MODEL=64 I get a load of these: src/core/simd.d(35): Error: base type of __vector must be a 16 byte static array, not void[32LU] src/core/simd.d(52): Error: template instance core.simd.Vector!(void[32LU]) error instantiating src/core/simd.d(35): Error: base type of __vector must be a 16 byte static array, not double[4LU] src/core/simd.d(53): Error: template instance core.simd.Vector!(double[4LU]) error instantiating src/core/simd.d(35): Error: base type of __vector must be a 16 byte static array, not float[8LU] src/core/simd.d(54): Error: template instance core.simd.Vector!(float[8LU]) error instantiating src/core/simd.d(35): Error: base type of __vector must be a 16 byte static array, not byte[32LU] src/core/simd.d(55): Error: template instance core.simd.Vector!(byte[32LU]) error instantiating src/core/simd.d(35): Error: base type of __vector must be a 16 byte static array, not ubyte[32LU] src/core/simd.d(56): Error: template instance core.simd.Vector!(ubyte[32LU]) error instantiating src/core/simd.d(35): Error: base type of __vector must be a 16 byte static array, not short[16LU] src/core/simd.d(57): Error: template instance core.simd.Vector!(short[16LU]) error instantiating src/core/simd.d(35): Error: base type of __vector must be a 16 byte static array, not ushort[16LU] src/core/simd.d(58): Error: template instance core.simd.Vector!(ushort[16LU]) error instantiating src/core/simd.d(35): Error: base type of __vector must be a 16 byte static array, not int[8LU] src/core/simd.d(59): Error: template instance core.simd.Vector!(int[8LU]) error instantiating src/core/simd.d(35): Error: base type of __vector must be a 16 byte static array, not uint[8LU] src/core/simd.d(60): Error: template instance core.simd.Vector!(uint[8LU]) error instantiating src/core/simd.d(35): Error: base type of __vector must be a 16 byte static array, not long[4LU] src/core/simd.d(61): Error: template instance core.simd.Vector!(long[4LU]) error instantiating src/core/simd.d(35): Error: base type of __vector must be a 16 byte static array, not ulong[4LU] src/core/simd.d(62): Error: template instance core.simd.Vector!(ulong[4LU]) error instantiating I tried MODEL=32 just in case and got the same but with "u" insteal of "LU"
Jun 25 2012
prev sibling next sibling parent "Martin Nowak" <dawg dawgfoto.de> writes:
On Mon, 25 Jun 2012 14:17:01 +0200, Jacob Carlborg <doob me.com> wrote:

 On 2012-06-24 16:39, John Colvin wrote:
 Hmm, nothing in the last 3 months. Looks like i may have to abandon os x
 for development at least for the near future.

I'm not entirely sure but maybe you're having this problem: http://d.puremagic.com/issues/show_bug.cgi?id=7995 Pull the latest source code from github and try that if you're using a release.

Right, it looks like that bug. Statically linking phobos into a dylib should work otherwise.
Jun 25 2012
prev sibling next sibling parent "John Colvin" <john.loughran.colvin gmail.com> writes:
On Monday, 25 June 2012 at 18:55:22 UTC, Jacob Carlborg wrote:

 Are you using the latest sources of DMD?

Yes I am.
Jun 26 2012
prev sibling next sibling parent "John Colvin" <john.loughran.colvin gmail.com> writes:
On Tuesday, 26 June 2012 at 18:31:34 UTC, John Colvin wrote:
 On Monday, 25 June 2012 at 18:55:22 UTC, Jacob Carlborg wrote:

 Are you using the latest sources of DMD?

Yes I am.

sorry, my mistake, i replaced the wrong dmd file. It compiles fine with the up to date dmd.
Jun 26 2012
prev sibling parent "John Colvin" <john.loughran.colvin gmail.com> writes:
On Wednesday, 27 June 2012 at 10:15:37 UTC, Jacob Carlborg wrote:
 On 2012-06-27 02:35, John Colvin wrote:
 On Tuesday, 26 June 2012 at 18:31:34 UTC, John Colvin wrote:
 On Monday, 25 June 2012 at 18:55:22 UTC, Jacob Carlborg wrote:

 Are you using the latest sources of DMD?

Yes I am.

sorry, my mistake, i replaced the wrong dmd file. It compiles fine with the up to date dmd.

Good, is that working any better ?

Yes, it appears the bug is fixed in the current druntime. Thanks for your help.
Jun 28 2012