Bug 13706 – 76 duplicate static dtors emitted and counting

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-11-10T10:39:49Z
Last change time
2024-12-13T18:33:40Z
Keywords
wrong-code
Assigned to
No Owner
Creator
Marco Leise
Moved to GitHub: dmd#18908 →

Comments

Comment #0 by Marco.Leise — 2014-11-10T10:39:49Z
When using separate compilation, DMD emits and calls many duplicate static dtors. In one larger code base I found the counter at 76 while debugging an issue. Here is a reduced test case that creates only one duplicate: ----------8<---------- module main; import a, b; void main() { A a; B b; } ---------->8---------- ----------8<---------- module a; import res; struct A { Block!() field; } ---------->8---------- ----------8<---------- module b; import std.typecons, res; struct B { Block!() field; } ---------->8---------- ----------8<---------- module res; struct Block() { import core.stdc.stdio; shared static ~this() { debug printf ("struct Block shared static dtor %s\n", __FUNCTION__.ptr); } static ~this() { debug printf ("struct Block static dtor %s\n", __FUNCTION__.ptr); } } ---------->8---------- This prints on DMD 2.066.1 and 2.065.0: struct Block static dtor res.Block!().Block._staticDtor6 struct Block static dtor res.Block!().Block._staticDtor4 struct Block shared static dtor res.Block!().Block._sharedStaticDtor5 struct Block shared static dtor res.Block!().Block._sharedStaticDtor3 On DMD 2.064.2 the output was: struct Block static dtor res.Block!().Block._staticDtor11 struct Block static dtor res.Block!().Block._staticDtor4 struct Block shared static dtor res.Block!().Block._sharedStaticDtor10 struct Block shared static dtor res.Block!().Block._sharedStaticDtor3 Tagged as wrong code, like when a common dtor would be called twice by the runtime. P.S.: I also wonder what the static dtors 1 and 2 are created for. I often get runtime errors about circular dependencies of modules with static constructors, but cannot see any in the respective modules.
Comment #1 by Marco.Leise — 2014-11-10T11:04:38Z
On a side note I also found the debug build executable size to increase from 5.4 to 16 MiB when using separate compilation. That is 3x the size and doesn't seem like a reasonable difference for a linked executable. This must be duplicated stuff that could not be merged.
Comment #2 by robert.schadek — 2024-12-13T18:33:40Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18908 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB