From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) by sourceware.org (Postfix) with ESMTPS id D60343858028 for ; Wed, 7 Apr 2021 14:44:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D60343858028 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 137EhfTh119553; Wed, 7 Apr 2021 14:44:49 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 37rva62s23-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 07 Apr 2021 14:44:48 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 137EZOpG038326; Wed, 7 Apr 2021 14:44:47 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 37rvb42x3v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 07 Apr 2021 14:44:47 +0000 Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 137EijQT022233; Wed, 7 Apr 2021 14:44:46 GMT Received: from dhcp-10-154-189-59.vpn.oracle.com (/10.154.189.59) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 07 Apr 2021 07:44:45 -0700 From: Qing Zhao Message-Id: <7E5D67EC-29CC-47CD-87EC-4F116528FE53@ORACLE.COM> Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Subject: Re: [patch for gcc12 stage1][version 2] add -ftrivial-auto-var-init and variable attribute "uninitialized" to gcc Date: Wed, 7 Apr 2021 09:44:44 -0500 In-Reply-To: <0CE28536-176B-44E1-BDC6-3942739B829C@oracle.com> Cc: Kees Cook , Gcc-patches Qing Zhao via To: richard Sandiford , Richard Biener References: <0CE28536-176B-44E1-BDC6-3942739B829C@oracle.com> X-Mailer: Apple Mail (2.3608.120.23.2.4) X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9947 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 suspectscore=0 adultscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104070104 X-Proofpoint-GUID: 3pgm8ns5CvW00HxA0aB3Zn5nI5lRvC30 X-Proofpoint-ORIG-GUID: 3pgm8ns5CvW00HxA0aB3Zn5nI5lRvC30 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9947 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 clxscore=1011 lowpriorityscore=0 suspectscore=0 adultscore=0 mlxlogscore=999 bulkscore=0 priorityscore=1501 impostorscore=0 phishscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104070105 X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, HTML_MESSAGE, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Apr 2021 14:45:02 -0000 Ping > On Mar 24, 2021, at 4:21 PM, Qing Zhao via Gcc-patches = wrote: >=20 > Hi,=20 >=20 > This is the 2nd version of the patch for the new security feature for = GCC. >=20 > Could you please take a look at it and let me know any comments and = issues. >=20 > Thanks. >=20 > Qing >=20 > ******compared to Version 1, this version added the following new = features to address Kees=E2=80=99s comments: >=20 > 1. correctly handle VLA inside a structure for pattern = initialization. > In tree.c (build_pattern_cst): >=20 > + /* if the field is a variable length array, it should be = the last > + field of the record, and no need to initialize. */ > + if (TREE_CODE (TREE_TYPE (field)) =3D=3D ARRAY_TYPE > + && TYPE_SIZE (TREE_TYPE (field)) =3D=3D NULL_TREE > + && ((TYPE_DOMAIN (TREE_TYPE (field)) !=3D NULL_TREE > + && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE = (field))) > + =3D=3D NULL_TREE) > + || TYPE_DOMAIN (TREE_TYPE (field)) =3D=3D = NULL_TREE)) > + continue; >=20 > 2. initialize all paddings to zero when -ftrivial-auto-var-init is = present. > In expr.c (store_constructor): >=20 > Clear the whole structure when > -ftrivial-auto-var-init and the structure has paddings. >=20 > In gimplify.c (gimplify_init_constructor): >=20 > Clear the whole structure when > -ftrivial-auto-var-init and the structure has paddings. >=20 > As agreed with Kees, treat the issue related to auto variables outside = of the cases and inside the switch as a low priority one.=20 >=20 > 3. Add the following new testing cases for the above 1 and 2: >=20 > * c-c++-common/auto-init-13.c: New test. > * c-c++-common/auto-init-14.c: New test.=20 >=20 > * gcc.target/aarch64/auto-init-9.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-20.c: New test. >=20 > * gcc.target/i386/auto-init-9.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-20.c: New test. >=20 > 4. Update the default approach as D, then when specify = -ftrivial-auto-var-init, the default approach is the = =E2=80=9C.DEFERRED_INIT=E2=80=9D=20 > Approach. No need to add -fauto-var-init-approach=3DD anymore. >=20 > If we need to compare approach A and D, we can add = -fauto-var-init-approach=3DA to get that implementation.=20 >=20 > 5. Delete all -fauto-var-init-approach=3DD in the testing cases.=20 >=20 > ****** others are the same as Version 1, please see the version 1 = description at: >=20 > https://gcc.gnu.org/pipermail/gcc-patches/2021-February/565581.html = >=20 >=20 > *******Changelog: >=20 > gcc/: >=20 > 2021-03-24 qing zhao >=20 > * common.opt (ftrivial-auto-var-init=3D): New. > (fauto-var-init-approach=3D): Likewise. > * doc/extend.texi: Document the uninitialized attribute. > * doc/invoke.texi: Document -ftrivial-auto-var-init. > * expr.c (store_constructor): Clear the whole structure when > -ftrivial-auto-var-init and the structure has paddings. > * flag-types.h (enum auto_init_type): New enumerated type > auto_init_type. > (enum auto_init_approach): New enumerated type = auto_init_approach. > * gimple.h (enum gf_mask): Add GF_CALL_MEMSET_FOR_UNINIT case. > (gimple_call_set_memset_for_uninit): New function. > (gimple_call_memset_for_uninit_p): Likewise. > * gimplify.c (gimplify_vla_decl): Add initialization to vla = per users' > requests.=20 > (build_deferred_init): New function. > (gimple_add_init_for_auto_var): Likewise. > (gimplify_decl_expr): Add initialization to automatic = variables per > users' requests. > (gimplify_init_constructor): Clear the whole structure when > -ftrivial-auto-var-init and the structure has paddings. > * internal-fn.c (expand_DEFERRED_INIT): New function. > * internal-fn.def (DEFERRED_INIT): New internal function. > * tree-cfg.c (verify_gimple_call): Skip calls to = DEFERRED_INIT. > * tree-core.h (tree_decl_with_vis): Add uninitialized field. > * tree-sra.c (sra_stats): Add two new fields deferred_init and > subtree_deferred_init. > (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_deferred_init): New > function. > (find_func_aliases_for_call): Handle calls to DEFERRED_INIT = specially. > * tree-ssa-uninit.c (warn_uninit): Handle calls to = DEFERRED_INIT > specially. > (check_defs): Handle calls to DEFERRED_INIT and MEMSET for = uninitialized > variable specially. > (warn_uninitialized_vars): Handle calls to DEFERRED_INIT = specially. > * tree-ssa.c (ssa_undefined_value_p): Handle calls to = DEFERRED_INIT > specially. > * tree.c (build_pattern_cst): New function. > (type_has_padding): Likewise. > * tree.h (DECL_UNINITIALIZED): New macro. > (build_pattern_cst): New declaration. > (type_has_padding): Likewise. >=20 > gcc/c-family/: >=20 > 2021-03-24 qing zhao >=20 > * c-attribs.c (handle_uninitialized_attribute): New function. > (c_common_attribute_table): Add "uninitialized" attribute. >=20 > gcc/testsuite/: >=20 > 2021-03-24 qing zhao >=20 > * 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-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-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. >=20 > ******The complete patch is attached as following: >=20 >=20 >=20 > <0001-add-ftrivial-auto-var-init-and-variable-attribute-un.patch>