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 BE22F3858D20 for ; Thu, 25 Apr 2024 19:22:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BE22F3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BE22F3858D20 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714072959; cv=pass; b=Kgl41MrVkdnJM54m+/RfDUv02Wln5wVV7JtlpIUJbjxHzTkHjGlz1WEMlbP92J/DBjoc9FOYV47TC1QNfEPEb9sbFQh5Dy8IMl9dkRW6Bz9tgPmHIT40v/zHcksPLZVZ/A8mCPPRqxufFOxe8sjftCbSZGGP+ZkAZMU8L+wL/98= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714072959; c=relaxed/simple; bh=pSkOjLuqYtG3aCDNxcCviDkdSnT/obml0CTcB/uN2Is=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=D70RSItH01teu2OToM9aZdyfx9mmWdq8paD4o7tQ/bzqNIpxpEyqKZ3zBQmmMLVV46L9aiYGhvuxnvILq4b9Sm0fU6KoCfZKk2fhfWXecgnpp+s6KUIwMj1vrbSsPs1Mj+p+QCxpJj/3vOTEDV6QUG1HnS342oafDXWjneA7E2A= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43PHO0og023674 for ; Thu, 25 Apr 2024 19:22:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=uvqjZOrsF2g+D4GrbdZ9p1cmucrGcJJJsyRn2zaYzNA=; b=I+HhoavKdYPZIskjo8rc67PLZyfYUtjF8PO4C6OuV2/wokOZ2FmdlwYsPK9vczBtlp0b tXR15/pp61Byy1OOu0i0HWscmMIhst/+3nklIZ/CmiG2YNb+K4iZxf8KLX/negFdPTc/ UbfHr81bIFgrYyt3/VHH97KRQOS6agHuZ0L8cpUYEZ0m5fw8G+qFyz9hQAyvOvz/Ns8T ZvQXY8fu4IcQ6U00+DrSc9GtlgOI7BzN3PEn5x6ccFgwoZ2Pe9s8uoEA/KOixyR5JCcn Rh5bAYygn/4RFojmXjX04hWz1Ry23RaU0027Kgs+PDgnzVHgM3iPmueasChcg0pZ9ykW pA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xm44f3xac-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 25 Apr 2024 19:22:35 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43PJ3MLw025222 for ; Thu, 25 Apr 2024 19:22:35 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1nam02lp2041.outbound.protection.outlook.com [104.47.57.41]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3xm45h58c7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 25 Apr 2024 19:22:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GGjCcz3xNCOvUKLqkPSIzlueTsJsvgoUVhpKhO0Bjvm3T/S41UrDJOC0JZ4DirZGjC6pYS7IvzR0F+c9+ivqbhfc/JUcfdwU4t6zTvUw8Wc5bEat0cWqvDX1YGNPUlnl+bau0WMvr4Bknm1P41QscsHbHULDISqHle4gA5FdkQ+K8bAEVHLX5LIx5fxUdL9jYfzBvgtOND+pYuek/zHTENTKHnF2MI52n7ZD1IzVjBZS2rmdnXzvZWdAaj+k5IMykCDDlpsvKagRJmqLVZdnQ9MC2bWo0Uw9+/qDipPf/R/EpPhZiZEVwRgWNh1a5Rwpe3BPqc2fr2GPf0i1iEvwMQ== 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=uvqjZOrsF2g+D4GrbdZ9p1cmucrGcJJJsyRn2zaYzNA=; b=f5WauFH5PabBIqb3rFlWoCzpaft3dm+xeBktLqFbsKFwtZ8aJbYZyCDUqOCF144hunMF5N6BO5sSKXSkKOLwcgenfX+nVBskx92MrIpr5lh8UyZ0jAyzGXeaqOXmHJ957f04p7Qq3T3OiE8X4Ls0/myYWo67GDykpktS42EsAunRM+8Gz/ef9CySGtryzIhqQ9S626ZK4NI4JbDzaQsYrr3UicZEF3MnqZ0cY4rUTn4NOY/OcWXJGmibvP22Cduoc3ACkJOMClFI9G5wBcgGOIIrZXOXbBw4qYIqE9yghYmtqw8iiRaIPzXyy/NFHVM7rL4xXE1524CUY1Jb5eVJKA== 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=uvqjZOrsF2g+D4GrbdZ9p1cmucrGcJJJsyRn2zaYzNA=; b=j9b0PPJVIl0txjx2SFbR12D4Y0EZI9VWKvErdP5BhrfFGqFdkCSetIoGIvh9AIigKWjOCK8anKmMnaqDbv+gqz9AFesQaWimKH9nv+5kSbID8RlsbIKNthFen4BD2iblEZSi5n3ZJQkQteG6pJesOoFxVtMBFrECYYbBMQ6cjZU= Received: from DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) by MN2PR10MB4157.namprd10.prod.outlook.com (2603:10b6:208:1dc::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Thu, 25 Apr 2024 19:22:32 +0000 Received: from DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::ddec:934d:1117:499d]) by DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::ddec:934d:1117:499d%3]) with mapi id 15.20.7409.042; Thu, 25 Apr 2024 19:22:32 +0000 From: David Faust To: binutils@sourceware.org Cc: jose.marchesi@oracle.com, cupertino.miranda@oracle.com, indu.bhagat@oracle.com Subject: [PATCH] bpf: fix calculation when deciding to relax branch Date: Thu, 25 Apr 2024 12:22:23 -0700 Message-ID: <20240425192223.8892-1-david.faust@oracle.com> X-Mailer: git-send-email 2.44.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: CY5PR03CA0017.namprd03.prod.outlook.com (2603:10b6:930:8::41) To DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR10MB7953:EE_|MN2PR10MB4157:EE_ X-MS-Office365-Filtering-Correlation-Id: 0bd178c7-c857-4456-aaf5-08dc655d0dc4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?DcEbW0P3I7adExX0P7n/R1EecYRIZri0L3TJ2h9we/3Mfx9pcjr5M9qazlaw?= =?us-ascii?Q?neiNHHLBunMhYlHB1sjEgdLSYJphZ8aFOIoVylqVwOOVHZq61BYCk0waQVU/?= =?us-ascii?Q?T7mWgYiBnjMIsh0X/hKmiqKaaoNNWEATtIMkGZF4C1/a/YQMyRAJg/sOQT/n?= =?us-ascii?Q?ZHC5ADUbXQbvlVgUQo0K+dq3WF5fxHvoHubXlY24+LQIWEC8g6pnmzFFCqbz?= =?us-ascii?Q?SiKOyYgOElu8jWKB5WY1l4zDmLaaoFOxHvWgVeVhaOANzxbxvTDVyLsYdrc5?= =?us-ascii?Q?3tU/IBI1ehM0GaIV83ykfY24W5p3BdBNxyk4X03s9fz3VuF0nW4vpzesbC+a?= =?us-ascii?Q?sd18mArqq/ksbmWhqtIdI+W0tpSR8VMojClMTkLxDN+MzEjXeSPCRw8T8ii6?= =?us-ascii?Q?jc13JxADBNMpMjK0mRImUK78nzdF5JBvbqncU7huzESDjNcLRLUKQ8aen0Pa?= =?us-ascii?Q?ti3dU1424IXuCb4kLaMZJGV8fTpL/rifJg24QqMUXdd8tn121xxm4uOQ0HDL?= =?us-ascii?Q?szScaKjSQ1/D8wg53OUP0MsVU2mgSxMlSx4wUPxVhewdiGIbiIdPIk2FPbOt?= =?us-ascii?Q?ySJpDSdCGTSGw4n/24DHDkF7L1om/pQP9wgK6x2mdMNUfFMd31ZWihnb9sj9?= =?us-ascii?Q?0JKtfNb0xmFSZ3BBVf1EeKElJC0Ah+fm9ySxTFrovS4DXg41x8tUhz4lnJrm?= =?us-ascii?Q?4JVqHe5BAD8rR7mmisYfukevvy97n3JIOd9HDWgXuucwi2IMZSA87vGBhR/q?= =?us-ascii?Q?69o2SbZ+FtkHQmj3HPDYw1+SnULVEt1C4P7dSGxFc0tj3HcTIKa6hwCP4Pyn?= =?us-ascii?Q?5HL3E3sPfaygveX6aVwCMg9RONJ2dT32mjHsR0Icg3yhysdNJuTCTSLgfdGb?= =?us-ascii?Q?bIXQXVzAeif3FdWkpvtz/rmK1hhX6jNsj2op1Lh6fOOvT29wInKYz1AaK2ke?= =?us-ascii?Q?AegW5jTXH3OFmtiMuXtQtcCqkRNHK1QIosrbz5FKg5J15FmQVedA9wtwmVkk?= =?us-ascii?Q?gV/HN0hZulmyIaN7o/8dbwl9dXUQ7mBfZ7Q0DZsHYd5wzK9jQF5SiIiRlwfP?= =?us-ascii?Q?LGNE0dqnhmAArR9FtfuqOKHgO8pAe32l1hPQ8TwmVMdzXOPllVsioLeCYuPb?= =?us-ascii?Q?hhO5DRe01q7Pk0ZPDOWuppaSXbljlDSrzOcEvkD/MOj1GttV8JZ6oZt2jnUI?= =?us-ascii?Q?2N4ok2J61UL4YE3Odu1njcPacORROkwhNyqIepTHbGIzMrZB1RbKYpOtrzJr?= =?us-ascii?Q?C37n2/tHQfgH4D7MOTyaUIke713ANti92o7h7G14uw=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS0PR10MB7953.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366007)(376005)(1800799015);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?SCuWz3rVMDYv0rOoSErRkr46iY4LgmncgCEgFu94oHOnHDVrnVDNnAi9Ei3r?= =?us-ascii?Q?T6NkJ1yH0DAtgJBS99kSDcwSzt7Ad+18PZPiM9DR6h8mJZIwF7V/BbTbSEba?= =?us-ascii?Q?zH2+TCwWkZnIb7Xy7c6tdTDPYvqdDnN5TMUsjy32jFpqEwAeLDmQscYxt8LV?= =?us-ascii?Q?89nDpv3Rn6fQnVp2muvlENns5CsG0khCBE8siJm90lBAKQ0ivBAajTmjuX+W?= =?us-ascii?Q?jx7q+5sPeoxwk+TpErugQHkPbUnvqgiAyXDp9y00lNarCn2ajEHOZrZx3oN5?= =?us-ascii?Q?56Qz7U7MKJrxmLqn6fjrtpPFkMEsxI1wjYA0tFPRweQMdilQxx8QGXnMzpNZ?= =?us-ascii?Q?JEtwtuUwWO5pCa4S1hMF1A/IehR36pVLv78AtH+CknOD1859K3YIKeMgh/E/?= =?us-ascii?Q?yvT/EIoHwPnNNE3kMWhbPS/H/vcnZeh4Dxih5TXP8kA4KwaDwNSZJZR3eEg2?= =?us-ascii?Q?Hb/ZfawNeBqoC7h5ZPkcsc3qnyfQsmlCkgi6bVJT6RcOgZB8dHCenejifx/Y?= =?us-ascii?Q?0uU2ilFEc4SBKx73jmNI2Ut7T/7U+y1F5CF8z+B9aWhLLC12hDcc2aGDtd17?= =?us-ascii?Q?UWPG5gV8fbYB+IM2AxFZs+AlBINBd9XnsBuaNyok6xERSzzbIu2GDvrBQDTR?= =?us-ascii?Q?MMjx68xz/yWWKeonMu7H+SXfwf811tJ/I9f8OLKnx/NRNXTFYJOJrhATXxPh?= =?us-ascii?Q?DvGN394A4+bmUDlsB48GNK472tX54n7jDLo9993Qtx3Whub4R7t8+t4H2Xl5?= =?us-ascii?Q?Y8d/8MOVJMhNlBOAe44epUuc9HbBoXf2Tezfy4YZSoXZuGCcgCOIJ6g7xW5j?= =?us-ascii?Q?b5he/o860JkvIg6H2rhRtV+PLTUuD22Ow3v8uxyxlWBqZt0wTcrGZJ8q6yvx?= =?us-ascii?Q?1uLrVbSGPuE47uUYZ3apoV7JeYG/g4+vF2zizFoWHaJE7rjqCBpFICK/NnD0?= =?us-ascii?Q?bGShKlnyNy3NECtuXFyWqydev3A1NwVXs+K2Zu0IkZb6KTGqFnbWs/xFZoRB?= =?us-ascii?Q?irNoGmMliaf3nDnFw9qt2yRQBfya+JdLk9KdfpQYtoVirti9NUPYxb8Uiqu9?= =?us-ascii?Q?b9DrwkZ1A68aQwBycDbcNOhJDzOOFCMacAc8SkvaFCERvcB4V/Vj6jPCC+mA?= =?us-ascii?Q?HwZMVwUytPmfpW4jdVzthW4bkGxJ+cT7PMhu2LSL/NTek8XkMQtaTPdp0wcb?= =?us-ascii?Q?jBdDeMOgIbCyX9G6QOpXG8s/mcl2jYFiiCCFjKRNfYyxFv4mVSTqPffbZPkn?= =?us-ascii?Q?tsbSgoIUDWKM62PPnsF1Mf1RRAS8ZMZBVOfOrMovAdkCl59l/OwIxJQKcyzI?= =?us-ascii?Q?5U/hqGNKB9GBftlh1avysoziWnxBdxqbvtnHPryjND/w9fB7tvX990g+fqoN?= =?us-ascii?Q?gkGE+632+NWLaLPsJLVZ9SPOY/WFP1rp67LNMjke7slNubDlL/sjjCj+YnYP?= =?us-ascii?Q?0C9tqGXS9Wt9yZyQkdzILITRlNuMInTQq/TIKarLV06ZdZtYYo+y4DAKFk/M?= =?us-ascii?Q?xJwCNUw4C1nKGksvoj/z4jWrhsg+1DrIOSEdqhzweXJ3r89YTPA+nMliccRK?= =?us-ascii?Q?sjt+JPhzQUPW7KfRByxuVZyI9kpT7Q5fELNnermA?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: oy/3goJuspU7S5qlwhD1yQuDw38loZrFLxI7dq6vHegu0THTwm9wVndNPWbJA4JtYb2YHQnWsH2dhNdApLt7K1aVx57gCUnjtn2ekWiMdDwg/5Ei24osXoe7jyNGyf92vlIs3IoudGt99CUb3AN+1Z1dXfN1MfE6pWoVqqtD/mtkUOqaUaygjJm52zAv2FY59b/7yekZlhX4hdiXW3dajL3LSawR6x4OYZN1Yz4fQUVa9O5lwze+16sF0Go3Hdo6h9DpEMJ9iEFdZ+Rqpv2cnnzaYgNLeLnhkIALGXspSp1qFPAgi7AVxsvh9d0r7htICM1MZtxaM0/m/YF5YFot5+6ItDM+7QeCN7bAhMHJbNYWsKAYVB5rgw1351zBwiMtiBLz2G6YIYiy1vgCDG9ZL8ZY2hiYNBNfIkP6W0oSz/2vf1PK/PgVcKtvx/kUZxMeHnSnmf2gBHnrfDevobyZvDLJtnbbBRc6El+mRQoRwq+lEnXNJtNRvFyCN6yoonL+fJVXCp7KeuEbkzCCbAsOtjNawxEyQdYKqKd/bacUaiW/ntTAN7hnGpIqIP+H/pkunOeXeP00bLmfHcUIQ+WDFbjOHRbVlM+Pf1Wy1m6p7ZI= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0bd178c7-c857-4456-aaf5-08dc655d0dc4 X-MS-Exchange-CrossTenant-AuthSource: DS0PR10MB7953.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Apr 2024 19:22:31.9237 (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: WEVG+B8FxHwGc/2IT99sU+XcamfoKWVJ+plGT9OGQoiqhLAuB0i/WU6J43AeBXEHqx1CR1jZV6JhxZP86/DRwg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB4157 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-25_19,2024-04-25_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 spamscore=0 malwarescore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404250139 X-Proofpoint-ORIG-GUID: Q27AjN9jtbk9k-NAz72umr5X9FE8iAfR X-Proofpoint-GUID: Q27AjN9jtbk9k-NAz72umr5X9FE8iAfR X-Spam-Status: No, score=-13.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_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP 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: In certain cases we were calculating the jump displacement incorrectly when deciding whether to relax a branch. This meant for some branches, such as a very long backwards conditional branch, relaxation was not done when it should have been. The result was to error later, because the actual jump displacement was too large to fit in the original instruction. This patch fixes up the displacement calculation so that those branches are correctly relaxed and no longer result in an error. In addition, it changes md_convert_frag to install fixups for the JAL instructions in the resulting relaxations rather than encoding the displacement value directly. Tested on x86_64-linux-gnu host for bpf-unknown-none target. Sanity checked building Linux kernel BPF selftests. gas/ * config/tc-bpf.c (relaxed_branch_length): Correct displacement calculation when relaxing. (md_convert_frag): Likewise. Install fixups for JAL instructions resulting from relaxation. * testsuite/gas/bpf/jump-relax-ja-be.d: Correct and expand test. * testsuite/gas/bpf/jump-relax-ja.d: Likewise. * testsuite/gas/bpf/jump-relax-ja.s: Likewise. * testsuite/gas/bpf/jump-relax-jump-be.d: Likewise. * testsuite/gas/bpf/jump-relax-jump.d: Likewise. * testsuite/gas/bpf/jump-relax-jump.s: Likewise. --- gas/config/tc-bpf.c | 38 +++++++++++++++++++--- gas/testsuite/gas/bpf/jump-relax-ja-be.d | 16 +++++---- gas/testsuite/gas/bpf/jump-relax-ja.d | 16 +++++---- gas/testsuite/gas/bpf/jump-relax-ja.s | 13 +++++--- gas/testsuite/gas/bpf/jump-relax-jump-be.d | 22 ++++++++----- gas/testsuite/gas/bpf/jump-relax-jump.d | 22 ++++++++----- gas/testsuite/gas/bpf/jump-relax-jump.s | 12 ++++--- 7 files changed, 96 insertions(+), 43 deletions(-) diff --git a/gas/config/tc-bpf.c b/gas/config/tc-bpf.c index dfa44ea194c..377ac6a7a4c 100644 --- a/gas/config/tc-bpf.c +++ b/gas/config/tc-bpf.c @@ -434,6 +434,7 @@ relaxed_branch_length (fragS *fragp, asection *sec, int update) && sec == S_GET_SEGMENT (fragp->fr_symbol)) { offsetT val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset; + val -= fragp->fr_address + fragp->fr_fix; /* Convert to 64-bit words, minus one. */ val = (val - 8) / 8; @@ -578,6 +579,7 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, && sec == S_GET_SEGMENT (fragp->fr_symbol)) { offsetT val = S_GET_VALUE (fragp->fr_symbol) + fragp->fr_offset; + val -= fragp->fr_address + fragp->fr_fix; /* Convert to 64-bit blocks minus one. */ disp_to_target = (val - 8) / 8; disp_is_known = 1; @@ -626,15 +628,27 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, { /* 16-bit disp is known and not in range. Turn the JA into a JAL with a 32-bit displacement. */ - char bytes[8]; + char bytes[8] = {0}; bytes[0] = ((BPF_CLASS_JMP32|BPF_CODE_JA|BPF_SRC_K) >> 56) & 0xff; bytes[1] = (word >> 48) & 0xff; bytes[2] = 0; /* disp16 high */ bytes[3] = 0; /* disp16 lo */ - encode_int32 ((int32_t) disp_to_target, bytes + 4); - write_insn_bytes (buf, bytes); + + /* Install fixup for the JAL. */ + reloc_howto_type *reloc_howto + = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_BPF_DISP32); + if (!reloc_howto) + abort(); + + fixp = fix_new_exp (fragp, buf - (bfd_byte *) fragp->fr_literal, + bfd_get_reloc_size (reloc_howto), + &exp, + reloc_howto->pc_relative, + BFD_RELOC_BPF_DISP32); + fixp->fx_file = fragp->fr_file; + fixp->fx_line = fragp->fr_line; } } else @@ -731,8 +745,24 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, bytes[1] = 0; bytes[2] = 0; bytes[3] = 0; - encode_int32 ((int32_t) disp_to_target, bytes + 4); + encode_int32 ((int32_t) 0, bytes + 4); write_insn_bytes (buf, bytes); + + /* Install fixup for the JAL. */ + reloc_howto_type *reloc_howto + = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_BPF_DISP32); + if (!reloc_howto) + abort(); + + fixp = fix_new_exp (fragp, + buf - (bfd_byte *) fragp->fr_literal, + 4 /* size */, + &exp, + true /* pc-relative */, + BFD_RELOC_BPF_DISP32); + fixp->fx_file = fragp->fr_file; + fixp->fx_line = fragp->fr_line; + buf += 8; } } diff --git a/gas/testsuite/gas/bpf/jump-relax-ja-be.d b/gas/testsuite/gas/bpf/jump-relax-ja-be.d index 5f07847e90c..e5ad30da807 100644 --- a/gas/testsuite/gas/bpf/jump-relax-ja-be.d +++ b/gas/testsuite/gas/bpf/jump-relax-ja-be.d @@ -8,10 +8,14 @@ Disassembly of section .text: 0+ <.*>: - 0: 05 00 80 00 00 00 00 00 ja -32768 - 8: 05 00 7f ff 00 00 00 00 ja 32767 - 10: 05 00 ff fd 00 00 00 00 ja -3 - 18: 05 00 00 00 00 00 00 00 ja 0 + 0: 05 00 80 00 00 00 00 00 ja -32768 + 8: 05 00 7f ff 00 00 00 00 ja 32767 + 10: 05 00 ff fd 00 00 00 00 ja -3 + 18: 05 00 00 00 00 00 00 00 ja 0 18: R_BPF_GNU_64_16 undefined - 20: 06 00 00 00 00 00 80 01 jal 32769 - 28: 06 00 00 00 00 00 80 01 jal 32769 + 20: 06 00 00 00 00 00 80 00 jal 32768 + 28: 05 00 7f ff 00 00 00 00 ja 32767 + ... + +0+40028 : + 40028: 06 00 00 00 ff ff 7f fa jal -32774 diff --git a/gas/testsuite/gas/bpf/jump-relax-ja.d b/gas/testsuite/gas/bpf/jump-relax-ja.d index ed3aa6bad4e..1ac33f5d2f5 100644 --- a/gas/testsuite/gas/bpf/jump-relax-ja.d +++ b/gas/testsuite/gas/bpf/jump-relax-ja.d @@ -8,10 +8,14 @@ Disassembly of section .text: 0+ <.*>: - 0: 05 00 00 80 00 00 00 00 ja -32768 - 8: 05 00 ff 7f 00 00 00 00 ja 32767 - 10: 05 00 fd ff 00 00 00 00 ja -3 - 18: 05 00 00 00 00 00 00 00 ja 0 + 0: 05 00 00 80 00 00 00 00 ja -32768 + 8: 05 00 ff 7f 00 00 00 00 ja 32767 + 10: 05 00 fd ff 00 00 00 00 ja -3 + 18: 05 00 00 00 00 00 00 00 ja 0 18: R_BPF_GNU_64_16 undefined - 20: 06 00 00 00 01 80 00 00 jal 32769 - 28: 06 00 00 00 01 80 00 00 jal 32769 + 20: 06 00 00 00 00 80 00 00 jal 32768 + 28: 05 00 ff 7f 00 00 00 00 ja 32767 + ... + +0+40028 : + 40028: 06 00 00 00 fa 7f ff ff jal -32774 diff --git a/gas/testsuite/gas/bpf/jump-relax-ja.s b/gas/testsuite/gas/bpf/jump-relax-ja.s index f164176bbd5..61f2e61cb3c 100644 --- a/gas/testsuite/gas/bpf/jump-relax-ja.s +++ b/gas/testsuite/gas/bpf/jump-relax-ja.s @@ -4,13 +4,18 @@ 1: ja -32768 ja 32767 /* The following instruction refers to a defined symbol that - is on reach, so it should not be relaxed. */ + is in reach, so it should not be relaxed. */ ja 1b /* The following instruction has an undefined symbol as a target. It is not to be relaxed. */ ja undefined + 10 - /* The following instructions refer to a defined symbol that - is not on reach. They shall be relaxed to a JAL. */ + /* The following instruction refers to a defined symbol that + is not in reach, so it shall be relaxed to JAL. */ ja tail - tail = .text + 262160 + /* Now the symbol is in reach, and the following instruction + shall not be relaxed. */ ja tail + .space 262136 + tail = . + /* The jump back is too large and shall be relaxed. */ + ja 1b diff --git a/gas/testsuite/gas/bpf/jump-relax-jump-be.d b/gas/testsuite/gas/bpf/jump-relax-jump-be.d index 0cacdb38fc9..5cf3bce2a2b 100644 --- a/gas/testsuite/gas/bpf/jump-relax-jump-be.d +++ b/gas/testsuite/gas/bpf/jump-relax-jump-be.d @@ -8,12 +8,16 @@ Disassembly of section .text: 0+ <.*>: - 0: 1d 12 80 00 00 00 00 00 jeq %r1,%r2,-32768 - 8: ad 12 7f ff 00 00 00 00 jlt %r1,%r2,32767 - 10: bd 12 ff fd 00 00 00 00 jle %r1,%r2,-3 - 18: 1d 12 00 01 00 00 00 00 jeq %r1,%r2,1 - 20: 05 00 00 01 00 00 00 00 ja 1 - 28: 06 00 00 00 00 00 80 01 jal 32769 - 30: 2d 12 00 01 00 00 00 00 jgt %r1,%r2,1 - 38: 05 00 00 01 00 00 00 00 ja 1 - 40: 06 00 00 00 00 00 80 01 jal 32769 + 0: 1d 12 80 00 00 00 00 00 jeq %r1,%r2,-32768 + 8: ad 12 7f ff 00 00 00 00 jlt %r1,%r2,32767 + 10: bd 12 ff fd 00 00 00 00 jle %r1,%r2,-3 + 18: 1d 12 00 01 00 00 00 00 jeq %r1,%r2,1 + 20: 05 00 00 01 00 00 00 00 ja 1 + 28: 06 00 00 00 00 00 80 00 jal 32768 + 30: 2d 12 7f ff 00 00 00 00 jgt %r1,%r2,32767 + ... + +0+40030 : + 40030: 55 10 00 01 00 00 00 00 jne %r1,0,1 + 40038: 05 00 00 01 00 00 00 00 ja 1 + 40040: 06 00 00 00 ff ff 7f f7 jal -32777 diff --git a/gas/testsuite/gas/bpf/jump-relax-jump.d b/gas/testsuite/gas/bpf/jump-relax-jump.d index dd31ba5f4e4..4300bf3f59f 100644 --- a/gas/testsuite/gas/bpf/jump-relax-jump.d +++ b/gas/testsuite/gas/bpf/jump-relax-jump.d @@ -8,12 +8,16 @@ Disassembly of section .text: 0+ <.*>: - 0: 1d 21 00 80 00 00 00 00 jeq %r1,%r2,-32768 - 8: ad 21 ff 7f 00 00 00 00 jlt %r1,%r2,32767 - 10: bd 21 fd ff 00 00 00 00 jle %r1,%r2,-3 - 18: 1d 21 01 00 00 00 00 00 jeq %r1,%r2,1 - 20: 05 00 01 00 00 00 00 00 ja 1 - 28: 06 00 00 00 01 80 00 00 jal 32769 - 30: 2d 21 01 00 00 00 00 00 jgt %r1,%r2,1 - 38: 05 00 01 00 00 00 00 00 ja 1 - 40: 06 00 00 00 01 80 00 00 jal 32769 + 0: 1d 21 00 80 00 00 00 00 jeq %r1,%r2,-32768 + 8: ad 21 ff 7f 00 00 00 00 jlt %r1,%r2,32767 + 10: bd 21 fd ff 00 00 00 00 jle %r1,%r2,-3 + 18: 1d 21 01 00 00 00 00 00 jeq %r1,%r2,1 + 20: 05 00 01 00 00 00 00 00 ja 1 + 28: 06 00 00 00 00 80 00 00 jal 32768 + 30: 2d 21 ff 7f 00 00 00 00 jgt %r1,%r2,32767 + ... + +0+40030 : + 40030: 55 01 01 00 00 00 00 00 jne %r1,0,1 + 40038: 05 00 01 00 00 00 00 00 ja 1 + 40040: 06 00 00 00 f7 7f ff ff jal -32777 diff --git a/gas/testsuite/gas/bpf/jump-relax-jump.s b/gas/testsuite/gas/bpf/jump-relax-jump.s index 5ea61109bca..6b23c56514a 100644 --- a/gas/testsuite/gas/bpf/jump-relax-jump.s +++ b/gas/testsuite/gas/bpf/jump-relax-jump.s @@ -2,11 +2,13 @@ fix in the jump 16-bit signed displacement operand. */ 1: jeq %r1, %r2, -32768 jlt %r1, %r2, 32767 - /* The following instruction refers to a defined symbol that - is on reach, so it should not be relaxed. */ + /* The following instructions refer to defined symbols that + are in reach, so they should not be relaxed. */ jle %r1, %r2, 1b - /* The following instructions refer to a defined symbol that - is not on reach. They shall be relaxed. */ jeq %r1, %r2, tail - tail = .text + 262160 jgt %r1, %r2, tail + /* The following instructions refers to defined symbols that + are not in reach, so they shall be relaxied. */ + .space 262136 + tail = . + jne %r1, 0, 1b -- 2.43.0