crt: tls: Call __dyn_tls_dtor also from the thread_local_exe_atexit_callback

msvc/UCRT calls the __dyn_tls_dtor function two times, once during the
exit() call via thread_local_exe_atexit_callback and second time from the
PE TLS callback.

So do the same thing in mingw-w64. Stores the __dyn_tls_dtor pointer into
the tentative __dyn_tls_dtor_callback variable, so it can be referenced and
called on demand. msvc also provides the __dyn_tls_dtor_callback symbol.

Note that __dyn_tls_dtor has already guard which prevents duplicate
execution of individual callbacks.

This change fixes execution order of atexit and __dyn_tls_dtor callbacks by
executing all __dyn_tls_dtor callbacks before atexit callbacks. This
matches the msvc behavior.

Signed-off-by: LIU Hao <lh_mouse@126.com>
2 files changed