diff mbox

Fix SH/FDPIC bad codegen with ssp enabled

Message ID 20151113165653.GA11709@brightrain.aerifal.cx
State New
Headers show

Commit Message

Rich Felker Nov. 13, 2015, 4:56 p.m. UTC
The "chk_guard_add" pattern used for loading the GOT slot address for
__stack_chk_guard hard-codes use of r12 as a fixed GOT register and
thus is not suitable for FDPIC, where the saved initial value of r12
from function entry is what we need.

I would actually prefer removing this hack entirely if possible. I
tried non-FDPIC with it disabled and did not experience any problems;
I suspect it was written to work around a bug that no longer exists.

2015-11-13  Rich Felker <dalias@libc.org>

	gcc/
	* config/sh/sh.md (symGOT_load): Suppress __stack_chk_guard
	address loading hack for FDPIC targets.

Comments

Kaz Kojima Nov. 14, 2015, 12:24 a.m. UTC | #1
Rich Felker <dalias@libc.org> wrote:
> The "chk_guard_add" pattern used for loading the GOT slot address for
> __stack_chk_guard hard-codes use of r12 as a fixed GOT register and
> thus is not suitable for FDPIC, where the saved initial value of r12
> from function entry is what we need.

The patch is OK.  Committed as revision 230366.

> I would actually prefer removing this hack entirely if possible. I
> tried non-FDPIC with it disabled and did not experience any problems;
> I suspect it was written to work around a bug that no longer exists.

Even we don't see the problem without that, it'll be a latent
issue with the old reload, I think.  When SH switches to LRA
completely, this should be revisit.

Regards,
	kaz
Rich Felker Nov. 15, 2015, 12:55 a.m. UTC | #2
On Sat, Nov 14, 2015 at 09:24:32AM +0900, Kaz Kojima wrote:
> Rich Felker <dalias@libc.org> wrote:
> > The "chk_guard_add" pattern used for loading the GOT slot address for
> > __stack_chk_guard hard-codes use of r12 as a fixed GOT register and
> > thus is not suitable for FDPIC, where the saved initial value of r12
> > from function entry is what we need.
> 
> The patch is OK.  Committed as revision 230366.

Thanks!

> > I would actually prefer removing this hack entirely if possible. I
> > tried non-FDPIC with it disabled and did not experience any problems;
> > I suspect it was written to work around a bug that no longer exists.
> 
> Even we don't see the problem without that, it'll be a latent
> issue with the old reload, I think.  When SH switches to LRA
> completely, this should be revisit.

I thought about trying a patch to eliminate the use of the hard-coded
PIC register and instead generate a pseudo for the GOT address. Then
some FDPIC and non-FDPIC code could potentially be unified to use this
pseudo, just with different ways of defining it (r12-at-entry vs
PC-relative symbolic load of _GLOBAL_OFFSET_TABLE_). Would this be
acceptable?

I've already done some experiments removing r12 from fixed_regs for
FDPIC and nothing visibly broke; gcc correctly used r12 as a temp in
functions which didn't need the GOT address, and codegen was improved
even in functions which do use it. These results were observed on musl
libc.so.

Rich
diff mbox

Patch

diff --git a/gcc/config/sh/sh.md b/gcc/config/sh/sh.md
index 7a40d0f..45c9995 100644
--- a/gcc/config/sh/sh.md
+++ b/gcc/config/sh/sh.md
@@ -11082,7 +11082,7 @@  (define_expand "symGOT_load"
   operands[2] = !can_create_pseudo_p () ? operands[0] : gen_reg_rtx (Pmode);
   operands[3] = !can_create_pseudo_p () ? operands[0] : gen_reg_rtx (Pmode);
 
-  if (!TARGET_SHMEDIA
+  if (!TARGET_SHMEDIA && !TARGET_FDPIC
       && flag_stack_protect
       && GET_CODE (operands[1]) == CONST
       && GET_CODE (XEXP (operands[1], 0)) == UNSPEC