Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to check if given program was compiled with GNU gprof instrumentation, i.e. with '-pg' flag passed to both compiler and linker, without running it to check if it would generate a gmon.out file?

share|improve this question
up vote 7 down vote accepted

You could check for references to function mcount (or possibly _mcount or __mcount according to Implementation of Profiling). This function is necessary for profiling to work, and should be absent for non-profiled binaries.

Something like:

$ readelf -s someprog | egrep "\s(_+)?mcount\b" && echo "Profiling is on for someprog"

The above works on a quick test here.

share|improve this answer

The regular expression in the answer above doesn't always work...but the general idea of grepping for "mcount" in the output of 'readelf -s [binary]' is correct, I think

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.