From 6c6d9bee68bc0068cede58b41a575fd923b04e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gardou?= Date: Mon, 28 Dec 2020 10:47:38 +0100 Subject: [PATCH] [CRT] Do not call atexit at process initialization There is no guarantee that the underlying APIs are initialized at this point CORE-17362 --- sdk/lib/crt/startup/crtexe.c | 12 +++++++++--- sdk/lib/crt/startup/gccmain.c | 2 -- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/sdk/lib/crt/startup/crtexe.c b/sdk/lib/crt/startup/crtexe.c index efc29191191..a09d4b5b441 100644 --- a/sdk/lib/crt/startup/crtexe.c +++ b/sdk/lib/crt/startup/crtexe.c @@ -115,6 +115,10 @@ _CRTALLOC(".CRT$XCAA") _PVFV mingw_pcppinit = pre_cpp_init; extern int _MINGW_INSTALL_DEBUG_MATHERR; +#ifdef __GNUC__ +extern void __do_global_dtors(void); +#endif + static int __cdecl pre_c_init (void) { @@ -211,8 +215,6 @@ int __cdecl mainCRTStartup (void) return ret; } -void __call_atexit(); - static __declspec(noinline) int __cdecl @@ -326,7 +328,11 @@ __tmainCRTStartup (void) #endif mainret = main (argc, argv, envp); #endif - __call_atexit(); + +#ifdef __GNUC__ + __do_global_dtors(); +#endif + if (!managedapp) exit (mainret); diff --git a/sdk/lib/crt/startup/gccmain.c b/sdk/lib/crt/startup/gccmain.c index a1cd04b026e..3370a126947 100644 --- a/sdk/lib/crt/startup/gccmain.c +++ b/sdk/lib/crt/startup/gccmain.c @@ -43,8 +43,6 @@ __do_global_ctors (void) { __CTOR_LIST__[i] (); } - - atexit (__do_global_dtors); } static int initialized = 0;