From patchwork Thu Nov 24 14:11:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiong Wang X-Patchwork-Id: 83904 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp131336qgi; Thu, 24 Nov 2016 06:12:23 -0800 (PST) X-Received: by 10.84.210.233 with SMTP id a96mr5915101pli.118.1479996743917; Thu, 24 Nov 2016 06:12:23 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id h67si39638870pfe.48.2016.11.24.06.12.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Nov 2016 06:12:23 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-442557-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-442557-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-442557-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=I5ZlIHscarnq8oTr4 DLxNS1Fpvi7yGMFrqxnKAZGu5q79vjFpUlsAfZVzBg74zKdZaUb2s+ncxD6evciB nE3JEBYJkmTxSKl5K16JisVyTHFKyCVIbGx95snwo9RIF876y3y0PIbwuxz1Rdj/ tKxorpXq8jm5MdPZoBdwKmHTyU= 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=WGxJo4gjg4R9DBnlZhisJwE N6II=; b=OLqOl53iPAa2Al3RC7JGC17YdpvRjnfOZgJN1z9BhrUc82Nyx7OvfFR MtBNmYLq7ub2DccFT1sAWXvcv7IYJZngWXRYEynPxj1IyOMDkW9wiGdH9iP9by3R KXnhA9H2aE3t1Q6tYqFy1fWvNGS/iGgfYQy8Qcmwb+t1Q4oSIZEY= Received: (qmail 5919 invoked by alias); 24 Nov 2016 14:12:09 -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 5895 invoked by uid 89); 24 Nov 2016 14:12:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.9 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=resolving, Documents, documents, protect 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; Thu, 24 Nov 2016 14:11:58 +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 559B316; Thu, 24 Nov 2016 06:11:56 -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 B7F2D3F24D; Thu, 24 Nov 2016 06:11:55 -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" , Joseph Myers From: Jiong Wang Message-ID: <2cb344c0-b841-70dd-91f5-c4e5bd6c9347@foss.arm.com> Date: Thu, 24 Nov 2016 14:11:54 +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: X-IsSubscribed: yes >> 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. >> >Like Joseph, I think this should be a hook rather than a new target macro. I do think it's closer to the right track though (separation of access to the guard from the rest of the SSP runtime bits). Hi Josephy, Jeff: Thanks for the review. I was planning to update the patch after resolving the pending DWARF issue (https://gcc.gnu.org/ml/gcc-patches/2016-11/msg01156.html), While as this patch itself it quite independent, so OK to commit the attached patch? x86-64 boostrap and regression OK. gcc/ 2016-11-24 Jiong Wang * target.def (stack_protect_runtime_enabled_p): New. * function.c (expand_function_end): Guard stack_protect_epilogue with targetm.stack_protect_runtime_enabled_p. * cfgexpand.c (pass_expand::execute): Likewise. * calls.c (expand_call): Likewise. * doc/tm.texi.in (TARGET_STACK_PROTECT_RUNTIME_ENABLED_P): Add it. * doc/tm.texi: Regenerate. diff --git a/gcc/calls.c b/gcc/calls.c index c916e07..21385ce 100644 --- a/gcc/calls.c +++ b/gcc/calls.c @@ -3083,7 +3083,9 @@ expand_call (tree exp, rtx target, int ignore) if (pass && (flags & ECF_MALLOC)) start_sequence (); - if (pass == 0 && crtl->stack_protect_guard) + if (pass == 0 + && crtl->stack_protect_guard + && targetm.stack_protect_runtime_enabled_p ()) stack_protect_epilogue (); adjusted_args_size = args_size; diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index 7ffb558..9c5a892 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -6334,7 +6334,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 && targetm.stack_protect_runtime_enabled_p ()) stack_protect_prologue (); expand_phi_nodes (&SA); diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 84bba07..c4f4ec3 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -4949,6 +4949,10 @@ The default version of this hook invokes a function called normally defined in @file{libgcc2.c}. @end deftypefn +@deftypefn {Target Hook} bool TARGET_STACK_PROTECT_RUNTIME_ENABLED_P (void) +Returns true if the target wants GCC's default stack protect runtime support, otherwise return false. The default implementation always returns true. +@end deftypefn + @deftypefn {Common Target Hook} bool TARGET_SUPPORTS_SPLIT_STACK (bool @var{report}, struct gcc_options *@var{opts}) Whether this target supports splitting the stack when the options described in @var{opts} have been passed. This is called after options have been parsed, so the target may reject splitting the stack in some configurations. The default version of this hook returns false. If @var{report} is true, this function may issue a warning or error; if @var{report} is false, it must simply return a value @end deftypefn diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index 9afd5daa..9202bfe6 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -3825,6 +3825,8 @@ generic code. @hook TARGET_STACK_PROTECT_FAIL +@hook TARGET_STACK_PROTECT_RUNTIME_ENABLED_P + @hook TARGET_SUPPORTS_SPLIT_STACK @node Miscellaneous Register Hooks diff --git a/gcc/function.c b/gcc/function.c index 0b1d168..871f5a0 100644 --- a/gcc/function.c +++ b/gcc/function.c @@ -5627,7 +5627,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 && targetm.stack_protect_runtime_enabled_p ()) stack_protect_epilogue (); /* If we had calls to alloca, and this machine needs diff --git a/gcc/target.def b/gcc/target.def index c24b4cf..a63b850 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -4039,6 +4039,15 @@ normally defined in @file{libgcc2.c}.", tree, (void), default_external_stack_protect_fail) +/* This target hook allows the operating system to disable the default stack + protector runtime support. */ +DEFHOOK +(stack_protect_runtime_enabled_p, + "Returns true if the target wants GCC's default stack protect runtime support,\ + otherwise return false. The default implementation always returns true.", + bool, (void), + hook_bool_void_true) + DEFHOOK (can_use_doloop_p, "Return true if it is possible to use low-overhead loops (@code{doloop_end}\n\