From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id AB65B3858D37 for ; Thu, 25 May 2023 13:22:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AB65B3858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 90A091042; Thu, 25 May 2023 06:23:42 -0700 (PDT) Received: from [10.2.78.54] (e120077-lin.cambridge.arm.com [10.2.78.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 07FC53F67D; Thu, 25 May 2023 06:22:56 -0700 (PDT) Message-ID: <2856489e-2127-8ab9-4902-6b8c6ea343bd@arm.com> Date: Thu, 25 May 2023 14:22:55 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH] PR30437 aarch64: make RELA relocs idempotent Content-Language: en-GB To: Michael Matz Cc: binutils@sourceware.org References: <1ba7b2c7-b489-79af-3f2a-56450c86d955@arm.com> <1ed54fc8-8ba0-9106-377e-61400af6c00c@arm.com> From: "Richard Earnshaw (lists)" In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3493.0 required=5.0 tests=BAYES_00,KAM_DMARC_NONE,KAM_DMARC_STATUS,KAM_LAZY_DOMAIN_SECURITY,NICE_REPLY_A,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 25/05/2023 13:29, Michael Matz via Binutils wrote: > Hello, > > On Thu, 25 May 2023, Richard Earnshaw (lists) wrote: > >> Thanks for the detailed explanation. That makes sense, overall. However... >> >> I didn't think we had separate relocation rules for REL/RELA format >> relocs. I know that we recommend RELA for aarch64, but how would an >> object file with REL format relocs be handled if src_mask is always >> zero? > > Right now the aarch64 bfd backend only support RELA > (elf_backend_may_use_rel_p is off). elf64-mips is an example that > supports both, and it has separate howto tables for rel and rela > descriptors (e.g. mips_elf64_howto_table_rel and > mips_elf64_howto_table_rela), with the appropriate > src_mask/partial_inplace settings depending on rel/rela: > > HOWTO (R_MIPS_32, /* type */ > ... > true, /* partial_inplace */ > 0xffffffff, /* src_mask */ > 0xffffffff, /* dst_mask */ > > vs. > > HOWTO (R_MIPS_32, /* type */ > ... > false, /* partial_inplace */ > 0, /* src_mask */ > 0xffffffff, /* dst_mask */ > > the rtype_to_howto backend routine appropriately switches between those > depending on side-info passed in parameters. (Whereas the name_lookup and > type_lookup routines always use the rela tables and contain a FIXME > comment to that effect :) ). Various non-mips embedded targets try to > also support this, but often only for read-in, not for generating both > types of relocs, and so get away with only one howto table. (I believe (!) > mips is the only one that actively tries to get REL+RELA support correct). > > > Ciao, > Michael. I'd be surprised if even that is totally correct. ELF permits relocations of a single 'place' to be chained provided that they are of the same type (all REL or all RELA); not that I've ever seen that done in practice. When this is done the addend for the second and subsequent relocations use the result of the previous relocation - they must be processed in order. Only the last relocation in a sequence writes a value back to the location being relocated. So really, we shouldn't need two tables, we just need to know where to get the addend value from at the start of a chain. R.