Retransmitting in text-mode only.
-------- Original Message --------
Subject: Re: __attribute__((alias())) for variables?
Date: Wed, 06 May 2009 09:34:44 +0200
From: Rabih Chrabieh <chrabieh@xxxxxxxxx>
To: Ian Lance Taylor <iant@xxxxxxxxxx>
CC: gcc-help@xxxxxxxxxxx
References: <4A009F3E.6080601@xxxxxxxxx> <m3d4amhj21.fsf@xxxxxxxxxx>
Thank you, Ian.
I will add the following question: for variables, it doesn't seem like
there is a mechanism to create an "alias" that is "local" to a file.
It seems like we must use "extern" (otherwise the compiler reports that
the variable is "defined both normally and as an alias").
And if we use extern, we cannot combine it with "static" (the compiler
reports "multiple storage classes").
Hence, contrary to functions, it looks like an aliased variable is
always global (the assembler is always using .global). This is partly an
issue of the C language that extern and static cannot be combined for
variables, but extern can be omitted for functions. Unless there is a
trick that you know of?
In summary, these constructs work properly for functions but not for
variables:
static void f() {return;}
static void g() __attribute__((alias("f")));
static int AAA;
extern static int BBB __attribute__((alias("AAA")));
Best regards,
Rabih
Ian Lance Taylor wrote:
Rabih Chrabieh <chrabieh@xxxxxxxxx> writes:
The alias attribute in __attribute__((alias())) is defined as a
function attribute
(http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html).
It is not defined as a variable attribute
(http://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html).
However, I tried using it for variables (under cygwin on pentium, gcc
version 3.4.4) and it seems to work!
For example,
int AAA;
extern int BBB __attribute__((alias("AAA")));
seems to work properly. And it also creates the proper stabs for
debugging info.
Then my question is: why does the online help (links above) define the
alias attribute for functions only?
- Is there a catch and it doesn't really work?
- Is the help not up to date?
- Or is the grammar general enough such that what works for functions
often automatically works for variables, but you didn't report it?
This is a bug in the documentation. The alias attribute for variables
works as it does for functions, and it should be documented as such.
Ian