From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [194.104.111.102]) by sourceware.org (Postfix) with ESMTPS id 4AE393858432 for ; Fri, 25 Feb 2022 11:19:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4AE393858432 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04lp2052.outbound.protection.outlook.com [104.47.14.52]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id de-mta-8-i32dHnJROd6MGtjwjwMb7g-1; Fri, 25 Feb 2022 12:19:46 +0100 X-MC-Unique: i32dHnJROd6MGtjwjwMb7g-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HQ6V+pEbPOH0Ua80qgMvUz8RYyVBheUxpRFv8hSB0/gNjQueS6tJO01ogkDHaTWj1Pp70FS5cxOALvnv5Yw4UEjV1JYEQTEemgWBYdDe2EElIW8WrtviiUyW4BUwRawYQlZ859qjzjwpVOGpInsG/+7yxZ2Yspa1mq52RAbyPVjgbctIWW9zZIgjsfc6SYlXe4GabY7iMrlZYfWCL9oq0jg7nfBxRPxFVOOmZYxapBBXsZdN6x6XomDuNcll903SzhGDFaKcBdZxfnAsK1tB6pBVYP6Bqk1f88bZZRu6tJRoQ5t2+3jK3+ilmnSgdMUenddAbpzpJHqbXTaWlmVuaw== 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=SVABVKQiDl0CUfPYNVa/kO1NcNiO+n1p2WfvYDKvY6g=; b=YqDZuHr1f+sbILSKJyjDxjt9Y4L9+4NHvRCOFzQ6lNHBoqqvKJPlgnFSu0GNhVg8booR7RuqKidKbDLmEVe9AiIfdOjFrcjIGmqivWOruFz5pwtmGiFJ5Fs94A3MV8AtBGyDg0GimNZ5l/evVBQErpXABZHWhD8GKGKnsZDSj+Z9mr8cyEF9C2bVUqaZ90RQOKrXuxTn+x3Q/Cp4AXV649WGY7V5BacgVyHMGRpvPlkMAURf7hbbgWJ67q4nwEoYNc0Nb6O7J3JMOoF/bK5qnuILZ8yZpGUeFMyAyusFlBuloUdoNoBDqFRhwfpB7OOO7kENqpgPaeQKMFCcdpi+dw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Received: from VI1PR04MB5600.eurprd04.prod.outlook.com (2603:10a6:803:e7::16) by VI1PR0402MB3567.eurprd04.prod.outlook.com (2603:10a6:803:c::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.24; Fri, 25 Feb 2022 11:19:44 +0000 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::d479:b728:345c:bd65]) by VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::d479:b728:345c:bd65%6]) with mapi id 15.20.5017.025; Fri, 25 Feb 2022 11:19:44 +0000 Message-ID: <9d8645a1-c97d-ef32-0f96-366f0ae43f06@suse.com> Date: Fri, 25 Feb 2022 12:19:42 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: [PATCH 1/2] x86: don't suppress overflow diagnostics in x32 mode Content-Language: en-US To: Binutils References: From: Jan Beulich In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: AM6P192CA0080.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:8d::21) To VI1PR04MB5600.eurprd04.prod.outlook.com (2603:10a6:803:e7::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dfb351dc-4775-4857-d6ed-08d9f850b97e X-MS-TrafficTypeDiagnostic: VI1PR0402MB3567:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yfnjYKBGrBJ0gBc+3OqpwxKP6727u5ARY5XPNgYKsIZzQxwLt/mqpD5rmSl8u1Vmz3PSIDpwqqRcWQPYvfMVoOvFwX/CdK7nQvteAjw+LKftlD+SF/aNW6F5d3z3Lo3DpAnQcGWYXvV6rb26eX1uUz/t7rJkXfGeCqhIiluXj1hiI3Xs0gbozBM1ZC6YWN7v+EE98WB7SYSSLKFiSQwoCmb6zdZkUNXoNmqbVX9EexsXvz1oQLkpq5yRaD80fcLifFVgkPNDyGs2H57c0m/F7ILzCreCiifvBnw1slQMxEOiIJoU3KzWZc7NjxcRdAY3EQJQ6tvpmib7oVL5yLlTGZ5kO/97mOZWUiXWKHiLZ3MDWlr7xmD1J7RfDCMggLSWMO7baIMapRnUEbI+ZWdZGxh8vZCJIGvWTS4dPUrl+IVCrHQzrRu+LpdfVI55/5Yy9cTlGoN391M8rGDSF22TkVRveVhsl6BD3eEgGQuBLjwULeaz2XjjbwNk9u1nAupZ03Ve+twym5gBsplswyk1/2oQeZSOsWsKb7n6oRUpFYGcWuxkUYm0BhEKxDQBu582wCS1m9xdogEmiEub0d5BQvIfmRF6Wc4sJ0guoLPGAF/Rwda9RfYVibhD1JZsUEi4SNgR3UMXMNkoOuApVLNrJShg1Xl1gQQXV9MqrRcffnHpoZuo7WUdIva200FbXOPiqilRccj+9oa+9KP+hnUM/V8+QhGp4wy8e4TUUpsD+t6k5yFEPVg1JDAuBA7xCkVy X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5600.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(5660300002)(2906002)(86362001)(186003)(36756003)(6486002)(26005)(508600001)(31696002)(83380400001)(38100700002)(66946007)(6506007)(8676002)(4326008)(31686004)(6512007)(66556008)(6916009)(2616005)(8936002)(316002)(66476007)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?TmtJazNuN25NbGl3T0Q5YzhiMmx2aHFNT2RmOWdIRk5XSHJXdXlkZVRKTnhq?= =?utf-8?B?TnJpemFrR0pXNUxZbVRkVGhSOWRId1MwYXA4cWMwemwwVkJ5R0lsL0VvNmV5?= =?utf-8?B?cW9CRXZZR1ZYaXhpZlhSeUZuejdPcUJTSUxUMElmbnArQ1oyVVY5V3lpYkd4?= =?utf-8?B?M3FHZUxUTnlJR3hpQzJDUlVGMkdNdkhadHBwZ2ozUkF6S1dJWWZoSjVQblFK?= =?utf-8?B?YlR3Lyt0Zzl6enB6R3ZxcFdnb3ZXbWJXNzlIQ2JaNGV4bWJyb09aNHZZVlN3?= =?utf-8?B?NmwrTzFBY29CcGNXQXdvVUR0UHBQeStvRW9SMmFVR0FzcGxlVHVVY2VCOUV4?= =?utf-8?B?YzErVmhWdnBtQzBLM2hYVkplUW5wVWc3N0VJbE1VUnh6ZEN1bGt6b3UxZDVP?= =?utf-8?B?NGtHM09oUWhCcW5vcEdCTnhJRFNsWGlLU2toM3ZoalpTaUwyTjBDbjNlVURL?= =?utf-8?B?MWoyVEphNWJKbmhUa1FKU1J3TGFMc1ZuTXoyenk3cTFLbG42ajV2ZUJGL0pW?= =?utf-8?B?aUVoR2NCRFJVREx6cHBIWFEzMDJicVFwN1I2K2ErK2l6MWVYRU4yK1BKOUk0?= =?utf-8?B?NEJ2TVpGT05oNGx0bnFmcnlWNkhaM0lhelk1emVKYmd6QUZDcEQ3a0F0WU9y?=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aa0R2?= =?utf-8?B?WVUvWjZvL25JZWZuRW81RVdLYVErdytncW5xZWE0dkpTbVBmT0RSbU9WdjF4?= =?utf-8?B?K2JlZnpReXBaejJuS1RLRXZCNGRVd3Jpay9Xd0l0MkFTWXJZMUR1YkRCNzdB?= =?utf-8?B?ZDd4Yk9KRy9YZXFpbWVzd25aT0RWS2dqL0hZektTT2VLOThZZkxaWEhyMWc3?= =?utf-8?B?VFIvS0JnYkpTbmpxNUNhUnJNVjdKZlhjQlFjRGoxYUEvdGxXTjFHZ0xyR1Bo?= =?utf-8?B?WDk4d1JNTGxqQ3d1WUpWNnV2TW05eFpZcytRN2E4bU1oc25tQ0FNTHNVMVUv?= =?utf-8?B?SU5wTGs3cG1BOU52MnQ0TU5idE1RRGc3SU5aaG5TQ05qZXVLRnNlVEY3Qmgw?= =?utf-8?B?akZpZkZHWjU4Q0Y4amZ0ay9uS1FpcldlNTk2YWdyYmoyZDRuOEdyb1YvQVRF?= =?utf-8?B?NEJSd0xmYUtlVG1qQVZyNjZpejlteUdvdHp5aGJHck9wZUpQbzdjWmpnTERQ?= =?utf-8?B?NnBySEFCUXZZM2EzY1lkR2pRbUhjN1psMU9ZT2RtZ2hUa0tnR1lXaHFUK1lk?= =?utf-8?B?SFZNc0V0ZFNZUTN1YVZ6UHNQakhCT2NFL2xCOFFJcTgveGp6ZkVsMWZuWU9n?= =?utf-8?Q?h9lgk0bkpH9RpTsUo0TJdvc=3D?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: dfb351dc-4775-4857-d6ed-08d9f850b97e X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5600.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Feb 2022 11:19:44.5305 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: IrRTNzGIUQ5ZqPQvrAwUUs5amw6/iWkJ2yIm2LSb2FsxC4JEyfyf9BXf9hV/KQYDqO6Bu3Ei09NpCX9YrHBsuw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3567 X-Spam-Status: No, score=-3032.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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, 25 Feb 2022 11:19:49 -0000 Unlike in 64-bit mode, where values wrap at the 64-bit boundary anyway, there's no wrapping at the 32-bit boundary here, and hence overflow detection shouldn't be suppressed just because rela relocations are going to be used. The extra check against NO_RELOC is actually a result of an ilp32 test otherwise failing. But thinking about it, reporting overflows for not-really-relocations (typically because of earlier errors) makes little sense in general. Perhaps this should even be extended to non- 64-bit modes. --- After 862be3fb9a6d ("Disallow 64bit relocations in x32 mode") introduced the checking for 64-bit relocations in tc_gen_reloc(), d7921315bafb ("Check R_X86_64_32 overflow and allow R_X86_64_64 for x32") removed BFD_RELOC_64 from the set again. Hence besides the error messages triggered by the change here for 32-bit (and smaller) relocations, for that 64-bit one some diagnostic is needed as well. But that'll be the topic of another patch, as that's affecting at least RISC-V as well. Of course I have to admit that I don't really see why e.g. BFD_RELOC_64_PCREL cannot be represented (as the diagnostic puts it) - it's all a matter of whether the addend fits. The relocated field can hold all values. As to NO_RELOC: While looking around I didn't find uses of this value which aren't accompanied by as_bad() invocations. Yet I'm still somewhat uncertain whether the added check may not end up suppressing necessary overflow checks. Note that the as_bad() triggered here is actually unhelpful: It reports the already truncated value (which does fit in 32 bits), leaving it to the user to infer that the real value was actually larger. Note further that similar diagnostics ought to be emitted for 32-bit code, but they are hidden by the effects of a442cac5084e ("ix86: wrap constants"). That change effectively dealt with one aspect of inconsistencies between BFD64 and !BFD64 builds by introducing another one: Numbers wider than 32 bits ar represented as bignum in !BFD64 builds, and bignums won't be accepted as relocation addends. Hence we have yet again a case where code would assemble in one case, but encounter errors in the other. It _may_ be acceptable in this case, where wider-than-32-bits values are supplied from the source file rather than being the result of calculations overflowing in 32 bits. --- a/gas/config/tc-i386.c +++ b/gas/config/tc-i386.c @@ -12790,7 +12790,8 @@ md_apply_fix (fixS *fixP, valueT *valP, #endif else if (use_rela_relocations) { - fixP->fx_no_overflow = 1; + if (!disallow_64bit_reloc || fixP->fx_r_type == NO_RELOC) + fixP->fx_no_overflow = 1; /* Remember value for tc_gen_reloc. */ fixP->fx_addnumber = value; value = 0; --- a/gas/testsuite/gas/i386/ilp32/reloc64.l +++ b/gas/testsuite/gas/i386/ilp32/reloc64.l @@ -52,3 +52,16 @@ .*:176: Error: .* .*:177: Error: .* .*:189: Error: .* +.*:192: Error: .* too large for field of 4 bytes at .* +.*:193: Error: .* too large for field of 4 bytes at .* +.*:194: Error: .* too large for field of 4 bytes at .* +.*:195: Error: .* too large for field of 4 bytes at .* +.*:196: Error: .* too large for field of 2 bytes at .* +.*:196: Error: .* too large for field of 1 byte at .* +.*:197: Error: .* too large for field of 2 bytes at .* +.*:197: Error: .* too large for field of 1 byte at .* +.*:200: Error: .* too large for field of 4 bytes at .* +.*:201: Error: .* too large for field of 2 bytes at .* +.*:202: Error: .* too large for field of 2 bytes at .* +.*:203: Error: .* too large for field of 1 byte at .* +.*:204: Error: .* too large for field of 1 byte at .* --- a/gas/testsuite/gas/i386/ilp32/reloc64.s +++ b/gas/testsuite/gas/i386/ilp32/reloc64.s @@ -187,3 +187,18 @@ bad .byte xtrn@tpoff .long xtrn@got - 4 .long xtrn@got + 4 bad .long xtrn@plt - . + + .text +bad add $x+0x123456789, %rax +bad add $x+0x123456789, %eax +bad add x+0x123456789, %eax +bad add x+0x123456789(%eax), %eax +bad enter $x+0x123456789, $x+0x123456789 +bad enter $x+0x12345, $x+0x123 + + .data +bad .long x+0x123456789 +bad .word x+0x123456789 +bad .word x+0x12345 +bad .byte x+0x123456789 +bad .byte x+0x123