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: ping: [PATCH] A global definition, followed by an extern declaration does not generate a defintion


Fariborz Jahanian <fjahanian@apple.com> writes:

> > I ran into this problem building 176.gcc with the GCC 3.4.  I can
> > reproduce this on Max OS X 10.2.  with -O2.
> > Culprit is the 'extern' decl after the definition.
> >
> > int merror = 0;
> > extern int merror;
> >
> > void mtherr (int code)
> > {
> >   merror = code + 1;
> > }
> >
> > int main()
> > {
> >         mtherr(7);
> > }
> >
> > % mygcc3.4 -c -O2 bad.c
> > /var/tmp//ccx1ZRjk.s:15:non-relocatable subtraction expression,
> > "_merror" minus "L00000000001$pb"
> > /var/tmp//ccx1ZRjk.s:15:symbol: "_merror" can't be undefined in a
> > subtraction expression
> > /var/tmp//ccx1ZRjk.s:13:non-relocatable subtraction expression,
> > "_merror" minus "L00000000001$pb"
> > /var/tmp//ccx1ZRjk.s:13:symbol: "_merror" can't be undefined in a
> > subtraction expression
> 
> Bug is side-effect of postponing generation of assembly definitions
> due to call-graph stuff.
> This change has exposed a bug in routine duplicate_decls. When the old
> declaration is a definition and
> the new declaration indiciates that it can be put in .common, the new
> declaration overrides the old declaration.
> Fix is to carry over the "common" attribute from the old to the new
> declaration. This in turn, preserves
> the attribute of the old declaration because new declaration attribute
> is copied to the old declaration
> attribute. So, when he assembly code for the variable is finally
> genarated (it was postponed), it will have
> a .global declaration. I have tested this fix on a Mac OS X version
> 10.2 with -O2.

This is OK.

> ChangeLog entry:
> 
> Index: ChangeLog
> ===================================================================
> RCS file: /cvs/gcc/gcc/gcc/ChangeLog,v
> retrieving revision 2.1262
> diff -c -p -r2.1262 ChangeLog
> *** ChangeLog   2 Oct 2003 17:22:51 -0000       2.1262
> --- ChangeLog   2 Oct 2003 21:53:52 -0000
> ***************
> *** 1,3 ****
> --- 1,7 ----
> + 2003-10-03  Fariborz Jahanian  <fjahanian@apple.com>
> +
> +       * c-decl.c (duplicate_decls): retain DECL_COMMON of old
> declaration
> +
>    2003-10-02  Zack Weinberg  <zack@codesourcery.com>
> 
>          * system.h: Poison macros obsoleted by earlier patch.
> 
> 
> Attached is the patch to fix this bug, a test case.
> 
> 
> Index: c-decl.c
> ===================================================================
> RCS file: /cvsroot/gcc/gcc/gcc/c-decl.c,v
> retrieving revision 1.453
> diff -c -p -r1.453 c-decl.c
> *** c-decl.c	28 Sep 2003 22:18:31 -0000	1.453
> --- c-decl.c	2 Oct 2003 21:32:27 -0000
> *************** duplicate_decls (tree newdecl, tree oldd
> *** 1385,1390 ****
> --- 1385,1391 ----
>         if (! DECL_EXTERNAL (newdecl))
>   	{
>   	  DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
> + 	  DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
>   	  /* If we have two non-EXTERNAL file-scope decls that are
>   	     the same, only one of them should be written out.  */
>   	  if (different_tu)
> 
> 
> 
> 
> 
> 
> 
> 
> Fariborz Jahanian  <fjahanian@apple.com>
> 
> 

-- 
- Geoffrey Keating <geoffk@geoffk.org>


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