From patchwork Fri Nov 11 18:41:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiong Wang X-Patchwork-Id: 81892 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp1407595qge; Fri, 11 Nov 2016 10:41:56 -0800 (PST) X-Received: by 10.99.237.69 with SMTP id m5mr6837577pgk.94.1478889716202; Fri, 11 Nov 2016 10:41:56 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id e6si11533972pgf.47.2016.11.11.10.41.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Nov 2016 10:41:56 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-441183-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-441183-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-441183-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=A4pCAmbKDyFivnzdD C1BD/fC5ZAeMDGaI2HG8hDVAjVXg760+ShzFZTxpw3ckUh9Sxvs1Ej/2xSGZIqwu lyjRWHLTS77Q+Kwgn5Vn+fQxGXk3bw/bzOHhPlF5/bRGGICyRIHvOcMuGJvOVzwZ WF6GY82DF8W3pR0F0pVNWoxfwc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=ghGq1h5mkX8CT+7kOTMLOJt 052g=; b=FvOt60pESVQRhuGoDdzx14RA/yLdLOnBwm888mlgwwf/v6jCSrjuJY6 yS7TDNmez0aOhizG38uxj5dA56ZrhtbLSv78WAk52vdifIfay02HQzfeckkYj7pk VndwZvDnPnZia3NhY04HnBioAhVOEAyJDi2qVOr7dNJr1IIuMqoc= Received: (qmail 32277 invoked by alias); 11 Nov 2016 18:41:39 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 32250 invoked by uid 89); 11 Nov 2016 18:41:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.5 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, KAM_LOTSOFHASH, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Documents, 20161111, documents X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 11 Nov 2016 18:41:28 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B5D2D16; Fri, 11 Nov 2016 10:41:26 -0800 (PST) Received: from [10.2.206.198] (e104437-lin.cambridge.arm.com [10.2.206.198]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 42E6D3F24D; Fri, 11 Nov 2016 10:41:26 -0800 (PST) Subject: Re: [Patch] Don't expand targetm.stack_protect_fail if it's NULL_TREE To: Jeff Law References: <8d2e98cb-8474-b8ef-92f1-2d632419c493@redhat.com> <705397b6-922e-713d-33bd-fbae3d2be68f@redhat.com> Cc: "gcc-patches@gcc.gnu.org" From: Jiong Wang Message-ID: Date: Fri, 11 Nov 2016 18:41:24 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <705397b6-922e-713d-33bd-fbae3d2be68f@redhat.com> X-IsSubscribed: yes On 24/10/16 16:22, Jeff Law wrote: > Asserting couldn't hurt. I'd much rather have the compiler issue an error, ICE or somesuch than silently not generate a call to the stack protector fail routine. Hi Jeff, I have just send out the other patch which accelerates -fstack-protector on AArch64, more background information there at: https://gcc.gnu.org/ml/gcc-patches/2016-11/msg01168.html Previous, I was emptying three target insns/hooks, and was relying GCC to optimize all remaining SSP runtime stuff out. I am thinking it's better and safer that GCC allow one backend to disable the default SSP runtime cleanly, so the backend does't need to rely on optimization level, and libssp is not needed at all optimization level. In this new patch, I introduced a new target macro for SSP to allow one backend GCC's default SSP runtime generation be disabled. How does this looks to you? Thanks. gcc/ 2016-11-11 Jiong Wang * function.c (expand_function_end): Guard stack_protect_epilogue with ENABLE_DEFAULT_SSP_RUNTIME. * cfgexpand.c (pass_expand::execute): Likewise guard for stack_protect_prologue. * defaults.h (ENABLE_DEFAULT_SSP_RUNTIME): New macro. Default set to 1. * doc/tm.texi.in (Misc): Documents ENABLE_DEFAULT_SSP_RUNTIME. * doc/tm.texi: Regenerate. diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index 130a16b1d7d06c4ec9e31439037ffcbcbd0e085f..99f055d2db622f7acd393a223b3968be12b6235f 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -6343,7 +6343,7 @@ pass_expand::execute (function *fun) /* Initialize the stack_protect_guard field. This must happen after the call to __main (if any) so that the external decl is initialized. */ - if (crtl->stack_protect_guard) + if (crtl->stack_protect_guard && ENABLE_DEFAULT_SSP_RUNTIME) stack_protect_prologue (); expand_phi_nodes (&SA); diff --git a/gcc/defaults.h b/gcc/defaults.h index af8fe916be49e745c842d992a5af372c46ec2fe3..ec5e52c9761e3e5aee5274c54628157d0bde1808 100644 --- a/gcc/defaults.h +++ b/gcc/defaults.h @@ -1404,6 +1404,14 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see # define DEFAULT_FLAG_SSP 0 #endif +/* Supply a default definition of ENABLE_DEFAULT_SSP_RUNTIME. GCC use this to + decide whether stack_protect_prologue and stack_protect_epilogue based + runtime support should be generated. */ + +#ifndef ENABLE_DEFAULT_SSP_RUNTIME +#define ENABLE_DEFAULT_SSP_RUNTIME 1 +#endif + /* Provide default values for the macros controlling stack checking. */ /* The default is neither full builtin stack checking... */ diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 586626062435f3718cfae84c6aab3024d08d79d7..64d20bc493470221286b6248354f0d6122405cb6 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -10487,6 +10487,14 @@ The default implementation does nothing. @c prevent bad page break with this line Here are several miscellaneous parameters. +@defmac ENABLE_DEFAULT_SSP_RUNTIME +Define this boolean macro to indicate whether or not your architecture +use GCC default stack protector runtime. If this macro is set to false, +stack_protect_prologue and stack_protect_epilogue based runtime support will be +generated, otherwise GCC assumes your architecture generates private runtime +support. This macro is default set to true. +@end defmac + @defmac HAS_LONG_COND_BRANCH Define this boolean macro to indicate whether or not your architecture has conditional branches that can span all of memory. It is used in diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index da133a4b7010533d85d5bb9a850b91e8a80ce1ca..729c76fa182076828a5819ab391b4f61fb80a771 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -7499,6 +7499,14 @@ c_register_addr_space ("__ea", ADDR_SPACE_EA); @c prevent bad page break with this line Here are several miscellaneous parameters. +@defmac ENABLE_DEFAULT_SSP_RUNTIME +Define this boolean macro to indicate whether or not your architecture +use GCC default stack protector runtime. If this macro is set to false, +stack_protect_prologue and stack_protect_epilogue based runtime support will be +generated, otherwise GCC assumes your architecture generates private runtime +support. This macro is default set to true. +@end defmac + @defmac HAS_LONG_COND_BRANCH Define this boolean macro to indicate whether or not your architecture has conditional branches that can span all of memory. It is used in diff --git a/gcc/function.c b/gcc/function.c index 53bad8736e9ef251347d23d40bc0ab767a979bc7..9dce8929590f6cb06155a540e33960c2cf0e3b16 100644 --- a/gcc/function.c +++ b/gcc/function.c @@ -5624,7 +5624,7 @@ expand_function_end (void) emit_insn (gen_blockage ()); /* If stack protection is enabled for this function, check the guard. */ - if (crtl->stack_protect_guard) + if (crtl->stack_protect_guard && ENABLE_DEFAULT_SSP_RUNTIME) stack_protect_epilogue (); /* If we had calls to alloca, and this machine needs