Bug 9697 – removing imports or static constructors from di files can break runtime initialization order

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-03-12T00:05:28Z
Last change time
2024-12-13T18:04:46Z
Assigned to
No Owner
Creator
Rainer Schuetze
Moved to GitHub: dmd#18534 →

Attachments

IDFilenameSummaryContent-TypeSize
1199initorder.zipdemonstrate broken init order with optimized di filesapplication/x-zip1318

Comments

Comment #0 by r.sagitario — 2013-03-12T00:05:28Z
Created attachment 1199 demonstrate broken init order with optimized di files D source files often import modules that are not needed for the declaration of public symbols in the module, but by their implementation. When reducing dependencies from di import files by removing imports, the runtime initialization order can be broken. This is caused by a module not being part of the dependency list in the module info, if it has no static constructor/destructor and none of its imports has one, transitively. See the attached file for an example. The straight forward solution is to always add imported modules to the dependency list. This has the drawback that C wrapper header files will always need to have a static library that contains the module info declarations. It might work to just add "static this();" to di files that have removed imports, if it is known to depend on these modules during runtime initialization. Adding a declaration for non-existing code seems like a dirty hack, there should be some more explicite way...
Comment #1 by robert.schadek — 2024-12-13T18:04:46Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18534 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB