[D-runtime] druntime should be a shared library/DLL

Rainer Schuetze r.sagitario at gmx.de
Thu Feb 7 23:18:04 PST 2013


On 06.02.2013 23:15, Walter Bright wrote:> This would go a long ways 
towards solving the dll issue, as then the gc
 > and thread instances will automatically be shared.

Time to dig up http://d.puremagic.com/issues/show_bug.cgi?id=4071 again. 
I had implemented a working shared phobos.dll at that time. I can try to 
bring it up to date if the approach seems appropriate.

One of the major issues is the missing compiler support to access data 
in another DLL. The access has to be redirected through the DLL import 
table, but without annotation in the imported files it's pretty hard to 
tell whether data is in the same DLL or not. That's why the relocation 
table is searched and code is patched at startup, but this seems 
fragile. I just figured it gets worse with TLS data, because you'll need 
the TLS index of the target DLL; the patch does not deal with this.

IIRC unloading a DLL is not supported in the patch. It is also quite 
problematic with a GC, because there might always still be objects on 
the heap that need to call their destructor in the DLL (maybe not 
collected due to false pointer references).

BTW: it's probably not a good idea to have multiple versions of phobos 
in different DLLs, because it also contains classes that you might want 
to share, like files and streams. Also, you'd get multiple instances of 
objects like moduleinfo and typeinfo, that are often compared by pointer 
identity.





More information about the D-runtime mailing list