public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: H.J. Lu <hjl@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-1180] i386: Disallow sibcall for calling ifunc functions with PIC register
Date: Mon, 20 Jun 2022 15:26:53 +0000 (GMT)	[thread overview]
Message-ID: <20220620152653.DC8143858C2C@sourceware.org> (raw)

https://gcc.gnu.org/g:fe9765c0b97e6b4ce2cd226631d329fc05ba2aa5

commit r13-1180-gfe9765c0b97e6b4ce2cd226631d329fc05ba2aa5
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Jun 14 08:20:16 2022 -0700

    i386: Disallow sibcall for calling ifunc functions with PIC register
    
    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.

Diff:
---
 gcc/config/i386/i386.cc                  |  9 +++++++++
 gcc/testsuite/gcc.target/i386/pr105960.c | 19 +++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index f158cc3aaea..b15b4893bb9 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 } } } */


                 reply	other threads:[~2022-06-20 15:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220620152653.DC8143858C2C@sourceware.org \
    --to=hjl@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).