Why do my application binaries always contain the _mcount symbol?

Joseph Garvin joseph.h.garvin@gmail.com
Thu Jan 14 19:51:00 GMT 2010


On Solaris 10, with GCC 4.2 and GCC 4.4, any application I compile
*always* has the _mcount symbol, which if I understand correctly
should only be present if my application is being built with
profiling. I've verified that I don't see this behavior on Linux, only
on Solaris, and I've double checked that gcc/g++ aren't aliased in my
shell. I am also linking no libraries explicitly. If I run ldd on the
resulting executable, and then run nm on all of the listed shared
libraries (libc and such) none of them contain the symbol _mcount,
although one does contain the symbol _mcount_newent.

Any idea why this would be happening? I have a post-build script that
verifies that _mcount is not present when the profile setting is off,
to ensure that my build system is working correctly. I could remove
it, but I don't want to do so unless this symbol is really supposed to
be present.

mytest.cpp:

int main () { return 0; }

$ g++ -O2 mytest.cpp
$ nm a.out | grep _mcount
[65]    | 134547444|       1|FUNC |GLOB |0    |11     |_mcount
$ ldd a.out
        libstdc++.so.6 =>        /opt/app/g++lib6/lib/libstdc++.so.6
        libm.so.2 =>     /lib/libm.so.2
        libgcc_s.so.1 =>         /opt/app/nonc++/lib/libgcc_s.so.1
        libc.so.1 =>     /lib/libc.so.1

$ nm /opt/app/g++lib6/lib/libstdc++.so.6 | grep _mcount
$ nm /lib/libm.so.2 | grep _mcount
$ nm /opt/app/nonc++/lib/libgcc_s.so.1 | grep _mcount
$ nm /lib/libc.so.1 | grep _mcount
[392]   |    285460|      70|FUNC |LOCL |2    |11     |_mcount_newent



More information about the Gcc-help mailing list