gcc - 为什么 GCC 编译的应用程序总是包含 _mcount 符号?

标签 gcc profiling shared-libraries symbols

库并不总是包含 _mcount 符号,但应用程序包含(您可以使用 gobjdump 或 nm 实用程序验证这一点)。我读过 _mcount 用于实现分析,但即使禁用分析并启用优化(-O2),该符号仍存在。它是否有其他其他用途?

更新:我在 Solaris 上,所以这是与 GCC 结合的 Solaris 链接器,我不确定这是否有所不同。 GCC 版本是 4.2.2。即使我编译了一个只包含代码 int main() { return 0; } 的文件,也会发生这种情况。没有链接库。

更新2:我输入:

$ g++ -O2 mytest.cpp
$ nm a.out | grep _mcount
[65]    | 134547444|       1|FUNC |GLOB |0    |11     |_mcount

并且 g++ 没有任何别名。另外,我试过用sun CC编译器编译,没有这个问题。我也尝试更新 GCC,符号仍然存在于 4.4.1。

最佳答案

嗯。奇怪,在我的机器上(ubuntu 9.10)这不会发生。

为了测试,我刚刚编译了一个小的 hello-word:

#include <stdio.h>

int main (int argc, char **args)
{
  printf ("hello world\n");
}

编译与
gcc test.c

它没有 _mcount 符号。我检查了:
nm a.out | grep -i count

尝试一些编译器开关(-g、-pg 等),结果证明只有在使用 -pg 编译应用程序时才会出现该符号,在这种情况下,您在启用分析的情况下进行编译,因此 _mcount 符号有存在的理由。

关于gcc - 为什么 GCC 编译的应用程序总是包含 _mcount 符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2028911/

相关文章:

C++ 将引用变量传递给 g++-4.7.4 中的线程

c++ - 为什么 GCC 优化掉这个增量?

java - 如何跟踪可能重叠的应用程序不同组件的不同性能改进?

c - 查找特定内存位置的数据最后一次修改的时间? (C、gcc、gdb、valgrid、clang?)

c - Linux C : Changing process name during compilation

Python 多处理 Pool.map 正在调用获取?

linux - GPerfTools/pprof : what does a dashed line mean?

java - 如何修复第三方库中的类

c++ - 共享库中的符号

c++ - 链接 boost 库时引发 "Error while loading shared libraries",但我无法使用 root 访问权限来修复它