Re: [PATCH] kasan: Fix tests by removing -ffreestanding

From: Huacai Chen
Date: Thu Jul 13 2023 - 00:33:57 EST


Hi, Andrey,

On Thu, Jul 13, 2023 at 12:12 AM Andrey Konovalov <andreyknvl@xxxxxxxxx> wrote:
>
> On Wed, Jul 12, 2023 at 12:14 PM Huacai Chen <chenhuacai@xxxxxxxxxxx> wrote:
> >
> > CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX hopes -fbuiltin for memset()/
> > memcpy()/memmove() if instrumentation is needed. This is the default
> > behavior but some archs pass -ffreestanding which implies -fno-builtin,
> > and then causes some kasan tests fail. So we remove -ffreestanding for
> > kasan tests.
>
> Could you clarify on which architecture you observed tests failures?
Observed on LoongArch [1], KASAN for LoongArch was planned to be
merged in 6.5, but at the last minute I found some tests fail with
GCC14 (CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX) so the patches are
dropped. After some debugging we found the root cause is
-ffreestanding.

[1] https://github.com/chenhuacai/linux/commit/af2da91541a8899b502bece9b1fde225b71f37a8

Huacai
>
> >
> > Signed-off-by: Huacai Chen <chenhuacai@xxxxxxxxxxx>
> > ---
> > mm/kasan/Makefile | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/mm/kasan/Makefile b/mm/kasan/Makefile
> > index 7634dd2a6128..edd1977a6b88 100644
> > --- a/mm/kasan/Makefile
> > +++ b/mm/kasan/Makefile
> > @@ -45,7 +45,9 @@ CFLAGS_KASAN_TEST += -fno-builtin
> > endif
> >
> > CFLAGS_kasan_test.o := $(CFLAGS_KASAN_TEST)
> > +CFLAGS_REMOVE_kasan_test.o := -ffreestanding
> > CFLAGS_kasan_test_module.o := $(CFLAGS_KASAN_TEST)
> > +CFLAGS_REMOVE_kasan_test_module.o := -ffreestanding
> >
> > obj-y := common.o report.o
> > obj-$(CONFIG_KASAN_GENERIC) += init.o generic.o report_generic.o shadow.o quarantine.o
> > --
> > 2.39.3
>
> +Marco