Eliminating unused functions based on gcov output

Amusing Muses amusingmuses@gmail.com
Fri Jun 6 18:56:00 GMT 2008

Hi, I'm trying to reduce code size of a huge project based on gcov output.

My strategy: I instrumented my code with gcov, parsed the output to
find all functions that were never called, and generated a list of
these functions, and now I need these functions to NOT get
compiled/take up space in the object... what's the best (i.e. laziest,
code is too huge for me to manually strip it down) way to do this?

Here's what I tried:
I initially wrote a script to set
__attribute__((section(".discardme")) on all these functions, I
created the object obj.o and the executable "prog" and then I ran
"objcopy --remove-section=.discardme prog".  This "discards" the
section alright, and according to objdump -h, just leaves a huge gap
in its place taking up just as much space! I suspect that's because
the .discardme section was put in between other sections.

I am kind of stumped here as to what to do next... do I have no choice
but to manually remove these functions or write a script that
understand enough of the C grammar to comment them out? I think a gcc
attribute to indicate a function definition should be ignored would be
useful... or is there some other way?


More information about the Gcc-help mailing list