This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Optimization and unused variables
- From: Jim Wilson <wilson at tuliptree dot org>
- To: e dot jokisch at u-code dot de
- Cc: gcc at gcc dot gnu dot org
- Date: Sat, 06 Sep 2003 18:39:51 -0700
- Subject: Re: Optimization and unused variables
- References: <200309061416.49847.e.jokisch@u-code.de>
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