public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Uros Bizjak <ubizjak@gmail.com>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>, liuhongt <hongtao.liu@intel.com>
Subject: Re: PING [PATCH] x86: Add ix86_ifunc_ref_local_ok
Date: Sun, 31 Jul 2022 19:35:28 +0200	[thread overview]
Message-ID: <CAFULd4aFvYmi_dtS8dZU-Ua_GudnFAhE-MYdMe9nNSDNGw_EVw@mail.gmail.com> (raw)
In-Reply-To: <CAMe9rOpZ2J3XFsxbQko_gPRPe+qS55236x+XD-oD8xd7CEcxig@mail.gmail.com>

On Wed, Jul 27, 2022 at 4:47 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Thu, Jul 21, 2022 at 11:53 AM H.J. Lu <hjl.tools@gmail.com> 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 <stdio.h>
> > +
> > +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.

      reply	other threads:[~2022-07-31 17:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-21 18:53 H.J. Lu
2022-07-27 14:46 ` PING " H.J. Lu
2022-07-31 17:35   ` Uros Bizjak [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFULd4aFvYmi_dtS8dZU-Ua_GudnFAhE-MYdMe9nNSDNGw_EVw@mail.gmail.com \
    --to=ubizjak@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hjl.tools@gmail.com \
    --cc=hongtao.liu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).