March 12, 2013

           Summary: removing imports or static constructors from di files
                    can break runtime initialization order
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD

--- Comment #0 from Rainer Schuetze <> 2013-03-12 00:05:28 PDT ---
Created an attachment (id=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...

Configure issuemail:
------- You are receiving this mail because: -------
Top | Discussion index | About this forum | D home