Index: gcc/c-decl.c =================================================================== RCS file: /cvsroot/gcc/gcc/gcc/c-decl.c,v retrieving revision 1.300.2.5 diff -u -p -r1.300.2.5 c-decl.c --- gcc/c-decl.c 28 Mar 2002 18:49:57 -0000 1.300.2.5 +++ gcc/c-decl.c 23 Apr 2002 21:41:28 -0000 @@ -1955,7 +1955,11 @@ 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 (olddecl); + if (!DECL_WEAK (newdecl) && DECL_WEAK (olddecl)) + declare_weak (newdecl); + /* For functions, static overrides non-static. */ if (TREE_CODE (newdecl) == FUNCTION_DECL) { Index: gcc/varasm.c =================================================================== RCS file: /cvsroot/gcc/gcc/gcc/varasm.c,v retrieving revision 1.250.2.7 diff -u -p -r1.250.2.7 varasm.c --- gcc/varasm.c 25 Mar 2002 00:54:26 -0000 1.250.2.7 +++ gcc/varasm.c 23 Apr 2002 21:41:28 -0000 @@ -4998,17 +4998,25 @@ declare_weak (decl) { if (! TREE_PUBLIC (decl)) error_with_decl (decl, "weak declaration of `%s' must be public"); - else if (TREE_ASM_WRITTEN (decl)) + else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl)) error_with_decl (decl, "weak declaration of `%s' must precede definition"); else if (SUPPORTS_WEAK) { if (! DECL_WEAK (decl)) weak_decls = tree_cons (NULL, decl, weak_decls); + if (TREE_CODE (decl) != FUNCTION_DECL && TREE_USED (decl)) + warning_with_decl (decl, "weak declaration of `%s' after first use may result in unspecified behaviour"); } else warning_with_decl (decl, "weak declaration of `%s' not supported"); DECL_WEAK (decl) = 1; + + if (DECL_RTL_SET_P (decl) + && GET_CODE (DECL_RTL (decl)) == MEM + && XEXP (DECL_RTL (decl), 0) + && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF) + SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1; } /* Emit any pending weak declarations. */ Index: gcc/cp/decl.c =================================================================== RCS file: /cvsroot/gcc/gcc/gcc/cp/decl.c,v retrieving revision 1.866.2.23 diff -u -p -r1.866.2.23 decl.c --- gcc/cp/decl.c 16 Apr 2002 03:15:54 -0000 1.866.2.23 +++ gcc/cp/decl.c 23 Apr 2002 21:41:28 -0000 @@ -3645,7 +3645,11 @@ duplicate_decls (newdecl, olddecl) } /* Merge the storage class information. */ - DECL_WEAK (newdecl) |= DECL_WEAK (olddecl); + if (DECL_WEAK (newdecl) && !DECL_WEAK (olddecl)) + declare_weak (olddecl); + if (!DECL_WEAK (newdecl) && DECL_WEAK (olddecl)) + declare_weak (newdecl); + DECL_ONE_ONLY (newdecl) |= DECL_ONE_ONLY (olddecl); DECL_DEFER_OUTPUT (newdecl) |= DECL_DEFER_OUTPUT (olddecl); TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);