This is the mail archive of the gcc@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: Optimization and unused variables


Eckhard Jokisch wrote:
Is this expected behaviour and (as I think it is) is there a way to get warnings about unused members/variables? Or a way to "optimze" them away?
I need this to find out possible chances to squeeze memory usage in an embedded unit.

Eliminating unused global variables requires link time optimizations. Eliminating unused structure members would require link time code generation and optimization, because the changing structure size would require generating new code. Gcc doesn't really do either of these things at present.


You can mostly get the first one by using -fdata-sections and -ffunction-sections. This puts every variable/function respectively in its own section, and then there us a linker option you can use to discard unused sections. For GNU ld, this is -Wl,--gc-sections. This requires an ELF target, and may require gcc/assembler/linker features that are not supported by every target (or may not be currently working). If you are using C++, there may be additional complications.
--
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com



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