[!!Mass Mail]Strange problem which involves libpthread and link flag.

Goffredo Baroncelli kreijack@inwind.it
Thu Mar 17 15:41:00 GMT 2016


On 2016-03-17 09:39, Sergey Gvozdetskiy wrote:
> Hello, Goffredo, and everybody!
> this bug doesn't happen with libc-2.21 and gcc version 4.9.3 too.

Yes, I downgrade my libc to 2.21, and the crash doesn't happen.


[....]

> 
> Return value after execute ./boom was 36, 40, 43, etc.

This is right, the main didn't return anything, so I think that the exit value is casual

> 
> Same strace out(with minimal differents) I had, while use gcc version 5.2.1.
> Return value of it, was 0.
> 
> Ubuntu 15.10, gcc's from repo.
> 
> It for more details, may be helpful.))
> Best regards!
Thanks, so the problem seems to related to libc 2.22.x

> 
> On 03/17/2016 01:50 AM, Goffredo Baroncelli wrote:
>> 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



More information about the Libc-help mailing list