[PATCH 06/17] arm: Use -mstrict-align when the MMU is off
Heinrich Schuchardt
xypron.glpk at gmx.de
Mon Feb 24 09:20:36 CET 2025
On 2/24/25 06:55, Sam Edwards wrote:
> On ARM, enabling the MMU is a prerequisite to enabling caching, which
> allows unaligned memory accesses by consolidating them into aligned
> accesses. When the MMU is disabled, however, all accesses must strictly
> adhere to the alignment rules.
>
> Some compilers (e.g. Clang) contain optimizations that may break these
> rules on the assumption that misaligned accesses merely incur a
> performance penalty. We do not necessarily want to prevent the compiler
> from applying these optimizations where it believes there may be net
> gains, but we do need to tell it to respect the alignment requirements
> when the MMU is disabled.
>
> Therefore, add the `-mstrict-align` compiler flag when SYS_ARM_MMU is
> not set.
>
> Signed-off-by: Sam Edwards <CFSworks at gmail.com>
> ---
> arch/arm/config.mk | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/arch/arm/config.mk b/arch/arm/config.mk
> index e0045e22271..98237b251f1 100644
> --- a/arch/arm/config.mk
> +++ b/arch/arm/config.mk
> @@ -33,6 +33,10 @@ PLATFORM_RELFLAGS += $(LLVM_RELFLAGS)
>
> PLATFORM_CPPFLAGS += -D__ARM__
>
> +ifneq ($(CONFIG_SYS_ARM_MMU),y)
> +PLATFORM_RELFLAGS += -mstrict-align
We don't set CONFIG_SYS_ARM_MMU on armv8 though we initialize the MMU.
The flag -mstrict-align seems only to exist for 64bit ARM and is already
set in arch/arm/cpu/armv8/config.mk.
On 32-bit ARM there is a flag -mno-unaligned-access which we set in
arch/arm/cpu/armv7/config.mk and arch/arm/cpu/armv7m/config.mk.
Here are some places we forbid unaligned access irrespective of
CONFIG_SYS_ARM_MMU:
arch/arm/cpu/arm1136/start.S:80: orr r0, r0, #0x00000002
@ set bit 1 (A) Align
arch/arm/cpu/arm1176/start.S:82: orr r0, r0, #0x00000002
@ set bit 1 (A) Align
arch/arm/cpu/arm920t/start.S:81: orr r0, r0, #0x00000002
@ set bit 1 (A) Align
arch/arm/cpu/arm926ejs/start.S:102: orr r0, r0, #0x00000002
/* set bit 1 (A) Align */
arch/arm/cpu/arm946es/start.S:88: orr r0, r0, #0x00000002
/* set bit 1 (A) Align */
arch/arm/cpu/armv7/start.S:229: orr r0, r0, #0x00000002 @ set
bit 1 (--A-) Align
Best regards
Heinrich
> +endif
> +
> ifdef CONFIG_ARM64
> PLATFORM_ELFFLAGS += -B aarch64 -O elf64-littleaarch64
> else
More information about the U-Boot
mailing list