Hide symbol(s) in Shared Object from LD

99封情书 提交于 2020-01-01 05:05:29

问题


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


回答1:


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.




回答2:


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.)



来源:https://stackoverflow.com/questions/335108/hide-symbols-in-shared-object-from-ld

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!