1

I have a program that is linked against a (shared) library libFoo.so. Now I needed to write a patched version of that library. Call it libFooPatch although the name will be libFoo.so too. This one defines an additional weak symbol Init.

First scenario (just for clarification):
Now suppose I would have implemented "Init" in the program. At runtime libFooPatch is loaded through LD_LIBRARY_PATH.
If the program was linked against libFoo calling "Init" from libFooPatch causes it to call only the weak referenced version, not the one from the program. Linking it against libFooPatch fixes that and it works without any problems.
1) But why is that? Shouldn't at runtime the strong referenced "Init" from the program be called?

Now the real problem (2nd scenario):
I cannot change the program itself. It does not define "Init" and is linked against libFoo. I can change libFooPatch which is still instead of libFoo by placing it into LD_LIBRARY_PATH.
I want to write a (shared) library libBar that is used in the program (most probably by dlopen), defines "Init" as a strong symbol and make libFooPatch call this one.
However I can't get it to work. My own Init function is never called and even obtaining a pointer within libBar gets me only the weak one from libFooPatch.

"nm libBar.so" returns "0000000000000eb0 T Init" so it is correctly defined there, isn't it?

Any pointers how I can get this to work?

Flamefire
  • 5,313
  • 3
  • 35
  • 70
  • Either the program defines `Init` or it doesn't, but you seem to change your mind about that several times in this question... – Lightness Races in Orbit Dec 03 '13 at 17:02
  • Consider exporting LD_LIBRARY_PATH then running code that uses libFoo. Place your new libFoo in /usr/local/lib or some other harmless place. – jim mcnamara Dec 03 '13 at 17:02
  • There are 2 separate scenarios. I changed the question to make that clear. Difference is that either the program or another shared lib defines init. @jimmcnamara As mentioned above LD_LIBRARY_PATH is already used for loading libFooPatch instead of the original one. – Flamefire Dec 04 '13 at 12:47

0 Answers0