From: Quentin Schulz <quentin.schulz@cherry.de>
To: Ilias Apalodimas <ilias.apalodimas@linaro.org>,
trini@konsulko.com, richard.henderson@linaro.org
Cc: casey.connolly@linaro.org, u-boot@lists.u-boot-project.org
Subject: Re: [PATCH 2/2] arm64: Add RELR relocs
Date: Wed, 25 Nov 2026 18:20:03 +0100 [thread overview]
Message-ID: <3a263d76-c2fc-4e15-9f2c-7795bb27a6e0@cherry.de> (raw)
In-Reply-To: <20261125074122.1965495-2-ilias.apalodimas@linaro.org>
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:
Tested-by: Quentin Schulz <quentin.schulz@cherry.de> # RK3588 Tiger
> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> ---
> Kconfig | 14 +++++++++++++
> arch/arm/config.mk | 10 +++++++--
> arch/arm/cpu/armv8/start.S | 38 ++++++++++++++++++++++++++++++++++
> arch/arm/cpu/armv8/u-boot.lds | 9 ++++++++
> arch/arm/lib/relocate_64.c | 28 +++++++++++++++++++++++++
> include/asm-generic/sections.h | 3 +++
> lib/efi_loader/efi_runtime.c | 9 +++++---
> 7 files changed, 106 insertions(+), 5 deletions(-)
>
> diff --git a/Kconfig b/Kconfig
> index c8cfbf5d5de2..ebe7b30d7b78 100644
> --- a/Kconfig
> +++ b/Kconfig
> @@ -40,6 +40,20 @@ config COMPILE_TEST
> here. If you are a user/distributor, say N here to exclude useless
> drivers to be distributed.
>
> +config RELR
> + bool "Use RELR packed relative relocations"
> + depends on ARM64
> + help
> + RELR stores relative relocations as 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 covering the 63 words that follow the previous
> + address. This usually leads to ~95% compression of emitted relocation
> + entries.
> + Due to the placement of the .relr.dyn section and the way ld
> + creates it we cannot currently relocate EFI functions at runtime.
> + SetVirtualAddressMap and ConvertPointer for EFI are marked as
> + unsupported.
> +
> config WERROR
> bool "Compile U-Boot with warnings as errors"
> default COMPILE_TEST
> diff --git a/arch/arm/config.mk b/arch/arm/config.mk
> index bce9a31e966b..ad73f728f7a2 100644
> --- a/arch/arm/config.mk
> +++ b/arch/arm/config.mk
> @@ -111,6 +111,9 @@ endif
>
> # needed for relocation
> LDFLAGS_u-boot += -pie
> +ifeq ($(CONFIG_RELR),y)
> +LDFLAGS_u-boot += -z pack-relative-relocs
> +endif
>
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).
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?)
Cheers,
Quentin
next prev parent reply other threads:[~2026-11-25 17:20 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 [this message]
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
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=3a263d76-c2fc-4e15-9f2c-7795bb27a6e0@cherry.de \
--to=quentin.schulz@cherry.de \
--cc=casey.connolly@linaro.org \
--cc=ilias.apalodimas@linaro.org \
--cc=richard.henderson@linaro.org \
--cc=trini@konsulko.com \
--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.