Thread overview
[Issue 20248] Module constructors in executable called twice, never in loaded shared library
Sep 27, 2019
John Colvin
Sep 27, 2019
John Colvin
Jul 05, 2021
kinke
Jul 29, 2021
kinke
Jul 29, 2021
kinke
Jul 29, 2021
kinke
Dec 17, 2022
Iain Buclaw
September 27, 2019
https://issues.dlang.org/show_bug.cgi?id=20248

John Colvin <john.loughran.colvin@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Module constructors in      |Module constructors in
                   |executable called twice, in |executable called twice,
                   |                            |never in loaded shared
                   |                            |library

--
September 27, 2019
https://issues.dlang.org/show_bug.cgi?id=20248

John Colvin <john.loughran.colvin@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |industry, wrong-code

--
July 05, 2021
https://issues.dlang.org/show_bug.cgi?id=20248

kinke <kinke@gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kinke@gmx.net

--- Comment #1 from kinke <kinke@gmx.net> ---
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.

--
July 29, 2021
https://issues.dlang.org/show_bug.cgi?id=20248

--- Comment #2 from kinke <kinke@gmx.net> ---
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.

--
July 29, 2021
https://issues.dlang.org/show_bug.cgi?id=20248

kinke <kinke@gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |backend
          Component|druntime                    |dmd
           Hardware|x86_64                      |All

--
July 29, 2021
https://issues.dlang.org/show_bug.cgi?id=20248

--- Comment #3 from kinke <kinke@gmx.net> ---
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.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=20248

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P2

--