为什么GCC编译的应用程序总是包含_mcount符号?
库并不总是包含 _mcount 符号,但应用程序包含(您可以使用 gobjdump 或 nm 实用程序验证这一点)。我读过 _mcount 用于实现分析,但即使禁用分析并启用优化(-O2),该符号仍然存在。它还有其他额外的用途吗?
更新:我使用的是 Solaris,所以这是 Solaris 链接器与 GCC 的结合,我不确定这是否有区别。 GCC 版本是 4.2.2。即使我编译一个仅包含代码 int main() { return 0; 的文件,也会发生这种情况。 }
没有链接库。
Update2:我输入:
$ g++ -O2 mytest.cpp
$ nm a.out | grep _mcount
[65] | 134547444| 1|FUNC |GLOB |0 |11 |_mcount
并且 g++ 没有给任何东西起别名。另外,我尝试用sun CC编译器编译,没有这个问题。我也尝试更新GCC,符号仍然存在于4.4.1中。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
嗯。奇怪的是,在我的机器(ubuntu 9.10)上这不会发生。
为了进行测试,我刚刚编译了一个小hello-word:
编译
它没有 _mcount 符号。我检查过:
尝试一些编译器开关(-g、-pg 等),结果发现该符号仅在使用 -pg 编译应用程序时出现,在这种情况下,您在启用分析的情况下进行编译,因此 _mcount 符号有一个原因存在。
Hm. strange, on my machine (ubuntu 9.10) this does not happen.
For a test I just compiled a small hello-word:
compiled with
It didn't has the _mcount symbol. I checked with:
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.
您是否正在链接启用了分析的库?这将引入
_mcount
。Are you linking with a library that has profiling enabled? That would pull in
_mcount
.有关信息,
在我的 Linux 机器 (Archlinux x86)、GCC 4.4.2 上,在
a.out
上运行nm
给出:并在
a.out
尝试通过在依赖库上运行
nm
来确定是否已使用分析支持构建了某个依赖库。正如 @Emerick 所说,这将引入_mcount
。For information,
On my Linux box (Archlinux x86), GCC 4.4.2, running
nm
ona.out
gives:and running
ldd
ona.out
givesTry to figure out whether one of the dependent libraries has been built with profiling support by running
nm
on them. As @Emerick said, this would pull in_mcount
.没有帮助,但也许提供了信息:
在全新安装 OpenSolaris 和 g++ 时,我看到了相同的结果。
在 OpenSolaris 上的 gcc/++ 手册页中,它指出调试信息的默认级别是“2”...但将其更改为 1 或 0 并不会消除 _mcount 符号。
如果我使用 cc-5.0 进行编译,则不存在 _mcount 符号。 (虽然使用 cc 进行编译,但 cc 只是 gcc 的别名/包装器)。
在 Ubuntu 和 Fedora 上,除非使用 -pg 选项进行编译,否则该符号不存在(在这种情况下,该符号是 mcount 而不是 _mcount)。
Not helpeful, but perhaps informative:
On a fresh install of OpenSolaris and g++, I see the same results.
In the man page for gcc/++ on OpenSolaris it notes the default level of debuging information is "2" ... but changing that to 1 or 0 does not eliminate the _mcount symbol.
If I compile with cc-5.0 the _mcount symbol is not present. (though compiling with cc it is as cc is just an alias/wrapper for gcc).
On Ubuntu and Fedora the symbol is not present unless compiling with the -pg option (in which case the symbol is mcount rather than _mcount).