Bugzilla will be upgraded to version 5.0. The upgrade date is tentatively scheduled for 2 December 2018, pending final testing and feedback.
Bug 76196 - programs statically linked against libpthread.a crash soon after startup
programs statically linked against libpthread.a crash soon after startup
Product: Red Hat Linux
Classification: Retired
Component: glibc (Show other bugs)
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
Depends On:
  Show dependency treegraph
Reported: 2002-10-17 21:42 EDT by Mark Fasheh
Modified: 2016-11-24 10:01 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2002-10-17 21:42:26 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Mark Fasheh 2002-10-17 21:42:19 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20020830

Description of problem:
When compiling a simple test program and statically linking it against the
pthreads library, the compile goes fine, but the program seg faults. Doing the
exact same thing on an older redhat (AS2.1) and a debian system (both have an
older glibc version) produces no problems - the program runs fine. Additionally,
I get the same error doing this on a debian system with glibc 2.3.

I'm compiling the software like so: 
gcc -D_REENTRANT main.c /usr/lib/libpthread.a -ggdb -lm

Below is a sample program to reproduce the bug:
#include <stdio.h>
#include <math.h>
#include <semaphore.h>
#include <string.h>
#include <errno.h>

int main(int argc, char **argv) {
  sem_t sem;

  if (sem_init(&sem, 0, 1) == -1) {
    printf("error initializing semaphore: %s\n", strerror(errno));
  printf("Hello World!\n");
  printf("pi = %.5f\n", 4 * atan(1.0));

Version-Release number of selected component (if applicable):
rpm -qif /usr/lib/libpthread.a tells me "glibc-devel" "2.2.93                  

How reproducible:

Steps to Reproduce:
1. Compile program above with "gcc -D_REENTRANT main.c /usr/lib/libpthread.a
-ggdb -lm"
2. Run it. "./a.out"
3. Watch it crash	

Actual Results:  segmentation fault after printing 'hello world'

Expected Results:  expect program to run to completion.

Additional info:
Comment 1 Jakub Jelinek 2002-10-18 03:34:48 EDT
That's expected. You cannot statically link libpthread and dynamically
libc or vice versa, both have to be dynamically linked or both have to be
linked statically.
Comment 2 Mark Fasheh 2002-10-18 20:35:39 EDT
Why should this be expected behavior? I see no technical reason why one could
not be linked differently than the other. I've done this with no problem against
older versions of glibc with no issues... Yes, I know they're somewhat
integrated but there are plenty of parts of pthreads which are seperate from the
rest of glibc...

Note You need to log in before you can comment on or make changes to this bug.