Red Hat Bugzilla – Bug 163083
Statically linked C++ program using pthreads will segfault
Last modified: 2007-11-30 17:11:09 EST
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):
Steps to Reproduce:
#include <string> // or <list> or <vector> etc
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 (188.8.131.52-1.21rh)
This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1".
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 ?? ()
#0 0x00000000 in ?? ()
#1 0x08048232 in main () at foo.cpp:7
Expected Results: No segfault
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).
Yes, this is a dup of #115157.
*** This bug has been marked as a duplicate of 115157 ***