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.109.102]) by sourceware.org (Postfix) with ESMTPS id 61FC0385843D for ; Fri, 25 Feb 2022 11:20:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 61FC0385843D Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-db5eur03lp2054.outbound.protection.outlook.com [104.47.10.54]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id de-mta-9-_o__RSmrPKidqn3wg0k4Gg-1; Fri, 25 Feb 2022 12:20:54 +0100 X-MC-Unique: _o__RSmrPKidqn3wg0k4Gg-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=asQqIhKCPrSEqkq9zOg4jPnFzv23Cn2Vsjayrj6+qCiBnGT0BSlv/KYi1ikVUTQSBdo6rGUmwLPu5llw1Bn7XFCOLpMBJdS3S0k8ZXNyl18dYtg3uXayRiTX/ijop+YFWSnUpkJfUp525yPyGBrmgSQbqc0IZOPaqS+YvR9FqIzqVKA1F/EORKT1TU1a7V0SefmdW6KKTZROa4yXofX5DUCi/MPpPtjm3DkaUTWbCAWrYG5K8FWGHGc55hqXcicsl5QmXp+xMVI4F4Rd5xG/MbPhH1lCT+e8Xtx7hiPdIYycv+FWQuLXi044LYNzVKmv2vQRUJE27fF99o5T4XSurQ== 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=NH60QBUUyw41WMgofy057QgKRILT4l1QTywVSCRFi6k=; b=Vu+CkhkhrVUuvIjACdJiGNwqPEby+FrqUEdCK5nDU0glZm/I1q6NaBFn1duowYoGw0jdStL4PnVBS4VBj5tocW/PAghp5L7XSwoOVcCmlBhbWlUctoTtU+vjRvymHsJz52k6kwKhJ3+RMn1oVEXJg9Gszhh9iIkHh50MvMVYMmNvK00qf/y+B47DU67Wj8l24rqTb0m4sTxwwZ9kBZLjWBuYPzZtZRRTgSy+QkDNouP8xu1+UERFwbP8+iHt/FmwPzy+rwtyZekX+SJcSFlZyVpT8BF8+HsRFxWzi92VjUwc1YPyO1jpw7pfBT991fZkxpPKnnQsD53faVC5iebHdQ== 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:20:52 +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:20:52 +0000 Message-ID: <3502746c-2308-33bf-919b-4248548024c3@suse.com> Date: Fri, 25 Feb 2022 12:20:50 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: [PATCH 2/2] ELF32: don't silently truncate relocation addends 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: AM6PR04CA0052.eurprd04.prod.outlook.com (2603:10a6:20b:f0::29) 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: 63537274-3d13-400a-a12a-08d9f850e21b 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: PEA3ItPQiLNItZT66DMuzKwhRm4Wnb2pghrPij4/3baOy9jEntKOwqvmkEbzOCXdKfNY5fU5OXK3bQBArmAHCPz9O3HEL4YeT/3m0tHBAEoY9xBsRjdCG7zV32u0/LbaAp/zLbVisuLbmP9iOOIj6R2w5bB1OZ0EEvmwtTnUcnaNMrx8xs9Mdm7lVpYXOLpyRpURkppen66WVft7YR8IAfWzSmk3Fjpav09U1B50p/udshqXUOC9ItHRZK9wtoC+7BjarmqEZoYzwEZtucuVO0ltweh5nPrz0/rqS3AcuYd9ff10rhsv7Uy5tFc6v+rGGYRvfOnuaOh9ImGfDfgE05kUdWXbsuMPqmOKnVQMBDHG9Hb2amqTdNBnxOncOe9a8JmvO9NaxZ7BjPDokIpei5QyWnEQhOkLhK2HwCXrW9ZVDPQXIv6GYSsfb28ZAVoGF0IMAJbyRZPsOAwGWIzC2t192NuyuDem6nDvzrpCZgqCwPy7kV+BJe1RfQyjWmtREwJp0lrFEMNOEi8M28prG5RqtGF8TstiKehM50NaISoDkvKui5NWhesAvqAlrT1UYjhOm/h625CNzczkcqvuT6fgW2KOXHT+ay8J7H1uKor3ktVFiDID692bJ9qngvhp/QTGCxn4zZUqkwmmnY01CH+om0we/EPeR8pYgtRiTPyH18lSss1pZVFl2OedqJWFaoKtmf3QW70hAY4xt2W4uVj5aXyg5nzhKHwbOLj50aQ= 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)(54906003)(316002)(66476007)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?bkpNZ2lTYUhqZXpXRXBLVWQ4VytnRzUraW83aWt1czBNWm5PQWFUQU0reG4z?= =?utf-8?B?TXdZOU5xalQyWWhUSnV2MFh3djNWWGR1ZnNxS0FqOGhxNG9JQzhRdEJ0ZUxP?= =?utf-8?B?ZThyUnQySlFpd2cxYlIwYmYxRzB3dTBDWmRRU3NGWTYxVmt4UjZONlJoSmFJ?= =?utf-8?B?d3krNzQyYU93U3FrQkRzZWRDN1BqZk01d2lJZ3RXMUR0RFphblB6bmg3VlF2?= =?utf-8?B?bHUwZjV0L3AwSGhBOVlqQmJLbGQwZytTTU9FMGtZUUVJbWRndlFVcmpGdVp2?= =?utf-8?B?UnJSaS9wUHhyQU5OL2pTeTlNSU5hbzFKcDJhVGZpN1dTRi81cnlremVjRnlT?= =?utf-8?B?ZFFSWVgyT1VhR0J2ZEpIc0hzNkMxR25tU1JqVXNyLzNsYnJkZTRMcVJSb2xa?= =?utf-8?B?MWVTNEc5UjZkZE5jQk5QV0hMYzhvOVVPSW5lZ0Q0N1Jrb2lNbWFJWEtSRW9D?= =?utf-8?B?V3o0ekdXUUpGRU1vUklUQkxab3g4eCtoZ0h6dy9jaVNJdDBVTGwySUNsM2Js?= =?utf-8?B?VHRnVFNLdTVURndMSFRrN0RFNCtRd2IzVHpnbC9yMWpiUmFUTFIrNUZ4OC84?= =?utf-8?B?U0M0U0JwYkxTNTgrVktQK21QeGdaUW9abXg5b2lmL044V012WWdBTllTUmc0?= =?utf-8?B?UVYrL1VWRzdOK1E0QXluVzlaUlhWbExCL1FhQVBJODlBa3hiSjluUzEzUnJz?= =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3FRd01SNGd5?= =?utf-8?B?YWhuL2FmLzFNOXdsZkR5cEJMeDh4TVVhSEZzN2VQYTIrdW1vQnJqOWNVdUhz?= =?utf-8?B?Wk5CM2N6dnplL3FyeFNwclVCRmJLdGc1bDJtcjdjaU5XSzBpd3I0QTZuSU10?= =?utf-8?B?LzVFZHg3M1RmNG1rdFNsY092WmM4a2JmN1grWXJ5ZFBMbGQxbkZCRG9hL2Rs?= =?utf-8?B?Wi9VNjd4THdob0dNSHU5WGJBRkIvL2RENkR0T0ZKZXczSTNoeFJOdGxHWVFm?= =?utf-8?B?US9CV0V2d3h0U1NYWUN2RCtkTFNJcE5KUWZtZXhiVUhTUHg2YTF5WkUrSkI0?= =?utf-8?B?Y1haWEFmYVZHNUtDNGdrbjhoTWMxa045azRwTUU5OTZJSW8raERUazk1NjZG?= =?utf-8?B?Vzl2d2k4blhXaGx2MU8vWHlqdzk3ai8xeEFqbGhXMkluaEFLWUU1QkI4Ym5R?= =?utf-8?B?WTBtUDh4UUs5Y1dYd3B5RGM3MmZFNHN3citqV0tIa3c5NUtVS3pMTUE4Sncy?= =?utf-8?B?OTEvcW5tanVsbGNXTHM1b2JWNDlvMHdRaURHTytUVmJFRStMSW82NUZRdlBF?= =?utf-8?Q?rxq8rHOmAgwrZN64aadko30=3D?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 63537274-3d13-400a-a12a-08d9f850e21b 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:20:52.5575 (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: Ch4hW/O0Oynhs88wSn8GGCBmlEzZxZ5/Chf8mlXLQml8b886dUNI74mCXgAi+soHkfop2ibfIAYneS1tUnAEhw== 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:20:58 -0000 At least x86-64's x32 sub-mode and RISC-V's 32-bit mode calculate addends as 64-bit values, but store them in signed 32-bit fields when generating the file without encountering any earlier error. When the relocated field is a 64-bit one, the value resulting after processing the relocation record when linking (or the latest when loading) may thus be wrong due to the truncation. With the code change in place, one x32 testcase actually triggers the new diagnostic. That one case of too large a (negative) addend is being adjusted alongside the addition of a new testcase to actually trigger the new error. (Note that due to internal BFD behavior the relocation in .data doesn't get processed anymore after the errors in .text.) Note that in principle it is possible to express 64-bit relocations in ELF32, but this would require .rel relocations, i.e. with the addend stored in the 64-bit field being relocated. But I guess it would be a lot of effort for little gain to actually support this. --- I guess this may not be the only place which wants such a check, but at least this looks to be one central place. Originally I had the conditional as if ((int64_t) ptr->addend != (int32_t) ptr->addend) but I thought it would be better to avoid the non-portability of the conversion from unsigned to signed types. Afaict the way it is now it ought to be portable, as it involves only a signed->unsigned conversion. --- a/bfd/elfcode.h +++ b/bfd/elfcode.h @@ -997,6 +997,17 @@ elf_write_relocs (bfd *abfd, asection *s return; } +#if defined(BFD64) && ARCH_SIZE == 32 + if (ptr->addend - INT32_MIN > UINT32_MAX) + { + _bfd_error_handler (_("%pB: %pA+%"BFD_VMA_FMT"x: " + "relocation addend %"BFD_VMA_FMT"x too large"), + abfd, sec, ptr->address, ptr->addend); + *failedp = true; + bfd_set_error (bfd_error_bad_value); + } +#endif + src_rela.r_offset = ptr->address + addr_offset; src_rela.r_info = ELF_R_INFO (n, ptr->howto->type); src_rela.r_addend = ptr->addend; --- a/gas/testsuite/gas/i386/ilp32/ilp32.exp +++ b/gas/testsuite/gas/i386/ilp32/ilp32.exp @@ -38,6 +38,7 @@ if [expr ([istarget "i*86-*-*"] || [ista } run_list_test "reloc64" "--defsym _bad_=1" + run_list_test "reloc-2" set ASFLAGS "$old_ASFLAGS" } --- /dev/null +++ b/gas/testsuite/gas/i386/ilp32/reloc-2.l @@ -0,0 +1,4 @@ +.*: \.text\+2:.*addend.*too large.* +.*: \.text\+b:.*addend.*too large.* +.*: Assembler messages: +.*: Fatal error: .* --- /dev/null +++ b/gas/testsuite/gas/i386/ilp32/reloc-2.s @@ -0,0 +1,7 @@ + .text +_start: + movabs $x+0x123456789, %rax + movabs x+0x123456789, %eax + + .data + .quad x+0x123456789 --- a/gas/testsuite/gas/i386/ilp32/reloc64.d +++ b/gas/testsuite/gas/i386/ilp32/reloc64.d @@ -61,7 +61,8 @@ Disassembly of section \.text: .*[ ]+R_X86_64_TPOFF32[ ]+xtrn .*[ ]+R_X86_64_TPOFF32[ ]+xtrn .*[ ]+R_X86_64_TPOFF32[ ]+xtrn -.*[ ]+R_X86_64_64[ ]+xtrn\+0x1 +.*[ ]+R_X86_64_64[ ]+xtrn\+0x7fffffff +.*[ ]+R_X86_64_64[ ]+xtrn\-0x80000000 Disassembly of section \.data: #... .*[ ]+R_X86_64_32[ ]+xtrn --- a/gas/testsuite/gas/i386/ilp32/reloc64.l +++ b/gas/testsuite/gas/i386/ilp32/reloc64.l @@ -51,17 +51,17 @@ .*:175: Error: .* .*:176: Error: .* .*:177: Error: .* -.*:189: Error: .* -.*:192: Error: .* too large for field of 4 bytes at .* +.*:190: Error: .* .*: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 .* +.*:196: Error: .* too large for field of 4 bytes 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 .* +.*:198: Error: .* too large for field of 2 bytes at .* +.*:198: Error: .* too large for field of 1 byte at .* +.*:201: Error: .* too large for field of 4 bytes at .* .*:202: Error: .* too large for field of 2 bytes at .* -.*:203: Error: .* too large for field of 1 byte at .* +.*:203: Error: .* too large for field of 2 bytes at .* .*:204: Error: .* too large for field of 1 byte at .* +.*:205: 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 @@ -178,7 +178,8 @@ bad .byte xtrn@tpoff .text mov xtrn@tpoff (%rbx), %eax - movabsq $xtrn - 4294967295, %rbp + movabsq $xtrn + 0x7fffffff, %rbx + movabsq $xtrn - 0x80000000, %rbp .data .quad xtrn