This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Strange problem which involves libpthread and link flag.
- From: Goffredo Baroncelli <kreijack at inwind dot it>
- To: libc-help at sourceware dot org
- Date: Wed, 16 Mar 2016 23:50:05 +0100
- Subject: Strange problem which involves libpthread and link flag.
- Authentication-results: sourceware.org; auth=none
- Reply-to: kreijack at inwind dot it
Hi All,
I hope that this is the right place where post this kind of question. If this is not the case, sorry for the inconvenience and please give me a suggestion where I have to put this question.
Investigating the reason why mosh crashed on my debian machine [*], I was able to create a test case to reproduce the crash.
I have to point out that the problem which I found was not related to mosh, but (I suppose) to a strange interaction between some linker flag and the using of the pthread library.
$ cat boom.c
extern void dofork();
int main() {
dofork();
}
$ cat dofork.c
#include <unistd.h>
void dofork() {
fork();
}
$ gcc -fPIC -c dofork.c
$ gcc -shared -Wl,-z,now -o libdofork.so dofork.o
$ gcc -o boom boom.c -lpthread -L$(pwd) -ldofork
$ LD_LIBRARY_PATH=$(pwd) ./boom
Segmentation fault
$ LD_LIBRARY_PATH=$(pwd) ldd ./boom linux-vdso.so.1 (0x00007ffe817dc000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f16b38ed000)
libdofork.so => /home/ghigo/mosh/libdofork.so (0x00007f16b36ec000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f16b3347000)
/lib64/ld-linux-x86-64.so.2 (0x0000562eba12a000)
$ dpkg --list | grep libc6
ii libc6:amd64 2.22-3
I was able to reproduce this bug also in a Fedora F23 machine (=libc 2.22). The bug happens even with different compiler versions (gcc-4.8, gcc-6, gcc-5.3, clang-3.8). In another regular debian machine equipped with libc-2.19 the crash doesn't happen. All the machines tested are linux x86-64.
In order to reproduce this problem:
- use the "-Wl,-z,now" in the shared library
- put fork() in the shared library
- compile the main program with "-lpthread" before the "-l<shared library>" (the order matters !)
So my questions are:
- I am wrong to suppose that this code should not crash ?
- I know that -lpthread is not needed, but is it forbid to use it even if not needed ? With -pthread only, the code works without problem (mosh too !)
- Could the problem be libc/pthread related ?
BR
G.Baroncelli
[*] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=817929
mosh problem
--
gpg @keyserver.linux.it: Goffredo Baroncelli <kreijackATinwind.it>
Key fingerprint BBF5 1610 0B64 DAC6 5F7D 17B2 0EDA 9B37 8B82 E0B5