Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
783 views
in Technique[技术] by (71.8m points)

android - Is there any way to override the -fvisibility=hidden at link time?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...