From patchwork Thu Sep 3 16:37:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 1356754 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Uo7Z3xBC; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bj62D3TSjz9sR4 for ; Fri, 4 Sep 2020 02:38:43 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0E5033986439; Thu, 3 Sep 2020 16:38:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0E5033986439 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1599151120; bh=NNG/MAIce2KtWRw129gjHI7NAQGmxjB5pXd+eqcOprw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Uo7Z3xBCZz+BYo9yBvSkLVXNNHlDzvz1GXOAcsMCfa7oe8IOMHIG8qQfMuLdRexvX CeqD6Zob4hADQRZpicYjHlgFgOfSg4f1Wlwmd2LKaN3OQjLQWo3w2nJvZCPbQvrq4L aWyVBE+/lS2mm4d9QzKS3XuJZrJxFCC1nw4NTHJA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by sourceware.org (Postfix) with ESMTPS id 9353F398643A for ; Thu, 3 Sep 2020 16:38:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9353F398643A Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 083GYC9f095141 for ; Thu, 3 Sep 2020 16:38:36 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 337eymhtsq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 03 Sep 2020 16:38:36 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 083Gar8U049726 for ; Thu, 3 Sep 2020 16:38:36 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 3380xaek4v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 03 Sep 2020 16:38:36 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 083GcU9r005953 for ; Thu, 3 Sep 2020 16:38:35 GMT Received: from sequence.us.oracle.com (/10.159.232.2) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 03 Sep 2020 09:38:29 -0700 To: gcc-patches@gcc.gnu.org Subject: [PATCH] bpf: generate indirect calls for xBPF Date: Thu, 3 Sep 2020 09:37:44 -0700 Message-Id: <20200903163744.25641-1-david.faust@oracle.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9733 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 spamscore=0 phishscore=0 mlxlogscore=999 adultscore=0 suspectscore=1 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030155 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9733 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 adultscore=0 priorityscore=1501 phishscore=0 mlxlogscore=999 mlxscore=0 lowpriorityscore=0 clxscore=1011 spamscore=0 bulkscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009030155 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: David Faust via Gcc-patches From: David Faust Reply-To: David Faust Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This patch updates the BPF back end to generate indirect calls via the 'call %reg' instruction when targetting xBPF. Additionally, the BPF ASM_SPEC is updated to pass along -mxbpf to gas, where it is now supported. 2020-09-03 David Faust gcc/ * config/bpf/bpf.h (ASM_SPEC): Pass -mxbpf to gas, if specified. * config/bpf/bpf.c (bpf_output_call): Support indirect calls in xBPF. gcc/testsuite/ * gcc.target/bpf/xbpf-indirect-call-1.c: New test. --- gcc/config/bpf/bpf.c | 9 ++++++-- gcc/config/bpf/bpf.h | 2 +- .../gcc.target/bpf/xbpf-indirect-call-1.c | 21 +++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.target/bpf/xbpf-indirect-call-1.c diff --git a/gcc/config/bpf/bpf.c b/gcc/config/bpf/bpf.c index 972a91adcd8..13181f21c5b 100644 --- a/gcc/config/bpf/bpf.c +++ b/gcc/config/bpf/bpf.c @@ -705,8 +705,13 @@ bpf_output_call (rtx target) break; } default: - error ("indirect call in function, which are not supported by eBPF"); - output_asm_insn ("call 0", NULL); + if (TARGET_XBPF) + output_asm_insn ("call\t%0", &target); + else + { + error ("indirect call in function, which are not supported by eBPF"); + output_asm_insn ("call 0", NULL); + } break; } diff --git a/gcc/config/bpf/bpf.h b/gcc/config/bpf/bpf.h index 940029ba606..359f389a134 100644 --- a/gcc/config/bpf/bpf.h +++ b/gcc/config/bpf/bpf.h @@ -22,7 +22,7 @@ /**** Controlling the Compilation Driver. */ -#define ASM_SPEC "%{mbig-endian:-EB} %{!mbig-endian:-EL}" +#define ASM_SPEC "%{mbig-endian:-EB} %{!mbig-endian:-EL} %{mxbpf:-mxbpf}" #define LINK_SPEC "%{mbig-endian:-EB} %{!mbig-endian:-EL}" #define LIB_SPEC "" #define STARTFILE_SPEC "" diff --git a/gcc/testsuite/gcc.target/bpf/xbpf-indirect-call-1.c b/gcc/testsuite/gcc.target/bpf/xbpf-indirect-call-1.c new file mode 100644 index 00000000000..dc4b3cfb12d --- /dev/null +++ b/gcc/testsuite/gcc.target/bpf/xbpf-indirect-call-1.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-mxbpf" } */ + +/* GCC should generate an indirect call instruction (call %REG) + when targetting xBPF. */ + +void +foo () +{ + ; +} + +void +bar() +{ + void (*funp) () = &foo; + + (*funp) (); +} + +/* { dg-final { scan-assembler "call\t%r" } } */