This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Eliminating unused functions based on gcov output


"Amusing Muses" <amusingmuses@gmail.com> writes:

> 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?

Assuming you are using the GNU linker:

Use -Wl,--verbose when linking to see the linker script.  Copy it into
a file.  Add "/DISCARD/ { *(.discardme) }" at the bottom of the
script.  Link with -Wl,-T,myscript .

Or compile with -ffunction-sections -fdata-sections and link with
-Wl,--gc-sections.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]