www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - Segmenation fault in rt_finalize2 when using std.stdio with shared

reply "Harm" <a example.com> writes:
I'm trying to create a shared D library. I use the code from 
http://dlang.org/dll-linux.html#dso10 (the last 2 files, main.d 
and dll.d). I can successfully compile and run them with:

ldc2 -oflibdll.so dll.d -shared -defaultlib=phobos2-ldc
ldc2 main.d -L-ldl -defaultlib=phobos2-ldc,druntime-ldc -L-rpath=.

As soon as I add import std.stdio to dll.d, the program gives me 
a segfault after it prints libdll.so shared static ~this. gdb 
tells me the crash is in rt_finalize2(). The wiki page warns 
about the multiple instances of the D runtime will conflict with 
each other. Since I could delete my druntime from the lib 
directory and still compile my .so file without errors the .so 
file probably does not contain a version of the d runtime.

I've build ldc from the master branch in github using 
-DBUILD_SHARED_LIBS=on using Xubuntu 14.04. Am I missing some 
flags or is the shared library support not complete yet?
Oct 18 2014
parent reply "David Nadlinger" <code klickverbot.at> writes:
On Saturday, 18 October 2014 at 19:24:23 UTC, Harm wrote:
 I've build ldc from the master branch in github using 
 -DBUILD_SHARED_LIBS=on using Xubuntu 14.04. Am I missing some 
 flags or is the shared library support not complete yet?
This use case should actually be covered by the druntime shared library tests: https://github.com/ldc-developers/druntime/tree/e383a9bbdcd05cc6c315554df25658d6487c7176/test/shared/src Thus this aspect of runtime loading should generally work on Linux x86_64, unless of course there is some kind of build system regression causing the tests not to be run on Travis CI. Maybe you could try experimenting with the druntime tests to see what might cause the issue? Use "ctest -R druntime-test-shared --verbose" to get the initial build command. David
Oct 18 2014
parent "Harm" <a example.com> writes:
On Saturday, 18 October 2014 at 22:36:07 UTC, David Nadlinger 
wrote:
 On Saturday, 18 October 2014 at 19:24:23 UTC, Harm wrote:
 I've build ldc from the master branch in github using 
 -DBUILD_SHARED_LIBS=on using Xubuntu 14.04. Am I missing some 
 flags or is the shared library support not complete yet?
This use case should actually be covered by the druntime shared library tests: https://github.com/ldc-developers/druntime/tree/e383a9bbdcd05cc6c315554df25658d6487c7176/test/shared/src Thus this aspect of runtime loading should generally work on Linux x86_64, unless of course there is some kind of build system regression causing the tests not to be run on Travis CI. Maybe you could try experimenting with the druntime tests to see what might cause the issue? Use "ctest -R druntime-test-shared --verbose" to get the initial build command. David
The tests run fine without problems. Somehow when I want to use libphobos2-ldc things start to crash. Just adding a -L/path/to/libphobos2-ldc.so to DFLAGS in the test makefile doesn't affect the test result. Using std.stdio does though (getting the segmentation fault again). I've been trying (kind of recklessly) trying several mutations to the wiki code and the tests without success.
Oct 19 2014