From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 33519385C6ED for ; Thu, 17 Aug 2023 08:06:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 33519385C6ED 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 (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37GNfd8q025569 for ; Thu, 17 Aug 2023 08:06:11 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=UFhGA+NMSTewIAg/esntwpLeC/CCovN1vFY/83+ytZw=; b=t8QM3uQvFjrPdSThhQbkKZ2RojYqPTD8s02anwI26SQSNgkSP2vgPAQoPN3pdeV8NN10 jhl52WJoBXVuC3tFWe391nwy09unc1dfRaI6kdrffpJp61H/iLGdyIrGaJL68fP0s3gZ YUtMEw6ZO2KZJRdGtbrj252YXnsrmaemULfGapVlD9ApTs9cSHLq4L+8e+6UEX8LSjdX QdkTgQDKJs00uyZIn3+uIGGzFr7M1rymcaEcgF962NJMs3DBPTvoAMi4cBq7TQ3nSZBI m9VbvaMpXa/7mXgc22sUOc+Xv6MWE9mxbUNgsCpvTwWSOJWtnyIt/zyfCXp8W+JoygP+ BA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3se2w60x07-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 17 Aug 2023 08:06:10 +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 37H64Sng003782 for ; Thu, 17 Aug 2023 08:06:09 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2168.outbound.protection.outlook.com [104.47.57.168]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3sexyma5ua-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 17 Aug 2023 08:06:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V3iJ102211eA3dQ3bhKpkS7a3s7xG3aA5qDZaB0RChnu3V7ahEKD8Dws1Q5w0JYDP29uNFgLV41wJPsx15+Caxcqu0bUTjxH2FhNd4cYddCeYujgpVwb45XSiy2qjxzTzQ3n2I1GOmwOI5fuGoIcXUr01l+J35aRn1GsdCphRjeplqrEoVjnCjXiz/TNrwfJFNZboaTiit+5ahqwjor0vguxxFFwlkqgBlhmOPA7v25WTKGRcMhjD1LQG97VoBkunuM5m+RDTe/Chcf19AxXJwHtD4889HmZGVdtuuLWCLAhUCfpOpHgAL41qwmUNJqL+hFAl8F2fRlm/gJXT05qKQ== 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=UFhGA+NMSTewIAg/esntwpLeC/CCovN1vFY/83+ytZw=; b=OUaKDohRMLHEh034xV55uKjvpsvA0UeQnwWDIgidL6Y83nGSCWps3pGazp5RJaxrjFfPHyszaUoCgGUWtMJy5esq7PTE50gdqGdaM28XH128HQQCynEzSdJiToU4d1ynZnzB9WSlkjWxzvLv/J/MDke9iHW/elty/bOgVeOh2Y6upKVbg60b2uVmQjBp+vdMKfbfIyw3fdpxRaXfK0V831SSVj6tsQ17Z8AyZNDzmE/kU+GYKmGxGFL0N5cmi75p7y7tfmNoXzBwyDxfzwRlgSjYsduEmudFHZQg7JKGie+bOvOkFK671TEMBBdxKXTnFbC9COv6CBxjmoKq0V05AA== 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=UFhGA+NMSTewIAg/esntwpLeC/CCovN1vFY/83+ytZw=; b=VkMMQ7h/oQD6gkOvD1/B/2Rrr7uXarNSKLGQJFPpatpKSIWBKToWTtqbL4bZm5K1aNt8shOFu4NW4gzuUH0+zVwX/bOtTFSHNjlr3ha1eD5Bt9Gu9G7G0qxofBd+3azHg5jfGK9mNylP+UUapr+fUs8XtFMcgG7JYgQgugAhVjo= Received: from BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) by DM6PR10MB4235.namprd10.prod.outlook.com (2603:10b6:5:210::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.30; Thu, 17 Aug 2023 08:06:06 +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; Thu, 17 Aug 2023 08:06:06 +0000 From: "Jose E. Marchesi" To: binutils@sourceware.org Subject: [COMMITTED] bpf: gas: consolidate handling of immediate overflows Date: Thu, 17 Aug 2023 10:06:00 +0200 Message-Id: <20230817080600.13169-1-jose.marchesi@oracle.com> X-Mailer: git-send-email 2.30.2 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: LO4P123CA0478.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a8::15) To BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB2888:EE_|DM6PR10MB4235:EE_ X-MS-Office365-Filtering-Correlation-Id: 4712ede7-32c6-416f-0d43-08db9ef8ceb7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lJ/MuHE/T4VXdifx/4yL1IDIU+UrPJgsSrz4gUzrAMttfNJoPHVCwqJzwgJhdI5mTAhFzWrN7mve4XmEl2H3uwhxWvQ3bEzq+OaL0Eaj1AlwiIG+bsAIecJm6E+zutYYXx3qOMCDt0OJpIZs/u5eD/S/7Fm+TQsl1GZAEZWO2jXJMTuhGgvkuTCR42o6gAdb5B6cX0oa9U06D4pnjhKWz/tLOlqjwTjqXwy3O93+EDxCzydNPSJKzt/9shx9WmxAgKU8B/tD/7lHwDrNs/izyEH6U+zQV4jS9e5k8Y+hwNpuk+ZTkDRJyaaIMhSMyqudDD5eKNm3t2ltmSieHLdShaReh6uRV+MtpTzFXpaIMe2NGFcVnnljjpLYZ3mvWQjgpdm96PCwZuL6W2Nyk+lTWTsLl5f+HD9yE9CfolD0G9D9EyncJXy00MJM61z4umOesV3+3PS+8hJALdly+aDYV7AHsX5usfXSC7HdkK3tGybuX4RqiKj6vgPZndmI+JY0NFQfS4/LlWE2wRGy9qAOb56C/piGW1ZLJ/J5ReC3NCFLd9pzBs80HzWMe5lNXnuwBMYkK4wV3ABA4mhs7inscn8DsL4nMKxd/h21A7KDQO8= 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)(39860400002)(376002)(346002)(136003)(366004)(396003)(1800799009)(451199024)(186009)(316002)(66476007)(6916009)(66946007)(66556008)(5660300002)(41300700001)(38100700002)(8936002)(8676002)(26005)(30864003)(2906002)(83380400001)(478600001)(86362001)(6512007)(36756003)(6506007)(6666004)(1076003)(6486002)(2616005)(14773001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?1adBtKR1g6tRH+ItML7YkbaIcC3b65ekSKK8l1K9GhnMYyImuWTRKLasKV4b?= =?us-ascii?Q?474krkedGg4Yj444PKTEkeStDU4Pgq9Asp0P+40eZRnpQS7in8w2oXlJhSqF?= =?us-ascii?Q?IvRbj4EC7u+qUSJv4a+qlBQ+1kv31IhLo8fRiJjnV1N+sytp2J6U8tBE7vGX?= =?us-ascii?Q?pJlwN51/mF7ZeTMBhqDdjyqqT5/mCYnALhdXobZEELNkoNoaEsfxtdAtqiA1?= =?us-ascii?Q?AOXi4oKeyGiFAoJGiQOAkofFMGE03CHFcqQGAQ2XBsKdH0pzr3oDjwtnstJy?= =?us-ascii?Q?UtnkjROx49tTJ7KZPggDY7GSZkA4vHtvGHmX3qPcpzYyLIX08DMnZ/+A4yKc?= =?us-ascii?Q?JdAchX9vBGk4eb0jjjwuGtr7DvPDXpoiCrqhbABrRxtvjkvXe8RquzFTaYYl?= =?us-ascii?Q?UY9KkyoJ4p+eDW+RUXnC7GftUgrlCsoFQ4rwB+VxsuPrem8K/zCCzAHj4Fsi?= =?us-ascii?Q?KFryAzqamV/bvkdzCZxdKeWy1bs2MyhLJ4QBM4ZYr1Ui4gZCk0WJzZQsO0VF?= =?us-ascii?Q?RpxNYjIcU9lNGuI6V5m5ycJ1qrCgLWdhpVmSGAQpZG04OhKbCB0f4n+UybI0?= =?us-ascii?Q?jvPRsd/ieRhN3i6RwZ+5MdFKACCyh46rFdEL0AOaTvkN4jqERLzgcbOy5s64?= =?us-ascii?Q?QnFW9iLapBuR+6vqk0GtVXYHF8Pi5VfxIXdlYu1+IQTapCXObwi9GOloIKp9?= =?us-ascii?Q?LMBUkLAz232cyvBgKMtp8WfN+0j9xyuBFrSRK7VP0fpFmAq8eP2Djo9NpLH+?= =?us-ascii?Q?xXAGuHyNcIeMQE0uUjllbMBPsFMHISjM3ebQPIF+gWfjTBPBCXJHy8YdQoCL?= =?us-ascii?Q?AcPtYQobaLzRL7qbq4tLq9ZHbnFDl+bREjsZIzsbLeGZ2a+n0liIpLXIF8Vx?= =?us-ascii?Q?ohMpoJVnqb+dphTeQerijWzJOljvAgXjVbCDVUQacjdqz9aWdveGGq6dKyhP?= =?us-ascii?Q?rNxL8EYAE1RKkc0cgn/G5uMz5wWGAWjEpy+7ZVNhw11SxDyWYdemdq7QzBvI?= =?us-ascii?Q?U5RJ73S6glEbwgw0w0hEyGwUVw8ku1Uk0EsdgmaP1AYMCd1BrNq3cikLze/N?= =?us-ascii?Q?eTssg67bWXIsnH8OHCOZF5eqqby0K1a66IlwWPwEiBH/IC0iMySGzMLYcdVc?= =?us-ascii?Q?+R7n4JNKs5t0XLv7rfGFGt6vFdX5JJ89EXzLhSg6sELVFef16sprX/xqzzZl?= =?us-ascii?Q?e2+XClO+6FfVTzrA8izxLnpnEQhAf3ap59whEAE+/NtdUV9Yi7ZwuSciaTxJ?= =?us-ascii?Q?Sqe/xd9wr7AIONhbj/rtrZlJ7WNoMLdjIF0I/NKWKadkoe6lnZt0PHsMTIgA?= =?us-ascii?Q?uESxhW/ua+7ntqdIwvQdqGP7UBh+neyjvyibbsP76ZtWNgvjbZhQuqGrprc4?= =?us-ascii?Q?iDOwHRiVD+802VMtv2bxAhJdn4SudNKyXtgXkS7/JBBXe+fghyqHJ5JvfwV3?= =?us-ascii?Q?AEo44GP3Q1d20rKq+V6LHnVBht2G/wEKucKjGKYeGqcrW2jAS8F2CK6ld17S?= =?us-ascii?Q?poWWyMCp8HRgltzaZMxAslPOtnHfFHNmFsJEQWdH2RGhp2k5PBt9pgY0L5+x?= =?us-ascii?Q?06HLGoYKOM4e7xPPzIU9+MbnXYedy2aLBKwr/6f+soD1LzrPMTHIYL6yD6ot?= =?us-ascii?Q?4g=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: zRNAE1Rd6AxEM1WWwyPTwyI77qQY36QJTeopVaKUn8Cff2I3sxiyTtdjgnzXUYXe9IEGT4vQfrFu5MIYEMJx42ZgKb9ZY+sUtC9/93ZgsAeMb3nLAGHyRvwZkmRuRlBsjJ5MgWNugyVU0ngCIUDWP9zPRs4YcL7aZahpX1kf+hl4ZpeZQKZSekGDRDl/PSBuSLQBPPYkIczYk7c+TrMSTsl2ajYLFkzbncpQxDEncY5TC+io03NC5nZ5FhNoIiVt15RywxyXiE5VPwZ6woBnXJgzdmJZHhaxr9s7rk77f/OW7YMjVVpBEIcGVOvJfPgfgvP7T/Kg3j/ZvFIQGk66Vd4UQCjhE4N/JLzOIOWyw9gVm57ggylSRbRu2GfIF3gioAMsQSJLLiHXzWEd9BfAUezCaMUGoRSGCqq8j5m6aqo9rx0oJp4P+yNcwwThnA4dfLr1oN+2IQJC6d0tJhtBUH54W+7wIVTWRoMfjsnQUBe3jxrEOCxYkICO1RpNBAiIDxVr5rzzie06aToPsr5u5viWpF+NvhlIswHFmQl+IInOqdINdZ8gLyrY9YODtEB4+5b5NAzjOlNmU/YNMNiwplIIFJha3BfeEBxsqRTBCXhsVony5McUx4I98y4ZXyLsPYAJVFnsisBHeHkNuG63UJvSApegQADBEB+7RPxYQsDVBXujbFO/LL1QMbpKPHVU505hwbIXIszcMQUMMfGeQArjL63Oa02DVrcj/9vIlDqY2QE4BSJH5zgFeq5e165s X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4712ede7-32c6-416f-0d43-08db9ef8ceb7 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2888.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2023 08:06:06.3135 (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: rjKEZ6Jt4wXMEOh2Gw+Uu8KU0mnJ42dgeJKA0co7za0qBmU4wZekTgbd6AFsBQDJrAQPJoRBd7sdfX41fPHD85BvZz35OXnpNbBynMO/G+M= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB4235 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-17_03,2023-08-15_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 phishscore=0 suspectscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2308170071 X-Proofpoint-ORIG-GUID: U5Fo4NTs77TEWX0HbXWAp7koM5JPFp_8 X-Proofpoint-GUID: U5Fo4NTs77TEWX0HbXWAp7koM5JPFp_8 X-Spam-Status: No, score=-12.5 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 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 commit changes the BPF GAS port in order to handle immediate overflows the same way than the clang BPF assembler: - For an immediate field of N bits, any written number (positive or negative) whose two's complement encoding fit in N its is accepted. This means that -2 is the same than 0xffffffe. It is up to the instructions to decide how to interpret the encoded value. - Immediate fields in jump instructions are no longer relaxed. Relaxing to jump instructions with wider range is only performed when expressions are involved. - The manual is updated to document this, and testsuite adapted accordingly. Tested in x86_64-linux-gnu host, bpf-unknown-none target. gas/ChangeLog: 2023-08-17 Jose E. Marchesi * config/tc-bpf.c (check_immediate_overflow): New function. (encode_insn): Use check_immediate_overflow. (md_assemble): Do not relax instructions with constant disp16 fields. * doc/c-bpf.texi (BPF Instructions): Add note about how numerical literal values are interpreted for instruction immediate operands. * testsuite/gas/bpf/disp16-overflow.s: Adapt accordingly. * testsuite/gas/bpf/jump-relax-jump.s: Likewise. * testsuite/gas/bpf/jump-relax-jump.d: Likewise. * testsuite/gas/bpf/jump-relax-jump-be.d: Likewise. * testsuite/gas/bpf/jump-relax-ja.s: Likewise. * testsuite/gas/bpf/jump-relax-ja.d: Likewise. * testsuite/gas/bpf/jump-relax-ja-be.d: Likewise. * testsuite/gas/bpf/disp16-overflow-relax.l: Likewise. * testsuite/gas/bpf/imm32-overflow.s: Likewise. * testsuite/gas/bpf/disp32-overflow.s: Likewise. * testsuite/gas/bpf/disp16-overflow.l: Likewise. * testsuite/gas/bpf/disp32-overflow.l: Likewise. * testsuite/gas/bpf/imm32-overflow.l: Likewise. * testsuite/gas/bpf/offset16-overflow.l: Likewise. --- gas/ChangeLog | 23 ++++++++++ gas/config/tc-bpf.c | 43 ++++++++++++++----- gas/config/tc-sparc.c | 2 +- gas/doc/c-bpf.texi | 8 ++++ gas/testsuite/gas/bpf/disp16-overflow-relax.l | 6 ++- gas/testsuite/gas/bpf/disp16-overflow-relax.s | 4 +- gas/testsuite/gas/bpf/disp16-overflow.l | 4 +- gas/testsuite/gas/bpf/disp16-overflow.s | 2 +- gas/testsuite/gas/bpf/disp32-overflow.l | 4 +- gas/testsuite/gas/bpf/disp32-overflow.s | 4 +- gas/testsuite/gas/bpf/imm32-overflow.l | 4 +- gas/testsuite/gas/bpf/imm32-overflow.s | 6 +-- gas/testsuite/gas/bpf/jump-relax-ja-be.d | 6 +-- gas/testsuite/gas/bpf/jump-relax-ja.d | 6 +-- gas/testsuite/gas/bpf/jump-relax-ja.s | 4 -- gas/testsuite/gas/bpf/jump-relax-jump-be.d | 12 ++---- gas/testsuite/gas/bpf/jump-relax-jump.d | 12 ++---- gas/testsuite/gas/bpf/jump-relax-jump.s | 5 --- gas/testsuite/gas/bpf/offset16-overflow.l | 4 +- gas/testsuite/gas/bpf/offset16-overflow.s | 4 +- 20 files changed, 96 insertions(+), 67 deletions(-) diff --git a/gas/ChangeLog b/gas/ChangeLog index 26d7dc1623b..3339c4cadd3 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,26 @@ +2023-08-17 Jose E. Marchesi + + * config/tc-bpf.c (check_immediate_overflow): New function. + (encode_insn): Use check_immediate_overflow. + (md_assemble): Do not relax instructions with + constant disp16 fields. + * doc/c-bpf.texi (BPF Instructions): Add note about how numerical + literal values are interpreted for instruction immediate operands. + * testsuite/gas/bpf/disp16-overflow.s: Adapt accordingly. + * testsuite/gas/bpf/jump-relax-jump.s: Likewise. + * testsuite/gas/bpf/jump-relax-jump.d: Likewise. + * testsuite/gas/bpf/jump-relax-jump-be.d: Likewise. + * testsuite/gas/bpf/jump-relax-ja.s: Likewise. + * testsuite/gas/bpf/jump-relax-ja.d: Likewise. + * testsuite/gas/bpf/jump-relax-ja-be.d: Likewise. + * testsuite/gas/bpf/disp16-overflow-relax.l: Likewise. + * testsuite/gas/bpf/imm32-overflow.s: Likewise. + * testsuite/gas/bpf/disp32-overflow.s: Likewise. + * testsuite/gas/bpf/disp16-overflow.l: Likewise. + * testsuite/gas/bpf/disp32-overflow.l: Likewise. + * testsuite/gas/bpf/imm32-overflow.l: Likewise. + * testsuite/gas/bpf/offset16-overflow.l: Likewise. + 2023-07-30 Jose E. Marchesi * config/tc-bpf.h (elf_tc_final_processing): Define. diff --git a/gas/config/tc-bpf.c b/gas/config/tc-bpf.c index b4566d89ddf..cdde05c9139 100644 --- a/gas/config/tc-bpf.c +++ b/gas/config/tc-bpf.c @@ -286,6 +286,26 @@ signed_overflow (offsetT value, unsigned bits) return (value < -lim || value >= lim); } +/* Return non-zero if the two's complement encoding of VALUE would + overflow an immediate field of width BITS bits. */ + +static bool +immediate_overflow (int64_t value, unsigned bits) +{ + if (value < 0) + return signed_overflow (value, bits); + else + { + valueT lim; + + if (bits >= sizeof (valueT) * 8) + return false; + + lim = (valueT) 1 << bits; + return ((valueT) value >= lim); + } +} + /* Functions concerning relocs. */ @@ -379,7 +399,7 @@ tc_gen_reloc (asection *sec ATTRIBUTE_UNUSED, fixS *fixP) #define RELAX_BRANCH_UNCOND(i) (((i) & 1) != 0) -/* Compute the length of a branch seuqence, and adjust the stored +/* Compute the length of a branch sequence, and adjust the stored length accordingly. If FRAG is NULL, the worst-case length is returned. */ @@ -854,7 +874,8 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED) immediates are encoded as zeroes. */ static void -encode_insn (struct bpf_insn *insn, char *bytes, int relaxed) +encode_insn (struct bpf_insn *insn, char *bytes, + int relaxed ATTRIBUTE_UNUSED) { uint8_t src, dst; @@ -911,8 +932,8 @@ encode_insn (struct bpf_insn *insn, char *bytes, int relaxed) { int64_t imm = insn->imm32.X_add_number; - if (signed_overflow (imm, 32)) - as_bad (_("signed immediate out of range, shall fit in 32 bits")); + if (immediate_overflow (imm, 32)) + as_bad (_("immediate out of range, shall fit in 32 bits")); else encode_int32 (insn->imm32.X_add_number, bytes + 4); } @@ -921,8 +942,8 @@ encode_insn (struct bpf_insn *insn, char *bytes, int relaxed) { int64_t disp = insn->disp32.X_add_number; - if (signed_overflow (disp, 32)) - as_bad (_("signed pc-relative offset out of range, shall fit in 32 bits")); + if (immediate_overflow (disp, 32)) + as_bad (_("pc-relative offset out of range, shall fit in 32 bits")); else encode_int32 (insn->disp32.X_add_number, bytes + 4); } @@ -931,8 +952,8 @@ encode_insn (struct bpf_insn *insn, char *bytes, int relaxed) { int64_t offset = insn->offset16.X_add_number; - if (signed_overflow (offset, 16)) - as_bad (_("signed pc-relative offset out of range, shall fit in 16 bits")); + if (immediate_overflow (offset, 16)) + as_bad (_("pc-relative offset out of range, shall fit in 16 bits")); else encode_int16 (insn->offset16.X_add_number, bytes + 2); } @@ -941,8 +962,8 @@ encode_insn (struct bpf_insn *insn, char *bytes, int relaxed) { int64_t disp = insn->disp16.X_add_number; - if (!relaxed && signed_overflow (disp, 16)) - as_bad (_("signed pc-relative offset out of range, shall fit in 16 bits")); + if (immediate_overflow (disp, 16)) + as_bad (_("pc-relative offset out of range, shall fit in 16 bits")); else encode_int16 (insn->disp16.X_add_number, bytes + 2); } @@ -1517,7 +1538,7 @@ md_assemble (char *str ATTRIBUTE_UNUSED) break; } insn.has_disp16 = 1; - insn.is_relaxable = 1; + insn.is_relaxable = (insn.disp16.X_op != O_constant); p += 4; } else if (strncmp (p, "%d32", 4) == 0) diff --git a/gas/config/tc-sparc.c b/gas/config/tc-sparc.c index c273bd75c08..8c23b65ca8b 100644 --- a/gas/config/tc-sparc.c +++ b/gas/config/tc-sparc.c @@ -844,7 +844,7 @@ struct pop_entry pop_table[] = { { "hix", BFD_RELOC_SPARC_HIX22, F_POP_V9 }, { "lox", BFD_RELOC_SPARC_LOX10, F_POP_V9 }, - { "hi", BFD_RELOC_HI22, F_POP_PCREL }, + { "hi"5, BFD_RELOC_HI22, F_POP_PCREL }, { "lo", BFD_RELOC_LO10, F_POP_PCREL }, { "pc22", BFD_RELOC_SPARC_PC22, F_POP_PCREL }, { "pc10", BFD_RELOC_SPARC_PC10, F_POP_PCREL }, diff --git a/gas/doc/c-bpf.texi b/gas/doc/c-bpf.texi index 6b43c77d5a0..75372de4ef4 100644 --- a/gas/doc/c-bpf.texi +++ b/gas/doc/c-bpf.texi @@ -172,6 +172,14 @@ Signed 32-bit immediate. Signed 64-bit immediate. @end table +@noindent +Note that the assembler allows to express the value for an immediate +using any numerical literal whose two's complement encoding fits in +the immediate field. For example, @code{-2}, @code{0xfffffffe} and +@code{4294967294} all denote the same encoded 32-bit immediate, whose +value may be then interpreted by different instructions as either as a +negative or a positive number. + @subsection Arithmetic instructions The destination register in these instructions act like an diff --git a/gas/testsuite/gas/bpf/disp16-overflow-relax.l b/gas/testsuite/gas/bpf/disp16-overflow-relax.l index ca572cbd0ff..935a8abaed3 100644 --- a/gas/testsuite/gas/bpf/disp16-overflow-relax.l +++ b/gas/testsuite/gas/bpf/disp16-overflow-relax.l @@ -1,3 +1,5 @@ .*: Assembler messages: -.*:2: Error: signed instruction operand out of range, shall fit in 32 bits -.*:4: Error: signed instruction operand out of range, shall fit in 32 bits +.*:1: Error: pc-relative offset out of range, shall fit in 16 bits +.*:2: Error: pc-relative offset out of range, shall fit in 16 bits +.*:3: Error: pc-relative offset out of range, shall fit in 16 bits +.*:4: Error: pc-relative offset out of range, shall fit in 16 bits diff --git a/gas/testsuite/gas/bpf/disp16-overflow-relax.s b/gas/testsuite/gas/bpf/disp16-overflow-relax.s index 3953992ad07..05d505caaae 100644 --- a/gas/testsuite/gas/bpf/disp16-overflow-relax.s +++ b/gas/testsuite/gas/bpf/disp16-overflow-relax.s @@ -1,4 +1,4 @@ - jeq %r1,%r2,2147483647 + jeq %r1,%r2,2147483647 ; Overflows. jlt %r3,%r4,2147483648 ; Overflows. - jge %r5,10,-2147483648 + jge %r5,10,-2147483648 ; Overflows. ja -2147483649 ; Overflows. diff --git a/gas/testsuite/gas/bpf/disp16-overflow.l b/gas/testsuite/gas/bpf/disp16-overflow.l index 6404b1b2076..1fd0f94d0e2 100644 --- a/gas/testsuite/gas/bpf/disp16-overflow.l +++ b/gas/testsuite/gas/bpf/disp16-overflow.l @@ -1,3 +1,3 @@ .*: Assembler messages: -.*:2: Error: signed pc-relative offset out of range, shall fit in 16 bits -.*:4: Error: signed pc-relative offset out of range, shall fit in 16 bits +.*:2: Error: pc-relative offset out of range, shall fit in 16 bits +.*:4: Error: pc-relative offset out of range, shall fit in 16 bits diff --git a/gas/testsuite/gas/bpf/disp16-overflow.s b/gas/testsuite/gas/bpf/disp16-overflow.s index ab66753af7d..4a8fd9fcf1c 100644 --- a/gas/testsuite/gas/bpf/disp16-overflow.s +++ b/gas/testsuite/gas/bpf/disp16-overflow.s @@ -1,4 +1,4 @@ ja 32767 - jeq %r1,%r2,32768 ; Overflows + jeq %r1,%r2,65536 ; Overflows jlt %r3,%r4,-32768 jge %r5,10,-32769 ; Overflows diff --git a/gas/testsuite/gas/bpf/disp32-overflow.l b/gas/testsuite/gas/bpf/disp32-overflow.l index 8a6b6479f07..40a20dd88fb 100644 --- a/gas/testsuite/gas/bpf/disp32-overflow.l +++ b/gas/testsuite/gas/bpf/disp32-overflow.l @@ -1,3 +1,3 @@ .*: Assembler messages: -.*:2: Error: signed pc-relative offset out of range, shall fit in 32 bits -.*:4: Error: signed pc-relative offset out of range, shall fit in 32 bits +.*:2: Error: pc-relative offset out of range, shall fit in 32 bits +.*:4: Error: pc-relative offset out of range, shall fit in 32 bits diff --git a/gas/testsuite/gas/bpf/disp32-overflow.s b/gas/testsuite/gas/bpf/disp32-overflow.s index 03a0d97e6c6..11128a20dff 100644 --- a/gas/testsuite/gas/bpf/disp32-overflow.s +++ b/gas/testsuite/gas/bpf/disp32-overflow.s @@ -1,4 +1,4 @@ call -2147483648 call -2147483649 ; This overflows. - call 2147483647 - call 2147483648 ; This overflows. + call 4294967295 + call 4294967296 ; This overflows. diff --git a/gas/testsuite/gas/bpf/imm32-overflow.l b/gas/testsuite/gas/bpf/imm32-overflow.l index f6691c49cd5..4e5ac5ae06f 100644 --- a/gas/testsuite/gas/bpf/imm32-overflow.l +++ b/gas/testsuite/gas/bpf/imm32-overflow.l @@ -1,3 +1,3 @@ .*: Assembler messages: -.*:2: Error: signed immediate out of range, shall fit in 32 bits -.*:4: Error: signed immediate out of range, shall fit in 32 bits +.*:2: Error: immediate out of range, shall fit in 32 bits +.*:4: Error: immediate out of range, shall fit in 32 bits diff --git a/gas/testsuite/gas/bpf/imm32-overflow.s b/gas/testsuite/gas/bpf/imm32-overflow.s index 5cb858cee05..b2ab43d2e7a 100644 --- a/gas/testsuite/gas/bpf/imm32-overflow.s +++ b/gas/testsuite/gas/bpf/imm32-overflow.s @@ -1,4 +1,4 @@ add %r1, 2147483647 - or %r2, 2147483648 ; This overflows. - xor %r3, -2147483648 - sub %r4, -2147483649 ; This overflows. + or %r2, 4294967296 ; This overflows. + xor %r3, 4294967295 + sub %r4, 4294967296 ; This overflows. diff --git a/gas/testsuite/gas/bpf/jump-relax-ja-be.d b/gas/testsuite/gas/bpf/jump-relax-ja-be.d index 08b85a97b45..5f07847e90c 100644 --- a/gas/testsuite/gas/bpf/jump-relax-ja-be.d +++ b/gas/testsuite/gas/bpf/jump-relax-ja-be.d @@ -13,7 +13,5 @@ Disassembly of section .text: 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 ff ff 7f ff jal -32769 - 28: 06 00 00 00 00 00 80 00 jal 32768 - 30: 06 00 00 00 00 00 80 01 jal 32769 - 38: 06 00 00 00 00 00 80 01 jal 32769 + 20: 06 00 00 00 00 00 80 01 jal 32769 + 28: 06 00 00 00 00 00 80 01 jal 32769 diff --git a/gas/testsuite/gas/bpf/jump-relax-ja.d b/gas/testsuite/gas/bpf/jump-relax-ja.d index 6b50973915d..ed3aa6bad4e 100644 --- a/gas/testsuite/gas/bpf/jump-relax-ja.d +++ b/gas/testsuite/gas/bpf/jump-relax-ja.d @@ -13,7 +13,5 @@ Disassembly of section .text: 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 ff 7f ff ff jal -32769 - 28: 06 00 00 00 00 80 00 00 jal 32768 - 30: 06 00 00 00 01 80 00 00 jal 32769 - 38: 06 00 00 00 01 80 00 00 jal 32769 + 20: 06 00 00 00 01 80 00 00 jal 32769 + 28: 06 00 00 00 01 80 00 00 jal 32769 diff --git a/gas/testsuite/gas/bpf/jump-relax-ja.s b/gas/testsuite/gas/bpf/jump-relax-ja.s index 8be3d7a4288..1faf67909eb 100644 --- a/gas/testsuite/gas/bpf/jump-relax-ja.s +++ b/gas/testsuite/gas/bpf/jump-relax-ja.s @@ -9,10 +9,6 @@ ;; The following instruction has an undefined symbol as a ;; target. It is not to be relaxed. ja undefined + 10 - ;; The following instructions are relaxed to JAL instructions - ;; so they can fit their displacements. - ja -32769 - ja 32768 ;; The following instructions refer to a defined symbol that ;; is not on reach. They shall be relaxed to a JAL. ja tail diff --git a/gas/testsuite/gas/bpf/jump-relax-jump-be.d b/gas/testsuite/gas/bpf/jump-relax-jump-be.d index 5626d568734..0cacdb38fc9 100644 --- a/gas/testsuite/gas/bpf/jump-relax-jump-be.d +++ b/gas/testsuite/gas/bpf/jump-relax-jump-be.d @@ -11,15 +11,9 @@ Disassembly of section .text: 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: 3d 12 00 01 00 00 00 00 jge %r1,%r2,1 + 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 ff ff 7f ff jal -32769 + 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 00 jal 32768 - 48: 1d 12 00 01 00 00 00 00 jeq %r1,%r2,1 - 50: 05 00 00 01 00 00 00 00 ja 1 - 58: 06 00 00 00 00 00 80 01 jal 32769 - 60: 2d 12 00 01 00 00 00 00 jgt %r1,%r2,1 - 68: 05 00 00 01 00 00 00 00 ja 1 - 70: 06 00 00 00 00 00 80 01 jal 32769 + 40: 06 00 00 00 00 00 80 01 jal 32769 diff --git a/gas/testsuite/gas/bpf/jump-relax-jump.d b/gas/testsuite/gas/bpf/jump-relax-jump.d index cd46ea7024e..dd31ba5f4e4 100644 --- a/gas/testsuite/gas/bpf/jump-relax-jump.d +++ b/gas/testsuite/gas/bpf/jump-relax-jump.d @@ -11,15 +11,9 @@ Disassembly of section .text: 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: 3d 21 01 00 00 00 00 00 jge %r1,%r2,1 + 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 ff 7f ff ff jal -32769 + 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 00 80 00 00 jal 32768 - 48: 1d 21 01 00 00 00 00 00 jeq %r1,%r2,1 - 50: 05 00 01 00 00 00 00 00 ja 1 - 58: 06 00 00 00 01 80 00 00 jal 32769 - 60: 2d 21 01 00 00 00 00 00 jgt %r1,%r2,1 - 68: 05 00 01 00 00 00 00 00 ja 1 - 70: 06 00 00 00 01 80 00 00 jal 32769 + 40: 06 00 00 00 01 80 00 00 jal 32769 diff --git a/gas/testsuite/gas/bpf/jump-relax-jump.s b/gas/testsuite/gas/bpf/jump-relax-jump.s index dabbab84f7c..3ee7c873320 100644 --- a/gas/testsuite/gas/bpf/jump-relax-jump.s +++ b/gas/testsuite/gas/bpf/jump-relax-jump.s @@ -5,11 +5,6 @@ ;; The following instruction refers to a defined symbol that ;; is on reach, so it should not be relaxed. jle %r1, %r2, 1b - ;; The following instructions are relaxed to sequences - ;; involving unconditional jumps, so they can fi their - ;; displacements. - jge %r1, %r2, -32769 - jgt %r1, %r2, 32768 ;; The following instructions refer to a defined symbol that ;; is not on reach. They shall be relaxed. jeq %r1, %r2, tail diff --git a/gas/testsuite/gas/bpf/offset16-overflow.l b/gas/testsuite/gas/bpf/offset16-overflow.l index 6404b1b2076..1fd0f94d0e2 100644 --- a/gas/testsuite/gas/bpf/offset16-overflow.l +++ b/gas/testsuite/gas/bpf/offset16-overflow.l @@ -1,3 +1,3 @@ .*: Assembler messages: -.*:2: Error: signed pc-relative offset out of range, shall fit in 16 bits -.*:4: Error: signed pc-relative offset out of range, shall fit in 16 bits +.*:2: Error: pc-relative offset out of range, shall fit in 16 bits +.*:4: Error: pc-relative offset out of range, shall fit in 16 bits diff --git a/gas/testsuite/gas/bpf/offset16-overflow.s b/gas/testsuite/gas/bpf/offset16-overflow.s index da9f633a337..ebd8e05c09e 100644 --- a/gas/testsuite/gas/bpf/offset16-overflow.s +++ b/gas/testsuite/gas/bpf/offset16-overflow.s @@ -1,4 +1,4 @@ - ldxh %r2, [%r1 + 32767] - ldxw %r2, [%r1 + 32768] ; This overflows + ldxh %r2, [%r1 + 65535] + ldxw %r2, [%r1 + 65536] ; This overflows stxw [%r2 - 32768], %r1 stxdw [%r2 - 32769], %r1 ; This overflows -- 2.30.2