www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5457] New: DLL startup code is out of order; gc proxy not set properly


           Summary: DLL startup code is out of order; gc proxy not set
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: druntime
        AssignedTo: sean invisibleduck.org
        ReportedBy: bugzilla digitalmars.com

--- Comment #0 from Walter Bright <bugzilla digitalmars.com> 2011-01-16
22:08:28 PST ---
DLLs link with gcstub.obj, this is because DLLs share the gc with the caller's
gc, instead of having a separate gc that fights the caller's. The general idea
is that upon initialization the DLL sets "proxy" to point to the caller's gc,
and then all gc calls are routed through the proxy.

First, in our DLL's DllMain(), we call:

        case DLL_PROCESS_ATTACH:

In dll_process_attach(), druntime calls:


which calls:


which calls:


which calls:


which looks like:

extern (C) void gc_addRange( void* p, size_t sz )
    if( proxy is null )
        Range* r = cast(Range*) realloc( ranges,
                                         (nranges+1) * ranges[0].sizeof );
        if( r is null )
        r[nranges].pos = p;
        r[nranges].len = sz;
        ranges = r;
    return proxy.gc_addRange( p, sz );

Note that proxy is null. It is supposed to be initialized by rt_loadLibrary().
But, sadly, it is too late since dll_process_attach() gets called first by

This bug makes D DLLs loaded dynamically from a D program unusable.

Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 16 2011