[Issue 24590] Illegal instruction with module constructors cycle and shared libphobos2 in _d_criticalenter2

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jun 9 12:32:17 UTC 2024


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

kinke <kinke at gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kinke at gmx.net

--- Comment #2 from kinke <kinke at gmx.net> ---
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() {}
```

--


More information about the Digitalmars-d-bugs mailing list