有没有什么办法可以覆盖链接时隐藏的-fvisibility =? [英] Is there any way to override the -fvisibility=hidden at link time?

查看:149
本文介绍了有没有什么办法可以覆盖链接时隐藏的-fvisibility =?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用第三方静态库,例如 A.a 用于android开发。我们将它作为共享库链接,并且它在一个应用程序中正常工作,但是当使用 B.so 来构建另一个 C.so Aa 中的某些符号找不到。我们已经使用 -Wl, - export-dynamic -Wl, - whole-archive 来构建 B.so 。我们使用 nm 来检查这些符号,它存在但列表为t而不是T,这意味着它是本地符号而不是外部符号。在som调查之后,接缝 A.a -fvisibility = hidden 构建。

但由于某些原因,我们很难立即获得新的构建库,因此我们需要一些解决方法。有没有办法将这些符号导出为全局的,即使它已经在 B.so 中用 -fvisibility = hidden

解决方案


我们使用nm来检查这些符号。 $ b

您不应:在ELF平台上, nm 不足工作。改为使用 readelf -Ws


它存在但是列表为t的T,这意味着它是本地符号而不是外部。接下来的Aa是在-svis调查后用-fvisibility =隐藏的。

你的结论并不遵循: / em>因为符号可能显示为 t 。使用 -fvisibility = hidden 进行编译只是众多可能性中的一种。


有任何方法可以将这些符号导出为全局的,即使它已经用 -fvisibility = hidden



$ b构建$ b

符号表只是一个线性表 Elf {32,64} _Sym [] s。您可以使用 readelf -WS foo.o |在对象文件中找到此表的开头。 grep'\.symtab',从 readelf -Ws 中查找违规符号的数量,并在 foo.o 结合这两者:

  sym-offset = .symtab偏移量+(sym-number * sizeof(Sym))

一旦获得了偏移量,就可以覆盖它的偏移量 .st_info STV_DEFAULT (如果您的理论正确并且您正确地找到了符号,则应该找到

一旦你修补了你的 foo.o >,符号将不再被隐藏,并且当您将 foo.o 链接到 B.so 时,它将会全球/出口。


We are using an third party static library, let say A.a for android development. We link it as shared library and it works fine in the one App, but when use B.so to build another C.so, some symbols in A.a cannot find. We have already use -Wl,--export-dynamic and -Wl,--whole-archive to build B.so. We have using nm to check those symbols, it exist but list as "t" instead of "T",which means it is local symbols instead of external. Seams the A.a are build with -fvisibility=hidden after som investigation.

But because some reason it is hard for us to got an new build library immediately, so we need some workaround. Is there any way to export those symbols as global even it has been build with -fvisibility=hidden in B.so at link time.

解决方案

We have using nm to check those symbols

You shouldn't: on ELF platforms, nm is inadequate for the job. Use readelf -Ws instead.

it exist but list as "t" instead of "T",which means it is local symbols instead of external. Seams the A.a are build with -fvisibility=hidden after som investigation.

Your conclusion does not follow: there are many reasons a symbol may show up as a t. Being compiled with -fvisibility=hidden is only one of many possibilities.

Is there any way to export those symbols as global even it has been build with -fvisibility=hidden

The symbol table is just a linear table of Elf{32,64}_Sym[]s. You can find the start of this table in the object file with readelf -WS foo.o | grep '\.symtab', find the number of offending symbol from readelf -Ws, and find the offset of the symbol in the foo.o by combining the two:

sym-offset = .symtab offset + (sym-number * sizeof(Sym))

Once you have the offset, you can override its .st_info with STV_DEFAULT (if your theory is correct and you located the symbol correctly, you should find STV_HIDDEN there currently).

Once you've patched your foo.o, the symbol will no longer be hidden, and when you link foo.o into B.so, it will be global / exported.

这篇关于有没有什么办法可以覆盖链接时隐藏的-fvisibility =?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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