diff options
author | Jakub Jelinek <jakub@redhat.com> | 2019-01-14 13:01:01 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2019-01-14 13:01:01 +0100 |
commit | a49a975f0eaf49d9882ba4bf4b583f99d56d0d3a (patch) | |
tree | 5d19df5d6e01eac1ed1c0504b50a318c3e91f688 /gcc/dse.c | |
parent | 7227b597ac26b10aa51d334d72bd74365047182c (diff) | |
download | gcc-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/dse.c')
-rw-r--r-- | gcc/dse.c | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -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); |