"Mike McTernan" <mmcternan@xxxxxxxxxxx> writes: > I'm trying to wrap the functions in a library and having some problems > when static linking with GNU ld version 2.17. > > The setup is that the library (actually linuxthreads) exports a bunch of > functions, but also makes use of some of its own functions internally > (mainly pthread_cond funcs). The problem is that I only want to wrap > the functions as used by the external API, and not the internal usage so > as not to harm internal operations. > > What I'd therefore like to do is get ld to resolve all references that > can be satisfied within the .a file itself as a first step, and to then > perform a link with the --wrap's and my application code. > > I've been trying to use "ld -r libpthread.a -o n.a" and various other > options to try and resolve the internal references for a first pass, but > the output always comes out as a tiny file having been stripped of > symbols. > > Are there any pointers or ideas as to how I can get this working? I don't think there is any way to do what you want with static linking short of editing the source code to call __real_FUNCTION rather than FUNCTION. If you can use a shared library, you could link it with -Bsymbolic, and then use a different forwarder library which exported the symbols and dlopen'ed the real library to get the real functions to call from the wrapping function. Ian