Bug 17326 – 2.072 gc changes broke 32 bit Windows DLLs
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2017-04-14T10:22:32Z
Last change time
2018-02-28T14:27:52Z
Keywords
dll
Assigned to
No Owner
Creator
Walter Bright
Comments
Comment #0 by bugzilla — 2017-04-14T10:22:32Z
How it is supposed to work is that if a program dynamically loads a DLL, then they need to share the same GC instance. This is done by the DLL, when it loads, calling gc_setProxy(the main program's gc instance pointer).
The DLL links in gcstub/gc.d, which contained a Proxy struct with a bunch of fields that are pointers to functions. The equivalent is gc/gc.d.
Unfortunately, 2.072 totally revamped everything about this in gc/*, but failed to update gcstub/gc. So now gcstub.gc_setProxy() gets sent a pointer to a completely different interface, causing it to crash when used.
This is a disastrous bug, as it makes using D DLLs completely unusable in Win32, and is likely the source of the common complaint that Windows DLLs do not work.
DLLs with clear separation of ownership work fine (e.g. Visual D is a DLL).
As said repeatedly, the GC proxy mechanism is no good but for very simple use cases. Threads need to be shared, too, so the GC can stop and analyze them. Anything happening in a destructor needs to be executed against the correct runtime library, including the C runtime.
Despite that, the proxy mechanism is still there, you can use it as shown in https://wiki.dlang.org/Win32_DLLs_in_D#D_code_calling_D_code_in_DLLs: export gc_setProxy by the DLL and use Runtime.loadLibrary instead of LoadLibraryA to load it.
It's unfortunate that gcstub/gc.d has not been updated (or better removed). You can now select something similar by embedding
extern(C) __gshared string[] rt_options = [ "gcopt=gc:manual" ]
into the binary. See http://dlang.org/spec/garbage.html#gc_config
Comment #3 by bugzilla — 2017-04-18T09:38:37Z
The problem is I cannot get the DLL test cases into the autotester test suite, which is why DLL support regularly breaks.