On Thu, Oct 29, 2020 at 12:55 AM Qing Zhao <qing.z...@oracle.com> wrote: > > Hi, > > This is the 5th version of the implementation of patch -fzero-call-used-regs. > > The major change compared to the previous version (4th version) are: > > 1. Documentation change per Richard’s suggestion; > 2. Use namespace for zero_regs_code; > 3. Add more general testing cases per Richard’s suggestion; > 4. I386 part, ST/MM register sets clearing per Uros’s suggestion. > 5. Add more i386 testing cases for ST/MM clearing per Uros’s suggestion. > 6. Some minor style fixes. > > I have tested this new GCC on both x86 and arm64, no regression. > > Please let me know whether it’s ready for stage 1 gcc11? > > Thanks. > > Qing > > ******The documentation (gcc.info): > 'zero_call_used_regs ("CHOICE")' > > The 'zero_call_used_regs' attribute causes the compiler to zero a > subset of all call-used registers at function return according to > CHOICE. This is used to increase the program security by either > mitigating Return-Oriented Programming (ROP) or preventing > information leak through registers. > > A "call-used" register is a register whose contents can be changed > by a function call; therefore, a caller cannot assume that the > register has the same contents on return from the function as it > had before calling the function. Such registers are also called > "call-clobbered", "caller-saved", or "volatile". > > In order to satisfy users with different security needs and control > the run-time overhead at the same time, GCC provides a flexible way > to choose the subset of the call-used registers to be zeroed. > > The three basic values of CHOICE are: > > * 'skip' doesn't zero any call-used registers. > > * 'used' only zeros call-used registers that are used in the > function. A "used" register is one whose content has been set > or referenced in the function. > > * 'all' zeros all call-used registers. > > In addition to these three basic choices, it is possible to modify > 'used' or 'all' as follows: > > * Adding '-gpr' restricts the zeroing to general-purpose > registers. > > * Adding '-arg' restricts the zeroing to registers that can > sometimes be used to pass function arguments. This includes > all argument registers defined by the platform's calling > conversion, regardless of whether the function uses those > registers for function arguments or not. > > The modifiers can be used individually or together. If they are > used together, they must appear in the order above. > > The full list of CHOICEs is therefore: > > * 'skip' doesn't zero any call-used register. > > * 'used' only zeros call-used registers that are used in the > function. > > * 'all' zeros all call-used registers. > > * 'used-arg' only zeros used call-used registers that pass > arguments. > > * 'used-gpr' only zeros used call-used general purpose > registers. > > * 'used-gpr-arg' only zeros used call-used general purpose > registers that pass arguments. > > * 'all-gpr-arg' zeros all call-used general purpose registers > that pass arguments. > > * 'all-arg' zeros all call-used registers that pass arguments. > > * 'all-gpr' zeros all call-used general purpose registers. > > Among this list, 'used-gpr-arg', 'used-arg', 'all-gpr-arg', and > 'all-arg' are mainly used for ROP mitigation. > > The default for the attribute is controlled by > '-fzero-call-used-regs’. > > '-fzero-call-used-regs=CHOICE' > Zero call-used registers at function return to increase the program > security by either mitigating Return-Oriented Programming (ROP) or > preventing information leak through registers. > > The possible values of CHOICE are the same as for the > 'zero_call_used_regs' attribute (*note Function Attributes::). The > default is 'skip'. > > You can control this behavior for a specific function by using the > function attribute 'zero_call_used_regs' (*note Function > Attributes::). > > ******The changelog: > > gcc/ChangeLog: > > 2020-10-28 Qing Zhao <qing.z...@oracle.com> > H.J.Lu <hjl.to...@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 fields zero_call_used_regs > and must_be_zero_on_return. > * flag-types.h (namespace zero_regs_code): 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-28 Qing Zhao <qing.z...@oracle.com> > H.J.Lu <hjl.to...@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-28 Qing Zhao <qing.z...@oracle.com> > H.J.Lu <hjl.to...@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.
OK for x86 part. Thanks, Uros.