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: PowerPC-sysV/eabi, harmonization of section attribute and small data optimization


Geoff Keating wrote:

> [The original patch proposal ...] reintroduces a bug that this code was
> designed to fix.  It is not OK.
>
> Code that triggers the bug can look like:
>
> static char array[4];
> t = array[x + 80000];   // valid values of x are -80000 through -79997
>
> GCC can internally optimise this into
>
> t = (array + 80000)[x];
>
> and 'array + 80000' can't be done with a SDA relocation.
>
> --
> - Geoffrey Keating <geoffk@geoffk.org>

As said before, you are right.

In order to allow objects to be explicitly allocated to the small data area with
the __attribute__((section (".sbss"))) *and* be subject to small data address
optimization, I came up with the endlosed enhanced patch. With this enhanced
patch, the above optimization-introduced compile-and-link error can occur only
for objects explicitly allocated to the small data area with a GNU compiler
extension.

I respectfully submit the patch to GNU gcc experts, whose judgment I will accept.

-----------------------------------------------------------
ChangeLog entry:

2003-02-17 Thierry Moreau <thierry.moreau@connotech.com>

* config/rs6000/rs6000.c functions rs6000_encode_section_info and
small_data_operand: PowerPC- sysV/eabi, harmonization of section attribute and
small data optimization
-----------------------------------------------------------

Many thanks for the GCC compiler technology.


Thanks.

--

- Thierry Moreau

CONNOTECH Experts-conseils inc.
9130 Place de Montgolfier
Montreal, Qc
H2M 2A1

Tel.: (514)385-5691
Fax:  (514)385-5900

e-mail: thierry.moreau@connotech.com

*** ../../../../gcc-3.2.2-orig/gcc/config/rs6000/rs6000.c	Thu Jan 23 17:19:42 2003
--- rs6000.c	Mon Feb 17 08:55:31 2003
***************
*** 1679,1691 ****
        rtx sum = XEXP (op, 0);
        HOST_WIDE_INT summand;
  
-       /* We have to be careful here, because it is the referenced address
-         that must be 32k from _SDA_BASE_, not just the symbol.  */
        summand = INTVAL (XEXP (sum, 1));
!       if (summand < 0 || summand > g_switch_value)
         return 0;
  
        sym_ref = XEXP (sum, 0);
      }
  
    if (*XSTR (sym_ref, 0) != '@')
--- 1679,1697 ----
        rtx sum = XEXP (op, 0);
        HOST_WIDE_INT summand;
  
        summand = INTVAL (XEXP (sum, 1));
!       if (summand < 0)
         return 0;
  
        sym_ref = XEXP (sum, 0);
+       /* We have to be careful here, because it is the referenced address
+         that must be 32k from _SDA_BASE_, not just the symbol,
+ 			e.g. as in int x[4]; x[25000-x]; -- the instruction referenced
+ 			address is x+100000.
+         Do not apply this test to objects explicitly allocated to a small section,
+ 			the g_switch _value does not apply to them. */
+       if ( XSTR (sym_ref, 0)[1] != '@' && summand > g_switch_value )
+        return 0;
      }
  
    if (*XSTR (sym_ref, 0) != '@')
***************
*** 11033,11060 ****
  	    abort ();
  	}
  
!       if ((size > 0 && size <= g_switch_value)
! 	  || (name
! 	      && ((len == sizeof (".sdata") - 1
  		   && strcmp (name, ".sdata") == 0)
! 		  || (len == sizeof (".sdata2") - 1
  		      && strcmp (name, ".sdata2") == 0)
! 		  || (len == sizeof (".sbss") - 1
  		      && strcmp (name, ".sbss") == 0)
! 		  || (len == sizeof (".sbss2") - 1
  		      && strcmp (name, ".sbss2") == 0)
! 		  || (len == sizeof (".PPC.EMB.sdata0") - 1
  		      && strcmp (name, ".PPC.EMB.sdata0") == 0)
! 		  || (len == sizeof (".PPC.EMB.sbss0") - 1
! 		      && strcmp (name, ".PPC.EMB.sbss0") == 0))))
  	{
  	  rtx sym_ref = XEXP (DECL_RTL (decl), 0);
  	  size_t len = strlen (XSTR (sym_ref, 0));
! 	  char *str = alloca (len + 2);
  
  	  str[0] = '@';
! 	  memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
! 	  XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1);
  	}
      }
  }
--- 11039,11068 ----
  	    abort ();
  	}
  
!       if (name?
! 		   ((len == sizeof (".sdata")
  		   && strcmp (name, ".sdata") == 0)
! 		  || (len == sizeof (".sdata2")
  		      && strcmp (name, ".sdata2") == 0)
! 		  || (len == sizeof (".sbss")
  		      && strcmp (name, ".sbss") == 0)
! 		  || (len == sizeof (".sbss2")
  		      && strcmp (name, ".sbss2") == 0)
! 		  || (len == sizeof (".PPC.EMB.sdata0")
  		      && strcmp (name, ".PPC.EMB.sdata0") == 0)
! 		  || (len == sizeof (".PPC.EMB.sbss0")
! 		      && strcmp (name, ".PPC.EMB.sbss0") == 0))
! 		   :(size > 0 && size <= g_switch_value))
  	{
  	  rtx sym_ref = XEXP (DECL_RTL (decl), 0);
  	  size_t len = strlen (XSTR (sym_ref, 0));
! 	  char *str = alloca (len + 3);
  
  	  str[0] = '@';
!      if (name)
!        str[1] = '@';
! 	  memcpy (str + 1 +(name!=NULL), XSTR (sym_ref, 0), len + 1);
! 	  XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1 +(name!=NULL));
  	}
      }
  }

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