Re: [PATCH] LoongArch: Drop -ffreestanding from CFLAGS
From: Xi Ruoyao
Date: Fri Aug 04 2023 - 11:56:19 EST
On Fri, 2023-08-04 at 08:46 -0700, Nick Desaulniers wrote:
> > Not all processors support unaligned access, so we need the
> > alternative mechanism to select memset/memcpy/memmove implementations.
> > If remove -ffreestanding, the builtin implementation cannot be used on
> > all hardware.
>
> That sounds like a compiler bug in that compiler's implementation of
> string.h builtins then; it should default to the safest implementation
> (aligned accesses) until instructed otherwise. Have you filed a bug
> against your compiler vendor for which compiler you observe that
> behavior from?
AFAIK there is no such bug in GCC.
But GCC indeed has a bug about builtin expansion: it generates really
stupid code for __builtin_memcpy and friends. See
https://gcc.gnu.org/PR109465. The bug is fixed for GCC 14, but GCC 14
won't be released soon.
> At the very least, there should be a comment above the addition of
> -ffreestanding justifying why it's being used, probably with a link to
> the above bug report.
>
> I would expect either -mcpu or perhaps some other -m flag to guide the
> compiler when it is safe to emit memcpy (and friends) in terms of
> unaligned access or not.
It's controlled by -m{no-,}strict-align. LoongArch kernel defaults to -
mstrict-align, with this the compiler should not generate unaligned
access. -mno-strict-align is hidden behind CONFIG_EXPERT (FWIW I
personally dislike the decision to hide it).
--
Xi Ruoyao <xry111@xxxxxxxxxxx>
School of Aerospace Science and Technology, Xidian University