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: [patch, spu] Fix invalid -fPIC leaf function code generation


Yes, this is OK.

Trevor

* Ulrich Weigand <uweigand@de.ibm.com> [2009-11-16 12:10]:
> 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


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