问题描述
库并不总是包含_mcount符号,但应用程序可以(您可以使用gobjdump或nm工具来验证)。我读过_mcount用于实现分析,但即使禁用了分析并启用了优化(-O2),符号仍然存在。它是否有其他用途?
更新:我在Solaris上,所以这是Solaris链接器与GCC的组合,我不确定这是否有所作为或不。 GCC版本是4.2.2。即使我编译的文件只包含代码 int main(){return 0;
Update2:I type:
$ 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
int main(int argc,char ** args)
{
printf(hello world\\\
);
$ / code>
使用
编译 gcc test.c
它没有_mcount符号。我查了一下:
nm a.out | grep -i count
尝试使用一些编译器开关(-g,-pg等)只有在使用-pg编译应用程序时才会出现该符号,在这种情况下,您可以在启用分析功能的情况下进行编译,因此_mcount符号存在理由。
Libraries don't always contain the _mcount symbol, but applications do (you can verify this with gobjdump or the nm utility). I've read that _mcount is used to implement profiling, but the symbol is present even when profiling is disabled and optimization is enabled (-O2). Does it serve some other additional purpose?
Update: I am on Solaris, so this is the Solaris linker combined with GCC, I'm not sure if that makes a difference or not. The GCC version is 4.2.2. This happens even if I compile a file that only contains the code int main() { return 0; }
with no libraries linked.
Update2: I type:
$ g++ -O2 mytest.cpp
$ nm a.out | grep _mcount
[65] | 134547444| 1|FUNC |GLOB |0 |11 |_mcount
And g++ is not aliased to anything. Also, I tried compiling with the sun CC compiler, and it doesn't have this issue. I also tried updating GCC, symbol still exists in 4.4.1.
Hm. strange, on my machine (ubuntu 9.10) this does not happen.
For a test I just compiled a small hello-word:
#include <stdio.h>
int main (int argc, char **args)
{
printf ("hello world\n");
}
compiled with
gcc test.c
It didn't has the _mcount symbol. I checked with:
nm a.out | grep -i count
Trying some compiler switches (-g, -pg ect.) it turns out that the symbol only appears if you compile your application with -pg, In this case you compile with profiling enabled, so the _mcount symbol has a reason to exist.
这篇关于为什么GCC编译的应用程序总是包含_mcount符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!