weak for Darwin
Geoff Keating
geoffk@geoffk.org
Tue Nov 2 03:15:00 GMT 2004
On 01/11/2004, at 1:37 PM, Aaron W. LaFramboise wrote:
> 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);
Aah, I see. You have both #2 and #1 but with the extra semantic that a
weak symbol never satisfies any reference.
>> 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?
Yes, it's different. It's a very long explanation as to why this
particular approach seems best.
It's not true that they're *always* overridable; it depends on the link
ordering.
>> 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?
Sure. Will you make a patch, or should I?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2410 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20041102/8266695a/attachment.p7s>
More information about the Libstdc++
mailing list