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

Qing Zhao qing.zhao@oracle.com
Wed Jul 7 17:38:02 GMT 2021


Hi, 

This is the 4th 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 and run CPU2017, without any issue.

Please take a look and let me know your comments and suggestions.

thanks.

Qing

******Compare with the 3rd version, the following are the major changes:

1. change -ftrivial-auto-var-init as an optimization option in order to refer it with "opt_for_fn";
2. delete option -fauto-var-init-approach;
3. update -ftrivial-auto-var-init doc by adding padding initialization and some clarification for pattern initializations.
4. delete the changes in the routine "store_constructor" and "gimplify_init_constructor" about padding initializations.
5. for VLA variable, also generate calls to .DEFERRED_INIT instead of calls to "meset", consistent with non-VLA.  
   delete all changes on "memset" calls for VLA initialization. 
6. change the definition of .DEFERRED_INIT:

From:
temp = .DEFERRED_INIT (temp, init_type)

To:

temp = .DEFERRED_INIT (SIZE_of_temp, init_type, IS_VLA) 

the first argument of .DEFERRED_INIT will be the size of the "temp", and the 
additional 3rd argument is a bool on whether it's a VLA or not.
 
7. in tree-cfg.c, update verifications of call to .DEFERRED_INIT according to 6.
8. "expand_DEFERRED_INIT" will do rtl expansion for both VLA and nonVLA;
   pattern initialization will use byte-repeatable pattern "0xFE" for initialization;
   for VLA and varibles that in stack, expand the call to a memset of zeroes or "FE"s;
   for variables that are in registers, expand the call by using "expand_assignment" 
    in order to generate better code for Integer, pointer and float type variables.
9. delete routines "build_pattern_cst_for_auto_init"; type_has_padding";
		    
10. update testing cases accordingly.

******Please see the version 3 at:

https://gcc.gnu.org/pipermail/gcc-patches/2021-May/570208.html

******Changelog is:

gcc/ChangeLog:

2021-07-06  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.
	* gimplify.c (gimple_add_init_for_auto_var): New function.
	(maybe_with_size_expr): Forword declaration.
	(build_deferred_init): New function.
	(gimplify_decl_expr): Add initialization to automatic variables per
	users' requests.
	* 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.
	(sra_modify_deferred_init): Likewise;
	(sra_modify_function_body): Handle calls to DEFERRED_INIT specially.
	* tree-ssa-structalias.c (find_func_aliases_for_call):
	* 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-06  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-06  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.
	* 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-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-10.c: New test.
	* gcc.target/aarch64/auto-init-11.c: New test.
	* gcc.target/aarch64/auto-init-12.c: New test.
	* gcc.target/aarch64/auto-init-13.c: New test.
	* gcc.target/aarch64/auto-init-14.c: New test.
	* gcc.target/aarch64/auto-init-15.c: New test.
	* gcc.target/aarch64/auto-init-16.c: New test.
	* gcc.target/aarch64/auto-init-17.c: New test.
	* gcc.target/aarch64/auto-init-18.c: New test.
	* gcc.target/aarch64/auto-init-19.c: New test.
	* gcc.target/aarch64/auto-init-2.c: New test.
	* gcc.target/aarch64/auto-init-20.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-9.c: New test.
	* gcc.target/i386/auto-init-1.c: New test.
	* gcc.target/i386/auto-init-10.c: New test.
	* gcc.target/i386/auto-init-11.c: New test.
	* gcc.target/i386/auto-init-12.c: New test.
	* gcc.target/i386/auto-init-13.c: New test.
	* gcc.target/i386/auto-init-14.c: New test.
	* gcc.target/i386/auto-init-15.c: New test.
	* gcc.target/i386/auto-init-16.c: New test.
	* gcc.target/i386/auto-init-17.c: New test.
	* gcc.target/i386/auto-init-18.c: New test.
	* gcc.target/i386/auto-init-19.c: New test.
	* gcc.target/i386/auto-init-2.c: New test.
	* gcc.target/i386/auto-init-20.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-9.c: New test.

******The complete 4th version of the patch is:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-4th-version-master.patch
Type: application/octet-stream
Size: 147189 bytes
Desc: 0001-4th-version-master.patch
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20210707/b0b88827/attachment-0001.obj>


More information about the Gcc-patches mailing list