Re: Eliminating unused functions based on gcov output

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Amusing Muses" <amusingmuses@xxxxxxxxx> 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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux