我有一个由(linux)gcc 4.8.2与-fvisibility =隐藏链接到一个共享库(我有两个版本,gcc之一与C代码和ifort与Fortran代码)编译的一个小的静态库。 静态库由一些内部函数组成,全部以“ST_LIB_”为前缀。
我想确保在静态库中声明的函数不能被连接到共享库的任何可执行文件/库使用。 什么是最好的命令在Linux上检查具有某些前缀的函数不能被任何外部库使用?
我努力了:
nm --dynamic shared_lib | grep -i "ST_LIB_" | wc -l
nm --dynamic shared_lib | grep -i "ST_LIB_" | wc -l
(输出0)
readelf -d shared_lib | grep -i "ST_LIB_" | wc -l
readelf -d shared_lib | grep -i "ST_LIB_" | wc -l
(输出0)
nm -g shared_lib | grep -i "ST_LIB_" | wc -l
nm -g shared_lib | grep -i "ST_LIB_" | wc -l
(输出26或0取决于共享lib)
readelf -s shared_lib | grep -i "ST_LIB_" | wc -l
readelf -s shared_lib | grep -i "ST_LIB_" | wc -l
(输出26或0取决于共享lib)
readelf -Ws shared_lib | grep -i "ST_LIB_" | grep -i "HIDDEN" | wc -l
readelf -Ws shared_lib | grep -i "ST_LIB_" | grep -i "HIDDEN" | wc -l
(输出26或0取决于共享lib)
nm --dynamic
应该是你要找的选项,因为它显示的符号,你可以链接(从共享库)。 readelf --dyn-syms
应显示相同的信息(不同的输出)。
使用nm
,请检查具有"T"
属性的符号。 从手册页:
The symbol type. At least the following types are used; others are, as well, depending on the object file format. If lowercase, the symbol is usually local; if uppercase, the symbol is global (external). There are however a few lowercase symbols that are shown for special global symbols ("u", "v" and "w"). [...] "T" "t" The symbol is in the text (code) section.
如果您希望100%确定,则可以随时编写一个与您的共享库链接的测试程序,并尝试使用其中一个ST_LIB_
符号。