GNU linker: alternative to --version-script to list exported symbols at the command line?

风格不统一 提交于 2020-01-01 02:44:10

问题


On Linux with the GNU toolchain, I know how to control exported symbols from a shared library with a version script (gcc -Wl,--version-script=symbols.map), but I would like to list exported symbols on the command line instead. IOW, I would like the equivalent of

link /EXPORT:foo 

from the MS toolchain. Is it possible ?

EDIT:

My question may not be very clearn: if I have a library libfoo.so, and I want to only export libraries foo1 and foo2, I can go create a version script foo.linux as follows

libfoo.so
{
global:
    foo1;
    foo2;
local:
    *;
}

And do

gcc -shared foo.c -Wl,--version-script=foo.linux -o libfoo.so -soname libfoo.so

I would like to be able to do something like this instead:

gcc -shared foo.c -Wl,--export-symbol=foo1 -Wl,--export-symbol=foo2 -o libfoo.so -soname libfoo.so

回答1:


I'm not sure that you can do this like you want. One way is with the linker version script like you mentioned. Another way is to add in your source code __attribute__ ((visibility("default"))) for whatever you want exported and compile everything with -fvisibility=hidden




回答2:


I may be eight years late, but yes, you actually can do what you want.

Use Bash process substitution:

gcc -shared foo.c -Wl,--version-script=<(echo "{global:foo1;foo2;local:*;};") -o libfoo.so -soname libfoo.so



回答3:


readelf and objdump have lots of options. How about:

readelf --symbols --use-dynamic $yourlib.so


来源:https://stackoverflow.com/questions/792195/gnu-linker-alternative-to-version-script-to-list-exported-symbols-at-the-comm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!