从 LD 隐藏共享对象中的符号
我有两个第三方库偶尔会导出相同的符号名称。 当加载可执行文件时,ld 通常会选择错误的文件,从而导致崩溃。 我无法对这些库的内容做太多的事情,所以可能有一种方法可以指导 ld 如何找到正确的实现?
操作系统 - Solaris 10,我的程序是由 autoconf/autotools/gcc 构建的,冲突的库是 libclntsh(Oracle 驱动程序的一部分)和 OpenLDAP。 不幸的是,我无法使用 Oracle 的 LDAP 客户端实现 - 它缺乏 OpenLDAP 的许多功能。
编辑:链接如下:libclntsh.so->A.so->MAIN<-B.so<-libldap_r.so
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种解决方案是将
LD_PRELOAD
环境变量设置为其符号应优先的库。 (如果该库有自己的共享库依赖项,您可能需要预加载其所有依赖项;只需将 LD_PRELOAD 设置为依赖库列表,并用空格分隔。)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 setLD_PRELOAD
to the list of dependent libraries, separated by spaces.)如果您不需要在编译时链接两个共享库(您的问题不清楚),则可以对共享库使用
-Bdirect
。 这将记录共享库中找到它们的所有符号; 如果在运行时出现该符号的第二个定义(来自其他共享库),它将被忽略。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.