aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2019-01-14 13:01:01 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2019-01-14 13:01:01 +0100
commita49a975f0eaf49d9882ba4bf4b583f99d56d0d3a (patch)
tree5d19df5d6e01eac1ed1c0504b50a318c3e91f688 /gcc
parent7227b597ac26b10aa51d334d72bd74365047182c (diff)
downloadgcc-a49a975f0eaf49d9882ba4bf4b583f99d56d0d3a.zip
gcc-a49a975f0eaf49d9882ba4bf4b583f99d56d0d3a.tar.gz
gcc-a49a975f0eaf49d9882ba4bf4b583f99d56d0d3a.tar.bz2
re PR rtl-optimization/88796 (-fstack-protector* kills RTL DSE opportunities)
PR rtl-optimization/88796 * emit-rtl.h (struct rtl_data): Add stack_protect_guard_decl field. * cfgexpand.c (stack_protect_prologue): Initialize crtl->stack_protect_guard_decl. * function.c (stack_protect_epilogue): Use it instead of calling targetm.stack_protect_guard again. * dse.c (check_mem_read_rtx): Ignore MEM_VOLATILE_P reads from MEMs with MEM_EXPR equal to crtl->stack_protect_guard or crtl->stack_protect_guard_decl. * config/i386/i386.c (ix86_stack_protect_guard): Set TREE_THIS_VOLATILE on the returned MEM_EXPR. * gcc.target/i386/pr88796.c: New test. From-SVN: r267916
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog14
-rw-r--r--gcc/cfgexpand.c1
-rw-r--r--gcc/config/i386/i386.c1
-rw-r--r--gcc/dse.c23
-rw-r--r--gcc/emit-rtl.h4
-rw-r--r--gcc/function.c2
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.target/i386/pr88796.c8
8 files changed, 56 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 2ba0b7c..c4a35e2 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,17 @@
+2019-01-14 Jakub Jelinek <jakub@redhat.com>
+
+ PR rtl-optimization/88796
+ * emit-rtl.h (struct rtl_data): Add stack_protect_guard_decl field.
+ * cfgexpand.c (stack_protect_prologue): Initialize
+ crtl->stack_protect_guard_decl.
+ * function.c (stack_protect_epilogue): Use it instead of calling
+ targetm.stack_protect_guard again.
+ * dse.c (check_mem_read_rtx): Ignore MEM_VOLATILE_P reads from
+ MEMs with MEM_EXPR equal to crtl->stack_protect_guard or
+ crtl->stack_protect_guard_decl.
+ * config/i386/i386.c (ix86_stack_protect_guard): Set TREE_THIS_VOLATILE
+ on the returned MEM_EXPR.
+
2019-01-12 Tom de Vries <tdevries@suse.de>
* config/nvptx/nvptx.c (nvptx_goacc_validate_dims_1): Alow setting
diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
index f4786d5..3b7a6e5 100644
--- a/gcc/cfgexpand.c
+++ b/gcc/cfgexpand.c
@@ -6219,6 +6219,7 @@ stack_protect_prologue (void)
tree guard_decl = targetm.stack_protect_guard ();
rtx x, y;
+ crtl->stack_protect_guard_decl = guard_decl;
x = expand_normal (crtl->stack_protect_guard);
if (targetm.have_stack_protect_combined_set () && guard_decl)
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 1bb535a..b0b7580 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -45094,6 +45094,7 @@ ix86_stack_protect_guard (void)
t = build_int_cst (asptrtype, ix86_stack_protector_guard_offset);
t = build2 (MEM_REF, asptrtype, t,
build_int_cst (asptrtype, 0));
+ TREE_THIS_VOLATILE (t) = 1;
}
return t;
diff --git a/gcc/dse.c b/gcc/dse.c
index 389c52d..6f6f768 100644
--- a/gcc/dse.c
+++ b/gcc/dse.c
@@ -2072,8 +2072,29 @@ check_mem_read_rtx (rtx *loc, bb_info_t bb_info)
insn_info = bb_info->last_insn;
if ((MEM_ALIAS_SET (mem) == ALIAS_SET_MEMORY_BARRIER)
- || (MEM_VOLATILE_P (mem)))
+ || MEM_VOLATILE_P (mem))
{
+ if (crtl->stack_protect_guard
+ && (MEM_EXPR (mem) == crtl->stack_protect_guard
+ || (crtl->stack_protect_guard_decl
+ && MEM_EXPR (mem) == crtl->stack_protect_guard_decl))
+ && MEM_VOLATILE_P (mem))
+ {
+ /* This is either the stack protector canary on the stack,
+ which ought to be written by a MEM_VOLATILE_P store and
+ thus shouldn't be deleted and is read at the very end of
+ function, but shouldn't conflict with any other store.
+ Or it is __stack_chk_guard variable or TLS or whatever else
+ MEM holding the canary value, which really shouldn't be
+ ever modified in -fstack-protector* protected functions,
+ otherwise the prologue store wouldn't match the epilogue
+ check. */
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ fprintf (dump_file, " stack protector canary read ignored.\n");
+ insn_info->cannot_delete = true;
+ return;
+ }
+
if (dump_file && (dump_flags & TDF_DETAILS))
fprintf (dump_file, " adding wild read, volatile or barrier.\n");
add_wild_read (bb_info);
diff --git a/gcc/emit-rtl.h b/gcc/emit-rtl.h
index edf66b5..7b1cecd 100644
--- a/gcc/emit-rtl.h
+++ b/gcc/emit-rtl.h
@@ -87,6 +87,10 @@ struct GTY(()) rtl_data {
Used for detecting stack clobbers. */
tree stack_protect_guard;
+ /* The __stack_chk_guard variable or expression holding the stack
+ protector canary value. */
+ tree stack_protect_guard_decl;
+
/* List (chain of INSN_LIST) of labels heading the current handlers for
nonlocal gotos. */
rtx_insn_list *x_nonlocal_goto_handler_labels;
diff --git a/gcc/function.c b/gcc/function.c
index 5260d73..1525d8b 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -4902,7 +4902,7 @@ init_function_start (tree subr)
void
stack_protect_epilogue (void)
{
- tree guard_decl = targetm.stack_protect_guard ();
+ tree guard_decl = crtl->stack_protect_guard_decl;
rtx_code_label *label = gen_label_rtx ();
rtx x, y;
rtx_insn *seq = NULL;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 373f39d..09ed22a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-01-14 Jakub Jelinek <jakub@redhat.com>
+
+ PR rtl-optimization/88796
+ * gcc.target/i386/pr88796.c: New test.
+
2019-01-14 Iain Buclaw <ibuclaw@gdcproject.org>
* gdc.dg/asm1.d: New test.
diff --git a/gcc/testsuite/gcc.target/i386/pr88796.c b/gcc/testsuite/gcc.target/i386/pr88796.c
new file mode 100644
index 0000000..f2ddbd5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr88796.c
@@ -0,0 +1,8 @@
+/* PR rtl-optimization/88796 */
+/* { dg-do compile { target { ! ia32 } } } */
+/* { dg-options "-O2 -fstack-protector-strong" } */
+/* { dg-require-effective-target fstack_protector } */
+
+#include "pr87370.c"
+
+/* { dg-final { scan-assembler-not "xmm" } } */