如何查找外部函数定义

发布于 2024-10-01 13:46:36 字数 408 浏览 2 评论 0原文

我正在编译一个大项目。该项目使用共享库,尤其是 lapack 的。

我想确定,对于给定的函数,系统在哪个共享库中找到它。

这里是 nm 输出:

$ nm -DC ~/bin/app | grep potrf
                 U dpotrf_

正如预期的那样,dpotrf_ 是未定义的。

这是 objdump 的结果:

$ objdump -TR  ~bin/app | grep potrf
0000000000925428 R_X86_64_JUMP_SLOT  dpotrf_

所以 objdump 找到了一些东西!是否有任何选项可以显示它在哪个共享库中找到它?或者另一个程序可以做到这一点?

I am compiling a big project. This project is using shared libraries, especially lapack ones.

I would want to be sure, for a given function, in which shared library the system finds it.

Here the nm output:

$ nm -DC ~/bin/app | grep potrf
                 U dpotrf_

As expected, dpotrf_ is undifined.

Here the result with objdump:

$ objdump -TR  ~bin/app | grep potrf
0000000000925428 R_X86_64_JUMP_SLOT  dpotrf_

So objdump find something! Is there any option to show in which shared lib it finds it? Or another program to do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

看海 2024-10-08 13:46:36

ldd 绝对是寻找候选库的起点。这是我在 .bashrc 中用于此类目的的内容(不美观,但符合我的目的)。

基本上,我对子目录中的所有库(.a、.so)执行 nm 操作。如果 nm 生成搜索符号的输出,我会打印 nm 中的库名称和相关行。然后,您的最后一步是搜索以“T”开头的行,因为这些行是将符号定义为程序代码(文本)的行。

# run nm on a set of objects (ending with the 1st parameter) and
# grep the output for the 2nd parameter
function nmgrep ()
{
    for i in $( find \. -name \*$1 ); do
        if [[ ! -e $i ]]; then
            continue;
        fi  
        nm $i | grep $2 > /tmp/foo.tmp;
        if [[ -s /tmp/foo.tmp ]]; then
            echo $i; 
            cat /tmp/foo.tmp | grep $2
        fi  
        rm /tmp/foo.tmp
    done  
}

# find symbols definied/referenced in libs
function libgrep ()
{
    nmgrep .a $@
    nmgrep .so $@
}

ldd is definitely a starting point to find the candidate libraries. Here's what I have in my .bashrc for such purposes (not beautiful, but serves my purposes).

Basically, I do nm on all libraries (.a, .so) in a subdirectory. If nm produces an output for the searched symbol, I print the library name and the relevant lines from nm. Your last step would then be to search for lines starting with "T" as these are the ones defining your symbol as program code (text).

# run nm on a set of objects (ending with the 1st parameter) and
# grep the output for the 2nd parameter
function nmgrep ()
{
    for i in $( find \. -name \*$1 ); do
        if [[ ! -e $i ]]; then
            continue;
        fi  
        nm $i | grep $2 > /tmp/foo.tmp;
        if [[ -s /tmp/foo.tmp ]]; then
            echo $i; 
            cat /tmp/foo.tmp | grep $2
        fi  
        rm /tmp/foo.tmp
    done  
}

# find symbols definied/referenced in libs
function libgrep ()
{
    nmgrep .a $@
    nmgrep .so $@
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文