This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: glibc2.1 [offtopic]


In article <m10EyNO-000390C@ocean.lucon.org> you write:
>>   In message <m10EkjF-000390C@ocean.lucon.org>you write:
>>   > #if SUPPORT_WEAK
>>   > extern void foo (void) __attribute__ ((weak));
>>   > #endif
>>   > 
>>   > That means we need to match foo's prototype in 2 places. We can do
>>   > 
>>   > #if SUPPORT_WEAK
>>   > extern void foo (void) __attribute__ ((weak));
>>   > #else
>>   > extern void foo (void);
>>   > #endif
>> Define an ATTRIBUTE_WEAK then write
>> extern void foo (void) ATTRIBUTE_WEAK;
>> 
>> This is how we deal with this problem elsewhere.  I see no reason for this
>> code to behave any differently.
>
>Have you really looked at how egcs deals with weak symbols for targets?
>I did

># cd gcc
># grep ATTRIBUTE_WEAK *
># grep "pragma[ \t]+weak" *
>gthr-posix.h:#pragma weak pthread_once
>gthr-posix.h:#pragma weak pthread_key_create
>gthr-posix.h:#pragma weak pthread_key_delete
>gthr-posix.h:#pragma weak pthread_getspecific
>gthr-posix.h:#pragma weak pthread_setspecific
>gthr-posix.h:#pragma weak pthread_create
>gthr-posix.h:#pragma weak pthread_mutex_lock 
>gthr-posix.h:#pragma weak pthread_mutex_trylock 
>gthr-posix.h:#pragma weak pthread_mutex_unlock 

Now, try to interpret the 3 last lines of gcc/config/openbsd.h 
with THAT in mind.

/* Otherwise, since we support weak, gthr.h errouneously tries to use
   #pragma weak. */
#define GTHREAD_USE_WEAK 0

Yep, that's right. You've got one operating system which *does* support
weak, but isn't  entirely too fond of #pragma, specifically does *not*
define HANDLE_SYSV_PRAGMA, and does not intend to unless something exterior
forces it too...

There are at least two issues to resolve there:
First, SUPPORTS_WEAK is definitely *not* a synonym for  
HANDLE_PRAGMA_WEAK, as defined *properly* in c-pragma.h
(maybe the definition should be moved to a more visible place, like
default.sh ?)

Second, attribute((weak)) is harder to use than pragma weak. Mainly,
#pragma weak acts as a lower level, where it only does change a symbol
property, whereas attribute((weak)) needs a proper declaration to work.
One pro is that it gets type-checking, and will work correctly for C++
identifiers. One con is that it is impossible to change the weakness status
of a symbol without knowing quite a lot about this symbol.

Maybe having the lower-level facility available without using pragma would
make sense ? Otherwise I see people continuing to use #pragma weak or,
failing that asm(".weak symbol"); to get around the type-checking system.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]