[PATCH] arch: arm: force 4K page alignment in linker
Peter Robinson
pbrobinson at gmail.com
Sun May 31 11:23:27 CEST 2026
On Sun, 31 May 2026 at 00:17, Sam Day <me at samcday.com> wrote:
>
> Hey Peter,
>
> On Friday, 29 May 2026 at 8:18 PM, Peter Robinson <pbrobinson at gmail.com> wrote:
>
> > Hi Sam,
> >
> > > Since 5c71f8110, the u-boot.elf produced by dragonboard410c_defconfig no
> > > longer fits in the 1MiB aboot partition it is intended for.
> > >
> > > To be precise, this issue occurs on toolchains that have a linker with a
> > > COMMONPAGESIZE > 4K. Since u-boot is hardcoded for 4K granules, we
> > > ensure that the linker doesn't try to align to anything larger than
> > > that, otherwise we're just filling our ELFs with a bunch of useless
> > > zeros.
> >
> > Is this just applicable to ELFs or can it be applied more widely?
>
> I'm not completely sure :)
>
> These linker options control ld's constants [1]. COMMONPAGESIZE is used
> to align sections in arm32/arm64 linker scripts [2]. Whether this affects
> anything else besides that is not fully clear to me.
>
> >
> > > Suggested-by: Stephan Gerhold <stephan.gerhold at linaro.org>
> > > Signed-off-by: Sam Day <me at samcday.com>
> > Tested-by: Peter Robinson <pbrobinson at gmail.com>
> >
> > Tested on a Rock960 where the elf output went from 9498864 to 9437424
>
> This isn't much of a change at all, I wonder what toolchain you're using,
> and what its default COMMONPAGESIZE is? You can run the snippet below to
> find out.
Fedora 44 with gcc 16, binutils 2.46
> ```sh
> echo 'SECTIONS { cps = CONSTANT(COMMONPAGESIZE); }' > /tmp/pg.lds &&
> echo 'int x;' | aarch64-linux-gnu-gcc -x c - -c -o /tmp/pg.o &&
> aarch64-linux-gnu-ld -T /tmp/pg.lds -o /tmp/pg.elf /tmp/pg.o &&
> aarch64-linux-gnu-nm /tmp/pg.elf \
> | awk '/cps/{print strtonum("0x"$1), "("$1")"}'
> ```
>
> [1]: https://sourceware.org/binutils/docs/ld/Symbolic-Constants.html
> [2]: https://github.com/search?q=repo%3Au-boot%2Fu-boot%20COMMONPAGESIZE&type=code
>
> Cheers,
> -Sam
>
> >
> > > ---
> > > arch/arm/config.mk | 8 ++++++++
> > > 1 file changed, 8 insertions(+)
> > >
> > > diff --git a/arch/arm/config.mk b/arch/arm/config.mk
> > > index a7eff84a267..bce9a31e966 100644
> > > --- a/arch/arm/config.mk
> > > +++ b/arch/arm/config.mk
> > > @@ -112,6 +112,14 @@ endif
> > > # needed for relocation
> > > LDFLAGS_u-boot += -pie
> > >
> > > +ifeq ($(CONFIG_ARM64),y)
> > > +# U-Boot uses fixed 4K granules, so we force the linker to match.
> > > +# Otherwise, we're subject to toolchain preferences, (e.g Fedora's
> > > +# aarch64-linux-none toolchain selects 64K granules) and we end up wasting
> > > +# a lot of space in ELFs with MMU_PGPROT enabled.
> > > +LDFLAGS_u-boot += -z common-page-size=0x1000 -z max-page-size=0x1000
> > > +endif
> > > +
> > > #
> > > # FIXME: binutils versions < 2.22 have a bug in the assembler where
> > > # branches to weak symbols can be incorrectly optimized in thumb mode
> > >
> > > ---
> > > base-commit: 987907ae4bcc5d6055bdf7d318a3edf53e14d5fa
> > > change-id: 20260528-4k-page-alignment-6cb594a073b0
> > >
> > > Best regards,
> > > --
> > > Sam Day <me at samcday.com>
> > >
> > >
> >
More information about the U-Boot
mailing list