This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] PR middle-end/11397: Weak aliases on Tru64


The following patch is my proposed solution to PR middle-end/11397
where we incorrectly generate assembler directives for weak aliases
on Tru64 and similar platforms.  The problem described in the PR is
that we emit both a ".weakext a __a" and a ".weakext a".

The problem is that at the point we generate the first weak alias,
in varasm.c's assemble_alias, we fail to remove the declaration
from the deferred weak_decls list.  Then when we call weak_finish
at the end of compilation, we re-emit a ".weakext" to mark the DECL
as weak, but this time without alias information.

I believe the correct solution is to remove the DECL from the
weak_decls list at the point we emit/mark it as a weak alias in
assemble_alias.  This makes assemble_alias consistent with the
other uses of ASM_WEAKEN_DECL in varasm.c, that also remove the
DECL from weak_decls.


I also noticed that the testcase wkali-2.c was failing on Tru64 with the
error message "only weak aliases are supported in this configuration".
I've no idea whether this is correct or not, but I've also tweaked the
testcase, such that we only run this test on platforms that support
aliases, to match the testcase's use of a non-weak alias in wkali-2b.c.


The following patch has been tested on both i686-pc-linux-gnu and
alphaev67-dec-osf5.1, with a full bootstrap, all languages except
Ada and treelang, and regression tested with a top-level "make -k check"
with no new failures.

Ok for mainline?  And the gcc-3_3-branch?



2004-01-11  Roger Sayle  <roger@eyesopen.com>

	PR middle-end/11397
	* varasm.c (assemble_alias): Remove weak aliases from weak_decls.

	* gcc.dg/special/wkali-2.c: Add dg-require-alias.


Index: varasm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/varasm.c,v
retrieving revision 1.402
diff -c -3 -p -r1.402 varasm.c
*** varasm.c	6 Jan 2004 16:51:21 -0000	1.402
--- varasm.c	12 Jan 2004 02:00:11 -0000
***************
*** 1,6 ****
  /* Output variables, constants and external declarations, for GNU compiler.
     Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
!    1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.

  This file is part of GCC.

--- 1,6 ----
  /* Output variables, constants and external declarations, for GNU compiler.
     Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
!    1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.

  This file is part of GCC.

*************** assemble_alias (tree decl, tree target A
*** 4411,4424 ****
  #endif
  #else /* !ASM_OUTPUT_DEF */
  #if defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
!   if (! DECL_WEAK (decl))
!     warning ("only weak aliases are supported in this configuration");
!
  #ifdef ASM_WEAKEN_DECL
!   ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
  #else
!   ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
  #endif
  #else
    warning ("alias definitions not supported in this configuration; ignored");
  #endif
--- 4411,4436 ----
  #endif
  #else /* !ASM_OUTPUT_DEF */
  #if defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
!   if (DECL_WEAK (decl))
!     {
!       tree *p, t;
  #ifdef ASM_WEAKEN_DECL
!       ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
  #else
!       ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
  #endif
+       /* Remove this function from the pending weak list so that
+ 	 we do not emit multiple .weak directives for it.  */
+       for (p = &weak_decls; (t = *p) ; )
+ 	if (DECL_ASSEMBLER_NAME (decl)
+ 	    == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
+ 	  *p = TREE_CHAIN (t);
+ 	else
+ 	  p = &TREE_CHAIN (t);
+     }
+   else
+     warning ("only weak aliases are supported in this configuration");
+
  #else
    warning ("alias definitions not supported in this configuration; ignored");
  #endif
Index: testsuite/gcc.dg/special/wkali-2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/special/wkali-2.c,v
retrieving revision 1.4
diff -c -3 -p -r1.4 wkali-2.c
*** testsuite/gcc.dg/special/wkali-2.c	5 Jun 2003 22:18:54 -0000	1.4
--- testsuite/gcc.dg/special/wkali-2.c	12 Jan 2004 02:00:11 -0000
***************
*** 1,5 ****
--- 1,6 ----
  /* { dg-do run } */
  /* { dg-require-weak "" } */
+ /* { dg-require-alias "" } */
  /* { dg-additional-sources "wkali-2a.c wkali-2b.c" } */

  #include <stdlib.h>


Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]