www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17707] New: unimported modules in libraries do not have their

https://issues.dlang.org/show_bug.cgi?id=17707

          Issue ID: 17707
           Summary: unimported modules in libraries do not have their
                    module constructors run
           Product: D
           Version: D2
          Hardware: x86_64
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: john.loughran.colvin gmail.com

First with object files:

% ls
app.d foo.d
% cat app.d
void main() { import core.stdc.stdio; puts("and from here"); }
% cat foo.d
static this() { import core.stdc.stdio; puts("hello"); }
% dmd -c app.d foo.d
% ls
app.d app.o foo.d foo.o
% gcc app.o foo.o -lphobos2
% ./a.out
hello
and from here

Everything looks fine there

% ar rcs foo.a foo.o
% gcc app.o foo.a -lphobos2
% ./a.out
and from here

the module constructor from foo.d has gone missing!

test on macOS and linux, with many different permutations. Splitting the object
file back out of the library makes it work again, so no information is lost.

On macOS it was easy to discover that the result of getsectbynamefromheader_64
for __DATA __minfodata is missing an entry for foo in the library case, but not
in the object case.

--
Jul 31 2017