This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Follow-on PATCH to `PATCH: Configure libstdc++-v3 against gthr.h'


Here is the follow-on patch to fix multi-threaded C++ EH support which
is currently broken on mainline and the 3.0 branch.

Both libstdc++-v3/libsupc++/eh_alloc.cc and [...]/eh_globals.cc were
written to compile against the gcc/gthr.h abstraction layer, but the
configuration was broken at some point and it now always maps to the
gcc/gthr-single.h configuration even if --enable-threads was provided
while configuring libstdc++-v3.  The upshot is that C++ EH is broken
in light of multi-threading.

This change has been fully bootstrapped on multiple architectures but
does require the last posted patch.  David originally caught this
problem and provided an initial version of this patch.  I adapted it
to work with the proposed configuration changes in libstdc++-v3.

I propose to apply this patch to the mainline ASAP (just after the
libstdc++-v3 configuration patch goes in on mainline).  If, after
additional testing on a wider selection of platforms, we see no
problems, then the two patches should go onto the 3.0 branch since we
have a regression from 2.95 otherwise.  The issue is that C++ EH is
broken in light of multi-threading; whereas it worked for 2.95.

Bootstrapped on i386-unknown-freebsd4.2 and alpha-unknown-freebsd4.2
without any new failures being spotted except g++.eh/badalloc1.C (with
-pthread only) which was only passing due to the dumb luck (and is not
a regression against 2.95 on this platform or any where mutex routines
may allocate memory - and, in any event, is a QoI failure not an error
against any standard).

(Again, it is hard to find a portable test case that prove this is now
 working as it should.  I checked testcases which are in dejagnu by
 hand with gdb to ensure that the correct __gthread calls are made
 under this patch).

2001-06-07  Loren J. Rittle  <ljrittle@acm.org>
	    John David Anglin  <dave@hiauly1.hia.nrc.ca>

	* libsupc++/eh_alloc.cc: Ensure that required macros are
	defined before including gthr.h.  Ensure that we get the
	version of gthr.h for which we know how to provide a
	configuration.
	* libsupc++/eh_globals.cc: Likewise.  And, bring the threading
	code path into line with the current EH model.  Use std, where
	appropriate.

Index: libsupc++/eh_alloc.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/eh_alloc.cc,v
retrieving revision 1.2.2.3
diff -c -r1.2.2.3 eh_alloc.cc
*** eh_alloc.cc	2001/05/25 20:07:25	1.2.2.3
--- eh_alloc.cc	2001/06/07 10:32:13
***************
*** 35,41 ****
  #include <cstring>
  #include <limits.h>
  #include "unwind-cxx.h"
! #include "gthr.h"
  
  using namespace __cxxabiv1;
  
--- 35,42 ----
  #include <cstring>
  #include <limits.h>
  #include "unwind-cxx.h"
! #include "bits/c++config.h"
! #include "bits/gthr.h"
  
  using namespace __cxxabiv1;
  
Index: libsupc++/eh_globals.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/eh_globals.cc,v
retrieving revision 1.1.2.1
diff -c -r1.1.2.1 eh_globals.cc
*** eh_globals.cc	2001/05/13 07:10:26	1.1.2.1
--- eh_globals.cc	2001/06/07 10:32:13
***************
*** 29,36 ****
  
  
  #include <exception>
  #include "unwind-cxx.h"
! #include "gthr.h"
  
  using namespace __cxxabiv1;
  
--- 29,38 ----
  
  
  #include <exception>
+ #include <cstdlib>
  #include "unwind-cxx.h"
! #include "bits/c++config.h"
! #include "bits/gthr.h"
  
  using namespace __cxxabiv1;
  
***************
*** 47,53 ****
  {
    __gthread_key_dtor (globals_key, ptr);
    if (ptr)
!     free (ptr);
  }
  
  static void
--- 49,55 ----
  {
    __gthread_key_dtor (globals_key, ptr);
    if (ptr)
!     std::free (ptr);
  }
  
  static void
***************
*** 90,113 ****
      return &globals_static;
  
    if (use_thread_key < 0)
!     get_globals_init_once ();
  
    g = (__cxa_eh_globals *) __gthread_getspecific (globals_key);
    if (! g)
      {
!       static __gthread_once_t once = __GTHREAD_ONCE_INIT;
! 
!       // Make sure use_thread_key got initialized.  Some systems have
!       // dummy thread routines in their libc that return a success.
!       if (__gthread_once (&once, eh_threads_initialize) != 0
! 	  || use_thread_key < 0)
! 	{
! 	  use_thread_key = 0;
! 	  return &globals_static;
! 	}
!       
!       if ((g = malloc (sizeof (__cxa_eh_globals))) == 0
! 	  || __gthread_setspecific (eh_context_key, (void *) g) != 0)
          std::terminate ();
        g->caughtExceptions = 0;
        g->uncaughtExceptions = 0;
--- 92,111 ----
      return &globals_static;
  
    if (use_thread_key < 0)
!     {
!       get_globals_init_once ();
! 
!       // Make sure use_thread_key got initialized.
!       if (use_thread_key == 0)
! 	return &globals_static;
!     }
  
    g = (__cxa_eh_globals *) __gthread_getspecific (globals_key);
    if (! g)
      {
!       if ((g = (__cxa_eh_globals *)
! 	   std::malloc (sizeof (__cxa_eh_globals))) == 0
! 	  || __gthread_setspecific (globals_key, (void *) g) != 0)
          std::terminate ();
        g->caughtExceptions = 0;
        g->uncaughtExceptions = 0;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]