静态库两次加载 [英] Static library loaded twice

查看:520
本文介绍了静态库两次加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的共享对象A.so其中静态链接到libssl.a&安培;另一个共享对象B.so也静态链接libssl.a。

I have shared object A.so which statically links to libssl.a & another shared object B.so which also statically links libssl.a .

&A.so放大器; B.so拥有在全球范围内libssl.a符号。我被选中此readelf -s A.so

A.so & B.so has symbols from libssl.a in GLOBAL scope. I checked this by readelf -s A.so

我有它加载A.so和B.so.一个可执行的a.out当a.out的结束,我收到了
双无差错,从libssl.a在A.so的象征之一。

I have an executable a.out which loads A.so and B.so. When a.out terminated I get a double free error in one of the symbols from libssl.a in A.so.

即使libssl.a静态链接到每个共享对象,因为它们暴露
全球范围内是有可能,相同的符号来代替共享采摘它的本地副本。

Even though libssl.a is statically linked to each shared object, since they are exposed globally is it possible that the same symbol is shared instead of picking it's local copy.

解决办法呢?如何使本地符号在这里?

What is the workaround this ? How to make the symbols local here ?

请帮忙

推荐答案

这的确是预期。 libssl.a 器插入(可能的子集),另外,其结果的一个实例并不pretty。您可以使用版本脚本( - 版本脚本来LD,与轮候册,为CC)控制什么是从 A.so B.so 导出。如果不出口的东西,它也不能插入。

This is indeed expected. One instance of libssl.a interposes (likely a subset of) the other, and the results are not pretty. You can use a version script (--version-script to ld, with -Wl, for cc) to control what is exported from A.so and B.so. If something is not exported, it cannot be interposed either.

另外,你可以编译 libssl.a 能见度标志像 -fvisibility隐藏= 。这些标志不仅影响到动态链接程序,而不是静态链接。你可能需要自己编译也无妨,因为运 .A 文件中会包含一些与位置相关的code,这意味着用于链接到可执行文件。只有一些平台,如32位x86让你这样code链接到共享对象,并且仅在文本重定位的成本脱身。

Alternatively, you could compile libssl.a with visibility flags like -fvisibility=hidden. These flags only affect the dynamic linker and not static linking. You likely needed to compile it yourself anyway because shipped .a files tend to contain position-dependent code, meant for linking into executables. Only some platforms such as 32-bit x86 let you get away with linking such code into shared objects and only at the cost of text relocations.

的dlopen RTLD_LOCAL 所建议的评论也应该工作,但它似乎的hackish使用的dlopen 用于这一目的。

The dlopen with RTLD_LOCAL as suggested in a comment should also work but it seems hackish to use dlopen for this purpose.

另一种方法是使用相同的共享 libssl.so 在这两个库。

Another option is to use the same shared libssl.so in both libraries.

这篇关于静态库两次加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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