All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tom Rini <trini@konsulko.com>
To: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Peter Robinson <pbrobinson@gmail.com>,
	Quentin Schulz <quentin.schulz@cherry.de>,
	richard.henderson@linaro.org, casey.connolly@linaro.org,
	u-boot@lists.u-boot-project.org
Subject: Re: [PATCH 2/2] arm64: Add RELR relocs
Date: Fri, 4 Dec 2026 09:12:19 -0600	[thread overview]
Message-ID: <20261204151219.GF3176972@bill-the-cat> (raw)
In-Reply-To: <CAC_iWj+gn6f9XqjegdKBy_7rU8YU2TSzLA=+f538mymYDu3dxA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 11048 bytes --]

On Fri, Dec 04, 2026 at 08:44:04AM +0200, Ilias Apalodimas wrote:
> On Fri, 4 Dec 2026 at 01:02, Tom Rini <trini@konsulko.com> wrote:
> >
> > On Fri, Dec 04, 2026 at 12:53:01AM +0200, Ilias Apalodimas wrote:
> > > On Fri, 4 Dec 2026 at 00:42, Tom Rini <trini@konsulko.com> wrote:
> > > >
> > > > On Fri, Dec 04, 2026 at 12:27:57AM +0200, Ilias Apalodimas wrote:
> > > > > Hi Tom
> > > > >
> > > > > On Fri, 27 Nov 2026 at 20:46, Tom Rini <trini@konsulko.com> wrote:
> > > > > >
> > > > > > On Thu, Nov 26, 2026 at 05:14:26PM +0200, Ilias Apalodimas wrote:
> > > > > > > Hi both
> > > > > > >
> > > > > > > On Thu, 26 Nov 2026 at 14:48, Peter Robinson <pbrobinson@gmail.com> wrote:
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > On Wed, 25 Nov 2026 at 17:20, Quentin Schulz <quentin.schulz@cherry.de> wrote:
> > > > > > > >>
> > > > > > > >> Hi Ilias,
> > > > > > > >>
> > > > > > > >> On 11/25/26 8:41 AM, Ilias Apalodimas wrote:
> > > > > > > >> > Linking U-Boot with -pie emits an R_AARCH64_RELATIVE entry for every
> > > > > > > >> > pointer that needs fixing up. Each Elf64_Rela entry is 24 bytes, so the
> > > > > > > >> > .rela.dyn section ends up being quite large.
> > > > > > > >> >
> > > > > > > >> > Modern toolchains support packing relative relocations in RELR format
> > > > > > > >> > via '-z pack-relative-relocs'. Instead of offset/info/addend tuples,
> > > > > > > >> > RELR stores a stream of 64-bit words. An even word is the link-time
> > > > > > > >> > address of a word to relocate and an odd word is a bitmap describing
> > > > > > > >> > which of the 63 words following the previous address need relocating.
> > > > > > > >> > The addend is the value already stored in the place.
> > > > > > > >> >
> > > > > > > >> > Compiling for QEMU with RELA vs RELR looks something like this:
> > > > > > > >> >
> > > > > > > >> > $~ readelf -SW u-boot  | grep relr
> > > > > > > >> > [ 9] .relr.dyn         RELR            000000000016f970 170970 000960 08   A  0   0  8
> > > > > > > >> > $~ readelf -SW u-boot.old  | grep rela
> > > > > > > >> > [ 7] .rela.dyn         RELA            0000000000115110 116110 0184f8 18   A  0   0  8
> > > > > > > >> >
> > > > > > > >> > which is ~98% decrease in the space reloc entries need.
> > > > > > > >> >
> > > > > > > >> > So let's add a Kconfig option and teach U-Boot RELR.
> > > > > > > >> > - pass '-z pack-relative-relocs' to the linker and add .relr.dyn
> > > > > > > >> >    in the linker script and the objcopy'ed binary. relr.dyn is still
> > > > > > > >> >    overlayed by .bss
> > > > > > > >> > - skip checkarmreloc, since we now expect R_AARCH64_RELATIVE entries
> > > > > > > >> >    to be packed in .rel*.dyn and older tools don't decode them
> > > > > > > >> >    properly
> > > > > > > >> > - process .relr.dyn in pie_fixup. It's worth noting that efi runtime
> > > > > > > >> >    relocs, due to how ld emits RELR, are now packed in .relr.dyn and
> > > > > > > >> >    efi_runtime_relocate() doesn't have to relocate anything.
> > > > > > > >> >    A sideeffect is that we can't support  SetVirtualAddressMap and ConvertPointer
> > > > > > > >> >    for EFI, but some architectures are already ommitting this call
> > > > > > > >> >    (e.g Linux on arm64, openBSD doesn't call it at all). [0]
> > > > > > > >> > - process .relr.dyn in relocate_code(). Note that the places are
> > > > > > > >> >    link-time addresses, so we still need the link-to-copy offset to find
> > > > > > > >> >    them, but the stored value has already been shifted to the run address
> > > > > > > >> >    by pie_fixup, so it needs to be adjusted by the run-to-copy offset
> > > > > > > >> >
> > > > > > > >> > [0] EFI runtime services relocate themselves when the OS calls
> > > > > > > >> > SetVirtualAddressMap, using the relocations between
> > > > > > > >> > __efi_runtime_rel_start and __efi_runtime_rel_stop. Those are collected
> > > > > > > >> > by the linker script from the .rela sections of the runtime code.
> > > > > > > >> > RELR packing, however, is done by the linker as a last step and all
> > > > > > > >> > relative relocations end up in a single .relr.dyn section for the entire
> > > > > > > >> > image. There's no way to emit an equivalent __efi_runtime_relr_start
> > > > > > > >> > marker for the runtime region, or emit RELA relocations for the EFI
> > > > > > > >> > runtime, so stop advertising SetVirtualAddressMap and ConvertPointer
> > > > > > > >> > in the EFI_RT_PROPERTIES_TABLE when RELR is enabled.
> > > > > > > >> >
> > > > > > > >>
> > > > > > > >> 6.4% size reduction for u-boot.itb with RELR enabled on
> > > > > > > >> tiger-rk3588_defconfig.
> > > > > > > >>
> > > > > > > >> $ aarch64-linux-gnu-ld --version
> > > > > > > >> GNU ld version 2.47.20260726
> > > > > > > >>
> > > > > > > >> from Fedora 45.
> > > > > > > >>
> > > > > > > >> I reached U-Boot proper CLI, which I have been told is sufficient to
> > > > > > > >> test this series, so:
> > > > > > > >
> > > > > > > >
> > > > > > > > I agree with enabling this by default, it should be opt out if there's issues.
> > > > > > > >
> > > > > > > > Looking at various default toolchains across distros (thanks Claude) Ubuntu 22.04 LTS has gcc11/binutils 2.38, RHEL 9 is gcc11/binutils 2.35.2, Debian 12 is gcc12.2/binutils 2.40
> > > > > > > >
> > > > > > > > All have options for later versions so I think we should be fine to enable by default and error if the toolchain isn't new enough. The reality is a lot of users will be using old U-Boot if they're on ancient distros anyway.
> > > > > > > >
> > > > > > > >>
> > > > > > > >> suggestion: make this transparent to the user
> > > > > > > >>
> > > > > > > >> We've talked about this in private but wanted to put it in writing so
> > > > > > > >> it's available on the mailing list archive. I think it makes more sense
> > > > > > > >> to always enable the option (if it's safe!), if the linker supports it.
> > > > > > > >> According to
> > > > > > > >> https://rfc.archlinux.page/0023-pack-relative-relocs/#motivation, that
> > > > > > > >> is GNU ld 2.36 and LLVM 15. We can use the same mechanism as in the
> > > > > > > >> kernel, c.f. CC_HAS_UBSAN_BOUNDS_STRICT with def_bool
> > > > > > > >> $(cc-option,-fsanitize=bounds-strict).
> > > > > > >
> > > > > > > I don't think that's a good idea. You turn on an option that promises
> > > > > > > to reduce the binary size. You compile but bercause you now made the
> > > > > > > linker flags conditional the end user finds an *identical* binary
> > > > > > > after enabling the option. I prefer breaking the build so users
> > > > > > > understand that this relies on a newer linker. Whether they can update
> > > > > > > it or not should not be our problem.
> > > > > >
> > > > > > So, we should be doing depends on LD_HAS_RELR_SUPPORT in the new options
> > > > > > and LD_HAS_RELR_SUPPORT is def_bool ..., and then the new option can be
> > > > > > default y.
> > > > >
> > > > > Ok, I can change thayt
> > > > >
> > > > > >
> > > > > > > >> What I don't like about it is that if it's default off, nobody will turn
> > > > > > > >> it on. If it's on and we force the option like in this patch, then
> > > > > > > >> builds will fail on older toolchains. I bet most people don't know where
> > > > > > > >> to get a newer toolchain than the one they have from their distro, or
> > > > > > > >> how to install it so lots of headaches for people I guess. If we stay
> > > > > > > >> with this solution here, is there a way to tell the user how to fix it
> > > > > > > >> (either via a Make message, or at least a comment next to the places
> > > > > > > >> where we set the flag?)
> > > > > > >
> > > > > > > There should be enough explanation in the commit message and Kconfig
> > > > > > > option why this is not enabled by default.
> > > > > > > TL;DR there are implications wrt to EFI if you enable RELR that do not
> > > > > > > affect Linux for arm64, but Linux is not the only OS we boot. Since we
> > > > > > > have it documented, I'd rather leave the option off, at least till the
> > > > > > > EFI implications are gone.
> > > > > >
> > > > > > Are the EFI implications something we can / will resolve, or should we
> > > > > > be asking the other OSes?
> > > > >
> > > > > We can but it requires many more changes in the EFI subsystem.
> > > > >
> > > > > >  Or, since the BSD folks do make it easy enough
> > > > > > to try them out, should the pushback be on you to fire up an installer
> > > > > > image or two? Or... is this something that won't blow up immediately and
> > > > > > rather you'd have to do some non-trivial testing to confirm?
> > > > >
> > > > > In theory (if the OS isn't buggy), nothing will blow up. When RELR is
> > > > > enabled SetVirtualAddressMap is marked as unsupported. So worst case
> > > > > is the OS will end up running without them. OS'es that avoid calling
> > > > > it, just map RT servives 1:1 already and work fine
> > > >
> > > > It sounds like we should document the needed EFI change then, but not
> > > > proactively do it?
> > >
> > > Sure, but where? In the commit message? docs?
> >
> > How about doc/api/efi.rst ? But..
> 
> I don't mind, OTOH the commit message explains enough already, I could
> just expand it.
> 
> >
> > >
> > > > But to try and be clearer, is it easy to test at
> > > > run-time (in the OS) or a quick grep around the kernel sources, if say a
> > > > BSD is relying on SetVirtualAddressMap being supported, today?
> > >
> > > From memory, openBSD doesn't, but FreeBSD does. I can double check
> > > tomorrow, but that was the main reason I wanted the feature to be opt
> > > in for now.
> >
> > Ah, OK. So some FOSS OSes do need it. OK, yes. Is it a lot of work
> > that's needed, or just a bit more sit down and do it work?
> 
> It requires significant work. We'll have to move all of the code
> that's annotated with efi_runtime_* in a different folder, compile it
> as an object and partially link it to U-Boot.  What we currently do
> under RELA is keep a separate section of efi_runtime* code and we
> relocate that part only during SVAM. However, the RELR changes are
> orthogonal. We can still pull this for anyone that *knows* he is
> booting an OS that doesn't call SVAM, but keep it opt-in, and then
> enable it by default once the EFI problems are gone.

There's annotations in 18 files, but a few of them aren't arm. If we
*only* need to refactor the files, that doesn't sound too bad, and we
should be able to keep the directory structure and manipulate the link
flags for making one object which is then linked to built-in.o, yes? I
thought there were examples of that but I don't see one quickly. Because
I'd really rather do all this at once, rather than RELR now and fix EFI
later, since EFI is default and it's not a commercial OS that needs it,
but another FOSS OS.

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2026-12-04 15:12 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  7:41 [PATCH 1/2] arm64: relocate: convert relocate_code to C Ilias Apalodimas
2026-11-25  7:41 ` [PATCH 2/2] arm64: Add RELR relocs Ilias Apalodimas
2026-11-25 17:20   ` Quentin Schulz
2026-11-26 12:48     ` Peter Robinson
2026-11-26 15:14       ` Ilias Apalodimas
2026-11-27 18:46         ` Tom Rini
2026-12-03 22:27           ` Ilias Apalodimas
2026-12-03 22:42             ` Tom Rini
2026-12-03 22:53               ` Ilias Apalodimas
2026-12-03 23:02                 ` Tom Rini
2026-12-04  6:44                   ` Ilias Apalodimas
2026-12-04 15:12                     ` Tom Rini [this message]
2026-12-04 15:50                       ` Ilias Apalodimas
2026-12-04 16:13                         ` Ilias Apalodimas
2026-11-26 16:35   ` Richard Henderson
2026-11-26 16:58     ` Ilias Apalodimas
2026-11-26 20:51       ` Ilias Apalodimas
2026-12-03 22:14         ` Richard Henderson
2026-11-25 17:07 ` [PATCH 1/2] arm64: relocate: convert relocate_code to C Quentin Schulz
2026-11-25 17:08   ` Casey Connolly
2026-11-25 17:11   ` Ilias Apalodimas
2026-11-27 18:35     ` Tom Rini
2026-11-26 16:11 ` Richard Henderson
2026-11-26 16:18   ` Ilias Apalodimas
2026-11-26 17:03     ` Ilias Apalodimas

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=20261204151219.GF3176972@bill-the-cat \
    --to=trini@konsulko.com \
    --cc=casey.connolly@linaro.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=pbrobinson@gmail.com \
    --cc=quentin.schulz@cherry.de \
    --cc=richard.henderson@linaro.org \
    --cc=u-boot@lists.u-boot-project.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.