This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
[PATCH] Fix order of dtors problem.
- From: Dave Korn <dave dot korn dot cygwin at googlemail dot com>
- To: cygwin-patches at cygwin dot com
- Date: Thu, 30 Jul 2009 14:47:06 +0100
- Subject: [PATCH] Fix order of dtors problem.
This is the patch I'm currently testing (so far, uneventfully). I thought I'd
send it here for posterity just in case I get squashed by a falling hippo or
anything over the weekend.
winsup/cygwin/ChangeLog:
* globals.cc (enum exit_states::ES_GLOBAL_DTORS): Delete.
* dcrt0.cc (__main): Schedule dll_global_dtors to run
atexit before global dtors.
(do_exit): Delete test for ES_GLOBAL_DTORS and call to
dll_global_dtors.
cheers,
DaveK
? foo
Index: dcrt0.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/dcrt0.cc,v
retrieving revision 1.359
diff -p -u -r1.359 dcrt0.cc
--- dcrt0.cc 3 Jul 2009 18:05:50 -0000 1.359
+++ dcrt0.cc 29 Jul 2009 15:22:07 -0000
@@ -993,8 +993,17 @@ cygwin_dll_init ()
extern "C" void
__main (void)
{
+ /* Ordering is critical here. DLL ctors have already been
+ run as they were being loaded, so we should stack the
+ queued call to DLL dtors now. */
+ atexit (dll_global_dtors);
do_global_ctors (user_data->ctors, false);
+ /* Now we have run global ctors, register their dtors. */
atexit (do_global_dtors);
+ /* At exit, global dtors will run first, so the app can still
+ use shared library functions while terminating; then the
+ DLLs will be destroyed; finally newlib will shut down stdio
+ and terminate itself. */
}
void __stdcall
@@ -1013,12 +1022,6 @@ do_exit (int status)
lock_process until_exit (true);
- if (exit_state < ES_GLOBAL_DTORS)
- {
- exit_state = ES_GLOBAL_DTORS;
- dll_global_dtors ();
- }
-
if (exit_state < ES_EVENTS_TERMINATE)
{
exit_state = ES_EVENTS_TERMINATE;
Index: globals.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/globals.cc,v
retrieving revision 1.7
diff -p -u -r1.7 globals.cc
--- globals.cc 17 Jul 2009 09:00:19 -0000 1.7
+++ globals.cc 29 Jul 2009 15:22:07 -0000
@@ -30,7 +30,6 @@ enum exit_states
{
ES_NOT_EXITING = 0,
ES_PROCESS_LOCKED,
- ES_GLOBAL_DTORS,
ES_EVENTS_TERMINATE,
ES_THREADTERM,
ES_SIGNAL,