https://issues.dlang.org/show_bug.cgi?id=24590
kinke <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |[email protected] --- Comment #2 from kinke <[email protected]> --- AFAICT, this happens because at program termination, each binary unregisters itself via a CRT destructor, incl. running the module dtors of that binary if druntime had been initialized via `rt_init()`. For libphobos2.so, this includes the `rt.trace` module dtor (whereas static druntime probably doesn't unless using tracing functionality), which uses an anonymous mutex, which depends on an initialized druntime (`_d_critical_init()` without `_d_critical_term()`). But `rt_init()` already cleans up via `_d_critical_term()` if initialization failed, e.g., due to module cycles here. AFAICT, the problem is `rt.sections_elf_shared._isRuntimeInitialized`, which is set once during the `initSections()` call, but would need to be unset if module ctors later throw. We should probably get rid of that variable and use `rt.dmain2._initCount` instead. This also crashes with `-defaultlib=libphobos2.so` only: ``` shared static this() { throw new Exception("oops"); } void main() {} ``` --
