August 23, 2016
https://issues.dlang.org/show_bug.cgi?id=16423

          Issue ID: 16423
           Summary: ModuleInfo missing when linking to static lib with
                    classes
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody@puremagic.com
          Reporter: schveiguy@yahoo.com

I am running into some issues where moduleinfo and classinfo that should be included in the runtime type info is missing, but only when linking via static libs.

An example:

libci.d:
module libci;

class C
{
}

extern(C) void foo()
{
    import std.stdio;
    auto c = new C;
    writeln("classinfo of C: ", typeid(c));
    auto x = ClassInfo.find("libci.C");
    writeln("searching for it: ", x);
}

version(works) static this()
{
    import std.stdio;
    writeln("here");
}

testit.d:
import std.stdio;
import libci;

void main()
{
    foo();
    auto ci = ClassInfo.find("libci.C");
    writeln("in main: ", ci);
    foreach(m; ModuleInfo)
    {
        writeln(m.name);
    }
}

If I build with:

dmd testit.d libci.d

Then I get:

classinfo of C: libci.C
searching for it: libci.C
in main: libci.C
testit
libci
object
... // all other modules

If I build with this:

dmd -lib libci.d
dmd -L-L. -L-lci testit.d

I get:
classinfo of C: libci.C
searching for it: null
in main: null
testit
object
... // all other modules, no libci!

So somehow the libci ModuleInfo isn't being linked, even though the classinfo is usable if you use it directly. IMO, the ModuleInfo is being incorrectly trimmed from the executable.

If you enable version=works when building the library, then the ModuleInfo is included.

Unsure if this is druntime or dmd bug, marked as dmd.

Note, this behavior is really old, and on both Linux and OSX. Tested as far back as 2.064.

--