diff mbox series

i386: Disallow sibcall when calling ifunc functions with PIC register

Message ID 20220614192548.1929268-1-hjl.tools@gmail.com
State New
Headers show
Series i386: Disallow sibcall when calling ifunc functions with PIC register | expand

Commit Message

H.J. Lu June 14, 2022, 7:25 p.m. UTC
Disallow siball when calling ifunc functions with PIC register so that
PIC register can be restored.

gcc/

	PR target/105960
	* config/i386/i386.cc (ix86_function_ok_for_sibcall): Return
	false if PIC register is used when calling ifunc functions.

gcc/testsuite/

	PR target/105960
	* gcc.target/i386/pr105960.c: New test.
---
 gcc/config/i386/i386.cc                  |  9 +++++++++
 gcc/testsuite/gcc.target/i386/pr105960.c | 19 +++++++++++++++++++
 2 files changed, 28 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr105960.c

Comments

H.J. Lu June 20, 2022, 2:02 p.m. UTC | #1
On Tue, Jun 14, 2022 at 12:25 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> Disallow siball when calling ifunc functions with PIC register so that
> PIC register can be restored.
>
> gcc/
>
>         PR target/105960
>         * config/i386/i386.cc (ix86_function_ok_for_sibcall): Return
>         false if PIC register is used when calling ifunc functions.
>
> gcc/testsuite/
>
>         PR target/105960
>         * gcc.target/i386/pr105960.c: New test.
> ---
>  gcc/config/i386/i386.cc                  |  9 +++++++++
>  gcc/testsuite/gcc.target/i386/pr105960.c | 19 +++++++++++++++++++
>  2 files changed, 28 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr105960.c
>
> diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
> index 3d189e124e4..1ca7836e11e 100644
> --- a/gcc/config/i386/i386.cc
> +++ b/gcc/config/i386/i386.cc
> @@ -1015,6 +1015,15 @@ ix86_function_ok_for_sibcall (tree decl, tree exp)
>         }
>      }
>
> +  if (decl && ix86_use_pseudo_pic_reg ())
> +    {
> +      /* When PIC register is used, it must be restored after ifunc
> +        function returns.  */
> +       cgraph_node *node = cgraph_node::get (decl);
> +       if (node && node->ifunc_resolver)
> +        return false;
> +    }
> +
>    /* Otherwise okay.  That also includes certain types of indirect calls.  */
>    return true;
>  }
> diff --git a/gcc/testsuite/gcc.target/i386/pr105960.c b/gcc/testsuite/gcc.target/i386/pr105960.c
> new file mode 100644
> index 00000000000..db137a1642d
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr105960.c
> @@ -0,0 +1,19 @@
> +/* { dg-do compile } */
> +/* { dg-require-ifunc "" } */
> +/* { dg-options "-O2 -fpic" } */
> +
> +__attribute__((target_clones("default","fma")))
> +static inline double
> +expfull_ref(double x)
> +{
> +  return __builtin_pow(x, 0.1234);
> +}
> +
> +double
> +exp_ref(double x)
> +{
> +  return expfull_ref(x);
> +}
> +
> +/* { dg-final { scan-assembler "jmp\[ \t\]*expfull_ref@PLT" { target { ! ia32 } } } } */
> +/* { dg-final { scan-assembler "call\[ \t\]*expfull_ref@PLT" { target ia32 } } } */
> --
> 2.36.1
>

PING.
Uros Bizjak June 20, 2022, 2:51 p.m. UTC | #2
On Mon, Jun 20, 2022 at 4:03 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Tue, Jun 14, 2022 at 12:25 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > Disallow siball when calling ifunc functions with PIC register so that
> > PIC register can be restored.
> >
> > gcc/
> >
> >         PR target/105960
> >         * config/i386/i386.cc (ix86_function_ok_for_sibcall): Return
> >         false if PIC register is used when calling ifunc functions.
> >
> > gcc/testsuite/
> >
> >         PR target/105960
> >         * gcc.target/i386/pr105960.c: New test.

LGTM.

Thanks,
Uros.

> > ---
> >  gcc/config/i386/i386.cc                  |  9 +++++++++
> >  gcc/testsuite/gcc.target/i386/pr105960.c | 19 +++++++++++++++++++
> >  2 files changed, 28 insertions(+)
> >  create mode 100644 gcc/testsuite/gcc.target/i386/pr105960.c
> >
> > diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
> > index 3d189e124e4..1ca7836e11e 100644
> > --- a/gcc/config/i386/i386.cc
> > +++ b/gcc/config/i386/i386.cc
> > @@ -1015,6 +1015,15 @@ ix86_function_ok_for_sibcall (tree decl, tree exp)
> >         }
> >      }
> >
> > +  if (decl && ix86_use_pseudo_pic_reg ())
> > +    {
> > +      /* When PIC register is used, it must be restored after ifunc
> > +        function returns.  */
> > +       cgraph_node *node = cgraph_node::get (decl);
> > +       if (node && node->ifunc_resolver)
> > +        return false;
> > +    }
> > +
> >    /* Otherwise okay.  That also includes certain types of indirect calls.  */
> >    return true;
> >  }
> > diff --git a/gcc/testsuite/gcc.target/i386/pr105960.c b/gcc/testsuite/gcc.target/i386/pr105960.c
> > new file mode 100644
> > index 00000000000..db137a1642d
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.target/i386/pr105960.c
> > @@ -0,0 +1,19 @@
> > +/* { dg-do compile } */
> > +/* { dg-require-ifunc "" } */
> > +/* { dg-options "-O2 -fpic" } */
> > +
> > +__attribute__((target_clones("default","fma")))
> > +static inline double
> > +expfull_ref(double x)
> > +{
> > +  return __builtin_pow(x, 0.1234);
> > +}
> > +
> > +double
> > +exp_ref(double x)
> > +{
> > +  return expfull_ref(x);
> > +}
> > +
> > +/* { dg-final { scan-assembler "jmp\[ \t\]*expfull_ref@PLT" { target { ! ia32 } } } } */
> > +/* { dg-final { scan-assembler "call\[ \t\]*expfull_ref@PLT" { target ia32 } } } */
> > --
> > 2.36.1
> >
>
> PING.
>
> --
> H.J.
H.J. Lu June 21, 2022, 2:45 p.m. UTC | #3
On Mon, Jun 20, 2022 at 7:51 AM Uros Bizjak <ubizjak@gmail.com> wrote:
>
> On Mon, Jun 20, 2022 at 4:03 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > On Tue, Jun 14, 2022 at 12:25 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> > >
> > > Disallow siball when calling ifunc functions with PIC register so that
> > > PIC register can be restored.
> > >
> > > gcc/
> > >
> > >         PR target/105960
> > >         * config/i386/i386.cc (ix86_function_ok_for_sibcall): Return
> > >         false if PIC register is used when calling ifunc functions.
> > >
> > > gcc/testsuite/
> > >
> > >         PR target/105960
> > >         * gcc.target/i386/pr105960.c: New test.
>
> LGTM.

OK to backport to GCC 12 branch?

Thanks.

> Thanks,
> Uros.
>
> > > ---
> > >  gcc/config/i386/i386.cc                  |  9 +++++++++
> > >  gcc/testsuite/gcc.target/i386/pr105960.c | 19 +++++++++++++++++++
> > >  2 files changed, 28 insertions(+)
> > >  create mode 100644 gcc/testsuite/gcc.target/i386/pr105960.c
> > >
> > > diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
> > > index 3d189e124e4..1ca7836e11e 100644
> > > --- a/gcc/config/i386/i386.cc
> > > +++ b/gcc/config/i386/i386.cc
> > > @@ -1015,6 +1015,15 @@ ix86_function_ok_for_sibcall (tree decl, tree exp)
> > >         }
> > >      }
> > >
> > > +  if (decl && ix86_use_pseudo_pic_reg ())
> > > +    {
> > > +      /* When PIC register is used, it must be restored after ifunc
> > > +        function returns.  */
> > > +       cgraph_node *node = cgraph_node::get (decl);
> > > +       if (node && node->ifunc_resolver)
> > > +        return false;
> > > +    }
> > > +
> > >    /* Otherwise okay.  That also includes certain types of indirect calls.  */
> > >    return true;
> > >  }
> > > diff --git a/gcc/testsuite/gcc.target/i386/pr105960.c b/gcc/testsuite/gcc.target/i386/pr105960.c
> > > new file mode 100644
> > > index 00000000000..db137a1642d
> > > --- /dev/null
> > > +++ b/gcc/testsuite/gcc.target/i386/pr105960.c
> > > @@ -0,0 +1,19 @@
> > > +/* { dg-do compile } */
> > > +/* { dg-require-ifunc "" } */
> > > +/* { dg-options "-O2 -fpic" } */
> > > +
> > > +__attribute__((target_clones("default","fma")))
> > > +static inline double
> > > +expfull_ref(double x)
> > > +{
> > > +  return __builtin_pow(x, 0.1234);
> > > +}
> > > +
> > > +double
> > > +exp_ref(double x)
> > > +{
> > > +  return expfull_ref(x);
> > > +}
> > > +
> > > +/* { dg-final { scan-assembler "jmp\[ \t\]*expfull_ref@PLT" { target { ! ia32 } } } } */
> > > +/* { dg-final { scan-assembler "call\[ \t\]*expfull_ref@PLT" { target ia32 } } } */
> > > --
> > > 2.36.1
> > >
> >
> > PING.
> >
> > --
> > H.J.
Uros Bizjak June 21, 2022, 2:53 p.m. UTC | #4
On Tue, Jun 21, 2022 at 4:46 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Mon, Jun 20, 2022 at 7:51 AM Uros Bizjak <ubizjak@gmail.com> wrote:
> >
> > On Mon, Jun 20, 2022 at 4:03 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> > >
> > > On Tue, Jun 14, 2022 at 12:25 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> > > >
> > > > Disallow siball when calling ifunc functions with PIC register so that
> > > > PIC register can be restored.
> > > >
> > > > gcc/
> > > >
> > > >         PR target/105960
> > > >         * config/i386/i386.cc (ix86_function_ok_for_sibcall): Return
> > > >         false if PIC register is used when calling ifunc functions.
> > > >
> > > > gcc/testsuite/
> > > >
> > > >         PR target/105960
> > > >         * gcc.target/i386/pr105960.c: New test.
> >
> > LGTM.
>
> OK to backport to GCC 12 branch?

OK.

Thanks,
Uros.

> Thanks.
>
> > Thanks,
> > Uros.
> >
> > > > ---
> > > >  gcc/config/i386/i386.cc                  |  9 +++++++++
> > > >  gcc/testsuite/gcc.target/i386/pr105960.c | 19 +++++++++++++++++++
> > > >  2 files changed, 28 insertions(+)
> > > >  create mode 100644 gcc/testsuite/gcc.target/i386/pr105960.c
> > > >
> > > > diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
> > > > index 3d189e124e4..1ca7836e11e 100644
> > > > --- a/gcc/config/i386/i386.cc
> > > > +++ b/gcc/config/i386/i386.cc
> > > > @@ -1015,6 +1015,15 @@ ix86_function_ok_for_sibcall (tree decl, tree exp)
> > > >         }
> > > >      }
> > > >
> > > > +  if (decl && ix86_use_pseudo_pic_reg ())
> > > > +    {
> > > > +      /* When PIC register is used, it must be restored after ifunc
> > > > +        function returns.  */
> > > > +       cgraph_node *node = cgraph_node::get (decl);
> > > > +       if (node && node->ifunc_resolver)
> > > > +        return false;
> > > > +    }
> > > > +
> > > >    /* Otherwise okay.  That also includes certain types of indirect calls.  */
> > > >    return true;
> > > >  }
> > > > diff --git a/gcc/testsuite/gcc.target/i386/pr105960.c b/gcc/testsuite/gcc.target/i386/pr105960.c
> > > > new file mode 100644
> > > > index 00000000000..db137a1642d
> > > > --- /dev/null
> > > > +++ b/gcc/testsuite/gcc.target/i386/pr105960.c
> > > > @@ -0,0 +1,19 @@
> > > > +/* { dg-do compile } */
> > > > +/* { dg-require-ifunc "" } */
> > > > +/* { dg-options "-O2 -fpic" } */
> > > > +
> > > > +__attribute__((target_clones("default","fma")))
> > > > +static inline double
> > > > +expfull_ref(double x)
> > > > +{
> > > > +  return __builtin_pow(x, 0.1234);
> > > > +}
> > > > +
> > > > +double
> > > > +exp_ref(double x)
> > > > +{
> > > > +  return expfull_ref(x);
> > > > +}
> > > > +
> > > > +/* { dg-final { scan-assembler "jmp\[ \t\]*expfull_ref@PLT" { target { ! ia32 } } } } */
> > > > +/* { dg-final { scan-assembler "call\[ \t\]*expfull_ref@PLT" { target ia32 } } } */
> > > > --
> > > > 2.36.1
> > > >
> > >
> > > PING.
> > >
> > > --
> > > H.J.
>
>
>
> --
> H.J.
diff mbox series

Patch

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index 3d189e124e4..1ca7836e11e 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -1015,6 +1015,15 @@  ix86_function_ok_for_sibcall (tree decl, tree exp)
 	}
     }
 
+  if (decl && ix86_use_pseudo_pic_reg ())
+    {
+      /* When PIC register is used, it must be restored after ifunc
+	 function returns.  */
+       cgraph_node *node = cgraph_node::get (decl);
+       if (node && node->ifunc_resolver)
+	 return false;
+    }
+
   /* Otherwise okay.  That also includes certain types of indirect calls.  */
   return true;
 }
diff --git a/gcc/testsuite/gcc.target/i386/pr105960.c b/gcc/testsuite/gcc.target/i386/pr105960.c
new file mode 100644
index 00000000000..db137a1642d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr105960.c
@@ -0,0 +1,19 @@ 
+/* { dg-do compile } */
+/* { dg-require-ifunc "" } */
+/* { dg-options "-O2 -fpic" } */
+
+__attribute__((target_clones("default","fma")))
+static inline double
+expfull_ref(double x)
+{
+  return __builtin_pow(x, 0.1234);
+}
+
+double
+exp_ref(double x)
+{
+  return expfull_ref(x);
+}
+
+/* { dg-final { scan-assembler "jmp\[ \t\]*expfull_ref@PLT" { target { ! ia32 } } } } */
+/* { dg-final { scan-assembler "call\[ \t\]*expfull_ref@PLT" { target ia32 } } } */