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]

Re: PPC -fpic bug introduced recently


Franz Sirl <Franz.Sirl-kernel@lauterbach.com> wrote:
> this change:
>
> Wed Sep  8 14:34:42 1999  Ian Piumarta  <piumarta@prof.inria.fr>
>                           Melissa O'Neill  <oneill@cs.sfu.ca>
>                           Geoffrey Keating  <geoffk@cygnus.com>
>
>         * config/rs6000/rs6000.c (first_reg_to_save): Don't save fixed or
>         call-used registers (call-saved registers must still be contiguous
>         and end with r31, of course).
>
> breaks compilation with -fpic (shared libs on Linux/PPC are completely
> broken now), cause PIC_OFFSET_TABLE_REGNUM will no longer be saved
> across calls. Please revert or correct it.

Looks like what it has really done is exposed another bug. If the pic
offset table register is supposed to be call-saved, it should be marked
as a call-saved register -- right now it's marked as a call-used register.

If you take a look at rs6000.h, you'll see (in the #definition of
CONDITIONAL_REGISTER_USAGE):
  if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)		\
      && flag_pic == 1)							\
    fixed_regs[PIC_OFFSET_TABLE_REGNUM]					\
      = call_used_regs[PIC_OFFSET_TABLE_REGNUM] = 1;			\

This says pretty clearly that PIC_OFFSET_TABLE_REGNUM is *not* to be
saved across calls.

Since the PPC defines PIC_OFFSET_TABLE_REGNUM to be a high numbered
register (r30), it's clear that the intent is for this register to be
a call-saved register.  (Someone might want to look at the tradeoffs
involved in using r13, leaving the above code alone, and defining
PIC_OFFSET_TABLE_REG_CALL_CLOBBERED, but my feeling is that that would
be a worse solution).

So anyway, it appears the logical patch would be:

(CONDITIONAL_REGISTER_USAGE)    Don't make the pic offset table register
				a call-used register.
--- config/rs6000/rs6000.h	Thu Aug 19 01:21:45 1999
+++ config/rs6000/rs6000.h.new	Tue Oct  5 09:28:15 1999
@@ -894,10 +894,9 @@
     for (i = 32; i < 64; i++)						\
       fixed_regs[i] = call_used_regs[i] = 1; 				\
   if ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_SOLARIS)		\
       && flag_pic == 1)							\
-    fixed_regs[PIC_OFFSET_TABLE_REGNUM]					\
-      = call_used_regs[PIC_OFFSET_TABLE_REGNUM] = 1;			\
+    fixed_regs[PIC_OFFSET_TABLE_REGNUM] = 1;				\
 }

 /* Specify the registers used for certain standard purposes.
    The values of these macros are register numbers.  */

Assuming this is right, the code register saving code should be modified
to be a little less zealous. (I think Ian Piumarta's test on
fixed_regs[first_reg] was redundant, and appears to disallowed fixed
registers that wanted to be call saved, which this case shows not to be
desirable):

(first_reg_to_save)		Removed redundant (and wrong) test. Fixed
				registers *can* be call-saved registers.
--- config/rs6000/rs6000.c	Fri Sep  3 00:54:28 1999
+++ config/rs6000/rs6000.c.new	Tue Oct  5 09:51:33 1999
@@ -3242,10 +3242,9 @@

   /* Find lowest numbered live register.  */
   for (first_reg = 13 + FIXED_R13; first_reg <= 31; first_reg++)
     if (regs_ever_live[first_reg]
-	&& !call_used_regs[first_reg]
-	&& !fixed_regs[first_reg])
+	&& !call_used_regs[first_reg])
       break;

   if (profile_flag)
     {

I'm not a PIC code expert, so insightful comments would be welcome.  If
you could try this patch and see if it works for compiling the shared
libraries, that would be great.

    Melissa.


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