is pthread in glibc.so implemented by weak symbol to provide pthread stub functions?
I know there is pthread.so t
See this SO answer. Several techniques can be used to allow the same symbol to be defined in multiple libraries against which a program is being linked, depending on whether dynamic or static linking is being used.
Symbol Interposition. When dynamic linking, if a symbol is defined in multiple libraries, then the linker will use the first version it finds (unless the symbols is internal, hidden or protected; see this blog article for a description of that)
Weak Objects. When static linking, if the linker finds two symbols of the same name, and one is a 'weak' reference, then the linker will use the non-weak reference.
Symbol versioning may also play a role.
In almost all cases, programs are dynamically linked to libc.
You can see the order in which the libs will be loaded using ldd:
$ ldd simple_pthread
linux-vdso.so.1 => (0x00007fffaddff000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fa13a474000)
libc.so.6 => /lib64/libc.so.6 (0x00007fa13a0e0000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa13a6a0000)
Here you can see that libpthread is before libc in the linking order. This is almost always going to be the case; libc is always linked last using default compiler options.
So, a program which is linked against libpthread will use the pthread versions of these symbols, since they are encountered first in the linking order.
If you are still unsure, starting your program with the environment variable LD_DEBUG set to 'bindings' will show the actual symbol bindings that are occurring.
If you are using static linking, you would be linking against libc.a instead of libc.so. You can use 'nm' to list details of the symbol. Weak symbols have a 'W' or 'w' for their type.
(Credit to @Kaz for pointing out that weak symbols to not affect dynamic linking).