GCC 3.4.3 static constants, named sections, and -fkeep-static-consts

James E Wilson wilson@specifixinc.com
Wed Mar 9 02:59:00 GMT 2005


Gary Funck wrote:
> When compiled with GCC 3.4.3, at -O2, the ident string above will _not_
> appear in the executable.  This is apparently expected behavior.

See the docs for __attribute__ ((used)).  Contrary to the docs, it works 
for more than functions.

> However, interestingly,
>   gcc -fkeep-static-consts -O2 t.c
> did not retain the ident string, rcsid, defined above.  Shouldn't
> -fkepp-static-consts have ensured that this static constant would appear
> in the executable?

Try re-reading the docs.  -fkeep-static-consts is the default.  The 
purpose of this is that we don't perform this optimization at -O0 
normally, but if you use -fno-keep-static-consts, then we do.  So this 
option can let you remove static consts in extra cases, but will never 
prevent the compiler from removing them.
-- 
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com



More information about the Gcc mailing list