从 LD 隐藏共享对象中的符号

发布于 2024-07-09 20:29:02 字数 363 浏览 11 评论 0原文

我有两个第三方库偶尔会导出相同的符号名称。 当加载可执行文件时,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枕梦 2024-07-16 20:29:03

一种解决方案是将 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 set LD_PRELOAD to the list of dependent libraries, separated by spaces.)

夜夜流光相皎洁 2024-07-16 20:29:02

如果您不需要在编译时链接两个共享库(您的问题不清楚),则可以对共享库使用 -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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文