This is the mail archive of the gcc-bugs@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]

Re: SIGSEGV: exceptions with thread specific data


On 10 Mar 1999 18:30:10 -0000, Wolfram Gloger wrote:
>> I would like to report a problem (possible bug) in exception
>> code, but it could also be a problem in glibc-2.0.7 or linuxthreads.
>> 
>> Please let me know if this problem exists on glibc-2.1.X or egcs-1.1.X
>> or if it is a bug of egcs or glibc or linuxthreads
>
>Please try at least egcs-1.1.1 -- versions before that are known to be
>unsafe with regard to threaded exception handling.

The bug appears with egcs-1.1.1 and the development egcs as well, and
with glibc 2.1.x (x=0 and x=1).

If I replace pthreads with a fake library that doesn't actually use
threads, then the egcs-1.1.1 compiled version segfaults in
__cp_push_exception, but the development version works correctly.  The
segfault with 1.1.1 and the fake library is a different bug: with the
real library, the thread executes successfully and the crash is in
pthread_join - I think (I'm having trouble tracing it).

I am guessing that there is a bug in the EH library routines which
causes them to corrupt the malloc arena, and this code tickles it.
(Yes, glibc's malloc() is threadsafe.)

Incidentally, on sparc-sun-solaris2.6 this program executes correctly
when compiled by egcs 1.1, using either the system threads library or
my fake library.  This may mean the bug is in Linux pthreads, or that
Solaris malloc() isn't as sensitive to corruption, or that the problem
is machine-dependent in egcs.

The fake library source is appended.  The typedefs are correct for
glibc and Solaris pthreads; you may have to adjust this for other
systems.

[There seems to be a lot of unnecessary code in the asm dump for the
test function - e.g. we ought to be able to figure out at compile time
that the try region will only ever throw an int, and omit the
unhandled exception code and the type verification.  Actually, we
ought to be able to delete the entire thing except for the printf.]

zw

-- fakepthread.c --

typedef unsigned int pthread_key_t;
typedef unsigned long int pthread_t;

extern void abort (void);

int
pthread_key_create (pthread_key_t *k, void *x)
{
  *k = 1;
  return 0;
}

int
pthread_key_delete(pthread_key_t k)
{
  return 0;
}

static void *keypt, *retval;

int
pthread_setspecific (pthread_key_t k, void *ptr)
{
 if (k != 1)
   abort();
 keypt = ptr;
 return 0;
}

int
pthread_create (pthread_t *id, void *unu, void * (*st) (void*), void *arg)
{
  *id = 1;
  retval = st(arg);
  return 0;
}

int
pthread_join (pthread_t id, void **rv)
{
  if (id != 1)
    abort();
  if (rv)
    *rv = retval;
  return 0;
}


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