From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 114534 invoked by alias); 5 Feb 2020 22:37:50 -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 114526 invoked by uid 89); 5 Feb 2020 22:37:50 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-1.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (205.139.110.61) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 05 Feb 2020 22:37:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580942267; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vMRaXv8ss4ziS28wirMA+b1qq+mtpvvOfawCIfieUto=; b=CYjdqGkUgPMLQ4/XREP2hS0H7f7OjjSX9M7fIM3/IFdlWXqCTLET+8PtzKKRuLMiFBAvZy G/op+7y5ev6ML+t/yvwb/8rcS1V/K1nSZ4SGQGhYkBVGNteGFmRg+igqHZyaiRhBQC3I/B a+uY3xwRqQ7iADJ07f2e9DUBoHJoYc0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-194-Q588B79VN9uCpWrtnRU_yw-1; Wed, 05 Feb 2020 17:37:43 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 800121081FA1; Wed, 5 Feb 2020 22:37:41 +0000 (UTC) Received: from redhat.com (unknown [10.20.4.137]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CE62E84DB8; Wed, 5 Feb 2020 22:37:39 +0000 (UTC) Date: Wed, 05 Feb 2020 22:37:00 -0000 From: Marek Polacek To: "H.J. Lu" Cc: GCC Patches , Uros Bizjak , Jeff Law , Richard Biener , Richard Earnshaw , Jakub Jelinek , Torsten Duwe , Szabolcs Nagy , Eric Botcazou , Richard Sandiford Subject: Re: [PATCH] Add patch_area_size and patch_area_entry to crtl Message-ID: <20200205223737.GF1941471@redhat.com> References: <20200205143300.144541-1-hjl.tools@gmail.com> <20200205143300.144541-3-hjl.tools@gmail.com> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-SW-Source: 2020-02/txt/msg00304.txt.bz2 On Wed, Feb 05, 2020 at 02:24:48PM -0800, H.J. Lu wrote: > On Wed, Feb 5, 2020 at 12:20 PM H.J. Lu wrote: > > > > On Wed, Feb 5, 2020 at 9:00 AM Richard Sandiford > > wrote: > > > > > > "H.J. Lu" writes: > > > > Currently patchable area is at the wrong place. > > > > > > Agreed :-) > > > > > > > It is placed immediately > > > > after function label and before .cfi_startproc. A backend should b= e 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 patch= able > > > > area info is available in RTL passes. > > > > > > It might be better to add it to crtl, since it should only be needed > > > during rtl generation. > > > > > > > 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_si= ze > > > > and cfun->patch_area_entry. > > > > * function.h (function): Add patch_area_size and patch_area_e= ntry. > > > > * 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_si= ze > > > > 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_e= ntry-error-1.c > > > > create mode 100644 gcc/testsuite/c-c++-common/patchable_function_e= ntry-error-2.c > > > > create mode 100644 gcc/testsuite/c-c++-common/patchable_function_e= ntry-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=3D0}, no pad location is recorde= d. > > > > 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 h= ere. */ > > > > if (flag_stack_check =3D=3D GENERIC_STACK_CHECK) > > > > stack_check_probe_note =3D emit_note (NOTE_INSN_DELETED); > > > > + > > > > + unsigned HOST_WIDE_INT patch_area_size =3D function_entry_patch_= area_size; > > > > + unsigned HOST_WIDE_INT patch_area_entry =3D function_entry_patch= _area_start; > > > > + > > > > + tree patchable_function_entry_attr > > > > + =3D lookup_attribute ("patchable_function_entry", > > > > + DECL_ATTRIBUTES (cfun->decl)); > > > > + if (patchable_function_entry_attr) > > > > + { > > > > + tree pp_val =3D TREE_VALUE (patchable_function_entry_attr); > > > > + tree patchable_function_entry_value1 =3D TREE_VALUE (pp_val); > > > > + > > > > + patch_area_size =3D tree_to_uhwi (patchable_function_entry_v= alue1); > > > > + patch_area_entry =3D 0; > > > > + if (TREE_CHAIN (pp_val) !=3D NULL_TREE) > > > > + { > > > > + tree patchable_function_entry_value2 > > > > + =3D TREE_VALUE (TREE_CHAIN (pp_val)); > > > > + patch_area_entry =3D tree_to_uhwi (patchable_function_entry= _value2); > > > > + } > > > > + if (patch_area_size > USHRT_MAX || patch_area_size > USHRT_M= AX) > > > > + error ("invalid values for % attri= bute"); > > > > > > This should probably go in handle_patchable_function_entry_attribute > > > instead. It doesn't look like we have a clear policy about whether > > > errors or warnings are right for unrecognised arguments to known > > > attribute names, but handle_patchable_function_entry_attribute reports > > > an OPT_Wattributes warning for arguments that aren't integers. Doing= the > > > same for out-of-range integers would be more consistent and means that > > > we wouldn't break existing code if we relaxed/changed the rules in fu= ture. > > > > Like this? OK for master if there is no regression? > > >=20 > There is a small problem. Warnings from C and C++ frond-ends are differe= nt: >=20 > [hjl@gnu-skx-1 gcc]$ cat x.c > void > __attribute__((patchable_function_entry(65536))) > foo1 (void) > { /* { dg-warning "'patchable_function_entry' attribute argument > '65536' is out of range" } */ > } > [hjl@gnu-skx-1 gcc]$ ./xgcc -B./ -S x.c > x.c:4:1: warning: =E2=80=98patchable_function_entry=E2=80=99 attribute ar= gument > =E2=80=9865536=E2=80=99 is out of range (> 65535) [-Wattributes] > 4 | { /* { dg-warning "'patchable_function_entry' attribute > argument '65536' is out of range" } */ > | ^ > [hjl@gnu-skx-1 gcc]$ ./xg++ -B./ -S x.c > x.c:3:11: warning: =E2=80=98patchable_function_entry=E2=80=99 attribute a= rgument > =E2=80=9865536=E2=80=99 is out of range (> 65535) [-Wattributes] > 3 | foo1 (void) > | ^ > [hjl@gnu-skx-1 gcc]$ >=20 > C warns at line 4 and C++ warns at line 3. Do I need separate tests > for C and C++? I think better would be /* { dg-error "foo" "" { target c } } */ /* { dg-error "bar" "" { target c++ } .-1 } */ Marek