From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 115780 invoked by alias); 5 Feb 2020 14:33:06 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 115760 invoked by uid 89); 5 Feb 2020 14:33:06 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.3 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=H*Ad:U*ebotcazou, clique X-HELO: mail-pf1-f193.google.com Received: from mail-pf1-f193.google.com (HELO mail-pf1-f193.google.com) (209.85.210.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 05 Feb 2020 14:33:04 +0000 Received: by mail-pf1-f193.google.com with SMTP id i6so1314121pfc.1 for ; Wed, 05 Feb 2020 06:33:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=paHHed5y5C7ZrhMh4dBXZACwr4gmR+9Z8clAYt/4gPQ=; b=ROKaLVaFEmmI0T3sHryw/7AuTH70oLVyfK8FIWUq6SW0rcL80lJebY7WnT1UHY8QDC /J49Tyy6ZXeMMoojYJrYWhg9U1uXxNW8T6obfq6iWHDinD4f9Mb27JrJZjPtxhFroQrV tldPutMCQ+iT92R94CdMlHLy1X5xHnXfnnt/fmkI4wQJdxShyznGwa0e4BBHH+s/CUuW X+od5pRMLG3DcZVo1ZUr6g7LVG8AlEz14TNBz79AIkb7BOuqO4q+mapYQt28EOEaUYOS yLLVkVfoQuY7AzdbyCTjE/PQDfI8UJZhcP+oTfzsTxKwV6xPve0Z7gXTqfmIRUT5g42J HplQ== Return-Path: Received: from gnu-cfl-2.localdomain (c-73-93-86-59.hsd1.ca.comcast.net. [73.93.86.59]) by smtp.gmail.com with ESMTPSA id e7sm30081496pfj.114.2020.02.05.06.33.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2020 06:33:01 -0800 (PST) Received: from gnu-cfl-2.hsd1.ca.comcast.net (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 8F31BC040B; Wed, 5 Feb 2020 06:33:00 -0800 (PST) From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Cc: Uros Bizjak , Jeff Law , Richard Biener , Richard Earnshaw , Jakub Jelinek , Richard Sandiford , Torsten Duwe , Szabolcs Nagy , Eric Botcazou Subject: [PATCH 2/3] Add patch_area_size and patch_area_entry to cfun Date: Wed, 05 Feb 2020 14:33:00 -0000 Message-Id: <20200205143300.144541-3-hjl.tools@gmail.com> In-Reply-To: <20200205143300.144541-1-hjl.tools@gmail.com> References: <20200205143300.144541-1-hjl.tools@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2020-02/txt/msg00267.txt.bz2 Currently patchable area is at the wrong place. It is placed immediately after function label and before .cfi_startproc. A backend should be able to add a pseudo patchable area instruction durectly into RTL. This patch adds patch_area_size and patch_area_entry to cfun so that the patchable area info is available in RTL passes. It also limits patch_area_size and patch_area_entry to 65535, which is a reasonable maximum size for patchable area. gcc/ PR target/93492 * function.c (expand_function_start): Set cfun->patch_area_size and cfun->patch_area_entry. * function.h (function): Add patch_area_size and patch_area_entry. * opts.c (common_handle_option): Limit function_entry_patch_area_size and function_entry_patch_area_start to USHRT_MAX. Fix a typo in error message. * varasm.c (assemble_start_function): Use cfun->patch_area_size and cfun->patch_area_entry. * doc/invoke.texi: Document the maximum value for -fpatchable-function-entry. gcc/testsuite/ PR target/93492 * c-c++-common/patchable_function_entry-error-1.c: New test. * c-c++-common/patchable_function_entry-error-2.c: Likewise. * c-c++-common/patchable_function_entry-error-3.c: Likewise. --- gcc/doc/invoke.texi | 1 + gcc/function.c | 35 +++++++++++++++++++ gcc/function.h | 6 ++++ gcc/opts.c | 4 ++- .../patchable_function_entry-error-1.c | 9 +++++ .../patchable_function_entry-error-2.c | 9 +++++ .../patchable_function_entry-error-3.c | 20 +++++++++++ gcc/varasm.c | 30 ++-------------- 8 files changed, 85 insertions(+), 29 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/patchable_function_entry-error-1.c create mode 100644 gcc/testsuite/c-c++-common/patchable_function_entry-error-2.c create mode 100644 gcc/testsuite/c-c++-common/patchable_function_entry-error-3.c diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 35b341e759f..dd4835199b0 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -13966,6 +13966,7 @@ If @code{N=0}, no pad location is recorded. The NOP instructions are inserted at---and maybe before, depending on @var{M}---the function entry address, even before the prologue. +The maximum value of @var{N} and @var{M} is 65535. @end table diff --git a/gcc/function.c b/gcc/function.c index d8008f60422..badbf538eec 100644 --- a/gcc/function.c +++ b/gcc/function.c @@ -5202,6 +5202,41 @@ expand_function_start (tree subr) /* If we are doing generic stack checking, the probe should go here. */ if (flag_stack_check == GENERIC_STACK_CHECK) stack_check_probe_note = emit_note (NOTE_INSN_DELETED); + + unsigned HOST_WIDE_INT patch_area_size = function_entry_patch_area_size; + unsigned HOST_WIDE_INT patch_area_entry = function_entry_patch_area_start; + + tree patchable_function_entry_attr + = lookup_attribute ("patchable_function_entry", + DECL_ATTRIBUTES (cfun->decl)); + if (patchable_function_entry_attr) + { + tree pp_val = TREE_VALUE (patchable_function_entry_attr); + tree patchable_function_entry_value1 = TREE_VALUE (pp_val); + + patch_area_size = tree_to_uhwi (patchable_function_entry_value1); + patch_area_entry = 0; + if (TREE_CHAIN (pp_val) != NULL_TREE) + { + tree patchable_function_entry_value2 + = TREE_VALUE (TREE_CHAIN (pp_val)); + patch_area_entry = tree_to_uhwi (patchable_function_entry_value2); + } + if (patch_area_size > USHRT_MAX || patch_area_size > USHRT_MAX) + error ("invalid values for % attribute"); + } + + if (patch_area_entry > patch_area_size) + { + if (patch_area_size > 0) + warning (OPT_Wattributes, + "patchable function entry %wu exceeds size %wu", + patch_area_entry, patch_area_size); + patch_area_entry = 0; + } + + cfun->patch_area_size = patch_area_size; + cfun->patch_area_entry = patch_area_entry; } void diff --git a/gcc/function.h b/gcc/function.h index 1ee8ed3de53..1ed7c400f23 100644 --- a/gcc/function.h +++ b/gcc/function.h @@ -332,6 +332,12 @@ struct GTY(()) function { /* Last assigned dependence info clique. */ unsigned short last_clique; + /* How many NOP insns to place at each function entry by default. */ + unsigned short patch_area_size; + + /* How far the real asm entry point is into this area. */ + unsigned short patch_area_entry; + /* Collected bit flags. */ /* Number of units of general registers that need saving in stdarg diff --git a/gcc/opts.c b/gcc/opts.c index 7affeb41a96..c6011f1f9b7 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -2598,10 +2598,12 @@ common_handle_option (struct gcc_options *opts, function_entry_patch_area_start = 0; } if (function_entry_patch_area_size < 0 + || function_entry_patch_area_size > USHRT_MAX || function_entry_patch_area_start < 0 + || function_entry_patch_area_start > USHRT_MAX || function_entry_patch_area_size < function_entry_patch_area_start) - error ("invalid arguments for %<-fpatchable_function_entry%>"); + error ("invalid arguments for %<-fpatchable-function-entry%>"); free (patch_area_arg); } break; diff --git a/gcc/testsuite/c-c++-common/patchable_function_entry-error-1.c b/gcc/testsuite/c-c++-common/patchable_function_entry-error-1.c new file mode 100644 index 00000000000..f60bf46cfe3 --- /dev/null +++ b/gcc/testsuite/c-c++-common/patchable_function_entry-error-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile { target { ! { nvptx*-*-* visium-*-* } } } } */ +/* { dg-options "-O2 -fpatchable-function-entry=65536,1" } */ +/* { dg-additional-options "-fno-pie" { target sparc*-*-* } } */ +/* { dg-error "invalid arguments for '-fpatchable-function-entry'" "" { target *-*-* } 0 } */ + +void +foo (void) +{ +} diff --git a/gcc/testsuite/c-c++-common/patchable_function_entry-error-2.c b/gcc/testsuite/c-c++-common/patchable_function_entry-error-2.c new file mode 100644 index 00000000000..90f88c78be7 --- /dev/null +++ b/gcc/testsuite/c-c++-common/patchable_function_entry-error-2.c @@ -0,0 +1,9 @@ +/* { dg-do compile { target { ! { nvptx*-*-* visium-*-* } } } } */ +/* { dg-options "-O2 -fpatchable-function-entry=1,65536" } */ +/* { dg-additional-options "-fno-pie" { target sparc*-*-* } } */ +/* { dg-error "invalid arguments for '-fpatchable-function-entry'" "" { target *-*-* } 0 } */ + +void +foo (void) +{ +} diff --git a/gcc/testsuite/c-c++-common/patchable_function_entry-error-3.c b/gcc/testsuite/c-c++-common/patchable_function_entry-error-3.c new file mode 100644 index 00000000000..b6e449425d2 --- /dev/null +++ b/gcc/testsuite/c-c++-common/patchable_function_entry-error-3.c @@ -0,0 +1,20 @@ +/* { dg-do compile { target { ! { nvptx*-*-* visium-*-* } } } } */ +/* { dg-additional-options "-fno-pie" { target sparc*-*-* } } */ + +void + __attribute__((patchable_function_entry(65536))) +foo1 (void) /* { dg-error "invalid values for 'patchable_function_entry'" } */ +{ +} + +void + __attribute__((patchable_function_entry(65536,1))) +foo2 (void) /* { dg-error "invalid values for 'patchable_function_entry'" } */ +{ +} + +void + __attribute__((patchable_function_entry(65536,65536))) +foo3 (void) /* { dg-error "invalid values for 'patchable_function_entry'" } */ +{ +} diff --git a/gcc/varasm.c b/gcc/varasm.c index dc6da6c0b5b..93251f07d6e 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -1857,34 +1857,8 @@ assemble_start_function (tree decl, const char *fnname) if (DECL_PRESERVE_P (decl)) targetm.asm_out.mark_decl_preserved (fnname); - unsigned HOST_WIDE_INT patch_area_size = function_entry_patch_area_size; - unsigned HOST_WIDE_INT patch_area_entry = function_entry_patch_area_start; - - tree patchable_function_entry_attr - = lookup_attribute ("patchable_function_entry", DECL_ATTRIBUTES (decl)); - if (patchable_function_entry_attr) - { - tree pp_val = TREE_VALUE (patchable_function_entry_attr); - tree patchable_function_entry_value1 = TREE_VALUE (pp_val); - - patch_area_size = tree_to_uhwi (patchable_function_entry_value1); - patch_area_entry = 0; - if (TREE_CHAIN (pp_val) != NULL_TREE) - { - tree patchable_function_entry_value2 - = TREE_VALUE (TREE_CHAIN (pp_val)); - patch_area_entry = tree_to_uhwi (patchable_function_entry_value2); - } - } - - if (patch_area_entry > patch_area_size) - { - if (patch_area_size > 0) - warning (OPT_Wattributes, - "patchable function entry %wu exceeds size %wu", - patch_area_entry, patch_area_size); - patch_area_entry = 0; - } + unsigned short patch_area_size = cfun->patch_area_size; + unsigned short patch_area_entry = cfun->patch_area_entry; /* Emit the patching area before the entry label, if any. */ if (patch_area_entry > 0) -- 2.24.1