On Fri, Jan 29, 2010 at 9:54 AM, John David Anglin <dave@xxxxxxxxxxxxxxxxxx> wrote: > Think you missed that I said the application was being linked with > -static. As a result, pthread_create.o won't be loaded from libpthread.a > just to resolve __nptl_nthreads. I linked with -static, and it was resolved to pthread_create.o from libpthread.a. However, my application called pthread_create *before* calling pthread_exit. > This is the application: > > // This test only applies to glibc (NPTL) targets. > // { dg-do run { target *-*-linux* } } > // { dg-options "-pthread" } > > #include <pthread.h> > #include <cxxabi.h> > extern "C" int printf (const char *, ...); > > int main() > { > try > { > pthread_exit (0); > } > catch (abi::__forced_unwind &) > { > printf ("caught forced unwind\n"); > throw; > } > catch (...) > { > printf ("caught ...\n"); > return 1; > } > } > > This is the gcc link command: > > /home/dave/gnu/gcc/objdir/gcc/testsuite/g++/../../collect-ld -static -o ./forced.xgs /usr/lib/crt1.o /usr/lib/crti.o /home/dave/gnu/gcc/objdir/gcc/testsuite/g++/../../crtbeginT.o -L/home/dave/gnu/gcc/objdir/hppa-linux/./libstdc++-v3/src/.libs -L/home/dave/gnu/gcc/objdir/hppa-linux/./libstdc++-v3/src/.libs -L/home/dave/gnu/gcc/objdir/hppa-linux/./libiberty -L/home/dave/gnu/gcc/objdir/gcc/testsuite/g++/../.. -L/home/dave/gnu/gcc/objdir/hppa-linux/./libstdc++-v3/src/.libs /tmp/ccmLwpAe.o -lstdc++ -lm --start-group -lgcc -lgcc_eh -lpthread -lc --end-group /home/dave/gnu/gcc/objdir/gcc/testsuite/g++/../../crtend.o /usr/lib/crtn.o > > Compile with: > > g++ -o xx -static -pthread xx.C > > Given what you said, the same fault would likely occur on x86. This isn't supported by glibc. You must pull in pthread_create.o if you call pthread_exit(). Otherwise nothing defines __nptl_nthreads. This test crashes on x86. carlos@crasus:~$ readelf -a test | grep __nptl_nthreads 1863: 00000000 0 NOTYPE WEAK DEFAULT UND __nptl_nthreads carlos@crasus:~$ ./test caught forced unwind Segmentation fault I don't know why it crashes so late on x86, perhaps during another operation that manipulate ptr_nthreads? We blow up in nptl-ini.c during the static initialization that sets ptr_nthreads to &__nptl_nthreads e.g. ~~~ static const struct pthread_functions pthread_functions = { .ptr_pthread_attr_destroy = __pthread_attr_destroy, ... .ptr_nthreads = &__nptl_nthreads, .ptr___pthread_unwind = &__pthread_unwind, .ptr__nptl_deallocate_tsd = __nptl_deallocate_tsd, .ptr__nptl_setxid = __nptl_setxid, /* For now only the stack cache needs to be freed. */ .ptr_freeres = nptl_freeres }; ~~~ This is technically a generic glibc bug. Does linking with `-u pthread_create` fix the testcase? It fixes the failure on x86. Cheers, Carlos. -- To unsubscribe from this list: send the line "unsubscribe linux-parisc" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html