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


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

sjlj exception and malloc


When using sjlj exceptions, malloc gets called very early in order to
allocate the static eh context.  This is a real problem for us because
we implement our own malloc in C++.  The result is infinite recursion.

Because there is only one of these static objects, it's straightforward
to statically allocate the object and then just do the initialization,
which breaks the loop.  I've observed no negative side effects other
than the 12 bytes of data space that aren't used when eh_context_static
isn't used.

*** libgcc2.c.orig      Mon Jul  6 16:52:21 1998
--- libgcc2.c   Thu Oct 15 19:32:49 1998
***************
*** 3164,3185 ****
  
    return (*get_eh_context) ();
  }
  
  /* Return a static EH context. */
  
  static struct eh_context *
  eh_context_static ()
  {
    static struct eh_context *eh;
!   if (! eh)
!     eh = new_eh_context ();
    return eh;
  }
  
  #if __GTHREADS
  /* Return a thread specific EH context. */
  
  static struct eh_context *
  eh_context_specific ()
  {
    struct eh_context *eh;
--- 3164,3189 ----
  
    return (*get_eh_context) ();
  }
  
  /* Return a static EH context. */
  
  static struct eh_context *
  eh_context_static ()
  {
    static struct eh_context *eh;
!   if (! eh) {
!       static struct eh_context seh;
!       eh = &seh;
!       memset (eh, 0, sizeof *eh);
!       eh->dynamic_handler_chain = top_elt;
!   }
    return eh;
  }
  
  #if __GTHREADS
  /* Return a thread specific EH context. */
  
  static struct eh_context *
  eh_context_specific ()
  {
    struct eh_context *eh;


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