将符号限制为linux可执行文件的本地作用域 [英] Restricting symbols to local scope for linux executable

查看:83
本文介绍了将符号限制为linux可执行文件的本地作用域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以提出一些建议,限制我们将符号导出到全局符号表吗?

Can anyone please suggest some way we can restrict exporting of our symbols to global symbol table?

预先感谢

感谢您的回复...

实际上,我有一个静态链接到第三方库的可执行文件,例如"ver1.a",并且还使用了第三方".so"文件,该文件再次链接到相同的库,但版本不同,却说"ver2.a" .问题是这两个版本的实现都不相同.开始时,加载可执行文件时,"ver1.a"中的符号将被导出到全局符号表中.现在,无论何时加载".so",它都将尝试引用来自ver2.a的符号,最终将引用先前加载的来自"ver1.a"的符号.因此,我们的二进制文件崩溃了.

Actually I have an executable which is statically linked to a third party library say "ver1.a" and also uses a third party ".so" file which is again linked with same library but different version say "ver2.a". Problem is implementation of both these versions is different. At the beginning, when executable is loaded, symbols from "ver1.a" will get exported to global symbol table. Now whenever ".so" is loaded it will try to refer to symbols from ver2.a, it will end up referring to symbols from "ver1.a" which were previously loaded.Thus crashing our binary.

我们想到了一个解决方案,我们不会将可执行文件的符号导出到全局符号表,因此,当加载".so"并尝试使用ver2.a中的符号时,它将不会在全局符号表中找到它将使用自己的符号,即来自ver2.a的符号

we thought of a solution that we wont be exporting the symbols for executable to Global symbol table, thus when ".so" gets loaded and will try to use symbols from ver2.a it wont find it in global symbol table and it will use its own symbols i.e symbols from ver2.a

我找不到任何方法可以限制将符号导出到全局符号表.我尝试了--version-script和keep-symbol-file,但是没有用.对于-fvisibility = hidden选项,其错误提示"-f选项只能与-shared一起使用".因此,我想,-version-script"也仅适用于共享库,而不适用于可执行二进制文件.

I cant find any way by which i can restrict exporting of symbols to global symbol table. I tried with --version-script and retain-symbol-file, but it didn't work. For -fvisibility=hidden option, its giving an error that " -f option may only be used with -shared". So I guess, this too like "--version-script" works only for shared libraries not for executable binaries.

代码在c ++,OS-Linux,gcc版本3.2中.可能无法重新编译任何第三方库和".so".因此,排除了使用bsymbolic标志重新编译"so"文件的选项.

code is in c++, OS-Linux, gcc version-3.2. It may not be possible to recompile any of the third party libraries and ".so"s. So option of recompiling "so' file with bsymbolic flag is ruled out.

任何帮助将不胜感激.

推荐答案

使用dlopen拉入第三方库.

Pull in the 3rd party library with dlopen.

通过创建隐藏所有第三方符号并仅向其公开自己的API的共享库,您也许能够避免这种情况,但是dlopen可以完全控制您.

You might be able to avoid that by creating your own shared lib that hides all the third party symbols and only exposes your own API to them, but if all else fails dlopen gives you complete control.

这篇关于将符号限制为linux可执行文件的本地作用域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆