public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug nptl/1812] New: segv when thread exits after throw/catch of C++ exception
@ 2005-11-04 22:23 ed dot connell at sas dot com
  2005-11-06 20:01 ` [Bug nptl/1812] " drepper at redhat dot com
  0 siblings, 1 reply; 2+ messages in thread
From: ed dot connell at sas dot com @ 2005-11-04 22:23 UTC (permalink / raw)
  To: glibc-bugs

I have a simple C program that spawns a thread; the thread calls into a dlopen'd
shared library.  The shared library is in C++ and its lone entry point just does
a throw and catch before returning.  We return back into the thread and when the
thread exits it crashes.  This happens on at least x86, x86_64 and ia64 on both
SLES 9 and RHEL 4.  I'm not sure if the problem is in libpthread or libstdc++ or
gcc...apologies if this ends up being the wrong venue.

$ gcc -o threadtest threadtest.c -pthread -lpthread -ldl -g
$ g++ -shared -o libthrow.so throw.cpp -lstdc++ -g
$ export LD_LIBRARY_PATH=.
$ ./threadtest
thread done, program should exit
Segmentation fault

threadtest.c
********
#include <pthread.h>
#include <stdio.h>
#include <dlfcn.h>

int ThreadFn(void *arg)
{
    int (*throw_entry)(void);
    void *handle;

    handle = dlopen("libthrow.so", RTLD_NOW);
    throw_entry = dlsym(handle, "throw_entry");

    if (throw_entry() != 123) {
         printf("throw_entry() didn't return 123 as expected\n");
    } 

    dlclose(handle);

    printf("thread done, program should exit\n");
    return 0;
}

int main(int argc, char* argv[])
{
   pthread_t thread;
   void *ret;

   pthread_create(&thread, NULL, (void *(*)(void *))ThreadFn, 0);
   pthread_join(thread, &ret);

   return 0;
}
********


throw.cpp
********
extern "C" {
 int throw_entry(void);
};

class foo {};

int throw_entry(void)
{
    try
    {
        throw foo();
    }
    catch(foo)
    {
        return 123;
    }
    return 0;
}
********

-- 
           Summary: segv when thread exits after throw/catch of C++
                    exception
           Product: glibc
           Version: 2.3.4
            Status: NEW
          Severity: normal
          Priority: P2
         Component: nptl
        AssignedTo: drepper at redhat dot com
        ReportedBy: ed dot connell at sas dot com
                CC: glibc-bugs at sources dot redhat dot com


http://sourceware.org/bugzilla/show_bug.cgi?id=1812

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug nptl/1812] segv when thread exits after throw/catch of C++ exception
  2005-11-04 22:23 [Bug nptl/1812] New: segv when thread exits after throw/catch of C++ exception ed dot connell at sas dot com
@ 2005-11-06 20:01 ` drepper at redhat dot com
  0 siblings, 0 replies; 2+ messages in thread
From: drepper at redhat dot com @ 2005-11-06 20:01 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From drepper at redhat dot com  2005-11-06 20:01 -------
That's a problem in libstdc++.  They use pthread_key_create to create a TSD key
but never call pthread_key_delete if the libstdc++ DSO is unloaded.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


http://sourceware.org/bugzilla/show_bug.cgi?id=1812

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-11-06 20:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-04 22:23 [Bug nptl/1812] New: segv when thread exits after throw/catch of C++ exception ed dot connell at sas dot com
2005-11-06 20:01 ` [Bug nptl/1812] " drepper at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).