From: Michael Matz <matz@suse.de>
To: "Richard Earnshaw (lists)" <Richard.Earnshaw@arm.com>
Cc: binutils@sourceware.org
Subject: Re: [PATCH] PR30437 aarch64: make RELA relocs idempotent
Date: Thu, 25 May 2023 14:12:04 +0000 (UTC) [thread overview]
Message-ID: <alpine.LSU.2.20.2305251357390.13548@wotan.suse.de> (raw)
In-Reply-To: <2856489e-2127-8ab9-4902-6b8c6ea343bd@arm.com>
Hello,
On Thu, 25 May 2023, Richard Earnshaw (lists) wrote:
> 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.
Sort of, except ... it's not just for a chain of relocs (to the same
place) steming from a single input file, but also about the similar
situation when the same place is relocated multiple times due to 'ld -r'
or pre-existing (non-zero) section content in an input file to a final
link. In this situation it's not easily determined what's the start of a
reloc chain.
I still agree with you that abstractly multiple howto tables shouldn't be
needed, because RELA relocs _always_ should ignore section content on
read-in, and hence the reloc routines could simply special-case the
RELA/REL distinction by just not looking at src_mask or partial_inplace
for RELA relocs. It's just that BFD isn't structured in this way.
The internal representation of relocs always has an addend, no matter if
it comes from read-in section contents or a RELA reloc, and the
information of where it came from is lost (and section content isn't
zeroed on read-in for REL relocs, when transferring the addend to the bfd
reloc structure). So, to get this all somewhat working correctly right
now multiple howto entries are necessary (or special-casing target
reloc-swap-in and swap-out routines).
I'm totally sure, once one tries to _really_ start mixing REL and RELA
relocs in a link, at the latest when ld -r and/or other toolchains are
involved, that a heap of bugs will be uncovered :-)
(And of course, it's always possible that REL relocations cannot always be
used to achieve idempotence even in presence of 'ld -r', in which case
RELA must be used. The aarch64 psABI thankfully even spells this out.)
Ciao,
Michael.
next prev parent reply other threads:[~2023-05-25 14:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-10 14:04 Michael Matz
2023-05-17 14:35 ` Nick Clifton
2023-05-24 15:26 ` Richard Earnshaw (lists)
2023-05-24 16:03 ` Michael Matz
2023-05-25 9:35 ` Richard Earnshaw (lists)
2023-05-25 12:29 ` Michael Matz
2023-05-25 13:22 ` Richard Earnshaw (lists)
2023-05-25 14:12 ` Michael Matz [this message]
2023-05-25 15:56 ` Richard Earnshaw (lists)
2023-05-25 16:01 ` Michael Matz
2023-05-24 22:54 ` Alan Modra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LSU.2.20.2305251357390.13548@wotan.suse.de \
--to=matz@suse.de \
--cc=Richard.Earnshaw@arm.com \
--cc=binutils@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).