Bug 76196 - programs statically linked against libpthread.a crash soon after startup
Summary: programs statically linked against libpthread.a crash soon after startup
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: glibc
Version: 8.0
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2002-10-18 01:42 UTC by Mark Fasheh
Modified: 2016-11-24 15:01 UTC (History)
1 user (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2002-10-18 01:42:26 UTC
Embargoed:


Attachments (Terms of Use)

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...


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