Revert "crt: Implement standard-conforming termination support with mcfgthread"

This reverts commit 1f742045ed65fc0799422b2e186181d196193f14.
diff --git a/mingw-w64-crt/crt/crtdll.c b/mingw-w64-crt/crt/crtdll.c
index a90a7f5..08cd592 100644
--- a/mingw-w64-crt/crt/crtdll.c
+++ b/mingw-w64-crt/crt/crtdll.c
@@ -31,12 +31,6 @@
 #endif
 #include <sect_attribs.h>
 #include <locale.h>
-#include <stdio.h>
-#ifdef __USING_MCFGTHREAD__
-#include <mcfgthread/cxa.h>
-#endif
-
-extern HANDLE __dso_handle;
 
 extern void __cdecl _initterm(_PVFV *,_PVFV *);
 extern void __main ();
@@ -187,14 +181,7 @@
 	  }
     }
   if (dwReason == DLL_PROCESS_ATTACH)
-    {
-#ifdef __USING_MCFGTHREAD__
-      /* Register `fflush(NULL)` before user-defined constructors, so
-       * it will be executed after all user-defined destructors.  */
-      __MCF_cxa_atexit ((__MCF_cxa_dtor_cdecl*)(intptr_t) fflush, NULL, &__dso_handle);
-#endif
-      __main ();
-    }
+    __main ();
   retcode = DllMain(hDllHandle,dwReason,lpreserved);
   if (dwReason == DLL_PROCESS_ATTACH && ! retcode)
     {
@@ -208,16 +195,6 @@
 	if (_CRT_INIT (hDllHandle, dwReason, lpreserved) == FALSE)
 	  retcode = FALSE;
     }
-#ifdef __USING_MCFGTHREAD__
-  if (dwReason == DLL_PROCESS_DETACH && lpreserved == NULL)
-    {
-      /* Call `__cxa_finalize(dso_handle)` if the library is unloaded
-       * dynamically. This conforms to the Itanium C++ ABI. Note it is
-       * not called in case of process termination, where a call to
-       * `__cxa_finalize(NULL)` shall have been made instead.  */
-      __MCF_cxa_finalize (&__dso_handle);
-    }
-#endif
 i__leave:
   __native_dllmain_reason = UINT_MAX;
   return retcode ;
@@ -226,11 +203,7 @@
 
 int __cdecl atexit (_PVFV func)
 {
-#ifdef __USING_MCFGTHREAD__
-    return __MCF_cxa_atexit ((__MCF_cxa_dtor_cdecl*)(intptr_t) func, NULL, &__dso_handle);
-#else
     return _register_onexit_function(&atexit_table, (_onexit_t)func);
-#endif
 }
 
 char __mingw_module_is_dll = 1;
diff --git a/mingw-w64-crt/crt/crtexe.c b/mingw-w64-crt/crt/crtexe.c
index e0b02a8..1656b0e 100644
--- a/mingw-w64-crt/crt/crtexe.c
+++ b/mingw-w64-crt/crt/crtexe.c
@@ -20,10 +20,6 @@
 #include <tchar.h>
 #include <sect_attribs.h>
 #include <locale.h>
-#include <stdio.h>
-#ifdef __USING_MCFGTHREAD__
-#include <mcfgthread/cxa.h>
-#endif
 
 #if defined(__SEH__) && (!defined(__clang__) || __clang_major__ >= 7)
 #define SEH_INLINE_ASM
@@ -49,7 +45,6 @@
 extern int _fmode;
 extern int _commode;
 extern int _dowildcard;
-extern HANDLE __dso_handle;
 
 extern _CRTIMP void __cdecl _initterm(_PVFV *, _PVFV *);
 
@@ -261,11 +256,6 @@
     _fpreset ();
 
     duplicate_ppstrings (argc, &argv);
-#ifdef __USING_MCFGTHREAD__
-    /* Register `fflush(NULL)` before user-defined constructors, so
-     * it will be executed after all user-defined destructors.  */
-    __MCF_cxa_atexit ((__MCF_cxa_dtor_cdecl*)(intptr_t) fflush, NULL, &__dso_handle);
-#endif
     __main (); /* C++ initialization. */
 #ifdef _UNICODE
     __winitenv = envp;
@@ -342,11 +332,7 @@
 
 int __cdecl atexit (_PVFV func)
 {
-#ifdef __USING_MCFGTHREAD__
-    return __MCF_cxa_atexit ((__MCF_cxa_dtor_cdecl*)(intptr_t) func, NULL, &__dso_handle);
-#else
     return _onexit((_onexit_t)func) ? 0 : -1;
-#endif
 }
 
 char __mingw_module_is_dll = 0;
diff --git a/mingw-w64-crt/crt/exit_wrappers.c b/mingw-w64-crt/crt/exit_wrappers.c
index ab6896f..256c26d 100644
--- a/mingw-w64-crt/crt/exit_wrappers.c
+++ b/mingw-w64-crt/crt/exit_wrappers.c
@@ -5,10 +5,6 @@
  */
 
 #include <_mingw.h>
-#ifdef __USING_MCFGTHREAD__
-#include <mcfgthread/exit.h>
-#include <mcfgthread/cxa.h>
-#endif
 
 /* `exit()`, C89  */
 void exit(int status) __attribute__((__noreturn__));
@@ -16,11 +12,7 @@
 
 void exit(int status)
 {
-#ifdef __USING_MCFGTHREAD__
-  __MCF_exit(status);
-#else
   (*__MINGW_IMP_SYMBOL(exit))(status);
-#endif
 }
 
 /* `_exit()`, POSIX  */
@@ -29,23 +21,5 @@
 
 void _exit(int status)
 {
-#ifdef __USING_MCFGTHREAD__
-  __MCF__Exit(status);
-#else
   (*__MINGW_IMP_SYMBOL(_exit))(status);
-#endif
 }
-
-#ifdef __USING_MCFGTHREAD__
-/* `at_quick_exit()`, C99  */
-typedef void (__cdecl *_PVFV)(void);
-int at_quick_exit(_PVFV func);
-
-typedef void* HANDLE;
-extern HANDLE __dso_handle;
-
-int at_quick_exit(_PVFV func)
-{
-  return __MCF_cxa_at_quick_exit ((__MCF_cxa_dtor_cdecl*)(intptr_t) func, NULL, &__dso_handle);
-}
-#endif  /* __USING_MCFGTHREAD__  */
diff --git a/mingw-w64-crt/crt/tls_atexit.c b/mingw-w64-crt/crt/tls_atexit.c
index 0b8f83a..f39731a 100644
--- a/mingw-w64-crt/crt/tls_atexit.c
+++ b/mingw-w64-crt/crt/tls_atexit.c
@@ -4,29 +4,6 @@
  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
  */
 
-typedef void (__thiscall * dtor_fn)(void*);
-int __mingw_cxa_atexit(dtor_fn dtor, void *obj, void *dso);
-int __mingw_cxa_thread_atexit(dtor_fn dtor, void *obj, void *dso);
-
-/* This is the per-module DSO handle as required by Itanium ABI.  */
-void* __dso_handle;
-
-#ifdef __USING_MCFGTHREAD__
-
-#include <mcfgthread/cxa.h>
-
-int __mingw_cxa_atexit(dtor_fn dtor, void *obj, void *dso)
-{
-  return __MCF_cxa_atexit(dtor, obj, dso);
-}
-
-int __mingw_cxa_thread_atexit(dtor_fn dtor, void *obj, void *dso)
-{
-  return __MCF_cxa_thread_atexit(dtor, obj, dso);
-}
-
-#else  /* __USING_MCFGTHREAD__  */
-
 #include <sect_attribs.h>
 
 #ifndef WIN32_LEAN_AND_MEAN
@@ -41,6 +18,10 @@
 #include <process.h>
 
 
+typedef void (__thiscall * dtor_fn)(void*);
+int __mingw_cxa_atexit(dtor_fn dtor, void *obj, void *dso);
+int __mingw_cxa_thread_atexit(dtor_fn dtor, void *obj, void *dso);
+
 typedef struct dtor_obj dtor_obj;
 struct dtor_obj {
   dtor_fn dtor;
@@ -48,6 +29,7 @@
   dtor_obj *next;
 };
 
+HANDLE __dso_handle;
 extern char __mingw_module_is_dll;
 
 static CRITICAL_SECTION lock;
@@ -177,5 +159,3 @@
 }
 
 _CRTALLOC(".CRT$XLB") PIMAGE_TLS_CALLBACK __xl_b = (PIMAGE_TLS_CALLBACK) tls_callback;
-
-#endif  /* __USING_MCFGTHREAD__  */
diff --git a/mingw-w64-crt/crt/ucrt_exit_wrappers.c b/mingw-w64-crt/crt/ucrt_exit_wrappers.c
index 4ef52a6..112d8e3 100644
--- a/mingw-w64-crt/crt/ucrt_exit_wrappers.c
+++ b/mingw-w64-crt/crt/ucrt_exit_wrappers.c
@@ -14,11 +14,7 @@
 
 void quick_exit(int status)
 {
-#ifdef __USING_MCFGTHREAD__
-  __MCF_quick_exit(status);
-#else
   (*__MINGW_IMP_SYMBOL(quick_exit))(status);
-#endif
 }
 
 /* `_Exit()`, C99  */
@@ -27,9 +23,5 @@
 
 void _Exit(int status)
 {
-#ifdef __USING_MCFGTHREAD__
-  __MCF__Exit(status);
-#else
   (*__MINGW_IMP_SYMBOL(_Exit))(status);
-#endif
 }
diff --git a/mingw-w64-crt/crt/ucrtbase_compat.c b/mingw-w64-crt/crt/ucrtbase_compat.c
index 52c22d6..02910ff 100644
--- a/mingw-w64-crt/crt/ucrtbase_compat.c
+++ b/mingw-w64-crt/crt/ucrtbase_compat.c
@@ -55,6 +55,8 @@
 // Declared in new.h, but only visible to C++
 _CRTIMP int __cdecl _set_new_mode(int _NewMode);
 
+extern char __mingw_module_is_dll;
+
 
 // Wrappers with legacy msvcrt.dll style API, based on the new ucrtbase.dll functions.
 int __cdecl __getmainargs(int * _Argc, char *** _Argv, char ***_Env, int _DoWildCard, _startupinfo *_StartInfo)
@@ -88,10 +90,6 @@
 
 _onexit_t __cdecl (*__MINGW_IMP_SYMBOL(_onexit))(_onexit_t func) = _onexit;
 
-// When using mcfgthread, `at_quick_exit()` is provided in 'exit_wrappers.c'.
-#ifndef __USING_MCFGTHREAD__
-extern char __mingw_module_is_dll;
-
 int __cdecl at_quick_exit(void (__cdecl *func)(void))
 {
   // In a DLL, we can't register a function with _crt_at_quick_exit, because
@@ -103,7 +101,6 @@
 }
 
 int __cdecl (*__MINGW_IMP_SYMBOL(at_quick_exit))(void (__cdecl *)(void)) = at_quick_exit;
-#endif  // __USING_MCFGTHREAD__
 
 void __cdecl _amsg_exit(int ret) {
   fprintf(stderr, "runtime error %d\n", ret);