Bug 76196

Summary: programs statically linked against libpthread.a crash soon after startup
Product: [Retired] Red Hat Linux Reporter: Mark Fasheh <mark.fasheh>
Component: glibcAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: Brian Brock <bbrock>
Severity: medium Docs Contact:
Priority: medium    
Version: 8.0CC: fweimer
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2002-10-18 01:42:26 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Mark Fasheh 2002-10-18 01:42:19 UTC
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));
    return(1);
   }
  printf("Hello World!\n");
  printf("pi = %.5f\n", 4 * atan(1.0));
  sem_destroy(&sem);
  return(0);
}


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


How reproducible:
Always

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 07:34:48 UTC
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-19 00:35:39 UTC
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...