Re: [PATCH] LoongArch: Make -mstrict-align be configurable

From: Xi Ruoyao
Date: Mon Feb 06 2023 - 08:31:17 EST


On Mon, 2023-02-06 at 21:13 +0800, Jianmin Lv wrote:
> > (1) Is the difference contributed by a bad code generation of GCC?  If
> > true, it's better to improve GCC before someone starts to build a distro
> > for LA264 as it would benefit the user space as well.
> >
> AFAIK, GCC builds to produce unaligned-access-enabled target binary by
> default (without -mstrict-align) for improving user space performance
> (small size and runtime high performance), which is also based the fact
> that the vast majority of LoongArch CPUs support unaligned-access.

I mean: if someone starts to build a distro for a less-capable LoongArch
processor, (s)he will need an entire user space compiled with -mstrict-
align. So it would be better to start preparation now.

And it's likely (s)he will either submit a GCC patch to make GCC
enable/disable -mstrict-align based on the -march= (--with-arch at
configure time) value, or hack GCC to enable -mstrict-align by default
for the distro. So I think we'll also need:

> +ifdef CONFIG_ARCH_STRICT_ALIGN may enable strict align by default.
> # Don't emit unaligned accesses.
> # Not all LoongArch cores support unaligned access, and as kernel we can't
> # rely on others to provide emulation for these accesses.
> KBUILD_CFLAGS += $(call cc-option,-mstrict-align)
+else
+# Distros designed for running on both kind of processors may disable
+# strict align by default, but the user may want a no-strict-align 
+# kernel for his/her specific hardware.
KBUILD_CFLAGS += $(call cc-option,-mno-strict-align)
> +endif

--
Xi Ruoyao <xry111@xxxxxxxxxxx>
School of Aerospace Science and Technology, Xidian University