The following program crashes with SIGSEGV when linked with -static and -lpthread: #include <errno.h> #include <stdio.h> int main () { printf("Hello world, %d!\n",errno); return 0; } Linked without the ptread library and/or linking dynamically there is no problem. Tested with gcc versions 2.95.3-r8, 3.2.3-r3 and 3.3.2-r5, and glibc versions 2.3.2-r3, 2.3.2-r9 and 2.3.3_pre20040207. (gcc-3.3.x with glibc 2.3.2 on a Debian system works fine.) Reproducible: Always Steps to Reproduce: 1. gcc -static -o test test.c -lpthread 2. ./test 3. Actual Results: piglet:~/work/pthread-bug% gcc -static -o test test.c -lpthread piglet:~/work/pthread-bug% ./test Segmentation fault (core dumped) Expected Results: piglet:~/work/pthread-bug% gcc -static -o test test.c piglet:~/work/pthread-bug% ./test Hello world, 0! Backtrace from gdb: Program terminated with signal 11, Segmentation fault. #0 0x08048247 in __errno_location () (gdb) bt #0 0x08048247 in __errno_location () #1 0x08048229 in main () (gdb)
x86/gcc-3.4.0/glibc-2.3.3_pre20040420 = works hppa/gcc-3.3.2/glibc-2.3.2-r10 = segfault arm/gcc-3.3.3-r4/glibc-2.3.2-r10 = work i wonder if it's the gcc-3.3.2 doing it ...
I have a similar problem with a bit different test program: #include <pthread.h> pthread_key_t key; int main() { pthread_key_create(&key, NULL); return 0; } It crashes when compiled statically: # gcc -o test test.cpp -static -pthread # ./test Segmentation fault I have upgraded glibc to ~x86 to check if this bug disappears, but it is still here. # emerge info Gentoo Base System version 1.4.16 Portage 2.0.50-r11 (default-x86-1.4, gcc-3.3.4, glibc-2.3.4.20040808-r1, 2.6.7-gentoo-r14) ================================================================= System uname: 2.6.7-gentoo-r14 i686 AMD Duron(tm) processor distcc 2.16 i686-pc-linux-gnu (protocols 1 and 2) (default port 3632) [disabled] Autoconf: sys-devel/autoconf-2.59-r4 Automake: sys-devel/automake-1.8.5-r1 ACCEPT_KEYWORDS="x86" AUTOCLEAN="yes" CFLAGS="-Os -march=athlon-tbird -fomit-frame-pointer -pipe" CHOST="i686-pc-linux-gnu" COMPILER="" CONFIG_PROTECT="/etc /usr/X11R6/lib/X11/xkb /usr/kde/2/share/config /usr/kde/3.2/share/config /usr/kde/3.3/env /usr/kde/3.3/share/config /usr/kde/3.3/shutdown /usr/kde/3/share/config /usr/lib/mozilla/defaults/pref /usr/share/config /var/qmail/control" CONFIG_PROTECT_MASK="/etc/gconf /etc/terminfo /etc/env.d" CXXFLAGS="-Os -march=athlon-tbird -fomit-frame-pointer -pipe" DISTDIR="/usr/portage/distfiles" FEATURES="autoaddcvs ccache sandbox" GENTOO_MIRRORS="http://gentoo.osuosl.org http://distro.ibiblio.org/pub/Linux/distributions/gentoo" MAKEOPTS="-j1" PKGDIR="/usr/portage-packages" PORTAGE_TMPDIR="/var/tmp" PORTDIR="/usr/portage" PORTDIR_OVERLAY="/usr/portage-overlay" SYNC="rsync://rsync.gentoo.org/gentoo-portage" USE="X alsa apache2 apm arts avi berkdb bitmap-fonts cdr crypt esd f77 fbcon flac foomaticdb gd gdbm gif gnome gpm gtk gtk2 guile icq imlib java jpeg kde ldap libwww mad mikmod mmx motif mozilla mpeg mysql ncurses nls nptl oggvorbis opengl pam pdflib perl png python qt quicktime readline ruby samba sdl slang spell sqlite ssl tcltk tcpd truetype x86 xml2 xmms xprint xv zlib"
Looks like static linking is severely broken. Just look at the following bugreport too: http://bugs.gentoo.org/show_bug.cgi?id=69194 By the way, static linking is very important for developers who need to provide linux binaries. Read some user comments here regarding the need of static binaries: http://happypenguin.org/show?UFO2000&showall=1#comments So I think that fixing this bug is fairly important. Could anyone with enough skills about this build tools kitchen try to fix it please?
still occurs with gcc-3.4.3 and glibc-2.3.4.20041006
both test cases now work for me with this toolchain combination: amd64 gcc-3.4.3-20050110 glibc-2.3.5 binutils-2.15.92.0.2-r8 can someone verify with a current stable x86 system ?
x86 gcc-3.3.5.20050130-r1 glibc-2.3.4.20041102-r1 binutils-2.15.92.0.2-r7 first testcase: segmentation fault second testcase: ok
first test case still segfaults on x86 with: binutils 2.16.1 gcc 3.4.4 glibc 2.3.5
Both of these still fail on stable: gcc-3.4.4, glibc-2.3.5-r2, binutils-2.16.1. Seems to work fine with this combination: gcc-4.0.2-r3, glibc-2.3.6-r2, binutils-2.16.1-r1
no longer able to reproduce in my x86 chroot with gcc-3.4.4/binutils-2.16.1/glibc-2.3.5