Linking to multiple libraries, one of which wraps a set of system calls

c, ld, linker, linux, posix

Solution

If `A` is linked with `-wrap=write`, `foo` will call the wrapper. If it's not, it won't.

The same is true about calls to `write` in `C`. There's no difference whatsoever between `A` and `C` as far as calling `write` is concerned.

Problem

So this is the scenario that I'm looking at: I have 3 libraries - A, B and C. - Library A implements function `foo()` and exposes it as an API. - Function `foo()` calls the POSIX `write()` call to write some data. - Library B writes a wrapper to the `write()` glibc call using the linker -wrap option. - Library C links to both A and B. Any `write()` call that the library C makes will get intercepted by the wrapper library B. But, my question is, if library C calls `foo()`, will the `write()` call inside foo() get intercepted by B?

Original source

Related problems