I have a question: if we have an application, which uses no threads, we can link it in two ways:
1) Link as usual, without -lpthread
and -ldl
2) Add to the link two libraries: libpthread and libdl.
E.g.
$ cat a.c
int main(){printf("Hehe");}
$ gcc a.c -w -o a
$ gcc a.c -w -o a1 -ldl -lpthread
By default, both libs 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 be there between version a
and version a1
? What will be working in different way inside application itself and int glibc ? Will linking of pthreads change something inside from thread-unsafe to thread-safe algorithm?
E.g.
$ strace ./a 2>&1 |wc -l
73
$ strace ./a1 2>&1 |wc -l
103
In a1 trace, two additional libs are loaded, some more mprotect
s are called, and added section of:
set_tid_address; set_robust_list; rt_sigaction x 2; rt_sigprocmask; getrlimit; uname