This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
TARGET_ATTRIBUTE_WEAK vs. pragma
- To: law at cygnus dot com
- Subject: TARGET_ATTRIBUTE_WEAK vs. pragma
- From: hjl at lucon dot org (H.J. Lu)
- Date: Thu, 25 Feb 1999 10:45:17 -0800 (PST)
- Cc: egcs at egcs dot cygnus dot com
>
>
> 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.