* [Bug other/32163] Compiling with stack protector causes reigster spill failure
2007-05-31 11:35 [Bug other/32163] New: Compiling with stack protector causes reigster spill failure uwe at netbsd dot org
@ 2007-05-31 11:37 ` uwe at netbsd dot org
2007-05-31 11:44 ` uwe at netbsd dot org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: uwe at netbsd dot org @ 2007-05-31 11:37 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from uwe at netbsd dot org 2007-05-31 11:37 -------
Created an attachment (id=13638)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13638&action=view)
Preprocessed source of the file that causes the error.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32163
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug other/32163] Compiling with stack protector causes reigster spill failure
2007-05-31 11:35 [Bug other/32163] New: Compiling with stack protector causes reigster spill failure uwe at netbsd dot org
2007-05-31 11:37 ` [Bug other/32163] " uwe at netbsd dot org
@ 2007-05-31 11:44 ` uwe at netbsd dot org
2007-05-31 13:30 ` [Bug target/32163] " kkojima at gcc dot gnu dot org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: uwe at netbsd dot org @ 2007-05-31 11:44 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from uwe at netbsd dot org 2007-05-31 11:44 -------
Before failing to compile pic version of asprintf.o as reportde above,
non-pic version is successfully compiled.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32163
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/32163] Compiling with stack protector causes reigster spill failure
2007-05-31 11:35 [Bug other/32163] New: Compiling with stack protector causes reigster spill failure uwe at netbsd dot org
2007-05-31 11:37 ` [Bug other/32163] " uwe at netbsd dot org
2007-05-31 11:44 ` uwe at netbsd dot org
@ 2007-05-31 13:30 ` kkojima at gcc dot gnu dot org
2007-06-01 0:17 ` kkojima at gcc dot gnu dot org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: kkojima at gcc dot gnu dot org @ 2007-05-31 13:30 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from kkojima at gcc dot gnu dot org 2007-05-31 13:30 -------
I've confirmed that this fails with 4.1.2, 4.2.0 and 4.3.0
on sh4-unknown-linux-gnu. A reduced testcase is:
--
int foo ()
{
char *p;
char fext[128];
p = fext;
bar (&p, (void *)0);
if (p)
free (p);
return 0;
}
--
which fails with -O -fpic -fstack-protector. Curiously the error
went away with -O2 -fpic -fstack-protector.
--
kkojima at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |kkojima at gcc dot gnu dot
| |org
Status|UNCONFIRMED |NEW
Component|other |target
Ever Confirmed|0 |1
Keywords| |ice-on-valid-code
Known to fail| |4.1.2 4.2.0 4.3.0
Last reconfirmed|0000-00-00 00:00:00 |2007-05-31 13:30:12
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32163
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/32163] Compiling with stack protector causes reigster spill failure
2007-05-31 11:35 [Bug other/32163] New: Compiling with stack protector causes reigster spill failure uwe at netbsd dot org
` (2 preceding siblings ...)
2007-05-31 13:30 ` [Bug target/32163] " kkojima at gcc dot gnu dot org
@ 2007-06-01 0:17 ` kkojima at gcc dot gnu dot org
2007-06-03 4:39 ` kkojima at gcc dot gnu dot org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: kkojima at gcc dot gnu dot org @ 2007-06-01 0:17 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from kkojima at gcc dot gnu dot org 2007-06-01 00:17 -------
In the faulty case, stack protector inserts PIC codes after the result
is set to R0 register. It looks like
rX = __stack_chk_guard@GOT
A = rX + r12
B = mem[A]
and combine optimization pass makes this turn into
rX = __stack_chk_guard@GOT
B = mem[rX + r12]
Unfortunately, the last insn requires R0 which is already used and we
see the famous R0 spill failure. We didn't get this error on SH4 with
-O2 because the first insn scheduling and other optimizations move
the insn which set the result to R0 after these protector codes.
But it looks to be fragile even on SH4 -O2. I'm testing the patch
below on the trunk.
* config/sh/sh.md (symGOT_load): Don't schedule insns when
the symbol is generated with the stack protector.
--- ORIG/trunk/gcc/config/sh/sh.md 2007-04-27 21:30:47.000000000 +0900
+++ LOCAL/trunk/gcc/config/sh/sh.md 2007-06-01 08:21:18.000000000 +0900
@@ -8502,6 +8502,20 @@ label:
operands[2],
gen_rtx_REG (Pmode, PIC_REG)));
+ /* When stack protector inserts codes after the result is set to
+ R0, @(rX, r12) will cause a spill failure for R0. Don't schedule
+ insns to avoid combining (set A (plus rX r12)) and (set op0 (mem A))
+ when rX is a GOT address for the guard symbol. Ugly but doesn't
+ matter because this is a rare situation. */
+ if (!TARGET_SHMEDIA
+ && flag_stack_protect
+ && GET_CODE (operands[1]) == CONST
+ && GET_CODE (XEXP (operands[1], 0)) == UNSPEC
+ && GET_CODE (XVECEXP (XEXP (operands[1], 0), 0, 0)) == SYMBOL_REF
+ && strcmp (XSTR (XVECEXP (XEXP (operands[1], 0), 0, 0), 0),
+ \"__stack_chk_guard\") == 0)
+ emit_insn (gen_blockage ());
+
/* N.B. This is not constant for a GOTPLT relocation. */
mem = gen_rtx_MEM (Pmode, operands[3]);
MEM_NOTRAP_P (mem) = 1;
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32163
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/32163] Compiling with stack protector causes reigster spill failure
2007-05-31 11:35 [Bug other/32163] New: Compiling with stack protector causes reigster spill failure uwe at netbsd dot org
` (3 preceding siblings ...)
2007-06-01 0:17 ` kkojima at gcc dot gnu dot org
@ 2007-06-03 4:39 ` kkojima at gcc dot gnu dot org
2007-06-08 5:54 ` kkojima at gcc dot gnu dot org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: kkojima at gcc dot gnu dot org @ 2007-06-03 4:39 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from kkojima at gcc dot gnu dot org 2007-06-03 04:39 -------
Subject: Bug 32163
Author: kkojima
Date: Sun Jun 3 04:38:52 2007
New Revision: 125292
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=125292
Log:
PR target/32163
* config/sh/sh.md (symGOT_load): Don't schedule insns when
the symbol is generated with the stack protector.
Modified:
trunk/gcc/ChangeLog
trunk/gcc/config/sh/sh.md
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32163
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/32163] Compiling with stack protector causes reigster spill failure
2007-05-31 11:35 [Bug other/32163] New: Compiling with stack protector causes reigster spill failure uwe at netbsd dot org
` (4 preceding siblings ...)
2007-06-03 4:39 ` kkojima at gcc dot gnu dot org
@ 2007-06-08 5:54 ` kkojima at gcc dot gnu dot org
2007-06-08 5:56 ` kkojima at gcc dot gnu dot org
2007-06-08 5:58 ` kkojima at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: kkojima at gcc dot gnu dot org @ 2007-06-08 5:54 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from kkojima at gcc dot gnu dot org 2007-06-08 05:54 -------
Subject: Bug 32163
Author: kkojima
Date: Fri Jun 8 05:53:57 2007
New Revision: 125558
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=125558
Log:
PR target/32163
Backport from mainline.
* config/sh/sh.md (symGOT_load): Don't schedule insns when
the symbol is generated with the stack protector.
Modified:
branches/gcc-4_2-branch/gcc/ChangeLog
branches/gcc-4_2-branch/gcc/config/sh/sh.md
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32163
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/32163] Compiling with stack protector causes reigster spill failure
2007-05-31 11:35 [Bug other/32163] New: Compiling with stack protector causes reigster spill failure uwe at netbsd dot org
` (5 preceding siblings ...)
2007-06-08 5:54 ` kkojima at gcc dot gnu dot org
@ 2007-06-08 5:56 ` kkojima at gcc dot gnu dot org
2007-06-08 5:58 ` kkojima at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: kkojima at gcc dot gnu dot org @ 2007-06-08 5:56 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from kkojima at gcc dot gnu dot org 2007-06-08 05:56 -------
Subject: Bug 32163
Author: kkojima
Date: Fri Jun 8 05:56:28 2007
New Revision: 125559
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=125559
Log:
PR target/32163
Backport from mainline.
* config/sh/sh.md (symGOT_load): Don't schedule insns when
the symbol is generated with the stack protector.
Modified:
branches/gcc-4_1-branch/gcc/ChangeLog
branches/gcc-4_1-branch/gcc/config/sh/sh.md
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32163
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/32163] Compiling with stack protector causes reigster spill failure
2007-05-31 11:35 [Bug other/32163] New: Compiling with stack protector causes reigster spill failure uwe at netbsd dot org
` (6 preceding siblings ...)
2007-06-08 5:56 ` kkojima at gcc dot gnu dot org
@ 2007-06-08 5:58 ` kkojima at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: kkojima at gcc dot gnu dot org @ 2007-06-08 5:58 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from kkojima at gcc dot gnu dot org 2007-06-08 05:58 -------
Fixed.
--
kkojima at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32163
^ permalink raw reply [flat|nested] 9+ messages in thread