9

I'm trying to learn more about library versioning in Linux and how to put it all to work. Here's the context:

-- I have two versions of a dynamic library which expose the same set of interfaces, say libsome1.so and libsome2.so.

-- An application is linked against libsome1.so.

-- This application uses libdl.so to dynamically load another module, say libmagic.so.

-- Now libmagic.so is linked against libsome2.so. Obviously, without using linker scripts to hide symbols in libmagic.so, at run-time all calls to interfaces in libsome2.so are resolved to libsome1.so. This can be confirmed by checking the value returned by libVersion() against the value of the macro LIB_VERSION.

-- So I try next to compile and link libmagic.so with a linker script which hides all symbols except 3 which are defined in libmagic.so and are exported by it. This works... Or at least libVersion() and LIB_VERSION values match (and it reports version 2 not 1).

-- However, when some data structures are serialized to disk, I noticed some corruption. In the application's directory if I delete libsome1.so and create a soft link in its place to point to libsome2.so, everything works as expected and the same corruption does not happen.

I can't help but think that this may be caused due to some conflict in the run-time linker's resolution of symbols. I've tried many things, like trying to link libsome2.so so that all symbols are alised to symbol@@VER_2 (which I am still confused about because the command nm -CD libsome2.so still lists symbols as symbol and not symbol@@VER_2)... Nothing seems to work!!! Help!!!!!!

Edit: I should have mentioned it earlier, but the app in question is Firefox, and libsome1.so is libsqlite3.so shipped with it. I don't quite have the option of recompiling them. Also, using version scripts to hide symbols seems to be the only solution right now. So what really happens when symbols are hidden? Do they become 'local' to the SO? Does rtld have no knowledge of their existence? What happens when an exported function refers to a hidden symbol?

10
  • Have you tried at unix.stackexchange.com ? Commented Jan 11, 2011 at 17:18
  • 2
    @joksnet: I thought stackexchange was for users and not developers... This question is related to development in C++ Linux... Or am I just deluded? :) Edit: I am wrong!!! For some reason I thought stackexchange = serverfault!! I wasn't aware of unix.stackexchange.com!! Commented Jan 11, 2011 at 17:26
  • 2
    @joksnet I fail to see how a question about the technical aspects of linking isn't on topic for Stack Overflow. Commented Jan 12, 2011 at 4:56
  • 1
    I agree with Mark. I've added a bounty on to see if we can get a decent explanation. Commented Jan 13, 2011 at 20:24
  • 1
    Related background information on so numbers: unix.stackexchange.com/questions/475/… from my own question. Commented Jan 14, 2011 at 15:10

1 Answer 1

4
+100

Try compiling both libsome1.so and libsome2.so to add symbol versioning, each with their own version (use the --version-script option to ld). Then link the application and libmagic.so using the new libraries. Then, libsome1.so and libsome2.so should be completely separate.

Problems can still occur if there are unversioned references to symbols. Such references can be satisfied by versioned definitions (so that it is possible to add symbol versioning to a library without breaking binary compatibility). If there are multiple symbols of the same name, it can sometimes be hard to predict which one will be used.

Regarding tools, nm -D does not display any information about symbol versioning. Try objdump -T or readelf -s instead.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the info. I did learn something new! I probably should've mentioned it earlier, but the app in question is Firefox and libsome1.so is libsqlite3.so shipped with it. So there's no way I have the option of recompiling them. However I did try your solution on minimalist sample I had created to model the situation... And it worked!
I'm awarding you the bounty. I think this is well deserved; your answer is good. Have some more rep!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.