[Issue 22367] Modules compiled with -betterC never generate a ModuleInfo

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Dec 6 09:20:57 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=22367

--- Comment #17 from Walter Bright <bugzilla at digitalmars.com> ---
I looked further into this.

Essentially, betterC code cannot generate ModuleInfo, because ModuleInfo also
generates a call to _d_so_registry in druntime.

Having a `static this` in a betterC module, or a betterC module importing a
module with a `static this`, requires a ModuleInfo to guarantee the semantics.
Simply turning off ModuleInfo generation will get the program to link, but will
leave the static this code un-run, i.e. the code will not work.

Instead, betterC code must use pragma(crt_constructor) functions instead to
perform static initializations. These functions will be called by the C runtime
startup code.

To reply on pragma(crt_constructor) means fixing the reported problems with
them, and making sure they are correctly defined. To that end is:

https://github.com/dlang/dmd/pull/14669

which is to be followed by going through druntime to replace `static this` with
`pragma(crt_constructor)` wherever possible, such as with:

https://github.com/dlang/dmd/pull/14671

--


More information about the Digitalmars-d-bugs mailing list