有没有什么办法可以覆盖链接时隐藏的-fvisibility =? [英] Is there any way to override the -fvisibility=hidden at link time?
问题描述
我们正在使用第三方静态库,例如 但由于某些原因,我们很难立即获得新的构建库,因此我们需要一些解决方法。有没有办法将这些符号导出为全局的,即使它已经在 我们使用nm来检查这些符号。 $ b 您不应:在ELF平台上, 它存在但是列表为t的T,这意味着它是本地符号而不是外部。接下来的Aa是在-svis调查后用-fvisibility =隐藏的。 你的结论并不遵循: / em>因为符号可能显示为 有任何方法可以将这些符号导出为全局的,即使它已经用 符号表只是一个线性表 一旦获得了偏移量,就可以覆盖它的偏移量 一旦你修补了你的 We are using an third party static library, let say 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 We have using nm to check those symbols You shouldn't: on ELF platforms, 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 Is there any way to export those symbols as global even it has been build with The symbol table is just a linear table of Once you have the offset, you can override its Once you've patched your 这篇关于有没有什么办法可以覆盖链接时隐藏的-fvisibility =?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! A.a
用于android开发。我们将它作为共享库链接,并且它在一个应用程序中正常工作,但是当使用 B.so
来构建另一个 C.so $ c时$ c>,
Aa
中的某些符号找不到。我们已经使用 -Wl, - export-dynamic
和 -Wl, - whole-archive
来构建 B.so
。我们使用 nm
来检查这些符号,它存在但列表为t
而不是T
,这意味着它是本地符号而不是外部符号。在som调查之后,接缝 A.a
用 -fvisibility = hidden
构建。
B.so
中用 -fvisibility = hidden
nm
不足工作。改为使用 readelf -Ws
。
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
时,它将会全球/出口。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. -fvisibility=hidden
in B.so
at link time.
nm
is inadequate for the job. Use readelf -Ws
instead.
t
. Being compiled with -fvisibility=hidden
is only one of many possibilities.
-fvisibility=hidden
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))
.st_info
with STV_DEFAULT
(if your theory is correct and you located the symbol correctly, you should find STV_HIDDEN
there currently).foo.o
, the symbol will no longer be hidden, and when you link foo.o
into B.so
, it will be global / exported.