This is the mail archive of the
mailing list for the GCC project.
Re: weak for Darwin
Geoff Keating wrote:
> On 01/11/2004, at 11:21 AM, Aaron W. LaFramboise wrote:
>>> 2. Applied to a symbol that isn't defined in the current translation
>>>unit it makes a weak undefined symbol (i.e. one whose address must be
>>>tested before the symbol is used, because at runtime it may or may
>>>not have a definition).
> How can something be 'not external' and yet not 'defined in the current
> translation unit' either? Is weak on PECOFF just a way of saying "this
> symbol is NULL"?
Quick map of PECOFF weak symantics:
If symbol is weak 'w' in a particular object
If symbol is defined 'D' in any translation unit
References to that symbol are resolved normally to the
defined symbol (weak has no effect in this case).
If symbol is not defined in any other translation unit
References within the object that has the weak symbol
are resolved to the default value for the weak symbol
(which may or may not be 0, depending on whether it
has been specified a value or alias locally.)
In particular, 'U' undefined symbols in obj1.o will never be resolved to
'w' symbols in obj2.o.
This still preserves the normal usage and semantics we expect of weak
symbols. For example, the example from
<http://gcc.gnu.org/onlinedocs/libstdc++/debug.html#mem> works as expected:
extern void* __dso_handle __attribute__ ((__weak__));
__cxa_atexit((void (*) (void *)) __libc_freeres, NULL,
&__dso_handle ? __dso_handle : NULL);
> I really do want the semantics of 'weak' as on ELF. In particular, I
> want the property that:
>>> 1. Applied to a symbol that's defined in the current translation
>>>unit, it makes it a weak definition. (i.e. one that can be overridden
>>>by a strong definition elsewhere).
This is the part that confuses me. I thought it was the usual case that
symbols in libraries such as libsupc++ are always overridable (certainly
they are on ELF and COFF) by user code. Is this different with Darwin's
linker or loader?
> It would be possible to have PECOFF disable the weak-ness using a macro.
OK. What do you think about adding a macro named something like
_GLIBCXX_WEAK_DEFINITION that is __attribute__((weak)) for Darwin,
nothing for PE targets, and whatever the concensus is for other targets?
Aaron W. LaFramboise