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 <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

Reply via email to