I'd like to be able to compile the Linux kernel with both
-ffunction-sections and profiling (-pg). Using gcc with both
-ffunction-sections and -pg causes the following warning to be printed:
"warning: -ffunction-sections disabled; it makes profiling impossible"
and indeed -ffunction-sections is disabled. I've not been able to find
any documentation or mailing list threads that explain this conflict,
though the discussion starting at [1] speculates it is related to the
labels emitted for profiling support, and notes that the code for
disabling -ffunction-sections was written when -ffunction-sections was
introduced back in 1996.
However, I've compiled gcc 4.3.2 on i386 after removing the code that
disables -ffunction-sections when profiling is enabled. It does generate
working -ffunction-sections code that has mcount calls at the start of
each function. I've also tried gprof with a simple program compiled with
-ffunction-sections -pg, and it gave similar (though definitely not
identical) results to those from using gprof with the same program
compiled with just -pg.
So, why does gcc disable -ffunction-sections when compiling with -pg?
-Tim Abbott
[1] http://lists.debian.org/debian-hppa/2005/06/msg00062.html