From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id 6FFE4385C323 for ; Tue, 14 Jun 2022 19:25:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6FFE4385C323 Received: by mail-pl1-x62c.google.com with SMTP id d5so5948297plo.12 for ; Tue, 14 Jun 2022 12:25:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5bOUmoZDMviTFIxcsn58JFQjOreBu6FUJEq5M7aVnOU=; b=tukvudp64WmrIAF0eZbno+gyJvLa0vYykZgJaIy+k/x2ulylfhUjlvSraigKdWIb2y xKOpuDzK22Vqu/RhrwJAtyKjkWvrJb+2OtRPW+kCpCdK9oquzFsJNB69+TOs4D4oe5QS 3lBW4aXgweWhv0ZH4p2srtSo9r0FP92lYIW4LelNp0STVuOAkwI0t6UBPruGaMx/+yai z8EFZTEdw+aDlfIfzVz+hLFrhV0OIXXRZrPo6vrk5eH7Vbcur4SLNGcIeWB6t6yp9XNw R9bmzGj7OEMDIU2RT9nerbPfmSY7tln8YmKhz9tvzWWgISAhrriTJrCLMZc/XQEmzkmt IT+g== X-Gm-Message-State: AJIora80yDQfpDoMqxq8g+cRfelWi7cIMw7nnm2hwyZ7Tky95acUqddN fb7Fp9HZ+BUHKGIWFMikUIvYdGlENJU= X-Google-Smtp-Source: AGRyM1u16lUBoplzBu8GCHi9cS2hjzyVBD0W/MTTmnZLEsRa0ZHu7Lra9HyjKG68jkH6tGTn0cUhdQ== X-Received: by 2002:a17:90b:1c82:b0:1dd:1b46:5aa9 with SMTP id oo2-20020a17090b1c8200b001dd1b465aa9mr6160761pjb.158.1655234749682; Tue, 14 Jun 2022 12:25:49 -0700 (PDT) Received: from gnu-tgl-3.localdomain ([172.58.37.78]) by smtp.gmail.com with ESMTPSA id h3-20020a63b003000000b004087f361074sm5011880pgf.43.2022.06.14.12.25.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 12:25:49 -0700 (PDT) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id 16A28C043F; Tue, 14 Jun 2022 12:25:48 -0700 (PDT) From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Subject: [PATCH] i386: Disallow sibcall when calling ifunc functions with PIC register Date: Tue, 14 Jun 2022 12:25:48 -0700 Message-Id: <20220614192548.1929268-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3027.8 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, T_SCC_BODY_TEXT_LINE 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: Tue, 14 Jun 2022 19:25:55 -0000 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