You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
% cat modcon.d
import modcon2;
void main()
{
import core.runtime : Runtime;
import core.sys.posix.dlfcn;
import std.stdio;
writeln("HI");
assert(Runtime.loadLibrary("./libmodcon2.so"));
}
% cat modcon2.d
__gshared int a;
shared static this() { foo(); }
void foo()
{
import core.stdc.stdio;
printf("%p ", &a);
printf("%p
", &foo);
}
% dmd -shared modcon2.d -of=libmodcon2.so
% dmd -defaultlib=libphobos2.so modcon.d modcon2.d
% ./modcon
0x7f920f3a2140 0x7f920f39f930
HI
0x7f920f3a2140 0x7f920f39f930
As you can see from the printed pointers, the module constructor from the executable is called twice - once on process start and once on loading the shared library - and the module constructor from the shared library is never called.
Module constructors are normally designed to be called only once, so this causes some havok
The text was updated successfully, but these errors were encountered:
This 'works' with LDC v1.27 (but DMD v2.097 still fails):
0x55debef38074 0x55debef34090
HI
0x7fdfb6c12064 0x7fdfb6c10870
I think this is more likely related to compiler differences wrt. relocation model, not a druntime divergence.
Further tests have shown that with DMD, the ModuleInfos of modules contained in both executable and library are apparently resolved to the executable's.
E.g., versioning out the module ctor in `modcon2.d` for the library still leads to it being invoked when loading the library; the opposite case, versioning it out for the executable, means it's not invoked at all.
There's a related issue regarding CRT ctors - if both executable and library contain an identically mangled `pragma(crt_constructor)` function (doesn't even need to be in the same module - and name collision is quite likely due to the `extern(C)` requirement...), the executable one is invoked twice. Again DMD-specific, works with LDC.
John Colvin (@John-Colvin) reported this on 2019-09-27T09:38:47Z
Transferred from https://issues.dlang.org/show_bug.cgi?id=20248
CC List
Description
% cat modcon.d import modcon2; void main() { import core.runtime : Runtime; import core.sys.posix.dlfcn; import std.stdio; writeln("HI"); assert(Runtime.loadLibrary("./libmodcon2.so")); } % cat modcon2.d __gshared int a; shared static this() { foo(); } void foo() { import core.stdc.stdio; printf("%p ", &a); printf("%p ", &foo); } % dmd -shared modcon2.d -of=libmodcon2.so % dmd -defaultlib=libphobos2.so modcon.d modcon2.d % ./modcon 0x7f920f3a2140 0x7f920f39f930 HI 0x7f920f3a2140 0x7f920f39f930 As you can see from the printed pointers, the module constructor from the executable is called twice - once on process start and once on loading the shared library - and the module constructor from the shared library is never called. Module constructors are normally designed to be called only once, so this causes some havokThe text was updated successfully, but these errors were encountered: