Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide symbol(s) in Shared Object from LD

I have two third-party libraries occasionally having the same symbol name exported. When the executable is loaded, ld usually picks the wrong one and I getting crash as a result. I cannot do too much about the content of these libraries, so may be there is a way to instruct ld how to find the proper imlementation ?

OS - Solaris 10, my program is built by autoconf/autotools/gcc, conflicting libraries are libclntsh (part of Oracle driver) and OpenLDAP. Unfortuinately, I cannot use Oracle's implementation of LDAP client - it lacks many features OpenLDAP has.

Edited: The linkage is as following: libclntsh.so->A.so->MAIN<-B.so<-libldap_r.so

like image 523
Dmitry Khalatov Avatar asked Dec 02 '08 19:12

Dmitry Khalatov


2 Answers

If you don't need to link in both shared libraries at compile time (which isn't clear from your question), you can use -Bdirect for the shared library. This will record for all symbols from the shared library where they had been found; if then at run-time a second definition of the symbol appears (from the other shared library), it will be ignored.

like image 74
Martin v. Löwis Avatar answered Sep 19 '22 11:09

Martin v. Löwis


One solution is to set the LD_PRELOAD environment variable to the library whose symbols should take precedence. (If that library has shared library dependencies of its own, you may need to preload all of its dependencies; just set LD_PRELOAD to the list of dependent libraries, separated by spaces.)

like image 20
Josh Kelley Avatar answered Sep 23 '22 11:09

Josh Kelley