Fileutils

Florian Engelhardt f.engelhardt at gmx.net
Wed Jul 18 08:27:38 PDT 2001


> it's a gcc 2.95.3 bug. franz sirl created a patch

here's the patch:



Index: gcc/c-decl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-decl.c,v
retrieving revision 1.61.4.2
diff -u -p -r1.61.4.2 c-decl.c
--- gcc/c-decl.c        2001/01/25 14:02:59     1.61.4.2
+++ gcc/c-decl.c        2001/05/01 17:11:23
@@ -1,6 +1,6 @@
 /* Process declarations and variables for C compiler.
-   Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
-   Free Software Foundation, Inc.
+   Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
+   2001 Free Software Foundation, Inc.

 This file is part of GNU CC.

@@ -29,6 +29,7 @@ Boston, MA 02111-1307, USA.  */

 #include "config.h"
 #include "system.h"
+#include "rtl.h"
 #include "tree.h"
 #include "flags.h"
 #include "output.h"
@@ -41,6 +42,8 @@ Boston, MA 02111-1307, USA.  */
 extern cpp_reader parse_in;
 #endif

+extern void declare_weak PARAMS ((tree));
+
 /* In grokdeclarator, distinguish syntactic contexts of declarators.  */
 enum decl_context
 { NORMAL,                      /* Ordinary declaration */
@@ -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)
     {
Index: gcc/rtl.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/rtl.h,v
retrieving revision 1.105.4.4
diff -u -p -r1.105.4.4 rtl.h
--- gcc/rtl.h   2001/04/06 11:37:50     1.105.4.4
+++ gcc/rtl.h   2001/05/01 17:11:27
@@ -162,7 +162,8 @@ typedef struct rtx_def
   unsigned int used : 1;
   /* Nonzero if this rtx came from procedure integration.
      In a REG, nonzero means this reg refers to the return value
-     of the current function.  */
+     of the current function.
+      1 in a SYMBOL_REF if the symbol is weak.  */
   unsigned integrated : 1;
   /* 1 in an INSN or a SET if this rtx is related to the call frame,
      either changing how we compute the frame address or saving and
@@ -660,6 +661,9 @@ extern char *note_insn_name[];

 /* 1 means a SYMBOL_REF has been the library function in emit_library_call.  */
 #define SYMBOL_REF_USED(RTX) ((RTX)->used)
+
+/* 1 means a SYMBOL_REF is weak.  */
+#define SYMBOL_REF_WEAK(RTX) ((RTX)->integrated)

 /* For an INLINE_HEADER rtx, FIRST_FUNCTION_INSN is the first insn
    of the function that is not involved in copying parameters to
Index: gcc/rtlanal.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/rtlanal.c,v
retrieving revision 1.36.4.2
diff -u -p -r1.36.4.2 rtlanal.c
--- gcc/rtlanal.c       2001/01/25 14:03:22     1.36.4.2
+++ gcc/rtlanal.c       2001/05/01 17:11:27
@@ -136,11 +136,9 @@ rtx_addr_can_trap_p (x)
   switch (code)
     {
     case SYMBOL_REF:
+      return SYMBOL_REF_WEAK (x);
+
     case LABEL_REF:
-      /* SYMBOL_REF is problematic due to the possible presence of
-        a #pragma weak, but to say that loads from symbols can trap is
-        *very* costly.  It's not at all clear what's best here.  For
-        now, we ignore the impact of #pragma weak.  */
       return 0;

     case REG:
Index: gcc/varasm.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/varasm.c,v
retrieving revision 1.59.4.8
diff -u -p -r1.59.4.8 varasm.c
--- gcc/varasm.c        2001/03/28 09:02:17     1.59.4.8
+++ gcc/varasm.c        2001/05/01 17:11:28
@@ -118,6 +118,8 @@ struct constant_descriptor;
 struct rtx_const;
 struct pool_constant;

+void declare_weak PROTO ((tree));
+
 static const char *strip_reg_name      PROTO((const char *));
 static int contains_pointers_p         PROTO((tree));
 static void decode_addr_const          PROTO((tree, struct addr_const *));
@@ -143,6 +145,7 @@ static int output_addressed_constants       PR
 static void output_after_function_constants PROTO((void));
 static void output_constructor         PROTO((tree, int));
 static void remove_from_pending_weak_list      PROTO ((char *));
+static int is_on_pending_weak_list     PROTO ((char *));
 #ifdef ASM_OUTPUT_BSS
 static void asm_output_bss             PROTO((FILE *, tree, char *, int, int));
 #endif
@@ -755,6 +758,9 @@ make_decl_rtl (decl, asmspec, top_level)
          DECL_RTL (decl) = gen_rtx_MEM (DECL_MODE (decl),
                                         gen_rtx_SYMBOL_REF (Pmode, name));
          MEM_ALIAS_SET (DECL_RTL (decl)) = get_alias_set (decl);
+         if (is_on_pending_weak_list (name))
+           declare_weak (decl);
+         SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = DECL_WEAK (decl);

          /* If this variable is to be treated as volatile, show its
             tree node has side effects.  If it has side effects, either
@@ -4344,8 +4350,15 @@ declare_weak (decl)
 {
   if (! TREE_PUBLIC (decl))
     error_with_decl (decl, "weak declaration of `%s' must be public");
+#if 0
+  /* Due to a bug this error was never active, enabling it now would break
+   glibc.  */
   else if (TREE_ASM_WRITTEN (decl))
     error_with_decl (decl, "weak declaration of `%s' must precede definition");
+  /* This would be a new error, but it would break glibc too :-(.  */
+  else if (TREE_USED (decl))
+    error_with_decl (decl, "weak declaration of `%s' must precede its uses");
+#endif
   else if (SUPPORTS_WEAK)
     DECL_WEAK (decl) = 1;
 #ifdef HANDLE_PRAGMA_WEAK
@@ -4397,6 +4410,24 @@ remove_from_pending_weak_list (name)
        }
     }
 #endif
+}
+
+static int
+is_on_pending_weak_list (name)
+     char *name;
+{
+#ifdef HANDLE_PRAGMA_WEAK
+  if (HANDLE_PRAGMA_WEAK)
+    {
+      struct weak_syms *t;
+      for (t = weak_decls; t; t = t->next)
+       {
+         if (t->name && strcmp (name, t->name) == 0)
+           return 1;
+       }
+    }
+#endif
+  return 0;
 }

 void

-- 
Unsubscribe: send email to lfs-discuss-request at linuxfromscratch.org
and put unsubscribe in the subject header of the message



More information about the lfs-dev mailing list