PATCH: Don't allow weak variables in COMMON

Mark Mitchell mark@codesourcery.com
Thu May 23 11:25:00 GMT 2002


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;
+ }



More information about the Gcc-patches mailing list