- To: Erik Leunissen <e.leunissen@xxxxxxxxx>
- Subject: Re: Can weak references refer to a variable (instead of a function)?
- From: Ian Lance Taylor <iant@xxxxxxxxxx>
- Date: Tue, 26 Jun 2012 22:35:40 -0700
- Cc: gcc-help@xxxxxxxxxxx
- Comment: DKIM? See http://www.dkim.org
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
- In-reply-to: <4FE8DB34.1060201@hccnet.nl> (Erik Leunissen's message of "Mon, 25 Jun 2012 23:42:12 +0200")
- User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)
Erik Leunissen <e.leunissen@xxxxxxxxx> writes:
> Weak references are explained in section 6.30 of the GCC manual
> (Declaring Attributes of Functions).
> ^^^^^^^^^
>
> The example in that section declares a function x() as a weak
> reference to some symbol y in another translation unit/object file.
There are a few different versions of weak symbols, and I'm not sure
which one you mean. Are you talking about __attribute__ ((weak,
alias("name"))), or just __attribute__ ((weak)), or __attribute__
((weakref("name")))?
> No mention of variables, either as the alias or the symbol referred to.
>
> All of this leads me to understand that weak references apply to
> functions only.
Let's say you are talking about __attribute__ ((weakref("name"))). That
works for variables as well as functions, at least on ELF systems.
> a. is that true for both the alias and the symbol to which it refers?
I guess no.
> b. with respect to the symbol referred to, does it matter what its
> storage class is (global extent, static local extent or automatic
> local extent)?
It certainly can't be automatic. It can be static and defined in the
same file, or it can be global.
> c. does it matter whether the link is resolved by the link editor or
> dynamically, at runtime, by the loader?
No. __attribute__ ((weakref("name"))) only works with static symbols,
so it is basicall just renaming the symbol in the compiler. No
significant linker action is involved.
Ian
[Linux C Programming]
[Linux Kernel]
[eCos]
[Fedora Development]
[Fedora Announce]
[Autoconf]
[The DWARVES Debugging Tools]
[Yosemite Campsites]
[Yosemite News]
[Linux GCC]