gpt4 book ai didi

linux - 列出 ld 链接器可用的所有符号

转载 作者:太空狗 更新时间:2023-10-29 11:19:18 24 4
gpt4 key购买 nike

我有一个由 (linux) gcc 4.8.2 编译的带有 -fvisibility=hidden 的小型静态库,它链接到一个共享库(我有两个版本,gcc 一个带有 C 代码,ifort 一个带有 Fortran 代码)。静态库由一些内部函数组成,所有函数都以“ST_LIB_”为前缀。

我想确保静态库中声明的函数不能被链接到共享库的任何可执行文件/库使用。 在 Linux 上检查带有某些前缀的函数是否不能被任何外部库使用的最佳命令是什么?

我试过:

nm --dynamic shared_lib | grep -i “ST_LIB_” | wc -l(输出 0)

readelf -d shared_lib | grep -i “ST_LIB_” | wc -l(输出 0)

nm -g shared_lib | grep -i “ST_LIB_” | wc -l(根据共享库输出 26 或 0)

readelf -s shared_lib | grep -i “ST_LIB_” | wc -l(根据共享库输出 26 或 0)

readelf -Ws shared_lib | grep -i “ST_LIB_” | grep -i “隐藏” | wc -l(根据共享库输出 26 或 0)

最佳答案

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_ 符号之一的测试程序。

关于linux - 列出 ld 链接器可用的所有符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22328191/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com