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

Walter Bright walter at digitalmars.com
Fri Feb 8 10:05:54 PST 2013


On 2/7/2013 11:18 PM, Rainer Schuetze wrote:
> 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.

You're going to get those multiple instances regardless of whether Phobos is a 
dll or not, because there'll be other dlls. The only reasonable solution is to 
compare the typeinfo strings, too.


More information about the D-runtime mailing list