Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 571
crazyg33k Avatar asked Sep 21 '12 19:09

crazyg33k


1 Answers

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.

like image 66
n. 1.8e9-where's-my-share m. Avatar answered Nov 15 '22 23:11

n. 1.8e9-where's-my-share m.