fix weak-5 on alpha
Richard Henderson
rth@redhat.com
Wed May 15 10:44:00 GMT 2002
This test was aborting due to a weakening after definition error.
I.e. the test case was incorrect.
I've adjusted the varasm.c widgetry to catch this.
Tested on alphaev6-linux.
r~
* varasm.c (merge_weak): Error for any weakening after definition.
Adjust weakening after use warning to catch more cases.
(assemble_alias): Set TREE_USED and TREE_ASM_WRITTEN consistently.
* config/alpha/alpha.c (alpha_encode_section_info): Do not abort.
* gcc.dg/weak-5.c (vfoo1c): No warning here.
(vfoo1f): Warning here.
(vfoo1l): Don't redefine the alias.
Index: gcc/varasm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/varasm.c,v
retrieving revision 1.273
diff -c -p -d -r1.273 varasm.c
*** gcc/varasm.c 15 May 2002 09:00:12 -0000 1.273
--- gcc/varasm.c 15 May 2002 16:42:32 -0000
*************** merge_weak (newdecl, olddecl)
*** 4830,4843 ****
if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
return;
- if (SUPPORTS_WEAK
- && DECL_WEAK (newdecl)
- && DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)
- && (TREE_CODE (olddecl) != VAR_DECL || ! TREE_STATIC (olddecl))
- && TREE_USED (olddecl)
- && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
- warning_with_decl (newdecl, "weak declaration of `%s' after first use results in unspecified behavior");
-
if (DECL_WEAK (newdecl))
{
tree wd;
--- 4830,4835 ----
*************** merge_weak (newdecl, olddecl)
*** 4848,4857 ****
go back and make it weak. This error cannot caught in
declare_weak because the NEWDECL and OLDDECL was not yet
been merged; therefore, TREE_ASM_WRITTEN was not set. */
! if (TREE_CODE (olddecl) == FUNCTION_DECL && TREE_ASM_WRITTEN (olddecl))
error_with_decl (newdecl,
"weak declaration of `%s' must precede definition");
!
if (SUPPORTS_WEAK)
{
/* We put the NEWDECL on the weak_decls list at some point.
--- 4840,4865 ----
go back and make it weak. This error cannot caught in
declare_weak because the NEWDECL and OLDDECL was not yet
been merged; therefore, TREE_ASM_WRITTEN was not set. */
! if (TREE_ASM_WRITTEN (olddecl))
error_with_decl (newdecl,
"weak declaration of `%s' must precede definition");
!
! /* If we've already generated rtl referencing OLDDECL, we may
! have done so in a way that will not function properly with
! a weak symbol. */
! else if (TREE_USED (olddecl)
! && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl))
! /* ??? Not impossible that some platform may generate code
! that doesn't function *at all* with incorrect declaration
! before use. However, all known at present will assume
! exteral and common symbols are not "local". */
! /* ??? Probably these exceptions to the rule will just
! confuse users about the true nature of the problem and
! we should warn for *any* use before weakening. */
! && ! (DECL_EXTERNAL (olddecl)
! || DECL_COMMON (olddecl)))
! warning_with_decl (newdecl, "weak declaration of `%s' after first use results in unspecified behavior");
!
if (SUPPORTS_WEAK)
{
/* We put the NEWDECL on the weak_decls list at some point.
*************** assemble_alias (decl, target)
*** 4992,4998 ****
#else
ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
#endif
- TREE_ASM_WRITTEN (decl) = 1;
#else /* !ASM_OUTPUT_DEF */
#if defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
if (! DECL_WEAK (decl))
--- 5000,5005 ----
*************** assemble_alias (decl, target)
*** 5003,5013 ****
#else
ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
#endif
- TREE_ASM_WRITTEN (decl) = 1;
#else
warning ("alias definitions not supported in this configuration; ignored");
#endif
#endif
}
/* Emit an assembler directive to set symbol for DECL visibility to
--- 5010,5023 ----
#else
ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
#endif
#else
warning ("alias definitions not supported in this configuration; ignored");
#endif
#endif
+
+ TREE_USED (decl) = 1;
+ TREE_ASM_WRITTEN (decl) = 1;
+ TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
}
/* Emit an assembler directive to set symbol for DECL visibility to
Index: gcc/config/alpha/alpha.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/alpha/alpha.c,v
retrieving revision 1.246
diff -c -p -d -r1.246 alpha.c
*** gcc/config/alpha/alpha.c 5 May 2002 21:54:38 -0000 1.246
--- gcc/config/alpha/alpha.c 15 May 2002 16:42:33 -0000
*************** alpha_encode_section_info (decl, first)
*** 1678,1684 ****
XSTR (XEXP (DECL_RTL (decl), 0), 0) = string;
}
else if (symbol_str[0] == '@')
! abort ();
}
/* legitimate_address_p recognizes an RTL expression that is a valid
--- 1678,1688 ----
XSTR (XEXP (DECL_RTL (decl), 0), 0) = string;
}
else if (symbol_str[0] == '@')
! {
! /* We're hosed. This can happen when the user adds a weak
! attribute after rtl generation. They should have gotten
! a warning about unspecified behaviour from varasm.c. */
! }
}
/* legitimate_address_p recognizes an RTL expression that is a valid
Index: gcc/testsuite/gcc.dg/weak-5.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/weak-5.c,v
retrieving revision 1.2
diff -c -p -d -r1.2 weak-5.c
*** gcc/testsuite/gcc.dg/weak-5.c 8 May 2002 14:37:55 -0000 1.2
--- gcc/testsuite/gcc.dg/weak-5.c 15 May 2002 16:42:33 -0000
*************** void * foo1c (void)
*** 44,50 ****
{
return (void *)&vfoo1c;
}
! extern int vfoo1c __attribute__((weak)); /* { dg-warning "weak declaration" "weak declaration" } */
extern int vfoo1d __attribute__((weak));
--- 44,50 ----
{
return (void *)&vfoo1c;
}
! extern int vfoo1c __attribute__((weak));
extern int vfoo1d __attribute__((weak));
*************** void * foo1f (void)
*** 68,74 ****
{
return (void *)&vfoo1f;
}
! extern int vfoo1f __attribute__((weak));
extern int vfoo1g;
--- 68,74 ----
{
return (void *)&vfoo1f;
}
! extern int vfoo1f __attribute__((weak)); /* { dg-warning "weak declaration" "weak declaration" } */
extern int vfoo1g;
*************** int vfoo1k = 1;
*** 111,116 ****
int vfoox1l = 1;
- extern int vfoo1l __attribute__((alias ("vfoox1l")));
extern int vfoo1l __attribute__((weak, alias ("vfoox1l")));
-
--- 111,114 ----
More information about the Gcc-patches
mailing list