Loading multiple shared libraries with different versions
Asked Answered
A

2

16

I have an executable on Linux that loads libfoo.so.1 (that's a SONAME) as one of its dependencies (via another shared library). It also links to another system library, which, in turn, links to a system version, libfoo.so.2. As a result, both libfoo.so.1 and libfoo.so.2 are loaded during execution, and code that was supposed to call functions from library with version 1 ends up calling (binary-incompatible) functions from a newer system library with version 2, because some symbols stay the same. The result is usually stack smashing and a subsequent segfault.

Now, the library which links against the older version is a closed-source third-party library, and I can't control what version of libfoo it compiles against. Assuming that, the only other option left is rebuilding a bunch of system libraries that currently link with libfoo.so.2 to link with libfoo.so.1.

Is there any way to avoid replacing system libraries wiith local copies that link to older libfoo? Can I load both libraries and have the code calling correct version of symbols? So I need some special symbol-level versioning?

Addressee answered 23/10, 2008 at 0:59 Comment(3)
Alex: how did you solve the problem? could you please share it with us?Pug
@Nawaz I don't remember exactly, it has been 9 years ago! I think I gave up and made it so that only one version of the library is loaded.Addressee
Alex, this article talks about this problem and have also suggested a solution. I've not tried it yet. But it's interesting to know/explore.Pug
T
8

You may be able to do some version script tricks:

http://sunsite.ualberta.ca/Documentation/Gnu/binutils-2.9.1/html_node/ld_26.html

This may require that you write a wrapper around your lib that pulls in libfoo.so.1 that exports some symbols explicitly and masks all others as local. For example:

MYSYMS { global: foo1; foo2; local: *; };

and use this when you link that wrapper like:

gcc -shared -Wl,--version-script,mysyms.map -o mylib wrapper.o -lfoo -L/path/to/foo.so.1

This should make libfoo.so.1's symbols local to the wrapper and not available to the main exe.

Transcalent answered 24/10, 2008 at 16:15 Comment(0)
D
0

I can only come up with a work-around. Which would be to statically link a version of the "system library" that you are using. For your static build, you could make it link against the same old version as the third-party library. Given that it does not rely on the newer version...

Perhaps it is also possible to avoid these problems with not linking to the third-party library the ordinary way. Instead, your program could load it at execution time. Perhaps then it could be shadowed against the rest. But I don't know much about that.

Design answered 23/10, 2008 at 1:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.