public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/22309] New: mt allocator doesn't pthread_key_delete it's keys
@ 2005-07-05 13:54 jakub at redhat dot com
  2005-07-05 16:27 ` [Bug libstdc++/22309] " pcarlini at suse dot de
                   ` (21 more replies)
  0 siblings, 22 replies; 24+ messages in thread
From: jakub at redhat dot com @ 2005-07-05 13:54 UTC (permalink / raw)
  To: gcc-bugs

With libstdc++ configured with --enable-libstdcxx-allocator=mt (on 4.0 branch
or on HEAD for linux even without it, as mt is the default there), following
testcase crashes:

cat > O.c <<EOF
#include <dlfcn.h>
#include <pthread.h>

void *
tf (void *arg)
{
  void *h = dlopen ("./libO.so", RTLD_LAZY);
  void (*fn) (void);
  if (!h) return 0;
  fn = dlsym (h, "foo");
  fn ();
  dlclose (h);
  return 0;
}

int
main (void)
{
  pthread_t th;
  pthread_create (&th, NULL, tf, NULL);
  pthread_join (th, NULL);
  return 0;
}
EOF
cat > libO.C <<EOF
#include <string>

extern "C" void
foo (void)
{
  std::string s;
  s += "hello";
}
EOF
g++ -g -O2 -shared -fpic -o libO.so libO.C
gcc -g -O2 -o O O.c -ldl -lpthread

The problem is that __gnu_cxx::__pool<true>::_M_initialize () calls
pthread_key_create but doesn't ensure pthread_key_delete is called when
libstdc++.so is unloaded.  So when glibc attempts destroys a thread or program
and calls the registered key cleanup routine (_S_destroy_thread_key), if
libstdc++.so is not mapped at that moment any longer, either whatever other
code happens to be mapped at that address is run, or the program crashes
immediately.

mt_allocator.cc should ensure that gthread_key_delete is called on the key
after all users of the key have been destroyed.

-- 
           Summary: mt allocator doesn't pthread_key_delete it's keys
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jakub at redhat dot com
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22309


^ permalink raw reply	[flat|nested] 24+ messages in thread
[parent not found: <bug-22309-138@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2006-03-03 17:55 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-05 13:54 [Bug libstdc++/22309] New: mt allocator doesn't pthread_key_delete it's keys jakub at redhat dot com
2005-07-05 16:27 ` [Bug libstdc++/22309] " pcarlini at suse dot de
2005-07-05 16:32 ` pcarlini at suse dot de
2005-07-05 16:48 ` jakub at redhat dot com
2005-07-05 16:55 ` pcarlini at suse dot de
2005-07-14 12:48 ` jakub at redhat dot com
2005-07-14 13:01 ` jakub at redhat dot com
2005-07-14 13:38 ` jakub at redhat dot com
2005-07-14 17:06 ` pinskia at gcc dot gnu dot org
2005-08-26 18:01 ` bkoz at gcc dot gnu dot org
2005-09-01 21:02 ` bkoz at gcc dot gnu dot org
2005-09-09  8:26 ` jakub at gcc dot gnu dot org
2005-09-09  9:19 ` bkoz at gcc dot gnu dot org
2005-09-09 18:21 ` bkoz at gcc dot gnu dot org
2005-09-12  4:49 ` cvs-commit at gcc dot gnu dot org
2005-09-12 19:03 ` bkoz at gcc dot gnu dot org
2005-09-13 19:40 ` bkoz at gcc dot gnu dot org
2005-09-20  5:25 ` [Bug libstdc++/22309] mt allocator doesn't pthread_key_delete its keys cvs-commit at gcc dot gnu dot org
2005-09-24 14:45 ` Woebbeking at web dot de
2005-09-26 23:03 ` bkoz at gcc dot gnu dot org
2005-09-27 14:38 ` Woebbeking at web dot de
2005-09-27 14:43 ` jakub at gcc dot gnu dot org
2005-09-28 17:16 ` Woebbeking at web dot de
     [not found] <bug-22309-138@http.gcc.gnu.org/bugzilla/>
2006-03-03 17:55 ` bkoz at gcc dot gnu dot org

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).