This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch, spu] Fix invalid -fPIC leaf function code generation
- From: "Ulrich Weigand" <uweigand at de dot ibm dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: trevor_smigiel at playstation dot sony dot com, andrew_pinski at playstation dot sony dot com
- Date: Mon, 16 Nov 2009 21:06:07 +0100 (CET)
- Subject: [patch, spu] Fix invalid -fPIC leaf function code generation
Hello,
when compiling the following test program with -fPIC
int a;
int *test (void) { return &a; }
current FSF compilers generate
test:
ila $75,.+8
brsl $126,4
sf $126,$75,$126
stqd $sp,-48($sp)
ai $sp,$sp,-48
ila $2,%pic(a)
a $2,$2,$126
ori $3,$2,0
ai $sp,$sp,48
bi $lr
Note how register 126 is clobbered by using it as PIC base register,
but it is never saved and restored -- breaking the ABI.
The reason is that need_to_save_reg assumes that in a leaf function
that doesn't otherwise use register 74, we can use *it* instead of
the PIC register and therefore do not need to save it. However,
the get_pic_reg routine ignores this and always uses register 126.
The following patch fixes this by performing the same test in get_pic_reg
that we did in need_to_save_reg and use register 74 when possible.
Tested on spu-elf without regressions.
OK for mainline / 4.4 branch / 4.3 branch?
Bye,
Ulrich
Index: gcc/config/spu/spu.c
===================================================================
*** gcc/config/spu/spu.c (revision 154075)
--- gcc/config/spu/spu.c (working copy)
*************** get_pic_reg (void)
*** 1710,1715 ****
--- 1710,1717 ----
rtx pic_reg = pic_offset_table_rtx;
if (!reload_completed && !reload_in_progress)
abort ();
+ if (current_function_is_leaf && !df_regs_ever_live_p (LAST_ARG_REGNUM))
+ pic_reg = gen_rtx_REG (SImode, LAST_ARG_REGNUM);
return pic_reg;
}
--
Dr. Ulrich Weigand
GNU Toolchain for Linux on System z and Cell BE
Ulrich.Weigand@de.ibm.com