This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: ATTRIBUTE_WEAK not working in crtstuff.c?
- From: Franz Sirl <Franz dot Sirl-kernel at lauterbach dot com>
- To: Alan Modra <amodra at bigpond dot net dot au>
- Cc: Raja R Harinath <harinath at cs dot umn dot edu>,gcc at gcc dot gnu dot org,gcc-patches at gcc dot gnu dot org
- Date: Thu, 18 Apr 2002 10:29:47 +0200
- Subject: Re: ATTRIBUTE_WEAK not working in crtstuff.c?
- References: <d9d6wxx233.fsf@bose.cs.umn.edu><d9d6wxx233.fsf@bose.cs.umn.edu>
At 09:52 18.04.2002, Alan Modra wrote:
>Hmm, we put the new decl on weakdecls list, but then never use the
>new one so the !TREE_USED test in weak_finish prevents the asm
>.weak being emitted. This is one way to fix the problem.
>
>gcc/ChangeLog
> * c-decl.c (duplicate_decls): Call declare_weak on olddecl.
>
>diff -urpN -xCVS -x*~ gcc-ppc64-31.orig/gcc/c-decl.c gcc-ppc64-31/gcc/c-decl.c
>--- gcc-ppc64-31.orig/gcc/c-decl.c Wed Apr 3 09:00:04 2002
>+++ gcc-ppc64-31/gcc/c-decl.c Thu Apr 18 17:14:08 2002
>@@ -1421,6 +1421,9 @@ duplicate_decls (newdecl, olddecl, diffe
> }
> }
>
>+ if (DECL_WEAK (newdecl) && !DECL_WEAK (olddecl))
>+ declare_weak (olddecl);
>+
> DECL_ATTRIBUTES (newdecl)
> = (*targetm.merge_decl_attributes) (olddecl, newdecl);
> }
Well, this cures only part of the problem, check the discussions on
SYMBOL_REF_WEAK shortly before gcc-3.0 was released.
Weak handling vs. multiple declarations vs. #pragma weak vs. ordering is
currently more or less unspecified. If you look at my initial patch back
then, there was:
@@ -2028,7 +2031,15 @@ duplicate_decls (newdecl, olddecl, diffe
}
/* Merge the storage class information. */
- DECL_WEAK (newdecl) |= DECL_WEAK (olddecl);
+ if (!DECL_WEAK (newdecl) && DECL_WEAK (olddecl))
+ declare_weak (newdecl);
+ if (DECL_WEAK (newdecl) && !DECL_WEAK (olddecl))
+ declare_weak (olddecl);
+ if (DECL_WEAK (newdecl) && DECL_RTL (newdecl)
+ && GET_CODE (DECL_RTL (newdecl)) == MEM
+ && XEXP (DECL_RTL (newdecl), 0)
+ && GET_CODE (XEXP (DECL_RTL (newdecl), 0)) == SYMBOL_REF)
+ SYMBOL_REF_WEAK (XEXP (DECL_RTL (newdecl), 0)) = 1;
/* For functions, static overrides non-static. */
if (TREE_CODE (newdecl) == FUNCTION_DECL)
{
Even that didn't cover all cases IIRC. If someone would come up with some
testcases specifying the desired semantics of attribute((weak)) vs. #pragma
weak vs. declaration vs. definition, I'm willing to work on it again. It
doesn't make much sense to work on it when the desired semantics we want to
support (!, I think there are cases we should warn about or even error out)
are largely unspecified or unknown.
Franz.