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]

Re: #pragma weak is broken in 3.1, partail fix


On Tue, May 21, 2002 at 11:31:49AM -0700, Richard Henderson wrote:
> On Tue, May 21, 2002 at 04:57:08PM +0200, Marc Espie wrote:
> > Both the following snippets show the same problem:
> > void f();
> > #pragma weak f=_f

> This one should work,

> > void f() __attribute__ ((weak, alias("_f")));
> > #pragma weak f=_f

> This one defines the weak alias twice, and is in error.
> A declaration with an alias attribute is a definition,
> not a declaration.


Here is a better patch, that fixes things on gcc 3.1.

Basically, there are two problems.

* one is structural:   I don't understand how new code to handle #pragma
weak could have been written and never even TESTED on any testcase before
being committed.

* the code that handles attribute lists is exceptionally brittle. It
shouldn't matter in which order alias/weak attributes are declared. Well,
right now it does.


So, I'd like the following patch in both HEAD and 3.1 branch. And I think
that mid-term, fixing the handling of __attribute__((alias("string"), weak)
so that it *works* should be done.


2002-05-25	Marc Espie <espie@openbsd.org>
	c-pragma.c (apply_pragma_weak):  Rearrange attribute building to work.

*** c-pragma.c.orig	Tue May 21 08:28:15 2002
--- c-pragma.c	Sat May 25 10:48:45 2002
*************** static void
*** 283,297 ****
  apply_pragma_weak (decl, value)
       tree decl, value;
  {
    if (value)
!     decl_attributes (&decl, build_tree_list (get_identifier ("alias"),
! 				             build_tree_list (NULL, value)),
  		     0);
    if (SUPPORTS_WEAK && DECL_EXTERNAL (decl) && TREE_USED (decl)
        && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
      warning_with_decl (decl, "applying #pragma weak `%s' after first use results in unspecified behavior");
- 
-   declare_weak (decl);
  }
  
  void
--- 283,299 ----
  apply_pragma_weak (decl, value)
       tree decl, value;
  {
+   declare_weak (decl);
    if (value)
!     decl_attributes (&decl, 
!     		     build_tree_list (get_identifier ("alias"),
! 				      build_tree_list (NULL, 
! 				      		       build_string (IDENTIFIER_LENGTH (value), 
! 						       		     IDENTIFIER_POINTER (value)))),
  		     0);
    if (SUPPORTS_WEAK && DECL_EXTERNAL (decl) && TREE_USED (decl)
        && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
      warning_with_decl (decl, "applying #pragma weak `%s' after first use results in unspecified behavior");
  }
  
  void


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