This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: Don't allow weak variables in COMMON
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 23 May 2002 11:05:39 -0700
- Subject: PATCH: Don't allow weak variables in COMMON
- Reply-to: mark at codesourcery dot com
If you tried something like:
__attribute__((weak) int i;
you got an assembler error telling you that you can't have weak
symbols in common.
That's true; the fix is to have the compiler put the variable in
an ordinary data section if it's weak.
Bootstrapped and tested on i686-pc-linux-gnu; applied on the mainline.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
2002-05-23 Mark Mitchell <mark@codesourcery.com>
* varasm.c (make_decl_rtl): Don't allow weak variables to be
placed in common.
2002-05-23 Mark Mitchell <mark@codesourcery.com>
* gcc/testsuite/gcc.dg/weak-8.c: New test.
Index: gcc/varasm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/varasm.c,v
retrieving revision 1.284
diff -c -p -r1.284 varasm.c
*** gcc/varasm.c 22 May 2002 01:11:17 -0000 1.284
--- gcc/varasm.c 23 May 2002 17:57:36 -0000
*************** make_decl_rtl (decl, asmspec)
*** 922,927 ****
--- 922,931 ----
&& DECL_COMMON (decl))
DECL_COMMON (decl) = 0;
+ /* Variables can't be both common and weak. */
+ if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
+ DECL_COMMON (decl) = 0;
+
/* Can't use just the variable's own name for a variable
whose scope is less than the whole file, unless it's a member
of a local class (which will already be unambiguous).
Index: testsuite/gcc.dg/weak-8.c
===================================================================
RCS file: testsuite/gcc.dg/weak-8.c
diff -N testsuite/gcc.dg/weak-8.c
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.dg/weak-8.c 23 May 2002 18:05:23 -0000
***************
*** 0 ****
--- 1,10 ----
+ /* { dg-do assemble } */
+
+ /* COFF does not support weak, and dg doesn't support UNSUPPORTED. */
+ /* { dg-do assemble { xfail *-*-coff i?86-pc-cygwin h8300-*-hms } } */
+
+ __attribute__ ((weak)) int i;
+
+ int f() {
+ return i;
+ }