[patch][version 6] add -ftrivial-auto-var-init and variable attribute "uninitialized" to gcc

Qing Zhao qing.zhao@oracle.com
Tue Jul 27 03:26:00 GMT 2021


Hi,

This is the 6th version of the patch for the new security feature for GCC.

I have tested it with bootstrap on both x86 and aarch64, regression testing on both x86 and aarch64.
Also compile CPU2017 (running is ongoing), without any issue. (With the fix to bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101586).

Please take a look and let me know any issue.

Thanks

Qing

******Compared with the 5th version, the changes are:

 1. Fix two issues raised by Martin Jambor in tree-sra.c:

   A. Inside "scan_function", Do not set cannot_scalarize_away_bitmap for a call to DEFERRED_INIT.
   B. Fix a potential issue for single-field structure.

 2. Add two testing cases based on gcc/testsuite/gcc.dg/tree-ssa/sra-12.c to verity SRA total scalarization will not be confused by auto initializatoin.

******the 5th version compared with the 4th version, the following are the major changes:

1. delete the code for handling "grp_to_be_debug_replaced" since they are not needed per Martin Jambor's suggestion.
2. for Pattern init, call __builtin_clear_padding after the call to .DEFERRED_INIT to initialize the paddings to zeroes;
3. for partially or fully initialized auto variables, call   __builtin_clear_padding before the real initialization to initialize
   the paddings to zeroes.
4. Update the documentation with padding initialization to zeroes.
5. in order to reuse __builtin_clear_padding for auto init purpose, add one more dummy argument to indiciate whether it's for auto init or not,
  if for auto init, do not emit error messages to avoid confusing users.
6. Add new testing cases to verify padding initializations.
7. rename some of the old testing cases to make the file name reflecting the testing purpose per Kees Cook's suggestions.

******Please see version 5 at:
https://gcc.gnu.org/pipermail/gcc-patches/2021-July/575977.html

******ChangeLog is:

gcc/ChangeLog:

2021-07-26  qing zhao  <qing.zhao@oracle.com>

        * builtins.c (expand_builtin_memset): Make external visible.
        * builtins.h (expand_builtin_memset): Declare extern.
        * common.opt (ftrivial-auto-var-init=): New option.
        * doc/extend.texi: Document the uninitialized attribute.
        * doc/invoke.texi: Document -ftrivial-auto-var-init.
        * flag-types.h (enum auto_init_type): New enumerated type
        auto_init_type.
        * gimple-fold.c (clear_padding_type): Add one new parameter.
        (clear_padding_union): Likewise.
        (clear_padding_emit_loop): Likewise.
        (clear_type_padding_in_mask): Likewise.
        (gimple_fold_builtin_clear_padding): Handle this new parameter.
        * gimplify.c (gimple_add_init_for_auto_var): New function.
        (maybe_with_size_expr): Forword declaration.
        (build_deferred_init): New function.
        (gimple_add_padding_init_for_auto_var): New function.
        (gimplify_decl_expr): Add initialization to automatic variables per
        users' requests.
        (gimplify_call_expr): Add one new parameter for call to
        __builtin_clear_padding.
        (gimplify_modify_expr_rhs): Add padding initialization before
        gimplify_init_constructor.
        * internal-fn.c (INIT_PATTERN_VALUE): New macro.
        (expand_DEFERRED_INIT): New function.
        * internal-fn.def (DEFERRED_INIT): New internal function.
        * tree-cfg.c (verify_gimple_call): Verify calls to .DEFERRED_INIT.
        * tree-sra.c (generate_subtree_deferred_init): New function.
        (scan_function): Avoid setting cannot_scalarize_away_bitmap for
        calls to .DEFERRED_INIT.
        (sra_modify_deferred_init): New function.
        (sra_modify_function_body): Handle calls to DEFERRED_INIT specially.
        * tree-ssa-structalias.c (find_func_aliases_for_call): Likewise.
        * tree-ssa-uninit.c (warn_uninit): Handle calls to DEFERRED_INIT
        specially.
        (check_defs): Likewise.
        (warn_uninitialized_vars): Likewise.
        * tree-ssa.c (ssa_undefined_value_p): Likewise.

gcc/c-family/ChangeLog:

2021-07-26  qing zhao  <qing.zhao@oracle.com>

        * c-attribs.c (handle_uninitialized_attribute): New function.
        (c_common_attribute_table): Add "uninitialized" attribute.

gcc/testsuite/ChangeLog:


2021-07-26  qing zhao  <qing.zhao@oracle.com>

        * c-c++-common/auto-init-1.c: New test.
        * c-c++-common/auto-init-10.c: New test.
        * c-c++-common/auto-init-11.c: New test.
        * c-c++-common/auto-init-12.c: New test.
        * c-c++-common/auto-init-13.c: New test.
        * c-c++-common/auto-init-14.c: New test.
        * c-c++-common/auto-init-15.c: New test.
        * c-c++-common/auto-init-16.c: New test.
        * c-c++-common/auto-init-2.c: New test.
        * c-c++-common/auto-init-3.c: New test.
        * c-c++-common/auto-init-4.c: New test.
        * c-c++-common/auto-init-5.c: New test.
        * c-c++-common/auto-init-6.c: New test.
        * c-c++-common/auto-init-7.c: New test.
        * c-c++-common/auto-init-8.c: New test.
        * c-c++-common/auto-init-9.c: New test.
        * c-c++-common/auto-init-esra.c: New test.
        * c-c++-common/auto-init-padding-1.c: New test.
        * c-c++-common/auto-init-padding-2.c: New test.
        * c-c++-common/auto-init-padding-3.c: New test.
        * g++.dg/auto-init-uninit-pred-1_a.C: New test.
        * g++.dg/auto-init-uninit-pred-1_b.C: New test.
        * g++.dg/auto-init-uninit-pred-2_a.C: New test.
        * g++.dg/auto-init-uninit-pred-2_b.C: New test.
        * g++.dg/auto-init-uninit-pred-3_a.C: New test.
        * g++.dg/auto-init-uninit-pred-3_b.C: New test.
        * g++.dg/auto-init-uninit-pred-4.C: New test.
        * g++.dg/auto-init-uninit-pred-loop-1_a.cc: New test.
        * g++.dg/auto-init-uninit-pred-loop-1_b.cc: New test.
        * g++.dg/auto-init-uninit-pred-loop-1_c.cc: New test.
        * g++.dg/auto-init-uninit-pred-loop_1.cc: New test.
        * gcc.dg/auto-init-sra-1.c: New test.
        * gcc.dg/auto-init-sra-2.c: New test.
        * gcc.dg/auto-init-uninit-1.c: New test.
        * gcc.dg/auto-init-uninit-11.c: New test.
        * gcc.dg/auto-init-uninit-12.c: New test.
        * gcc.dg/auto-init-uninit-13.c: New test.
        * gcc.dg/auto-init-uninit-14.c: New test.
        * gcc.dg/auto-init-uninit-15.c: New test.
        * gcc.dg/auto-init-uninit-16.c: New test.
        * gcc.dg/auto-init-uninit-17.c: New test.
        * gcc.dg/auto-init-uninit-18.c: New test.
        * gcc.dg/auto-init-uninit-19.c: New test.
        * gcc.dg/auto-init-uninit-2.c: New test.
        * gcc.dg/auto-init-uninit-20.c: New test.
        * gcc.dg/auto-init-uninit-21.c: New test.
        * gcc.dg/auto-init-uninit-22.c: New test.
        * gcc.dg/auto-init-uninit-23.c: New test.
        * gcc.dg/auto-init-uninit-24.c: New test.
        * gcc.dg/auto-init-uninit-25.c: New test.
        * gcc.dg/auto-init-uninit-26.c: New test.
        * gcc.dg/auto-init-uninit-3.c: New test.
        * gcc.dg/auto-init-uninit-34.c: New test.
        * gcc.dg/auto-init-uninit-36.c: New test.
        * gcc.dg/auto-init-uninit-37.c: New test.
        * gcc.dg/auto-init-uninit-4.c: New test.
        * gcc.dg/auto-init-uninit-5.c: New test.
        * gcc.dg/auto-init-uninit-6.c: New test.
        * gcc.dg/auto-init-uninit-8.c: New test.
        * gcc.dg/auto-init-uninit-9.c: New test.
        * gcc.dg/auto-init-uninit-A.c: New test.
        * gcc.dg/auto-init-uninit-B.c: New test.
        * gcc.dg/auto-init-uninit-C.c: New test.
        * gcc.dg/auto-init-uninit-H.c: New test.
        * gcc.dg/auto-init-uninit-I.c: New test.
        * gcc.target/aarch64/auto-init-1.c: New test.
        * gcc.target/aarch64/auto-init-2.c: New test.
        * gcc.target/aarch64/auto-init-3.c: New test.
        * gcc.target/aarch64/auto-init-4.c: New test.
        * gcc.target/aarch64/auto-init-5.c: New test.
        * gcc.target/aarch64/auto-init-6.c: New test.
        * gcc.target/aarch64/auto-init-7.c: New test.
        * gcc.target/aarch64/auto-init-8.c: New test.
        * gcc.target/aarch64/auto-init-padding-1.c: New test.
        * gcc.target/aarch64/auto-init-padding-10.c: New test.
        * gcc.target/aarch64/auto-init-padding-11.c: New test.
        * gcc.target/aarch64/auto-init-padding-12.c: New test.
        * gcc.target/aarch64/auto-init-padding-2.c: New test.
        * gcc.target/aarch64/auto-init-padding-3.c: New test.
        * gcc.target/aarch64/auto-init-padding-4.c: New test.
        * gcc.target/aarch64/auto-init-padding-5.c: New test.
        * gcc.target/aarch64/auto-init-padding-6.c: New test.
        * gcc.target/aarch64/auto-init-padding-7.c: New test.
        * gcc.target/aarch64/auto-init-padding-8.c: New test.
        * gcc.target/aarch64/auto-init-padding-9.c: New test.
        * gcc.target/i386/auto-init-1.c: New test.
        * gcc.target/i386/auto-init-2.c: New test.
        * gcc.target/i386/auto-init-21.c: New test.
        * gcc.target/i386/auto-init-22.c: New test.
        * gcc.target/i386/auto-init-23.c: New test.
        * gcc.target/i386/auto-init-24.c: New test.
        * gcc.target/i386/auto-init-3.c: New test.
        * gcc.target/i386/auto-init-4.c: New test.
        * gcc.target/i386/auto-init-5.c: New test.
        * gcc.target/i386/auto-init-6.c: New test.
        * gcc.target/i386/auto-init-7.c: New test.
        * gcc.target/i386/auto-init-8.c: New test.
        * gcc.target/i386/auto-init-padding-1.c: New test.
        * gcc.target/i386/auto-init-padding-10.c: New test.
        * gcc.target/i386/auto-init-padding-11.c: New test.
        * gcc.target/i386/auto-init-padding-12.c: New test.
        * gcc.target/i386/auto-init-padding-2.c: New test.
        * gcc.target/i386/auto-init-padding-3.c: New test.
        * gcc.target/i386/auto-init-padding-4.c: New test.
        * gcc.target/i386/auto-init-padding-5.c: New test.
        * gcc.target/i386/auto-init-padding-6.c: New test.
        * gcc.target/i386/auto-init-padding-7.c: New test.
        * gcc.target/i386/auto-init-padding-8.c: New test.
        * gcc.target/i386/auto-init-padding-9.c: New test.

******The complete 6th version of the patch is:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-the-6th-version.patch
Type: application/octet-stream
Size: 170515 bytes
Desc: 0001-the-6th-version.patch
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20210727/61c70da9/attachment-0001.obj>


More information about the Gcc-patches mailing list