From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 1CCD43858C00 for ; Sun, 23 Jul 2023 23:23:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1CCD43858C00 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36NMnvlu023094 for ; Sun, 23 Jul 2023 23:22:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : content-transfer-encoding : content-type : mime-version; s=corp-2023-03-30; bh=6XmAJ5+FrhLUP+9di3NwuLBpBahvSEBiM4k9Ew0/EhY=; b=vySt+hOl6hC7AEyIYoF7d9tYOIOSFlXsT2QHLaVBg3zPHrF3MFbezunVcFvbe07pGAZj 1iZo/LYkf/EKSmbtF0JGJ0T3+UtOwT22FVTFimcXaa6XT5RGT6/Q0jfOOFEJCFs4VwLz Kupp9R9mxlxVhlqcQRadwYNc2AB56ctRwB74n1GCYrCSm3C7wXsRnIs4gTmb80Y0P1eW HQ4j3oWOxEf/3vtb34PoNHYJoUV/8am+6pja3SM+LD2rrJP93TQ1kbfZekeZcYRpWr1F q8fdLkshCNtZZNsi0DWlTAXt7lJwOfKXOMV0kl1G5+ys9hxBx312+7rybxT6VGhqcEXK iA== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3s06qtsk7j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sun, 23 Jul 2023 23:22:58 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 36NJSjWl029093 for ; Sun, 23 Jul 2023 23:22:57 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2173.outbound.protection.outlook.com [104.47.59.173]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3s05j919u6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sun, 23 Jul 2023 23:22:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SzRWVWU98/YurSW9cjOvmV09QzdUGjKs+bUgzSarAb7DvZ4VSe26GrXct73MpdYg8yb0AHQCrFr64CP1tXaNzuy52ro2Ozc01mSFOdNNMfDzg/t32W43ShVjConlL0CM4o+L5NqLZZ5CK1WiIlIgglghFJHXZaLndenxrd5HrIp81NVLfaXRw6g9lXeTY9SkMg10L0Torq/f6LzZ6uE5wGas+iCmyxX9P091sSyTVFzh1YFtXuXCeoAIvmrE33ml6hk17BA0O3UUdi8CJPO+aVQxPD8rjzPbD+vl/hgjxNLY/UpSTFHuh4nnRrAgCewOwNU9Jjwh5eBsh/bDnXuccw== 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=6XmAJ5+FrhLUP+9di3NwuLBpBahvSEBiM4k9Ew0/EhY=; b=e+Oz3zGHfKZQwmPJ4WsOTh2OBxfPYVuYIso/i/IX4psVif7vaLxyhI+n4nMwFknkZZPZ5AX4YwaboO7JpscxaKOaGcvGP6wWlIhnD49KT8vDsd4wYt6QcXLnYBqNiS8FS0h9D4i02YAouSVYercNWnjRTTMPxxS64prYp7ETzoSHpNxhx7VYMfrEqUj5qAotoflC0ijGp0B4SYBvYFI94K0CYo7Ahtx4m/ro/2EDBk2YQDH6TQIsa3Ul32ozNzDDT5B33Ej/M/5RZBFcXHkQKFTZhMUozrWhmRaLoiBhSN111tuqkCkMsT1/F34hEGv2aMZAhrLYf1e6yJtcNV/kLQ== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6XmAJ5+FrhLUP+9di3NwuLBpBahvSEBiM4k9Ew0/EhY=; b=PhamMWlZ5QhlWU7fPIy75NLumx46MGfi6HpOuLbvigk5Hze9NnAUqCh5/amQEsYGHsJdfNAXaUhO13M3Z36iwo6m0e1wwythnbkJSfy4j1ZXqxkx75r7FXq5mftwt/hV14wS1ZpVrU7IkfU0bV/x5V+5/N4pw48AckXg1TrO/to= Received: from BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) by CH3PR10MB7120.namprd10.prod.outlook.com (2603:10b6:610:127::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.32; Sun, 23 Jul 2023 23:22:55 +0000 Received: from BYAPR10MB2888.namprd10.prod.outlook.com ([fe80::4d0c:9857:9b42:2f6c]) by BYAPR10MB2888.namprd10.prod.outlook.com ([fe80::4d0c:9857:9b42:2f6c%4]) with mapi id 15.20.6609.031; Sun, 23 Jul 2023 23:22:55 +0000 From: "Jose E. Marchesi" To: binutils@sourceware.org Subject: [PATCH] bpf: add support for jal/gotol jump instruction with 32-bit target Date: Mon, 24 Jul 2023 01:22:49 +0200 Message-Id: <20230723232249.15739-1-jose.marchesi@oracle.com> X-Mailer: git-send-email 2.30.2 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: FR2P281CA0165.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:99::7) To BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB2888:EE_|CH3PR10MB7120:EE_ X-MS-Office365-Filtering-Correlation-Id: 0c68debf-0832-407a-9e93-08db8bd3be2c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sPumm5nBU5EgA0+4xLSrM+twYecGoYPl0KHzkH0fkXGWYLsEmltpAArIBO/x/d9wgE+RdPonBftLS30sBAJToSeOErUNWJspeLtxX23w3scHHoWhQROC3+sGw14zmlmDBcsmG2630VvcZ+zR4DBf7nv0VGjfbPLVEjUWoXwT2BNHENAp98IblwUX1kbLY/jH7HBB8mq5L45Y9CEhZwaucrT/r4JKR19m6a/MRtqZq0FDK8pVdm/ipPXy/D0cfxhiZNeGPIujveBK57bq4wzmaBPYhpk5YkF3ifJTjf+qZuqYVAJtPOXRZr889azyofMfEYngC3qawhBRcgCYEHDdWmigOo8bVb/HQz8IDIyYpLdD75Ykj4N8hhF8Hlhlt6MfrYKzzFFECqXhyAWZ/uLyuZwLxWxAW2UEA7v3fcEp7KxU+WV4OXl6HLL6P29E6ijiNDhogFrZDqFJ0QI/Vcm1HJydfkp9pq7p+tGM7my5AJHgkBBoud25DIy0bKUHfdfNKgWVcxaEOqryVBL69BplcI4s6PTR3wpv3JhonuZDZLJsK2PLIqL2jZhL0tjrOF6X 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:(13230028)(346002)(136003)(376002)(396003)(39860400002)(366004)(451199021)(83380400001)(38100700002)(36756003)(86362001)(30864003)(2906002)(478600001)(186003)(6506007)(1076003)(6666004)(6512007)(6486002)(5660300002)(8676002)(8936002)(316002)(41300700001)(66476007)(66946007)(66556008)(6916009)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?jaskPB3FH157NptRcSyQ+pTd7YXDJ3nyOHcIvQGKDCWKVY5hEQbntlOol3cP?= =?us-ascii?Q?3dQeXApn7Q94KSqmmmXV62fNiweqiKJerQBRhthipP1PqSpF2PoFVuAWMpoe?= =?us-ascii?Q?tAtkg6QdopBfuDnzlktxpA96JEd8+Cw166GNyfvhU/wv/rGWpwJqE5XutNTW?= =?us-ascii?Q?q+aUpseg7lv67J6q0wGoV5GaXAFxANuyNs8i2iyxfOWv0dHqsO1oVSmi8One?= =?us-ascii?Q?sxlWP1N6Yhx8QOndN9d11HQM1fwNSstwXmWwj/cxgqCBLgwecHDn+GsVisQf?= =?us-ascii?Q?zG+f/6aiqtC16CW3F4QZYos7pjjEIZoPc1ozXOjW3uj/rkFB5ZNOMspLjpD1?= =?us-ascii?Q?E38uEXeJbxkgi9aiXjytZXl3LyDAnb+upsvZky48jt6yBZzKhrpG1XFrpC6l?= =?us-ascii?Q?4JDFR0Zcj9b0sN8eYylM04MDKjmfite8cbXhOGaE9fHMp9sTeu5zi0y9SKwE?= =?us-ascii?Q?VAFRhl9Pg+ct8Ct958fd7LrVgCgea7CsqcC8d4oSSdenKA1IIoOt55lrjLjK?= =?us-ascii?Q?sox9KDpwo3FXTkfyNOJHx1HUR0Rhi/C8FHsCDK8xNcb5bvXyLrhMmluoOtMC?= =?us-ascii?Q?/wwgBYh8PfhuF9r/hOkfsPhlsyNMkei+C5KOs28ojiRXz0p0r9iOaS7GjO0X?= =?us-ascii?Q?YkIYCVB7pVLE4MtOoF3n3uyjZNynChuSvMmcXVV+h0z98dQ9wM1mLXr7by4h?= =?us-ascii?Q?/HK1stB9e1Ar9z2GCmcLwMIY/TqyMN1eycbGGVs/NoCLxNsCOtlPTRu1JZkq?= =?us-ascii?Q?8Cguk4NjDjS+KnpFQ3awqVtYI066jfCq4SjQWTdgRzrXYUjn41GDq01geECM?= =?us-ascii?Q?glD7Cm5vTIq8Llt6k2g+xzBiaHo6cqIrgcY+8nHW88g7My9jGCijdORpv+RK?= =?us-ascii?Q?Y0QAJe6YA2NCeHq2MQ/mLOwd93JNvU2Xx1UBA7Jl1GeQgkuuZzDxf26Bh91F?= =?us-ascii?Q?qO9iOV/eqyZtHi9+GeV9cJRXItFpVmQ0EwczuE5lfM1V7kBynsWYd8wOAx4v?= =?us-ascii?Q?OrJ2e83Riw6h00+4fAqpTj8vgvjybQmWAzpH5lWgs5w7h3xcSiUrNYXh2PN4?= =?us-ascii?Q?nrm5bqQP9FSkc4yZGPTIIoiBAYoj37hCVQHbFWzEGEuX6YoiXXivrNo5z8+E?= =?us-ascii?Q?8psoLlQouNdNdIwUcQeJPlaBwqqywctFMkuHYsPm/G7aHwjwNISW5zm+Paj+?= =?us-ascii?Q?9157G/OrqPGWVymR5HNM9ny/RVDp94Jw9tyxtFx65smQzwhgYwCkutqox8sz?= =?us-ascii?Q?Da9hpmy1UK0xqqVyB05LgnC2KzHGs5TjrEU+0BptvU2znbQlKkl7Nz+cn0Vk?= =?us-ascii?Q?VX34cMqFdYi5PBfAMvcYkNSGLBpFLuokXdZVuv6AaJ1i9Nt3BAFvPsyupSox?= =?us-ascii?Q?PRXO8zxQfvhKjDTEJgJugUJl/6nQaDNcp7De/+UTJLc8oGTwxm3VLCMtCyLp?= =?us-ascii?Q?3vCGmYISb1TJn4sJDIDV7wVOdEERTaS/k+iql9prhfA8qZImbs0ujAPLhZvp?= =?us-ascii?Q?nUR300WX0IiN9fiCcAuy0CKgA8+vqqHrnMNc9WSIgh3nL5115DRCQwLlDNNk?= =?us-ascii?Q?RlMIOgXhYAGny0ssmMUtVG5omgTBvvLs3O+Gvw7DSlSa8FcoKU+iqtn+ED72?= =?us-ascii?Q?sWHXBtamerTFKuV2ljEH7Zk+cVFhBbDbVALgyH9O1ZdqrF7fssJ2vh9xyTvg?= =?us-ascii?Q?szD+mg=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: uLfp5vfWuwGMBv9UZZRaWUBNl4mTTlNPy7672tDZDVrkqyfwt52w6nmp9HsQ9bGQwW4JpVhFSEEljH88mKxr+uOaA1sFmWErhOGH3NER8sE0BImIRRf14oRi8ZLwJwM/l4nHevQPuGME1/M/sph4VVgXM5gwu+rtKD37uMTtzLtQnz3opnWpXThzu/KBYiFjY/Eiddq6TBVQSJ8nm3D7MAPRF6mWmBTE6QUk4kmocjRFXnA9piBsLaodIcsxR1l9yhZ6M8griNP5SHNNEM1iLu0mLIEIx8bShntM95Djh75dTYUFnJYKHHRw37erra+K5hL5IDJnTBZdDq1+jcXhknLsEEuXJopwOA/OuUy21lCsQdrtLUyfTdKll5LhAKIi0lw9HRNTi+hi52elOh9v+rVG0U4b2Rp6cgKip4wFKZ72ogo1yUJU31jnaUh+63Ecsn2ChASq2yCTYhk0swknwc5/KnPDdxzocyNAoan0w9vTEAZrP9tFwv+kNpViwFviFnvEm65aB/g/+B1+TnbDgmX3q0rNl4Q27twyh+cS+MMmV6LyiiRS9rV2L/d4NOCFVXssNgJzeV5Q40wYgtBjKfc0YI2enY99wo+LkebN+urzKCZb7zr/kGGJJxxv62RkgdzsyKHW5prRs/bxQKihB3iQDeOaaAJAjLiEse2I9Z171HPoqqKXhQdwZHpXHwAgaQPAFtGjYdYA8PjqWBnL9UpWou+RQMHxWg2fW7OMeDZC3IP8B6DjbVecQoEdKd7Ie/q8oNy4aL1KrHjGpk2rQg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0c68debf-0832-407a-9e93-08db8bd3be2c X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2888.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jul 2023 23:22:55.2390 (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: vevxHX5X0h06zI2sFKfSfob5ZumnzTzGAPkiKUiuTiGJC7kO2gSGgDUqyPQhnjJpAYnDDjsDk/E57n5WhqVFenJjuCgZiKc06LdDcPH+3gI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR10MB7120 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-23_10,2023-07-20_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 adultscore=0 suspectscore=0 phishscore=0 malwarescore=0 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307230220 X-Proofpoint-ORIG-GUID: xZK0oeyfX6_Q2dhBDi6oPfjr6jHBdOSV X-Proofpoint-GUID: xZK0oeyfX6_Q2dhBDi6oPfjr6jHBdOSV X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 List-Id: This patch adds support for the V4 BPF instruction jal/gotol, which is like ja/goto but it supports a signed 32-bit PC-relative (in number of 64-bit words minus one) target operand instead of the 16-bit signed operand of the other instruction. This greatly increases the jump range in BPF programs. Tested in bpf-unkown-none. bfd/ChangeLog: 2023-07-24 Jose E. Marchesi * reloc.c: New reloc BFD_RELOC_BPF_DISPCALL32. * elf64-bpf.c (bpf_reloc_type_lookup): Handle the new reloc. * libbfd.h (bfd_reloc_code_real_names): Regenerate. gas/ChangeLog: 2023-07-24 Jose E. Marchesi * config/tc-bpf.c (struct bpf_insn): New field `id'. (md_assemble): Save the ids of successfully parsed instructions and use the new BFD_RELOC_BPF_DISPCALL32 whenever appropriate. (md_apply_fix): Adapt to the new BFD reloc. * testsuite/gas/bpf/jump.s: Test JAL. * testsuite/gas/bpf/jump.d: Likewise. * testsuite/gas/bpf/jump-pseudoc.d: Likewise. * testsuite/gas/bpf/jump-be.d: Likewise. * testsuite/gas/bpf/jump-be-pseudoc.d: Likewise. * doc/c-bpf.texi (BPF Instructions): Document new instruction jal/gotol. Document new operand type disp32. include/ChangeLog: 2023-07-24 Jose E. Marchesi * opcode/bpf.h (enum bpf_insn_id): Add entry BPF_INSN_JAL. (enum bpf_insn_id): Remove spurious entry BPF_INSN_CALLI. opcodes/ChangeLog: 2023-07-23 Jose E. Marchesi * bpf-opc.c (bpf_opcodes): Add entry for jal. --- bfd/ChangeLog | 6 +++ bfd/bfd-in2.h | 1 + bfd/elf64-bpf.c | 1 + bfd/libbfd.h | 1 + bfd/reloc.c | 2 + gas/ChangeLog | 15 +++++++ gas/config/tc-bpf.c | 56 +++++++++++++++---------- gas/doc/c-bpf.texi | 7 ++++ gas/testsuite/gas/bpf/jump-be-pseudoc.d | 2 + gas/testsuite/gas/bpf/jump-be.d | 2 + gas/testsuite/gas/bpf/jump-pseudoc.d | 2 + gas/testsuite/gas/bpf/jump-pseudoc.s | 2 + gas/testsuite/gas/bpf/jump.d | 2 + gas/testsuite/gas/bpf/jump.s | 4 +- include/ChangeLog | 5 +++ include/opcode/bpf.h | 3 +- opcodes/ChangeLog | 4 ++ opcodes/bpf-opc.c | 4 ++ 18 files changed, 95 insertions(+), 24 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 553dea5d0b0..db032df5ac2 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2023-07-24 Jose E. Marchesi + + * reloc.c: New reloc BFD_RELOC_BPF_DISPCALL32. + * elf64-bpf.c (bpf_reloc_type_lookup): Handle the new reloc. + * libbfd.h (bfd_reloc_code_real_names): Regenerate. + 2023-07-09 Fangrui Song PR 30592 diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index ba7440c2768..5f49807d7f2 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -7148,6 +7148,7 @@ assembler and not (currently) written to any object files. */ /* Linux eBPF relocations. */ BFD_RELOC_BPF_64, BFD_RELOC_BPF_DISP32, + BFD_RELOC_BPF_DISPCALL32, BFD_RELOC_BPF_DISP16, /* Adapteva EPIPHANY - 8 bit signed pc-relative displacement */ diff --git a/bfd/elf64-bpf.c b/bfd/elf64-bpf.c index 23ede4e5d96..aefad7da5ac 100644 --- a/bfd/elf64-bpf.c +++ b/bfd/elf64-bpf.c @@ -88,6 +88,7 @@ bpf_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, case BFD_RELOC_BPF_64: return &bpf_elf_howto_table[ (int) R_BPF_64_64_IDX]; case BFD_RELOC_BPF_DISP32: + case BFD_RELOC_BPF_DISPCALL32: return &bpf_elf_howto_table[ (int) R_BPF_64_32_IDX]; case BFD_RELOC_BPF_DISP16: return &bpf_elf_howto_table[ (int) R_BPF_GNU_64_16_IDX]; diff --git a/bfd/libbfd.h b/bfd/libbfd.h index 5dbb0871607..1fc88a88861 100644 --- a/bfd/libbfd.h +++ b/bfd/libbfd.h @@ -3346,6 +3346,7 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@", "BFD_RELOC_TILEGX_IMM8_Y1_TLS_ADD", "BFD_RELOC_BPF_64", "BFD_RELOC_BPF_DISP32", + "BFD_RELOC_BPF_DISPCALL32", "BFD_RELOC_BPF_DISP16", "BFD_RELOC_EPIPHANY_SIMM8", "BFD_RELOC_EPIPHANY_SIMM24", diff --git a/bfd/reloc.c b/bfd/reloc.c index e71a510e26c..07d35e45c8b 100644 --- a/bfd/reloc.c +++ b/bfd/reloc.c @@ -7753,6 +7753,8 @@ ENUM BFD_RELOC_BPF_64 ENUMX BFD_RELOC_BPF_DISP32 +ENUMX + BFD_RELOC_BPF_DISPCALL32 ENUMX BFD_RELOC_BPF_DISP16 ENUMDOC diff --git a/gas/ChangeLog b/gas/ChangeLog index f91c04572ec..b45fd9fa8bd 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,18 @@ +2023-07-24 Jose E. Marchesi + + * config/tc-bpf.c (struct bpf_insn): New field `id'. + (md_assemble): Save the ids of successfully parsed instructions + and use the new BFD_RELOC_BPF_DISPCALL32 whenever appropriate. + (md_apply_fix): Adapt to the new BFD reloc. + * testsuite/gas/bpf/jump.s: Test JAL. + * testsuite/gas/bpf/jump.d: Likewise. + * testsuite/gas/bpf/jump-pseudoc.d: Likewise. + * testsuite/gas/bpf/jump-be.d: Likewise. + * testsuite/gas/bpf/jump-be-pseudoc.d: Likewise. + * doc/c-bpf.texi (BPF Instructions): Document new instruction + jal/gotol. + Document new operand type disp32. + 2023-07-21 Jose E. Marchesi * testsuite/gas/bpf/mem.s: Add signed load instructions. diff --git a/gas/config/tc-bpf.c b/gas/config/tc-bpf.c index 7a54faccb59..c56b8fe984f 100644 --- a/gas/config/tc-bpf.c +++ b/gas/config/tc-bpf.c @@ -33,6 +33,7 @@ struct bpf_insn { + enum bpf_insn_id id; int size; /* Instruction size in bytes. */ bpf_insn_word opcode; uint8_t dst; @@ -375,30 +376,35 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED) minus one. */ *valP = (((long) (*valP)) - 8) / 8; break; + case BFD_RELOC_BPF_DISPCALL32: case BFD_RELOC_BPF_DISP32: - /* eBPF supports two kind of CALL instructions: the so called - pseudo calls ("bpf to bpf") and external calls ("bpf to - kernel"). - - Both kind of calls use the same instruction (CALL). However, - external calls are constructed by passing a constant argument - to the instruction, whereas pseudo calls result from - expressions involving symbols. In practice, instructions - requiring a fixup are interpreted as pseudo-calls. If we are - executing this code, this is a pseudo call. - - The kernel expects for pseudo-calls to be annotated by having - BPF_PSEUDO_CALL in the SRC field of the instruction. But - beware the infamous nibble-swapping of eBPF and take - endianness into account here. - - Note that the CALL instruction has only one operand, so - this code is executed only once per instruction. */ - md_number_to_chars (where + 1, target_big_endian ? 0x01 : 0x10, 1); - /* Convert from bytes to number of 64-bit words to the target, minus one. */ *valP = (((long) (*valP)) - 8) / 8; + + if (fixP->fx_r_type == BFD_RELOC_BPF_DISPCALL32) + { + /* eBPF supports two kind of CALL instructions: the so + called pseudo calls ("bpf to bpf") and external calls + ("bpf to kernel"). + + Both kind of calls use the same instruction (CALL). + However, external calls are constructed by passing a + constant argument to the instruction, whereas pseudo + calls result from expressions involving symbols. In + practice, instructions requiring a fixup are interpreted + as pseudo-calls. If we are executing this code, this is + a pseudo call. + + The kernel expects for pseudo-calls to be annotated by + having BPF_PSEUDO_CALL in the SRC field of the + instruction. But beware the infamous nibble-swapping of + eBPF and take endianness into account here. + + Note that the CALL instruction has only one operand, so + this code is executed only once per instruction. */ + md_number_to_chars (where + 1, target_big_endian ? 0x01 : 0x10, 1); + } break; case BFD_RELOC_16_PCREL: /* Convert from bytes to number of 64-bit words to the target, @@ -434,6 +440,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED) md_number_to_chars (where + 2, (uint16_t) *valP, 2); break; case BFD_RELOC_BPF_DISP32: + case BFD_RELOC_BPF_DISPCALL32: md_number_to_chars (where + 4, (uint32_t) *valP, 4); break; case BFD_RELOC_16_PCREL: @@ -852,6 +859,7 @@ md_assemble (char *str ATTRIBUTE_UNUSED) return; } + insn.id = opcode->id; insn.opcode = opcode->opcode; #undef PARSE_ERROR @@ -1044,8 +1052,12 @@ md_assemble (char *str ATTRIBUTE_UNUSED) { reloc_howto_type *reloc_howto; int size; + unsigned int bfd_reloc + = (insn.id == BPF_INSN_CALL + ? BFD_RELOC_BPF_DISPCALL32 + : BFD_RELOC_BPF_DISP32); - reloc_howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_BPF_DISP32); + reloc_howto = bfd_reloc_type_lookup (stdoutput, bfd_reloc); if (!reloc_howto) abort (); @@ -1053,7 +1065,7 @@ md_assemble (char *str ATTRIBUTE_UNUSED) fix_new_exp (frag_now, this_frag - frag_now->fr_literal, size, &insn.disp32, reloc_howto->pc_relative, - BFD_RELOC_BPF_DISP32); + bfd_reloc); break; } default: diff --git a/gas/doc/c-bpf.texi b/gas/doc/c-bpf.texi index bebf760f91f..d4fd1819dbe 100644 --- a/gas/doc/c-bpf.texi +++ b/gas/doc/c-bpf.texi @@ -160,6 +160,9 @@ Signed 16-bit immediate representing an offset in bytes. @item disp16 Signed 16-bit immediate representing a displacement to a target, measured in number of 64-bit words @emph{minus one}. +@item disp32 +Signed 32-bit immediate representing a displacement to a target, +measured in number of 64-bit words @emph{minus one}. @item imm32 Signed 32-bit immediate. @item imm64 @@ -555,6 +558,10 @@ holds true. @itemx goto disp16 Jump-always. +@item jal disp32 +@itemx gotol disp32 +Jump-always, long range. + @item jeq rd, rs, disp16 @itemx jeq rd, imm32, disp16 @itemx if rd == rs goto disp16 diff --git a/gas/testsuite/gas/bpf/jump-be-pseudoc.d b/gas/testsuite/gas/bpf/jump-be-pseudoc.d index 3874d58f73a..827731182c1 100644 --- a/gas/testsuite/gas/bpf/jump-be-pseudoc.d +++ b/gas/testsuite/gas/bpf/jump-be-pseudoc.d @@ -30,3 +30,5 @@ Disassembly of section .text: 98: cd 34 00 00 00 00 00 00 if r3s + + * opcode/bpf.h (enum bpf_insn_id): Add entry BPF_INSN_JAL. + (enum bpf_insn_id): Remove spurious entry BPF_INSN_CALLI. + 2023-07-21 Jose E. Marchesi * opcode/bpf.h (enum bpf_insn_id): Add entries for signed load diff --git a/include/opcode/bpf.h b/include/opcode/bpf.h index a491df6fbdf..dc1b6e7ae57 100644 --- a/include/opcode/bpf.h +++ b/include/opcode/bpf.h @@ -201,7 +201,8 @@ enum bpf_insn_id BPF_INSN_JEQI, BPF_INSN_JGTI, BPF_INSN_JSGTI, BPF_INSN_JGEI, BPF_INSN_JSGEI, BPF_INSN_JLTI, BPF_INSN_JSLTI, BPF_INSN_JSLEI, BPF_INSN_JLEI, BPF_INSN_JSETI, BPF_INSN_JNEI, - BPF_INSN_CALLI, + /* jump-always with 32-bit offset. */ + BPF_INSN_JAL, /* 32-bit compare-and-jump instructions (reg OP reg.) */ BPF_INSN_JEQ32R, BPF_INSN_JGT32R, BPF_INSN_JSGT32R, BPF_INSN_JGE32R, BPF_INSN_JSGE32R, BPF_INSN_JLT32R, BPF_INSN_JSLT32R, diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog index f88e9c846fb..d97eb389c9f 100644 --- a/opcodes/ChangeLog +++ b/opcodes/ChangeLog @@ -1,3 +1,7 @@ +2023-07-23 Jose E. Marchesi + + * bpf-opc.c (bpf_opcodes): Add entry for jal. + 2023-07-21 Jose E. Marchesi * bpf-opc.c (bpf_opcodes): Add entries for LDXS{B,W,H,DW} diff --git a/opcodes/bpf-opc.c b/opcodes/bpf-opc.c index efd32577821..4ffd86719a7 100644 --- a/opcodes/bpf-opc.c +++ b/opcodes/bpf-opc.c @@ -303,6 +303,10 @@ const struct bpf_opcode bpf_opcodes[] = {BPF_INSN_JNEI, "jne%W%dr , %i32 , %d16", "if%w%dr != %i32%wgoto%w%d16", BPF_V1, BPF_CODE, BPF_CLASS_JMP|BPF_CODE_JNE|BPF_SRC_K}, + /* 32-bit jump-always. */ + {BPF_INSN_JAL, "jal%W%d32", "gotol%w%d32", + BPF_V4, BPF_CODE, BPF_CLASS_JMP32|BPF_CODE_JA|BPF_SRC_K}, + /* 32-bit compare-and-jump instructions (reg OP reg). */ {BPF_INSN_JEQ32R, "jeq32%W%dr , %sr , %d16", "if%w%dw == %sw%wgoto%w%d16", BPF_V3, BPF_CODE, BPF_CLASS_JMP32|BPF_CODE_JEQ|BPF_SRC_X}, -- 2.30.2