From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-eopbgr150049.outbound.protection.outlook.com [40.107.15.49]) by sourceware.org (Postfix) with ESMTPS id 58279386F451 for ; Fri, 29 May 2020 15:05:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 58279386F451 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Alex.Coplan@arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KK1ZAoizjof2aqLY7/8uknTvfvUsSyUrRvIU8Xv2Huw=; b=qFQ04jPKwOI8vyCgm56gpLAAHQEfWnxHZTNewxjz8weFTMHXpQJSBP56b0VbQVqdTY6MHZGJWeu0AMYv19UtxUSMy9e2cNAyJ/+1iAAaMOZSbmhPaE47WeaXwGJ8fsXLL237A6PEzZeF3JTk9r5nSSC3hr5xRTp/qzDtOLkccpc= Received: from DB7PR05CA0061.eurprd05.prod.outlook.com (2603:10a6:10:2e::38) by AM0PR08MB3266.eurprd08.prod.outlook.com (2603:10a6:208:66::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3045.17; Fri, 29 May 2020 15:05:00 +0000 Received: from DB5EUR03FT046.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:2e:cafe::21) by DB7PR05CA0061.outlook.office365.com (2603:10a6:10:2e::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3045.17 via Frontend Transport; Fri, 29 May 2020 15:05:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; sourceware.org; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT046.mail.protection.outlook.com (10.152.21.230) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.23 via Frontend Transport; Fri, 29 May 2020 15:05:00 +0000 Received: ("Tessian outbound 444e8e881ac1:v57"); Fri, 29 May 2020 15:05:00 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: cc17e7b5fc1cc0d5 X-CR-MTA-TID: 64aa7808 Received: from f2c3b105ee65.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 57198399-3595-4CBE-B08F-04F349275272.1; Fri, 29 May 2020 15:04:54 +0000 Received: from EUR02-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id f2c3b105ee65.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 29 May 2020 15:04:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bTofMhRkGGmyjkYaDLn2mZPZb+CZ0NqrZOiEV7+uOwBfyLIHuDjwn3SQrhQ4oYimPeMPHiKLGM8kybVfpfjvJ6LFTDweBmIrpAW7xEY5vLlyujWZKe1CNEcnX/5v4CpGeqBo8heGzqaQxGHOjModjTRmNdjOlMDNVWiXzmxLRoge5OzaQbd8RjMifp+oLPrX92tyqGzRd1Ix2NVPNoFXmFL4qFupgRtLOAjlcyQ4eXLu9ZG66B51TS2DD1Ec+I7lB8JOKp3uF5goEuyoma3vScuKuihXb0mDM21t0v/OZOADGMyFoaFep/iwaqrP13RV0hxOK3W4JfBpj61ULE8RQQ== 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-SenderADCheck; bh=KK1ZAoizjof2aqLY7/8uknTvfvUsSyUrRvIU8Xv2Huw=; b=L//28weiCAv3Rq8ftDMUE0Vrpj7BIWM+S/fpfXlOgbfjJiX+llmqx/O/onSNUyB5ZF28ns3xdmAVXI4bkMa/kVU8N5KFHjaPSeNA7zFW+6DtK/xapp9dBxzGotnqBck08ildrlzNApWx4ihVaA64n7N3FWBR8I7BVOY49IxGqaHbjuNAye31TZqo+GTbWoH7P0y/ogdGQEzIVK1m8lhsV6lUrxjwM7WVatnA4+EBdFCrIV5+hEvku59piVQbTsUcTMNBblXnKld6wmA+CVQs24bsZrS3zJqgVLVtGjzTKI1C2Aas+Fq9RzDjNr/L1RjrFNI4MaGutZ6KAmA9h4CVbg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KK1ZAoizjof2aqLY7/8uknTvfvUsSyUrRvIU8Xv2Huw=; b=qFQ04jPKwOI8vyCgm56gpLAAHQEfWnxHZTNewxjz8weFTMHXpQJSBP56b0VbQVqdTY6MHZGJWeu0AMYv19UtxUSMy9e2cNAyJ/+1iAAaMOZSbmhPaE47WeaXwGJ8fsXLL237A6PEzZeF3JTk9r5nSSC3hr5xRTp/qzDtOLkccpc= Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from VI1PR08MB4029.eurprd08.prod.outlook.com (2603:10a6:803:ec::14) by VI1PR08MB3760.eurprd08.prod.outlook.com (2603:10a6:803:c1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3045.19; Fri, 29 May 2020 15:04:52 +0000 Received: from VI1PR08MB4029.eurprd08.prod.outlook.com ([fe80::88b4:476f:5960:5ae4]) by VI1PR08MB4029.eurprd08.prod.outlook.com ([fe80::88b4:476f:5960:5ae4%6]) with mapi id 15.20.3045.018; Fri, 29 May 2020 15:04:52 +0000 Date: Fri, 29 May 2020 16:04:50 +0100 From: Alex Coplan To: binutils@sourceware.org Cc: nd@arm.com, rearnsha@arm.com, marcus.shawcroft@arm.com, nickc@redhat.com, ramana.radhakrishnan@arm.com Subject: [PATCH] gas: Fix checking for backwards .org with negative offset Message-ID: <20200529150449.nhukb7pjbyo2cjf5@arm.com> Content-Type: multipart/mixed; boundary="eecascnf6m4aviwu" Content-Disposition: inline User-Agent: NeoMutt/20171215 X-ClientProxiedBy: LO2P265CA0022.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:62::34) To VI1PR08MB4029.eurprd08.prod.outlook.com (2603:10a6:803:ec::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from arm.com (217.140.106.50) by LO2P265CA0022.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:62::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3045.19 via Frontend Transport; Fri, 29 May 2020 15:04:52 +0000 X-Originating-IP: [217.140.106.50] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 24e15406-7ef1-417a-5ca0-08d803e1a874 X-MS-TrafficTypeDiagnostic: VI1PR08MB3760:|AM0PR08MB3266: X-LD-Processed: f34e5979-57d9-4aaa-ad4d-b122a662184d,ExtAddr X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:6430;OLM:6430; X-Forefront-PRVS: 04180B6720 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: p8QUIl7ER8volZrCi44665SmzDtbVMIhYuOyRJe2MEJIm4fkiQrJpFUNd3UZCGUOQ0UsrLMs0Yy4YpwPffZS3qNXSzelxw1mwVOlPlByi1dR1tb1Gd6r1lk/TnI0aZaPeGGFVt+N9iUS2mCxO986jILy/5mOloe232JDqbCYgfBK3T+5H1kQ15wKMNzJSAPSENa48TLf6Bveq/pKvVx/yufT/mvmwtVmYhbWsIgtOCWUhP5E/PKDEZfRre36+lUENptpBxK3IMB5i6juFieaZcNEm3aObBIh59VClG4lK/+bmXjaT0SDFss3sxJQ6Mjv8XfS3Z1SlGU0CBnGsqPlQoik01hQYu2gRtCd4tQ/0EyCTSe7EPtwJ8L6TO2yYTGC7M5bsbQ9wsv8fdyOr8IQPg0Hm6MfpWE6EWik30julJIovyENcVRd3+gEdufBY7lpJIN1GFLrjkujaY0wwKvmCAYLKCb4O9qIjB5P2ZxVM7s= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR08MB4029.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(366004)(376002)(346002)(136003)(396003)(39860400002)(6916009)(5660300002)(4326008)(8676002)(66946007)(55016002)(235185007)(8936002)(8886007)(66616009)(66476007)(66556008)(21480400003)(966005)(956004)(316002)(186003)(26005)(16526019)(1076003)(44832011)(2906002)(83380400001)(52116002)(36756003)(44144004)(33964004)(478600001)(2616005)(86362001)(7696005)(142923001)(2700100001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: nW3pWhIYlOAv36vTubME/SBCtXbgVNuvgvPgdyePZOCyI4fwq3fCPqqmWD59uND5YPDZzKZI8g4Wa8hfuH2lqNyZPginqGw2ixnTWfwtkMu1bMxGWmPtGOw+rEJJvCbCj7bZzlkNFB4Ax9LyhUavu6A1O6C8hl/0O0JI2+HFnz0NpXk3tCoXnxD/JjyPnehE9mCP1i/GXe/3o+C3x/C8RYlgMazdCDVRszq87YqlUbuq9oHzJir/Ab34i1ACaKP4GmADp6iBh3fMPA1KR5kcb/QQgp+mvsb2dhamiSS0OQkVjUfB+f3H7Xu9Z9qSkdhnkAEWmev1YneYJ5d2Jh93OuO5FLmLGBtny6dAr+SpLHbHwzOotyvICvD1jppF1hXZIgo00jb/kbp5oZQoWSvuFZZBjPUjbBJ7BhynDaKubTYxUWWVnpW6KhjshL6Jj5jtqafAQfnZVsmvXMX7sWIOE2euxRkTe9eFpLxPNHTVr2KJfl9WWw1677KLtJ3nl3BJ X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB3760 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT046.eop-EUR03.prod.protection.outlook.com X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFTY:; SFS:(4636009)(396003)(136003)(346002)(376002)(39860400002)(46966005)(86362001)(6916009)(4326008)(7696005)(82310400002)(47076004)(186003)(356005)(81166007)(55016002)(70586007)(70206006)(316002)(82740400003)(66616009)(16526019)(8936002)(36756003)(478600001)(966005)(26005)(21480400003)(336012)(5660300002)(44832011)(8676002)(235185007)(33964004)(83380400001)(956004)(2616005)(2906002)(44144004)(8886007)(1076003)(142923001)(2700100001); DIR:OUT; SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: aa311dc7-5e38-4437-b37e-08d803e1a3ef X-Forefront-PRVS: 04180B6720 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6Y2pMTKjR0vsNcBLmkZNxrmIxU1giiHkEHY97qABNhdAtcyKyHHIZu3FSMWWwXP75hpxhZIW0dXP341gRrFvYXAWZ9GUfeeCCDqWo+VzjeY57F38LY/K0ClRsOERqI7a6WjVRqUvcaNd10pytETq03JhZMpf1qzfeL+7rsnHLbyfcsIuYh/YHZ5jc4CWXSWsUjwmutcaT7leGq4uJ8+Q1NYcecIQoFy4nuW9prxl9bV0kKPwHFtKkCou/+sD+FbJ+UtETv1PxkTHzRXQGS8Zu1Lyp41EX8LCO7JEZc0cvMNTDLRbSpRIRACCVbh8sZKr8WR6U7zNv6TjUP8Sz3p4s43j5ufgh744N0/uibFEOork8e6FXkT/hQ3wwsFNQmyMYkC+dzrOBZ1Br5bquwP3JIXD8QS3s/fhGpELz4wYAq9fuloYf1oq9oJcbLYBCWxdFETr3957ZCv7jUjWXZkjDTs/zS3fLwrfPA6y8yxKuxPCO0fTKBDfeeeelwRY/CpKunL5okiXXPaYl9XK/PpvUA== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 May 2020 15:05:00.1578 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 24e15406-7ef1-417a-5ca0-08d803e1a874 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3266 X-Spam-Status: No, score=-19.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, 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: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 May 2020 15:05:05 -0000 --eecascnf6m4aviwu Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Hello, This patch fixes internal errors in (at least) arm and aarch64 GAS when assembling code that attempts a negative .org. For example, assembling: .=-1 nop would give: test.s: Assembler messages: test.s:1: Error: attempt to .org/.space/.nops backwards? (-1) test.s: Internal error in check_mapping_symbols at ../../../binutils-gdb/gas/config/tc-aarch64.c:8557. Please report this bug. on aarch64, and: test.s: Assembler messages: test.s:1: Error: attempt to .org/.space/.nops backwards? (-1) test.s: Internal error in make_mapping_symbol at ../../../../src/binutils-gdb/gas/config/tc-arm.c:3017. Please report this bug. on arm. The bug appears to be a regression introduced in binutils-2.29 by this commit: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=9875b36538d35f2292ddc3bb5e7c60e1582aa087 The problem is in the rs_org case of the main switch statement in gas/write.c:relax_segment(). This code assigns the signed variable `offset' to the unsigned variable `target' and then proceeds to do an unsigned comparison: if (address + fragP->fr_fix > target) which fails in this case because `offset' was -1 and so `target' wrapped to become UINT64_MAX. This patch uses a signed type for `target' and casts the LHS to ensure a signed comparison is used here. Testing: * New tests for arm and aarch64. * Regression tested on a wide variety of targets. * Bootstrapped on aarch64. Ok for master and backport to binutils-2.34? Thanks, Alex --- gas/ChangeLog: 2020-05-29 Alex Coplan * testsuite/gas/aarch64/org-neg.d: New test. * testsuite/gas/aarch64/org-neg.l: Error output for test. * testsuite/gas/aarch64/org-neg.s: Input for test. * testsuite/gas/arm/org-neg.d: New test. * testsuite/gas/arm/org-neg.l: Error output for test. * testsuite/gas/arm/org-neg.s: Input for test. * write.c (relax_segment): Fix handling of negative offset when relaxing an rs_org frag. --eecascnf6m4aviwu Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="patch.txt" diff --git a/gas/testsuite/gas/aarch64/org-neg.d b/gas/testsuite/gas/aarch64/org-neg.d new file mode 100644 index 0000000000..83e6af6afb --- /dev/null +++ b/gas/testsuite/gas/aarch64/org-neg.d @@ -0,0 +1,3 @@ +#name: negative org should not cause internal error +#source: org-neg.s +#error_output: org-neg.l diff --git a/gas/testsuite/gas/aarch64/org-neg.l b/gas/testsuite/gas/aarch64/org-neg.l new file mode 100644 index 0000000000..f8414adc19 --- /dev/null +++ b/gas/testsuite/gas/aarch64/org-neg.l @@ -0,0 +1,2 @@ +[^:]*: Assembler messages: +.*: Error: attempt to move .org backwards diff --git a/gas/testsuite/gas/aarch64/org-neg.s b/gas/testsuite/gas/aarch64/org-neg.s new file mode 100644 index 0000000000..403e70d5e0 --- /dev/null +++ b/gas/testsuite/gas/aarch64/org-neg.s @@ -0,0 +1,2 @@ +.=-1 +ret diff --git a/gas/testsuite/gas/arm/org-neg.d b/gas/testsuite/gas/arm/org-neg.d new file mode 100644 index 0000000000..83e6af6afb --- /dev/null +++ b/gas/testsuite/gas/arm/org-neg.d @@ -0,0 +1,3 @@ +#name: negative org should not cause internal error +#source: org-neg.s +#error_output: org-neg.l diff --git a/gas/testsuite/gas/arm/org-neg.l b/gas/testsuite/gas/arm/org-neg.l new file mode 100644 index 0000000000..f8414adc19 --- /dev/null +++ b/gas/testsuite/gas/arm/org-neg.l @@ -0,0 +1,2 @@ +[^:]*: Assembler messages: +.*: Error: attempt to move .org backwards diff --git a/gas/testsuite/gas/arm/org-neg.s b/gas/testsuite/gas/arm/org-neg.s new file mode 100644 index 0000000000..f60486e2c8 --- /dev/null +++ b/gas/testsuite/gas/arm/org-neg.s @@ -0,0 +1,2 @@ +.=-1 +nop diff --git a/gas/write.c b/gas/write.c index 5825117548..398c50bec0 100644 --- a/gas/write.c +++ b/gas/write.c @@ -2940,7 +2940,7 @@ relax_segment (struct frag *segment_frag_root, segT segment, int pass) case rs_org: { - addressT target = offset; + offsetT target = offset; addressT after; if (symbolP) @@ -2960,7 +2960,7 @@ relax_segment (struct frag *segment_frag_root, segT segment, int pass) /* Growth may be negative, but variable part of frag cannot have fewer than 0 chars. That is, we can't .org backwards. */ - if (address + fragP->fr_fix > target) + if ((offsetT)(address + fragP->fr_fix) > target) { growth = 0; --eecascnf6m4aviwu--