I have a question: if we have an application that does not use threads, we can link it in two ways:
1) Link, as usual, without -lpthread and -ldl
2) Add two libraries to the link: libpthread and libdl.
eg.
$ cat ac int main(){printf("Hehe");} $ gcc ac -w -oa $ gcc ac -w -o a1 -ldl -lpthread
By default, both libraries are dynamically linked:
$ ldd a linux-gate.so.1 libc.so.6 /lib/ld-linux.so.2 $ ldd a1 linux-gate.so.1 libdl.so.2 libpthread.so.0 libc.so.6 /lib/ld-linux.so.2
How much difference will there be between version a and version a1 ? What will work differently inside the application and int glibc? Will binding pthreads change anything internally from unsafe to thread safe?
eg.
$ strace ./a 2>&1 |wc -l 73 $ strace ./a1 2>&1 |wc -l 103
In trace a1, two additional libraries are loaded, a few more mprotect called, and a section is added:
set_tid_address; set_robust_list; rt_sigaction x 2; rt_sigprocmask; getrlimit; uname
linux pthreads glibc
osgx Jun 07 2018-11-11T00: 00Z
source share