This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Does weak work on PPC with -O2?
- To: Geoff Keating <geoffk at geoffk dot org>
- Subject: Re: Does weak work on PPC with -O2?
- From: "H . J . Lu" <hjl at gnu dot org>
- Date: Sun, 11 Mar 2001 21:14:03 -0800
- Cc: gcc-bugs at gcc dot gnu dot org
- References: <20010311154432.A32325@gnu.org> <jmvgpfvblv.fsf@geoffk.org>
On Sun, Mar 11, 2001 at 08:45:48PM -0800, Geoff Keating wrote:
> "H . J . Lu" <hjl@gnu.org> writes:
>
> > extern void *foo __attribute__ ((__weak__));
> >
> > printf ("foo: %p\n", &foo == NULL ? NULL : foo);
>
> This is a known problem in GCC. It only works on ia32 by accident.
> GCC does not believe that a reference like 'foo' can trap.
>
> The responsible code is rtx_addr_can_trap_p in rtlanal.c. You can see
> in the current version a comment explaining that it's wrong but it would
> be a large deoptimisation to fix in the obvious way.
>
> In general, it's better to avoid undefined weak symbols; instead, provide
> weak stub definitions.
>
Well, undefined weak symbol has a well defined semantics. Glibc
uses undefined weak symbol. I don't believe glibc is the only
package which uses it. It sounds a serious bug to me. Fortunately,
it works on ia32 "by accident".
BTW, if gcc cannot do it right, shouldn't it issue a warning instead
of generating incorrect code?
H.J.