From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by sourceware.org (Postfix) with ESMTPS id E4D243858CDA for ; Sun, 31 Jul 2022 17:35:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E4D243858CDA Received: by mail-qk1-x732.google.com with SMTP id e12so4369527qkl.2 for ; Sun, 31 Jul 2022 10:35:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=Lcw8z3NXQltOSSRcyeJQCKjExRX4C9njxXAM5i9lI3g=; b=BlCfzdYr2I0nXDdescjb5RhtIfHMX6Kss6F+wq0Rq14JrUKFu8UNQLHlKzT8DLWCxO S6TGbK3ikXLhZMnUcAERwH+HJrvtuwvW4ZaKaGYJvbG/lSI6MtH7x8vFS2nmm4yn6RQE 88F8Ucge39GTPny+ouIqkBmbZZl7biKAxWos/ch7bglwNQzM4AXpu49mr8Z0d4/I0N0k 8oZt2N3N0G9gEbmF3SoX5ObAeIr2luNZ7Jj0lUhBYple7GbE4ZUsUw/2G0xDZi8zV3ze xN+YoYgUTAurHwP9jKKKkBl1vhTfLTEg3bj7lHyvqtaQqadHQwC9p84LNfsDQ+JGEeLm TBdA== X-Gm-Message-State: AJIora/humdwRBvv8rbX7oQ0iNnjUkQwMZQFKH/t8GebvYfkGTbBtm8n UNbPr26zXC2w5F8fb3UxXmZ/BcRhnTbxXovbvSM= X-Google-Smtp-Source: AGRyM1tE+VPbLh8J60rfB3IUyZ6LnyGKmbADIY8gXWXpIfFBY8XApP4/Qve75Qm5QYuenjLZuh+rqjABFjUc0nG4g1k= X-Received: by 2002:a05:620a:2619:b0:6b5:eddf:ef8e with SMTP id z25-20020a05620a261900b006b5eddfef8emr9625755qko.674.1659288939265; Sun, 31 Jul 2022 10:35:39 -0700 (PDT) MIME-Version: 1.0 References: <20220721185306.1497618-1-hjl.tools@gmail.com> In-Reply-To: From: Uros Bizjak Date: Sun, 31 Jul 2022 19:35:28 +0200 Message-ID: Subject: Re: PING [PATCH] x86: Add ix86_ifunc_ref_local_ok To: "H.J. Lu" Cc: GCC Patches , liuhongt Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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: Sun, 31 Jul 2022 17:35:42 -0000 On Wed, Jul 27, 2022 at 4:47 PM H.J. Lu wrote: > > On Thu, Jul 21, 2022 at 11:53 AM H.J. Lu wrote: > > > > We can't always use the PLT entry as the function address for local IFUNC > > functions. When the PIC register is needed for PLT call, indirect call > > via the PLT entry will fail since the PIC register may not be set up > > properly for indirect call. Add ix86_ifunc_ref_local_ok to return false > > when the PLT entry can't be used as local IFUNC function pointers. > > > > gcc/ > > > > PR target/83782 > > * config/i386/i386.cc (ix86_ifunc_ref_local_ok): New. > > (TARGET_IFUNC_REF_LOCAL_OK): Use it. > > > > gcc/testsuite/ > > > > PR target/83782 > > * gcc.target/i386/pr83782-1.c: Require non-ia32. > > * gcc.target/i386/pr83782-2.c: Likewise. > > * gcc.target/i386/pr83782-3.c: New test. You are the expert in this area, I'll blindly rubber-stamp OK. Thanks, Uros. > > --- > > gcc/config/i386/i386.cc | 15 ++++++++++- > > gcc/testsuite/gcc.target/i386/pr83782-1.c | 8 +++--- > > gcc/testsuite/gcc.target/i386/pr83782-2.c | 4 +-- > > gcc/testsuite/gcc.target/i386/pr83782-3.c | 32 +++++++++++++++++++++++ > > 4 files changed, 50 insertions(+), 9 deletions(-) > > create mode 100644 gcc/testsuite/gcc.target/i386/pr83782-3.c > > > > diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc > > index e03f86d4a23..5e30dc884bf 100644 > > --- a/gcc/config/i386/i386.cc > > +++ b/gcc/config/i386/i386.cc > > @@ -16070,6 +16070,19 @@ ix86_call_use_plt_p (rtx call_op) > > return true; > > } > > > > +/* Implement TARGET_IFUNC_REF_LOCAL_OK. If this hook returns true, > > + the PLT entry will be used as the function address for local IFUNC > > + functions. When the PIC register is needed for PLT call, indirect > > + call via the PLT entry will fail since the PIC register may not be > > + set up properly for indirect call. In this case, we should return > > + false. */ > > + > > +static bool > > +ix86_ifunc_ref_local_ok (void) > > +{ > > + return !flag_pic || (TARGET_64BIT && ix86_cmodel != CM_LARGE_PIC); > > +} > > + > > /* Return true if the function being called was marked with attribute > > "noplt" or using -fno-plt and we are compiling for non-PIC. We need > > to handle the non-PIC case in the backend because there is no easy > > @@ -24953,7 +24966,7 @@ ix86_libgcc_floating_mode_supported_p > > ix86_get_multilib_abi_name > > > > #undef TARGET_IFUNC_REF_LOCAL_OK > > -#define TARGET_IFUNC_REF_LOCAL_OK hook_bool_void_true > > +#define TARGET_IFUNC_REF_LOCAL_OK ix86_ifunc_ref_local_ok > > > > #if !TARGET_MACHO && !TARGET_DLLIMPORT_DECL_ATTRIBUTES > > # undef TARGET_ASM_RELOC_RW_MASK > > diff --git a/gcc/testsuite/gcc.target/i386/pr83782-1.c b/gcc/testsuite/gcc.target/i386/pr83782-1.c > > index ce97b12e65d..85674346aec 100644 > > --- a/gcc/testsuite/gcc.target/i386/pr83782-1.c > > +++ b/gcc/testsuite/gcc.target/i386/pr83782-1.c > > @@ -1,4 +1,4 @@ > > -/* { dg-do compile } */ > > +/* { dg-do compile { target { ! ia32 } } } */ > > /* { dg-require-ifunc "" } */ > > /* { dg-options "-O2 -fpic" } */ > > > > @@ -20,7 +20,5 @@ bar(void) > > return foo; > > } > > > > -/* { dg-final { scan-assembler {leal[ \t]foo@GOTOFF\(%[^,]*\),[ \t]%eax} { target ia32 } } } */ > > -/* { dg-final { scan-assembler {lea(?:l|q)[ \t]foo\(%rip\),[ \t]%(?:e|r)ax} { target { ! ia32 } } } } */ > > -/* { dg-final { scan-assembler-not "foo@GOT\\\(" { target ia32 } } } */ > > -/* { dg-final { scan-assembler-not "foo@GOTPCREL\\\(" { target { ! ia32 } } } } */ > > +/* { dg-final { scan-assembler {lea(?:l|q)[ \t]foo\(%rip\),[ \t]%(?:e|r)ax} } } */ > > +/* { dg-final { scan-assembler-not "foo@GOTPCREL\\\(" } } */ > > diff --git a/gcc/testsuite/gcc.target/i386/pr83782-2.c b/gcc/testsuite/gcc.target/i386/pr83782-2.c > > index e25d258bbda..a654ded771f 100644 > > --- a/gcc/testsuite/gcc.target/i386/pr83782-2.c > > +++ b/gcc/testsuite/gcc.target/i386/pr83782-2.c > > @@ -1,4 +1,4 @@ > > -/* { dg-do compile } */ > > +/* { dg-do compile { target { ! ia32 } } } */ > > /* { dg-require-ifunc "" } */ > > /* { dg-options "-O2 -fpic" } */ > > > > @@ -20,7 +20,5 @@ bar(void) > > return foo; > > } > > > > -/* { dg-final { scan-assembler {leal[ \t]foo@GOTOFF\(%[^,]*\),[ \t]%eax} { target ia32 } } } */ > > /* { dg-final { scan-assembler {lea(?:l|q)[ \t]foo\(%rip\),[ \t]%(?:e|r)ax} { target { ! ia32 } } } } */ > > -/* { dg-final { scan-assembler-not "foo@GOT\\\(" { target ia32 } } } */ > > /* { dg-final { scan-assembler-not "foo@GOTPCREL\\\(" { target { ! ia32 } } } } */ > > diff --git a/gcc/testsuite/gcc.target/i386/pr83782-3.c b/gcc/testsuite/gcc.target/i386/pr83782-3.c > > new file mode 100644 > > index 00000000000..1536481cb79 > > --- /dev/null > > +++ b/gcc/testsuite/gcc.target/i386/pr83782-3.c > > @@ -0,0 +1,32 @@ > > +/* { dg-do run } */ > > +/* { dg-require-ifunc "" } */ > > +/* { dg-require-effective-target pie } */ > > +/* { dg-options "-fpie -pie" } */ > > + > > +#include > > + > > +static int __attribute__((noinline)) > > +implementation (void) > > +{ > > + printf ("'ere I am JH\n"); > > + return 0; > > +} > > + > > +static __typeof__ (implementation) *resolver (void) > > +{ > > + return (void *)implementation; > > +} > > + > > +extern int magic (void) __attribute__ ((ifunc ("resolver"))); > > + > > +__attribute__ ((weak)) > > +int > > +call_magic (int (*ptr) (void)) > > +{ > > + return ptr (); > > +} > > + > > +int main () > > +{ > > + return call_magic (magic); > > +} > > -- > > 2.36.1 > > > > PING. > > -- > H.J.