This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: static linking of pthread crashes with segfault
- From: Ian Lance Taylor <iant at google dot com>
- To: "Klaus Rudolph" <lts-rudolph at gmx dot de>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 03 May 2010 20:37:02 -0700
- Subject: Re: static linking of pthread crashes with segfault
- References: <20100503093748.258070@gmx.net> <l2u4348dea51005030610ucd8d56b6h842ed03a024a6bcf@mail.gmail.com> <20100503140442.249400@gmx.net>
"Klaus Rudolph" <lts-rudolph@gmx.de> writes:
> I tried to link a pthread application with -static and run into a segfault on x86, same on powerpc.
>
> I tried gcc 4.4.2 (linux/x86) and 4.0.2 for powerpc-unknown-linux-gnu
>
>
>
> For the x86 linux example I got in gdb:
> (gdb) bt
> #0 0x00000000 in ?? ()
> #1 0x08094d49 in __cxa_guard_release ()
This can happen when libstdc++ is configured without __thread support
and you statically link against -lpthread. The basic bug is that the
libstdc++ configure.ac only uses GCC_CHECK_TLS when configured native.
I thought this had been fixed, but perhaps not. There is a note on it
here: http://gcc.gnu.org/ml/libstdc++/2008-09/msg00003.html .
Assuming you are using a kernel which supports TLS (2.6.0 or later),
then one fix is to explicitly use --enable-tls when configuring gcc.
Another fix is to use -Wl,--whole-archive -lpthread
-Wl,--no-whole-archive when linking.
Ian