0

I have two shared libraries. A lib loads lib B by using dlopen.

They implement same set of APIs.

My client running on the same system, when it tries to access the API which library it is going to load?

Or this is an invalid thing to do ? I have to make B a static library.

My goal is to have client only access lib A.

Jens Gustedt
  • 76,821
  • 6
  • 102
  • 177

1 Answers1

0

Are you in control of the client (i.e., you can recompile it)? If so, you can just specify library A when linking; then it will be A's care to dlopen B.

If you are trying to hijack a call to function foo in B, then your client is trying to load library B. You can use LD_PRELOAD to force it to load library A instead. Then the client will issue a call to foo() and it will be answered by A, which will be able to route the call to foo()@B after modifying, altering, and/or logging both input values and returned values.

You call your client with LD_PRELOAD=B.so ./client instead of ./client.

LSerni
  • 55,617
  • 10
  • 65
  • 107