Add -fzero-call-used-regs option and zero_call_used_regs function attributes.
authorqing zhao <qinzhao@gcc.gnu.org>
Fri, 30 Oct 2020 19:41:38 +0000 (20:41 +0100)
committerqing zhao <qinzhao@gcc.gnu.org>
Fri, 30 Oct 2020 19:41:38 +0000 (20:41 +0100)
commitd10f3e900b0377b4760a090b0f90371bcef01686
treef78af058a8e7a4a1c04d601dbda48821a4eaa2e4
parent44fbc9c6e02ca5b8f98f25b514ed7588e7ba733d
Add -fzero-call-used-regs option and zero_call_used_regs function attributes.

This new feature causes the compiler to zero a  subset of all call-used
registers at function return.  This is used to increase program security
by either mitigating Return-Oriented Programming (ROP) attacks or
preventing information leakage through registers.

gcc/ChangeLog:

2020-10-30  Qing Zhao  <qing.zhao@oracle.com>
    H.J.Lu  <hjl.tools@gmail.com>

* common.opt: Add new option -fzero-call-used-regs
* config/i386/i386.c (zero_call_used_regno_p): New function.
(zero_call_used_regno_mode): Likewise.
(zero_all_vector_registers): Likewise.
(zero_all_st_registers): Likewise.
(zero_all_mm_registers): Likewise.
(ix86_zero_call_used_regs): Likewise.
(TARGET_ZERO_CALL_USED_REGS): Define.
* df-scan.c (df_epilogue_uses_p): New function.
(df_get_exit_block_use_set): Replace EPILOGUE_USES with
df_epilogue_uses_p.
* df.h (df_epilogue_uses_p): Declare.
* doc/extend.texi: Document the new zero_call_used_regs attribute.
* doc/invoke.texi: Document the new -fzero-call-used-regs option.
* doc/tm.texi: Regenerate.
* doc/tm.texi.in (TARGET_ZERO_CALL_USED_REGS): New hook.
* emit-rtl.h (struct rtl_data): New field must_be_zero_on_return.
* flag-types.h (namespace zero_regs_flags): New namespace.
* function.c (gen_call_used_regs_seq): New function.
(class pass_zero_call_used_regs): New class.
(pass_zero_call_used_regs::execute): New function.
(make_pass_zero_call_used_regs): New function.
* optabs.c (expand_asm_reg_clobber_mem_blockage): New function.
* optabs.h (expand_asm_reg_clobber_mem_blockage): Declare.
* opts.c (zero_call_used_regs_opts): New structure array
initialization.
(parse_zero_call_used_regs_options): New function.
(common_handle_option): Handle -fzero-call-used-regs.
* opts.h (zero_call_used_regs_opts): New structure array.
* passes.def: Add new pass pass_zero_call_used_regs.
* recog.c (valid_insn_p): New function.
* recog.h (valid_insn_p): Declare.
* resource.c (init_resource_info): Replace EPILOGUE_USES with
df_epilogue_uses_p.
* target.def (zero_call_used_regs): New hook.
* targhooks.c (default_zero_call_used_regs): New function.
* targhooks.h (default_zero_call_used_regs): Declare.
* tree-pass.h (make_pass_zero_call_used_regs): Declare.

gcc/c-family/ChangeLog:

2020-10-30  Qing Zhao  <qing.zhao@oracle.com>
    H.J.Lu  <hjl.tools@gmail.com>

* c-attribs.c (c_common_attribute_table): Add new attribute
zero_call_used_regs.
(handle_zero_call_used_regs_attribute): New function.

gcc/testsuite/ChangeLog:

2020-10-30  Qing Zhao  <qing.zhao@oracle.com>
    H.J.Lu  <hjl.tools@gmail.com>

* c-c++-common/zero-scratch-regs-1.c: New test.
* c-c++-common/zero-scratch-regs-10.c: New test.
* c-c++-common/zero-scratch-regs-11.c: New test.
* c-c++-common/zero-scratch-regs-2.c: New test.
* c-c++-common/zero-scratch-regs-3.c: New test.
* c-c++-common/zero-scratch-regs-4.c: New test.
* c-c++-common/zero-scratch-regs-5.c: New test.
* c-c++-common/zero-scratch-regs-6.c: New test.
* c-c++-common/zero-scratch-regs-7.c: New test.
* c-c++-common/zero-scratch-regs-8.c: New test.
* c-c++-common/zero-scratch-regs-9.c: New test.
* c-c++-common/zero-scratch-regs-attr-usages.c: New test.
* gcc.target/i386/zero-scratch-regs-1.c: New test.
* gcc.target/i386/zero-scratch-regs-10.c: New test.
* gcc.target/i386/zero-scratch-regs-11.c: New test.
* gcc.target/i386/zero-scratch-regs-12.c: New test.
* gcc.target/i386/zero-scratch-regs-13.c: New test.
* gcc.target/i386/zero-scratch-regs-14.c: New test.
* gcc.target/i386/zero-scratch-regs-15.c: New test.
* gcc.target/i386/zero-scratch-regs-16.c: New test.
* gcc.target/i386/zero-scratch-regs-17.c: New test.
* gcc.target/i386/zero-scratch-regs-18.c: New test.
* gcc.target/i386/zero-scratch-regs-19.c: New test.
* gcc.target/i386/zero-scratch-regs-2.c: New test.
* gcc.target/i386/zero-scratch-regs-20.c: New test.
* gcc.target/i386/zero-scratch-regs-21.c: New test.
* gcc.target/i386/zero-scratch-regs-22.c: New test.
* gcc.target/i386/zero-scratch-regs-23.c: New test.
* gcc.target/i386/zero-scratch-regs-24.c: New test.
* gcc.target/i386/zero-scratch-regs-25.c: New test.
* gcc.target/i386/zero-scratch-regs-26.c: New test.
* gcc.target/i386/zero-scratch-regs-27.c: New test.
* gcc.target/i386/zero-scratch-regs-28.c: New test.
* gcc.target/i386/zero-scratch-regs-29.c: New test.
* gcc.target/i386/zero-scratch-regs-30.c: New test.
* gcc.target/i386/zero-scratch-regs-31.c: New test.
* gcc.target/i386/zero-scratch-regs-3.c: New test.
* gcc.target/i386/zero-scratch-regs-4.c: New test.
* gcc.target/i386/zero-scratch-regs-5.c: New test.
* gcc.target/i386/zero-scratch-regs-6.c: New test.
* gcc.target/i386/zero-scratch-regs-7.c: New test.
* gcc.target/i386/zero-scratch-regs-8.c: New test.
* gcc.target/i386/zero-scratch-regs-9.c: New test.
67 files changed:
gcc/c-family/c-attribs.c
gcc/common.opt
gcc/config/i386/i386.c
gcc/df-scan.c
gcc/df.h
gcc/doc/extend.texi
gcc/doc/invoke.texi
gcc/doc/tm.texi
gcc/doc/tm.texi.in
gcc/emit-rtl.h
gcc/flag-types.h
gcc/function.c
gcc/optabs.c
gcc/optabs.h
gcc/opts.c
gcc/opts.h
gcc/passes.def
gcc/recog.c
gcc/recog.h
gcc/resource.c
gcc/target.def
gcc/targhooks.c
gcc/targhooks.h
gcc/testsuite/c-c++-common/zero-scratch-regs-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/zero-scratch-regs-10.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/zero-scratch-regs-11.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/zero-scratch-regs-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/zero-scratch-regs-3.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/zero-scratch-regs-4.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/zero-scratch-regs-5.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/zero-scratch-regs-6.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/zero-scratch-regs-7.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/zero-scratch-regs-8.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/zero-scratch-regs-9.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/zero-scratch-regs-attr-usages.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-10.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-11.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-12.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-13.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-14.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-15.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-16.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-17.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-18.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-19.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-20.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-21.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-22.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-23.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-24.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-25.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-26.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-27.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-28.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-29.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-30.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-31.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-4.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-5.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-6.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-7.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-8.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/zero-scratch-regs-9.c [new file with mode: 0644]
gcc/tree-pass.h