On Tue, 7 Apr 2015, Martijn van Duren wrote: > I'm currently experimenting with weak symbols for a library that I want > to be thread safe without hard linking in the entire libpthread. > > To test this I've set up the following code: ... > When compiling with pthread it seems it only resolves > pthread_mutex_init, but still uses the weak pthread_create and executes > secondary lock first: ... > Could someone please elaborate on what I'm doing wrong and how to implement > these weak symbols properly. Thank you in advance.
If the symbol is defined in the base executable, then it cannot be overriden by a shared library, regardless of its binding (global or weak) in the executable. Indeed, the reference will be resolved when the executable is created, leaving no relocation dependent on the symbol definition. If you want to work with symbol interposition like this, you'll need to actually build shared libraries. Philip Guenther

