【问题标题】:nm,objdump & pfunct giving contradicting answers to check if a function is inlined or notnm,objdump 和 pfunct 给出相互矛盾的答案来检查函数是否内联
【发布时间】:2014-08-27 12:12:41
【问题描述】:

我有一个共享的 obj 文件,比如 a.so,我想查看一个特定的函数(比如 fname)是否被内联。我尝试了以下 4 种方法并得到了不同的答案:

1) nm a.so | grep fname  

-> 这不会给出任何暗示该函数是内联的 o/p。 请让我知道这是否足以检查函数是否内联。

2) objdump -d a.so | grep fname  

->this 没有给出任何暗示该函数是内联的 o/p。如果我在这里的结论有误,请纠正我。

3) objdump -W a.so  

-> 对于函数 fname,这给了我下面的 o/p,最后一行写着“声明为内联但被忽略”

 DW_AT_name        : (indirect string, offset: 0x10411): fname
 DW_AT_decl_file   : 246
 DW_AT_decl_line   : 40
 DW_AT_prototyped  : 1
 DW_AT_inline      : 2      (declared as inline but ignored)

4) pfunct -G a.so | grep fname
->这个 dwarves 实用程序显示函数 fname,暗示该函数没有内联。

现在前两种方式意味着函数是内联的,而其余两种方式则相反。谁能解释一下:

1) Why are there differences in the above 4 ways ? 
2) Are there any known issues with objdump and pfunct ? 
3) Also let me know the best way to check if a function is inlined or not.

任何帮助将不胜感激。谢谢!!!

【问题讨论】:

  • 一个函数可能在某些地方被内联,而在其他地方没有被内联。 .so 中是否调用了您的函数?
  • 是的,该函数是静态的,并且只在该 .c 文件中的一处调用
  • 这个共享的 obj 文件是用调试信息编译的吗?如果不是,那么一个成功的内联函数将没有任何证据表明它曾经是一个函数。
  • yes .so 用调试信息编译
  • Also let me know the best way to check if a function is inlined or not. --- 如果检查gdb 下的代码怎么办?您可以创建一个测试程序并在gdb下运行它。

标签: c++ c linux unix objdump


【解决方案1】:

由于该函数仅在 .c 文件中的一处被调用,因此检查该函数是否内联的最佳方法如下:

objdump -d a.so | grep call | grep fname

如果有任何结果,则fname 不会被内联。否则,它必须被内联,因为它只在一个地方被调用并且没有找到调用站点。

【讨论】:

  • 任何解释为什么使用上述 4 种方法的结果差异?
  • 4 种方法: 1) 存在时输出fname 的地址。 2) 代码中使用fname 的输出。它包括 1) 以及调用 fname 的位置。 3) 输出调试信息,如定义行和文件,其签名等。 4) 对不起,我不知道pfunct
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-04
  • 2020-10-04
  • 1970-01-01
  • 1970-01-01
  • 2014-10-18
相关资源
最近更新 更多