> From: Sam Edwards <cfswo...@gmail.com> > Date: Sun, 23 Feb 2025 21:55:13 -0800
Hi Sam, > 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. The default for this option changed somewhat recently in clang for non-Linux targets, which may explain why this wasn't an issue in the past. One question though. I believe there is some C code in U-Boot that runs before the MMU gets turned on, even if SYS_ARM_MMU is set. That code should always be compiled with -mstrict-align. And what about SYS_ICACHE_OFF and SYS_DCACHE_OFF? So I wonder if -mstrict-align should always be used for arm. I doubt the optimizations the compiler is doing in absence of that option result in any measurable speedup. > Signed-off-by: Sam Edwards <cfswo...@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 > +endif > + > ifdef CONFIG_ARM64 > PLATFORM_ELFFLAGS += -B aarch64 -O elf64-littleaarch64 > else > -- > 2.45.2 > >