Subject: re: gcc-3.4 optimization kills "link sets"
To: matthew green <firstname.lastname@example.org>
From: Richard Earnshaw <Richard.Earnshaw@arm.com>
Date: 06/08/2004 11:39:26
On Tue, 2004-06-08 at 06:51, matthew green wrote:
> Trying to build a kernel with gcc-3.4 I've found that the
> optimisation settings of the current default kernel Makefile
> cause unreferenced static variables to be optimized away,
> regardless of an __attribute__((unused)).
> i've actually noticed this with an optimisation for the arm backend
> i've written. i think it's a bug in the new -funit-at-a-time code
> but i'm yet to figure out where it is, or really be sure it is a bug.
I suspect you are misinterpreting the difference between the used and
'used' means that the object is used in ways that the compiler may not
fully understand -- the compiler must not delete it even if it can't
find any real use.
'unused' means that the programmer knows that this may be unused and
doesn't want the compiler to complain about it. It's primarily for use
in things like variable definitions (where the use might depend on the
target) or in function arguments for generic routines (where the
argument might not be used in this instance, but would in another
function with the same interface). It can also be applied to
static-scope objects, especially if they might appear in a header file.
There's no need for the compiler to emit the object if it isn't used.