Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 43591 - Segmentation fault in __errno_location when linking with -static and -lpthread
Summary: Segmentation fault in __errno_location when linking with -static and -lpthread
Status: RESOLVED WORKSFORME
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Development (show other bugs)
Hardware: x86 Linux
: High normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-03-03 04:42 UTC by Peter Boros
Modified: 2006-01-16 01:52 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Boros 2004-03-03 04:42:41 UTC
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)
Comment 1 SpanKY gentoo-dev 2004-05-05 20:52:31 UTC
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 ...
Comment 2 Siarhei Siamashka 2004-10-09 07:19:30 UTC
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"
Comment 3 Siarhei Siamashka 2004-11-19 09:04:33 UTC
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?
Comment 4 SpanKY gentoo-dev 2004-11-23 21:39:39 UTC
still occurs with gcc-3.4.3 and glibc-2.3.4.20041006
Comment 5 SpanKY gentoo-dev 2005-04-27 15:10:26 UTC
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 ?
Comment 6 Siarhei Siamashka 2005-05-05 03:05:07 UTC
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
Comment 7 SpanKY gentoo-dev 2005-10-04 21:55:05 UTC
first test case still segfaults on x86 with:
binutils 2.16.1
gcc 3.4.4
glibc 2.3.5
Comment 8 Mark Loeser (RETIRED) gentoo-dev 2006-01-15 20:26:53 UTC
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
Comment 9 SpanKY gentoo-dev 2006-01-16 01:52:06 UTC
no longer able to reproduce in my x86 chroot with gcc-3.4.4/binutils-2.16.1/glibc-2.3.5