I\'d like to find unused functions in a codebase - including across compilations units. I\'m using gcc as my compiler.
Here\'s an example:
foo.c
gprof is the simplest solution I guess. I compiled the sample program you've put up with -pg option so that we get the gmon.out when we run a.out (which gprof can use later) and then I finally ran gprof -z a.out gmon.out | tee output.txt . I could find your function foo in the unused list! i.e called 0 times. -z is the option you should use along with gprof to track unused routines.
Thanks to this thread for the appropriate pointer!
PS: gprof threw up a slew of other unused library functions along with your unused function foo. I seriously don't know how to filter this :)