Contents
Creating a shared runtime
Note: This is highly experimental and only intended for compiler development! Do not use the shared runtime for production code!
Compile GDC as usual
see Installation
Compile
The following commands must be executed in objdir. Replace i686-pc-linux-gnu with your system's equivalent.
cd i686-pc-linux-gnu/libphobos make clean cd libdruntime PIC_FLAGS="-fPIC" make libgdruntime.so cd ../ PIC_FLAGS="-fPIC" make libgphobos2.so
Note: the shared libraries are libgdruntime.so.0 in the libdruntime folder and libgphobos2.so.0 in the libphobos folder. Those are not installed by default! Copy them manually to a desired location.
Compiling an application
There are a few annoyances when compiling an app against these shared libs:
libdruntime & libphobos are no longer combined. You must link manually against libgdruntime (-lgdruntime) (should be fixed in gdc)
Make sure the compiler finds your shared libraries: -L.. Also make sure you have the libgphobos2.so and libgdruntime.so symlinks.
The main function is not contained in the shared libraries. You must link it in manually when linking your app: libdruntime/rt/dmain2.o (should be fixed in gdc)
hello.d:
import std.stdio;
void main()
{
writeln("Hello World!");
}compiling:
gdc hello.d libdruntime/rt/dmain2.o -o hello -L. -lgdruntime
Running
You probably have to set LD_LIBRARY_PATH:
./hello ./hello: error while loading shared libraries: libgdruntime.so.0: cannot open shared object file: No such file or directory LD_LIBRARY_PATH=. ./hello Hello World!
Verifying
To check if the shared runtime is being used:
LD_LIBRARY_PATH=. ldd hello
linux-gate.so.1 => (0xb778e000)
/usr/lib/libXft-infinality/libXft.so.2 (0x4e6b2000)
/usr/lib/freetype-infinality/libfreetype.so.6 (0x4ec2f000)
libgdruntime.so.0 => ./libgdruntime.so.0 (0xb76f4000)
libgphobos2.so.0 => ./libgphobos2.so.0 (0xb7505000)
libm.so.6 => /lib/libm.so.6 (0x4e66d000)
libpthread.so.0 => /lib/libpthread.so.0 (0x4e63f000)
librt.so.1 => /lib/librt.so.1 (0x4e662000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x4e9db000)
libc.so.6 => /lib/libc.so.6 (0x4e48b000)
libfontconfig.so.1 => /lib/libfontconfig.so.1 (0x4ecd9000)
libXrender.so.1 => /lib/libXrender.so.1 (0x4eb72000)
libX11.so.6 => /lib/libX11.so.6 (0x4ea24000)
/lib/ld-linux.so.2 (0x4e468000)
libexpat.so.1 => /lib/libexpat.so.1 (0x4ebad000)
libxcb.so.1 => /lib/libxcb.so.1 (0x4ea00000)
libdl.so.2 => /lib/libdl.so.2 (0x4e65b000)
libXau.so.6 => /lib/libXau.so.6 (0x4e9fa000)
DSO test suite
An initial test suite for shared libraries is available: https://github.com/jpf91/dso-test
Known issues
- TLS section, gshared and static data in shared libraries is not scanned by GC (stack seems to be working)
- Because of that a shared druntime/phobos will usually crash after the first GC collection
