From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1039) id ACC1C3858281; Tue, 21 Jun 2022 17:45:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ACC1C3858281 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: H.J. Lu To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-8501] i386: Disallow sibcall for calling ifunc functions with PIC register X-Act-Checkin: gcc X-Git-Author: H.J. Lu X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: 00b26ae2d1c0e1d6cc990862f54dc3dbcbeed913 X-Git-Newrev: 2474c8e09a93027cde39ecb6a53742142c8496ed Message-Id: <20220621174531.ACC1C3858281@sourceware.org> Date: Tue, 21 Jun 2022 17:45:31 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2022 17:45:31 -0000 https://gcc.gnu.org/g:2474c8e09a93027cde39ecb6a53742142c8496ed commit r12-8501-g2474c8e09a93027cde39ecb6a53742142c8496ed Author: H.J. Lu 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. (cherry picked from commit fe9765c0b97e6b4ce2cd226631d329fc05ba2aa5) 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 83995a8cc6b..9dd9fa68722 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 } } } */