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]

TARGET_ATTRIBUTE_WEAK vs. pragma


> 
> 
>   In message <m10Fie3-000390C@ocean.lucon.org>you write:
> 
>   > Could you please show me how to use __attribute__ ((weak))? The code
>   > below doesn't make "foo" weak. BTW,
>   > 
> [ ... ]
>   > -- 
>   > H.J. Lu (hjl@gnu.org)
>   > ---
>   > extern void foo () __attribute__ ((weak));
>   > 
>   > bar ()
>   > {
>   >   if (foo) foo ();
>   > }
> This is the right way to get a weak declaration.  It didn't work because  of
> a trivial bug.  I've fixed that bug on the release branch (and will fix it
> shortly in the mainline tree).
> 

While working on the TARGET_ATTRIBUTE_WEAK patch, I found a problem.
We want to make __register_frame_info and __deregister_frame_info
weak external in crtstuff.c. How do we do it with __attribute__?
We can only add TARGET_ATTRIBUTE_WEAK for crtstuff.c, but not for
frame.c. That means we have to

1. Put normal prototypes in frame.h and put another one in crtstuff.c.
They have to match. Or

2. In frame.h, we have

#ifndef TARGET_ATTRIBUTE_WEAK  
# if SUPPORTS_WEAK && defined(IN_CRTSTUFF)
#  define TARGET_ATTRIBUTE_WEAK __attribute__ ((weak))
# else
#  define TARGET_ATTRIBUTE_WEAK
# endif
#endif

extern void *__deregister_frame_info (void *)
				     TARGET_ATTRIBUTE_WEAK;

and in crtuff.c, we have

#define IN_CRTSTUFF
#include "frame.h"

Neither solution is as clean as putting "#pragma" in crtstuff.c. Does
anyone have a better solution? The more I look at it, the more I like
"#pragma weak".

Thanks.


H.J.


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