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.
Comment #1 by bugzilla — 2017-04-14T10:29:35Z
Comment #2 by r.sagitario — 2017-04-15T06:45:00Z
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.
Comment #4 by bugzilla — 2017-10-07T19:33:21Z
Comment #5 by r.sagitario — 2017-10-07T20:01:16Z
That's why I've been saying for years that https://wiki.dlang.org/Win32_DLLs_in_D#D_code_calling_D_code_in_DLLs needs a big red warning that it doesn't work but in very simple cases.
Comment #6 by wererogue — 2017-10-07T20:19:24Z
I'd be lovely to have a doc on how it should be used in the complex cases - if it works at all :/
Comment #7 by r.sagitario — 2017-10-07T20:29:44Z
Benjamin Thaut has prototyped it and showed it at Dconf http://dconf.org/2016/talks/thaut.html. Development seems to have stalled at the moment, though. Latest version should be this: https://github.com/Ingrater/dmd/tree/DllSupportD2
Comment #8 by r.sagitario — 2018-02-28T14:27:52Z
gcstub has been removed, so I guess we can close this.