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 to fix bug 7544


This patch fixes bug 7544, as defined by the submitter:

# When using '#pragma weak bar = foo', gcc does not output anything,
# unless bar is declared.  gcc-2.95 and other compilers do not require
# such a declaration.

An oversimplified example was then given in the bug, but the
description was still an accurate description of a regression
(relative to 2.95.x and 3.0.x) bug in GCC: foo needs to be defined in
the translation unit for the pragma to make sense, but bar doesn't
need to be declared.  The tests I've added (for C, ObjC and C++ as
each language has code changes) deliberately cover only the meaningful
case where foo is defined.  Sun's specification indicates that the
case where foo isn't defined in the translation unit should be
rejected, but failing to reject it is a separate bug which is not a
regression.

This is the last patch from the Solaris 10 branches to be submitted
for mainline for now.  One non-regression fix
<http://gcc.gnu.org/ml/gcc-patches/2004-11/msg01895.html> submitted
before the freeze remains to be reviewed; two patches are present on
csl-sol210-3_4-branch but not csl-sol210-branch and are not proposed
for mainline for now (default RPATH for C++, and allowing #pragma
align after declaration); and a failure to build 64-bit libstdc++-v3
has yet to be investigated in detail and fixed.

Bootstrapped with no regressions on i386-pc-solaris2.10.  OK to
commit?

2004-11-28  Daniel Jacobowitz  <dan@codesourcery.com>

	PR c/7544
	* Makefile.in (c-lang.o): Update dependencies.
	* c-lang.c: Include "c-pragma.h".
	(finish_file): Call maybe_apply_pending_pragma_weaks.
	* c-pragma.c (maybe_apply_pending_pragma_weaks): New function.
	* c-pragma.h (maybe_apply_pending_pragma_weaks): New prototype.

cp:
2004-11-28  Daniel Jacobowitz  <dan@codesourcery.com>

	PR c/7544
	* Make-lang.in (cp/decl2.o): Update dependencies.
	* decl2.c (finish_file): Call maybe_apply_pending_pragma_weaks.

objc:
2004-11-28  Joseph Myers  <joseph@codesourcery.com>

	PR c/7544
	* Make-lang.in (objc/objc-act.o): Update dependencies.
	* objc-act.c (objc_finish_file): Call
	maybe_apply_pending_pragma_weaks if not OBJCPLUS.

testsuite:
2004-11-28  Joseph Myers  <joseph@codesourcery.com>

	PR c/7544
	* g++.dg/ext/weak1.C, gcc.dg/weak/weak-10.c, objc.dg/weak-1.m: New
	tests.

diff -rupN GCC.orig/gcc/Makefile.in GCC/gcc/Makefile.in
--- GCC.orig/gcc/Makefile.in	2004-11-26 14:53:32.000000000 +0000
+++ GCC/gcc/Makefile.in	2004-11-28 17:02:07.000000000 +0000
@@ -1380,7 +1380,7 @@ c-typeck.o : c-typeck.c $(CONFIG_H) $(SY
 c-lang.o : c-lang.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
     $(C_TREE_H) $(C_PRETTY_PRINT_H) $(DIAGNOSTIC_H) \
     $(GGC_H) langhooks.h $(LANGHOOKS_DEF_H) $(C_COMMON_H) gtype-c.h \
-    c-objc-common.h
+    c-objc-common.h c-pragma.h
 stub-objc.o : stub-objc.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TREE_H) \
     $(GGC_H) $(C_COMMON_H)
 c-lex.o : c-lex.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
diff -rupN GCC.orig/gcc/c-lang.c GCC/gcc/c-lang.c
--- GCC.orig/gcc/c-lang.c	2004-11-03 09:48:50.000000000 +0000
+++ GCC/gcc/c-lang.c	2004-11-28 16:59:31.000000000 +0000
@@ -34,6 +34,7 @@ Software Foundation, 59 Temple Place - S
 #include "diagnostic.h"
 #include "c-pretty-print.h"
 #include "c-objc-common.h"
+#include "c-pragma.h"
 
 enum c_language_kind c_language = clk_c;
 
@@ -88,6 +89,7 @@ const char *const tree_code_name[] = {
 void
 finish_file (void)
 {
+  maybe_apply_pending_pragma_weaks ();
 }
 
 #include "gtype-c.h"
diff -rupN GCC.orig/gcc/c-pragma.c GCC/gcc/c-pragma.c
--- GCC.orig/gcc/c-pragma.c	2004-11-23 23:16:21.000000000 +0000
+++ GCC/gcc/c-pragma.c	2004-11-28 17:00:05.000000000 +0000
@@ -294,6 +294,33 @@ maybe_apply_pragma_weak (tree decl)
       }
 }
 
+/* Process all "#pragma weak A = B" directives where we have not seen
+   a decl for A.  */
+void
+maybe_apply_pending_pragma_weaks (void)
+{
+  tree *p, t, alias_id, id, decl, *next;
+
+  for (p = &pending_weaks; (t = *p) ; p = next)
+    {
+      next = &TREE_CHAIN (t);
+      alias_id = TREE_PURPOSE (t);
+      id = TREE_VALUE (t);
+
+      if (TREE_VALUE (t) == NULL)
+	continue;
+
+      decl = build_decl (FUNCTION_DECL, alias_id, default_function_type);
+
+      DECL_ARTIFICIAL (decl) = 1;
+      TREE_PUBLIC (decl) = 1;
+      DECL_EXTERNAL (decl) = 1;
+      DECL_WEAK (decl) = 1;
+
+      assemble_alias (decl, id);
+    }
+}
+
 /* #pragma weak name [= value] */
 static void
 handle_pragma_weak (cpp_reader * ARG_UNUSED (dummy))
@@ -330,6 +357,11 @@ void
 maybe_apply_pragma_weak (tree ARG_UNUSED (decl))
 {
 }
+
+void
+maybe_apply_pending_pragma_weaks (void)
+{
+}
 #endif /* HANDLE_PRAGMA_WEAK */
 
 /* GCC supports two #pragma directives for renaming the external
diff -rupN GCC.orig/gcc/c-pragma.h GCC/gcc/c-pragma.h
--- GCC.orig/gcc/c-pragma.h	2004-11-23 23:16:21.000000000 +0000
+++ GCC/gcc/c-pragma.h	2004-11-28 17:00:25.000000000 +0000
@@ -60,6 +60,7 @@ extern void c_register_pragma (const cha
 extern void c_register_pragma_with_expansion (const char *, const char *,
 					      void (*) (struct cpp_reader *));
 extern void maybe_apply_pragma_weak (tree);
+extern void maybe_apply_pending_pragma_weaks (void);
 extern tree maybe_apply_renaming_pragma (tree, tree);
 extern void add_to_renaming_pragma_list (tree, tree);
 
diff -rupN GCC.orig/gcc/cp/Make-lang.in GCC/gcc/cp/Make-lang.in
--- GCC.orig/gcc/cp/Make-lang.in	2004-11-16 11:06:14.000000000 +0000
+++ GCC/gcc/cp/Make-lang.in	2004-11-28 16:59:31.000000000 +0000
@@ -232,7 +232,8 @@ cp/decl.o: cp/decl.c $(CXX_TREE_H) $(TM_
   cp/operators.def $(TM_P_H) tree-inline.h diagnostic.h c-pragma.h \
   debug.h gt-cp-decl.h timevar.h $(TREE_FLOW_H)
 cp/decl2.o: cp/decl2.c $(CXX_TREE_H) $(TM_H) flags.h cp/decl.h $(EXPR_H) \
-  output.h except.h toplev.h $(RTL_H) c-common.h gt-cp-decl2.h cgraph.h
+  output.h except.h toplev.h $(RTL_H) c-common.h gt-cp-decl2.h cgraph.h \
+  c-pragma.h
 cp/cp-objcp-common.o : cp/cp-objcp-common.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
   $(TM_H) $(TREE_H) $(CXX_TREE_H) c-common.h toplev.h langhooks.h \
   $(LANGHOOKS_DEF_H) $(DIAGNOSTIC_H) debug.h $(CXX_PRETTY_PRINT_H) \
diff -rupN GCC.orig/gcc/cp/decl2.c GCC/gcc/cp/decl2.c
--- GCC.orig/gcc/cp/decl2.c	2004-11-24 14:28:49.000000000 +0000
+++ GCC/gcc/cp/decl2.c	2004-11-28 16:59:31.000000000 +0000
@@ -48,6 +48,7 @@ Boston, MA 02111-1307, USA.  */
 #include "tree-mudflap.h"
 #include "cgraph.h"
 #include "tree-inline.h"
+#include "c-pragma.h"
 
 extern cpp_reader *parse_in;
 
@@ -3062,6 +3063,9 @@ cp_finish_file (void)
   if (priority_info_map)
     splay_tree_delete (priority_info_map);
 
+  /* Generate any missing aliases.  */
+  maybe_apply_pending_pragma_weaks ();
+
   /* We're done with static constructors, so we can go back to "C++"
      linkage now.  */
   pop_lang_context ();
diff -rupN GCC.orig/gcc/objc/Make-lang.in GCC/gcc/objc/Make-lang.in
--- GCC.orig/gcc/objc/Make-lang.in	2004-11-04 22:33:24.000000000 +0000
+++ GCC/gcc/objc/Make-lang.in	2004-11-28 17:02:33.000000000 +0000
@@ -73,7 +73,7 @@ objc/objc-act.o : objc/objc-act.c \
    $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) $(RTL_H) $(TM_P_H) \
    $(EXPR_H) $(TARGET_H) $(C_TREE_H) diagnostic.h toplev.h flags.h \
    objc/objc-act.h input.h function.h output.h debug.h langhooks.h \
-   $(LANGHOOKS_DEF_H) $(HASHTAB_H) gt-objc-objc-act.h
+   $(LANGHOOKS_DEF_H) $(HASHTAB_H) c-pragma.h gt-objc-objc-act.h
 
 objc.srcextra: objc/objc-parse.c objc/objc-parse.y
 	-cp -p $^ $(srcdir)/objc
diff -rupN GCC.orig/gcc/objc/objc-act.c GCC/gcc/objc/objc-act.c
--- GCC.orig/gcc/objc/objc-act.c	2004-11-09 21:18:12.000000000 +0000
+++ GCC/gcc/objc/objc-act.c	2004-11-28 17:01:30.000000000 +0000
@@ -55,6 +55,7 @@ Boston, MA 02111-1307, USA.  */
 #endif
 
 #include "c-common.h"
+#include "c-pragma.h"
 #include "flags.h"
 #include "langhooks.h"
 #include "objc-act.h"
@@ -602,6 +603,8 @@ objc_finish_file (void)
 
 #ifdef OBJCPLUS
   cp_finish_file ();
+#else
+  maybe_apply_pending_pragma_weaks ();
 #endif
 }
 
diff -rupN GCC.orig/gcc/testsuite/g++.dg/ext/weak1.C GCC/gcc/testsuite/g++.dg/ext/weak1.C
--- GCC.orig/gcc/testsuite/g++.dg/ext/weak1.C	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/g++.dg/ext/weak1.C	2004-11-28 17:27:06.000000000 +0000
@@ -0,0 +1,13 @@
+// Test for #pragma weak where the weak alias symbol isn't declared,
+// although the symbol it is an alias for is defined in the
+// translation unit.  Bug 7544.
+// Origin: Joseph Myers <joseph@codesourcery.com>
+// { dg-do compile }
+// { dg-require-weak "" }
+// { dg-require-alias "" }
+// { dg-options "-fno-common" }
+
+// { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?bar1" } } 
+
+#pragma weak bar1 = foo1
+extern "C" void foo1 (void) {}
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/weak/weak-10.c GCC/gcc/testsuite/gcc.dg/weak/weak-10.c
--- GCC.orig/gcc/testsuite/gcc.dg/weak/weak-10.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/weak/weak-10.c	2004-11-28 17:23:38.000000000 +0000
@@ -0,0 +1,13 @@
+/* Test for #pragma weak where the weak alias symbol isn't declared,
+   although the symbol it is an alias for is defined in the
+   translation unit.  Bug 7544.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-require-weak "" } */
+/* { dg-require-alias "" } */
+/* { dg-options "-fno-common" } */
+
+/* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?bar1" } } */
+
+#pragma weak bar1 = foo1
+void foo1 (void) {}
diff -rupN GCC.orig/gcc/testsuite/objc.dg/weak-1.m GCC/gcc/testsuite/objc.dg/weak-1.m
--- GCC.orig/gcc/testsuite/objc.dg/weak-1.m	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/objc.dg/weak-1.m	2004-11-28 17:24:47.000000000 +0000
@@ -0,0 +1,13 @@
+/* Test for #pragma weak where the weak alias symbol isn't declared,
+   although the symbol it is an alias for is defined in the
+   translation unit.  Bug 7544.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-require-weak "" } */
+/* { dg-require-alias "" } */
+/* { dg-options "-fno-common" } */
+
+/* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?bar1" } } */
+
+#pragma weak bar1 = foo1
+void foo1 (void) {}

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    jsm@polyomino.org.uk (personal mail)
    joseph@codesourcery.com (CodeSourcery mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)


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