From patchwork Fri Aug 18 13:53:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jose E. Marchesi" X-Patchwork-Id: 136019 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp1417154vqi; Fri, 18 Aug 2023 06:54:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEhlJZtW7thlNTgwoPxOxZT67sFSxTWIE2xBBjs7sfNY1F513AyLfEdpo82u9MKqvY8tilV X-Received: by 2002:a05:6512:3f08:b0:4fb:9fa7:dcda with SMTP id y8-20020a0565123f0800b004fb9fa7dcdamr2046001lfa.26.1692366895491; Fri, 18 Aug 2023 06:54:55 -0700 (PDT) Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id a13-20020a17090682cd00b00993211b85acsi1384725ejy.216.2023.08.18.06.54.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Aug 2023 06:54:55 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=c61PceKM; arc=fail (signature failed); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 10D32386480A for ; Fri, 18 Aug 2023 13:54:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 10D32386480A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692366894; bh=y3UCPOseNSDavbIQHMnNuuahLyBPktGnyLbZ8itJtlw=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=c61PceKMqtTqR5aCxaV8klxSdN1V8aa+U1v6O1fFYtRFD1aqT9qIZCA8dYtFe2Tbq Xssc+AAQtr1yURlzLkcfspRR83v2/wxZVvZbsgqeiXNWMKGvvE4Wl6dZNhjI8HEeJk KJyrF5Cv4y9x3iPhW7NSNzDHpURjtXOUzZThYsug= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 1B85D3858401 for ; Fri, 18 Aug 2023 13:54:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1B85D3858401 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37IC8gSL014917; Fri, 18 Aug 2023 13:54:07 GMT Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3se2xwv181-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Aug 2023 13:54:06 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 37IDmXNW027346; Fri, 18 Aug 2023 13:54:06 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1nam02lp2049.outbound.protection.outlook.com [104.47.57.49]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3sey1w5vj9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 18 Aug 2023 13:54:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kvhqAmMBejhY10t2rpsx/xAmqytLJ8eRHWiLRkRkJfcJBZa2PFD1OjvgMEBY7Vs/GQJlZB7PA+ZJ/XyhG49e3bH4O+/Db6NyN3Cz9Y9lCJNDfkl1SLJdGiP4TGuytvf1wKa4A8hCbeWstbzqKHlu+OdvV47onzMS/6K+6Pc60qIsAj7KzJq8NpjqGi7NDGRFNQatWBSGVp3vax96bXlIBJrDFN3XryF9Ki5FI2yzg4sk0y+ppPeXR3vpqut5kDJVwl3zc69ZKc9+A9OAhzoHr7CF8AuOLXapC+R/NZYlRZwGEcX/AedM92NflYinoaDv5i7eKGX3H/Q0x4XTb0ODXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=y3UCPOseNSDavbIQHMnNuuahLyBPktGnyLbZ8itJtlw=; b=JCiBAeoGTXdixxoNgAodYr8sjBJulNsa9vhQkXJNjZ99AX5Bukt073DWMnuZWkzyhdXLJ3hCBUhZ3pi6pO8w1BaYodtl2TAtdB3KnUXXlLa4NS1rsskPR/0y45Tf0Y75XV+3c2b3CFBeMGv9pmsKD5eE4w+1d8Cp8iX5+foYwc/FtBijNc0sJIUPoxseHQnH76Vc0xDfiQCclY1EhQyJ5H239CwJR+qWkjnsO2oXdcqAMj/4UwWHpduV4M2lFyst4jf0ZN3GB7MWflrkTYGx7kvzFBCVPCLt5AnBjrPxoAVM4aJrexV9fMYg3vOwTHREDnCTWjLD7pZORuFdeUbD+g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none Received: from BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) by CH0PR10MB4953.namprd10.prod.outlook.com (2603:10b6:610:de::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.20; Fri, 18 Aug 2023 13:53:58 +0000 Received: from BYAPR10MB2888.namprd10.prod.outlook.com ([fe80::7d31:72cf:ebed:894f]) by BYAPR10MB2888.namprd10.prod.outlook.com ([fe80::7d31:72cf:ebed:894f%5]) with mapi id 15.20.6678.029; Fri, 18 Aug 2023 13:53:58 +0000 To: gcc-patches@gcc.gnu.org Cc: Jakub Jelinek Subject: [PATCH] Emit funcall external declarations only if actually used. Date: Fri, 18 Aug 2023 15:53:51 +0200 Message-Id: <20230818135351.9177-1-jose.marchesi@oracle.com> X-Mailer: git-send-email 2.30.2 X-ClientProxiedBy: LO2P265CA0046.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:61::34) To BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB2888:EE_|CH0PR10MB4953:EE_ X-MS-Office365-Filtering-Correlation-Id: 5a703570-2bf9-4d0f-105b-08db9ff2918f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /f+2pqdazDwtcQUiUng743g/WyLFfmtWbqUbjle7FA5/MqyxATdI8lGhZOoztW6H4aEhUdX/aWLZSCoYMpPonD5AApWWYce00SgXACZMyeGkNftp9BkuX5w8MZxPP5V/Qwopk5l/IWfi5fobGIUH7Fd6yfXFueKtvMw8oL7I9VpW4zbTYSNZnlEMkEN3G0UltLr8yIC2sshW8hRVicSuz4BnVYayT953ThyrvM3Sh8ViCfrvIgEBPlAzcKdrPmz/2Dr927phVN1XljdYKQjE84A741alQsa5umitDFUUnOJZ5YioPE5Csu9qlqqTCa77BKbvqCL2v1LFPFmC2/ZMB5F7pNj6HUzm8lCdan2Md57cB4hJQ2FlgNq/BY7b1OpUzAJ/XWlCtsxPliocMvbk+LzEvxs7W1kwqF2QKDDBY4P3nvqFPPlY29mMK+m7CU383jC7tepM37mzefqyzBDocXYggRArLopBg5b6gwuzCQLaVTyAlcKqD6bn1T51qtdHgPdTUp6WtJwWnzhoodonsMHyaDDD4E/Ja45wi4mXkuk= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2888.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(346002)(136003)(39860400002)(366004)(376002)(396003)(186009)(1800799009)(451199024)(6666004)(6486002)(6506007)(38100700002)(6512007)(86362001)(1076003)(26005)(83380400001)(36756003)(2616005)(2906002)(66946007)(66476007)(66556008)(316002)(6916009)(84970400001)(41300700001)(5660300002)(8676002)(4326008)(8936002)(478600001)(966005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QrxI++ITNZ+wfqpp38+2rna/ljvlAX5LaPPZn3T/wStoIoldRwAVVsQYvwfLdfyb+mN4ajNNJAAEF0PRFcIdCwfF45Mjuawt+Et4oXsXFW4p4VU2GLy8Q3/WJf2wYMMkMbZ07ObwmPb7MimfDnuvMuinfgs8+qdAAoEiZ+SXmFeUaWLQgsqp9gTalgDQpgKNixqgU+YEi6qehfZmkwHnRWiTwZKyF6vW/359X9t/o/is8EccuMcf1o+U8GMRnZTqx/H4UXEaKMhOUNP6ZxwAttK8+ROfcB1GiqoiDYi5lrVFykR0MoT1p6er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87gCdv4Zbs3g== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5a703570-2bf9-4d0f-105b-08db9ff2918f X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2888.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Aug 2023 13:53:57.8652 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: mt3jnvdcqBo7LAbRqWpwNRWast5/niHo3bw80UdFP/ZtHkCrKr7qda1kaWr4QrLLe/nvmBkziS1AVEexwW49NrocEKwARqUSPjREvlP2r8s= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR10MB4953 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-18_17,2023-08-18_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2308180128 X-Proofpoint-ORIG-GUID: CxjH9ax_rmrXBgaTln2YYtNA6avFS-is X-Proofpoint-GUID: CxjH9ax_rmrXBgaTln2YYtNA6avFS-is X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, KAM_STOCKGEN, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, URIBL_BLACK 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-Patchwork-Original-From: "Jose E. Marchesi via Gcc-patches" From: "Jose E. Marchesi" Reply-To: "Jose E. Marchesi" Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774575309744623325 X-GMAIL-MSGID: 1774575309744623325 [Previous thread: https://gcc.gnu.org/pipermail/gcc-patches/2022-December/608162.html] There are many places in GCC where alternative local sequences are tried in order to determine what is the cheapest or best alternative to use in the current target. When any of these sequences involve a libcall, the current implementation of emit_library_call_value_1 introduce a side-effect consisting on emitting an external declaration for the funcall (such as __divdi3) which is thus emitted even if the sequence that does the libcall is not retained. This is problematic in targets such as BPF, because the kernel loader chokes on the spurious symbol __divdi3 and makes the resulting BPF object unloadable. Note that BPF objects are not linked before being loaded. This patch changes emit_library_call_value_1 to mark the target SYMBOL_REF as a libcall. Then, the emission of the external declaration is done in the first loop of final.cc:shorten_branches. This happens only if the corresponding sequence has been kept. Regtested in x86_64-linux-gnu. Tested with host x86_64-linux-gnu with target bpf-unknown-none. gcc/ChangeLog * rtl.h: New flag is_libcall. (SYMBOL_REF_LIBCALL): Define. * calls.cc (emit_library_call_value_1): Do not emit external libcall declaration here. * final.cc (shorten_branches): Do it here. gcc/testsuite/ChangeLog * gcc.target/bpf/divmod-libcall-1.c: New test. * gcc.target/bpf/divmod-libcall-2.c: Likewise. --- gcc/calls.cc | 7 ++++--- gcc/final.cc | 16 ++++++++++++++++ gcc/rtl.h | 6 ++++++ .../gcc.target/bpf/divmod-libcall-1.c | 19 +++++++++++++++++++ .../gcc.target/bpf/divmod-libcall-2.c | 16 ++++++++++++++++ 5 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.target/bpf/divmod-libcall-1.c create mode 100644 gcc/testsuite/gcc.target/bpf/divmod-libcall-2.c diff --git a/gcc/calls.cc b/gcc/calls.cc index 1f3a6d5c450..e0ddda42442 100644 --- a/gcc/calls.cc +++ b/gcc/calls.cc @@ -4388,9 +4388,10 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value, || argvec[i].partial != 0) update_stack_alignment_for_call (&argvec[i].locate); - /* If this machine requires an external definition for library - functions, write one out. */ - assemble_external_libcall (fun); + /* Mark the emitted target as a libcall. This will be used by final + in order to emit an external symbol declaration if the libcall is + ever used. */ + SYMBOL_REF_LIBCALL (fun) = 1; original_args_size = args_size; args_size.constant = (aligned_upper_bound (args_size.constant diff --git a/gcc/final.cc b/gcc/final.cc index dd3e22547ac..80c112b91f7 100644 --- a/gcc/final.cc +++ b/gcc/final.cc @@ -815,6 +815,8 @@ make_pass_compute_alignments (gcc::context *ctxt) reorg.cc, since the branch splitting exposes new instructions with delay slots. */ +static rtx call_from_call_insn (rtx_call_insn *insn); + void shorten_branches (rtx_insn *first) { @@ -850,6 +852,20 @@ shorten_branches (rtx_insn *first) for (insn = get_insns (), i = 1; insn; insn = NEXT_INSN (insn)) { INSN_SHUID (insn) = i++; + + /* If this is a `call' instruction implementing a libcall, + and this machine requires an external definition for library + functions, write one out. */ + if (CALL_P (insn)) + { + rtx x = call_from_call_insn (dyn_cast (insn)); + x = XEXP (x, 0); + if (x && MEM_P (x) + && SYMBOL_REF_P (XEXP (x, 0)) + && SYMBOL_REF_LIBCALL (XEXP (x, 0))) + assemble_external_libcall (XEXP (x, 0)); + } + if (INSN_P (insn)) continue; diff --git a/gcc/rtl.h b/gcc/rtl.h index e1c51156f90..945e3267a34 100644 --- a/gcc/rtl.h +++ b/gcc/rtl.h @@ -402,6 +402,8 @@ struct GTY((desc("0"), tag("0"), 1 in a VALUE or DEBUG_EXPR is NO_LOC_P in var-tracking.cc. Dumped as "/i" in RTL dumps. */ unsigned return_val : 1; + /* 1 in a SYMBOL_REF if it is the target of a libcall. */ + unsigned is_libcall : 1; union { /* The final union field is aligned to 64 bits on LP64 hosts, @@ -2734,6 +2736,10 @@ do { \ #define SYMBOL_REF_USED(RTX) \ (RTL_FLAG_CHECK1 ("SYMBOL_REF_USED", (RTX), SYMBOL_REF)->used) +/* 1 if RTX is a symbol_ref that represents a libcall target. */ +#define SYMBOL_REF_LIBCALL(RTX) \ + (RTL_FLAG_CHECK1 ("SYMBOL_REF_LIBCALL", (RTX), SYMBOL_REF)->is_libcall) + /* 1 if RTX is a symbol_ref for a weak symbol. */ #define SYMBOL_REF_WEAK(RTX) \ (RTL_FLAG_CHECK1 ("SYMBOL_REF_WEAK", (RTX), SYMBOL_REF)->return_val) diff --git a/gcc/testsuite/gcc.target/bpf/divmod-libcall-1.c b/gcc/testsuite/gcc.target/bpf/divmod-libcall-1.c new file mode 100644 index 00000000000..f769c7a6deb --- /dev/null +++ b/gcc/testsuite/gcc.target/bpf/divmod-libcall-1.c @@ -0,0 +1,19 @@ +/* This test makes sure that no spurious external symbol declarations are + emitted for libcalls in tried but eventually not used code sequences. */ + +/* { dg-do compile } */ +/* { dg-options "-O2 -mcpu=v3" } */ +/* { dg-final { scan-assembler-not "__divdi3" } } */ +/* { dg-final { scan-assembler-not "__moddi3" } } */ + +int +foo (unsigned int len) +{ + return ((unsigned long)len) * 234 / 5; +} + +int +bar (unsigned int len) +{ + return ((unsigned long)len) * 234 % 5; +} diff --git a/gcc/testsuite/gcc.target/bpf/divmod-libcall-2.c b/gcc/testsuite/gcc.target/bpf/divmod-libcall-2.c new file mode 100644 index 00000000000..c6e86391a7b --- /dev/null +++ b/gcc/testsuite/gcc.target/bpf/divmod-libcall-2.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mcpu=v3" } */ +/* { dg-final { scan-assembler "__divdi3" } } */ +/* { dg-final { scan-assembler "__moddi3" } } */ + +int +foo (unsigned int len) +{ + return ((long)len) * 234 / 5; +} + +int +bar (unsigned int len) +{ + return ((long)len) * 234 % 5; +}