Bugzilla will be upgraded to version 5.0. The upgrade date is tentatively scheduled for 2 December 2018, pending final testing and feedback.
Bug 163083 - Statically linked C++ program using pthreads will segfault
Statically linked C++ program using pthreads will segfault
Status: CLOSED DUPLICATE of bug 115157
Product: Fedora
Classification: Fedora
Component: gcc (Show other bugs)
i386 Linux
medium Severity low
: ---
: ---
Assigned To: Jakub Jelinek
Depends On:
  Show dependency treegraph
Reported: 2005-07-12 15:31 EDT by Jason Beardsley
Modified: 2007-11-30 17:11 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2005-07-13 07:54:08 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 Jason Beardsley 2005-07-12 15:31:01 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511

Description of problem:
A C++ program that uses pthreads and the STL (or string) will segfault.  If no STL header is included, the program does not crash.

This is apparently due to certain pthreads functions not being included in the output executable.  This bug may duplicate #115157, and I apologize if so, but hopefully the included test case will be useful.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:

#include <pthread.h>
#include <string> // or <list> or <vector> etc
int main()
  pthread_mutex_t lock;
  pthread_mutex_init(&lock, NULL);
  return 0;

1. Compile as follows: g++ -g -static foo.cpp -o foo -lpthread
2. Run it in gdb.
3. Note the address of pthread_mutex_init is 0.

Actual Results:  GNU gdb Red Hat Linux (
This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) run
Starting program: /home/jason/t/foo
Reading symbols from shared object read from target memory...done.
Loaded system supplied DSO at 0xad7000

Program received signal SIGSEGV, Segmentation fault.
0x00000000 in ?? ()
(gdb) where
#0  0x00000000 in ?? ()
#1  0x08048232 in main () at foo.cpp:7

Expected Results:  No segfault

Additional info:

The suggestion in #115157 to forcibly link in all of libpthread.a is a valid workaround.

Linking dynamically also avoids the problem, however this is not possible in certain situations (e.g. creating a profiled executable requires static linking to be useful).
Comment 1 Jakub Jelinek 2005-07-13 07:54:08 EDT
Yes, this is a dup of #115157.

*** This bug has been marked as a duplicate of 115157 ***

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