Re: [RESEND PATCH v1] x86/build: add -fno-builtin flag to prevent shadowing

From: Vincent MAILHOL
Date: Sun May 08 2022 - 08:37:36 EST


Hi Arnd,

+CC: Kees Cook

On Sun. 8 May 2022 at 19:27, Arnd Bergmann <arnd@xxxxxxxxxx> wrote:
> On Sun, May 8, 2022 at 12:09 PM Vincent Mailhol
> <mailhol.vincent@xxxxxxxxxx> wrote:
> >
> > Aside of the __builtin_foo() ones, x86 does not directly rely on any
> > builtin functions.
> >
> > However, such builtin functions are not explicitly deactivated,
> > creating some collisions, concrete example being ffs() from bitops.h,
> > c.f.:
> >
> > | ./arch/x86/include/asm/bitops.h:283:28: warning: declaration of 'ffs' shadows a built-in function [-Wshadow]
> > | 283 | static __always_inline int ffs(int x)
> >
> > This patch adds -fno-builtin to KBUILD_CFLAGS for the x86
> > architectures in order to prevent shadowing of builtin functions.
> >
> > Signed-off-by: Vincent Mailhol <mailhol.vincent@xxxxxxxxxx>
> > ---
> > FYI, I tested this patch on a "make allyesconfig" for both x86_32 and
> > x86_64.
> >
> > This is a resend. Only difference is that I dropped the RFC flag and
> > added Arnd in CC because he did a similar patch to fix ffs shadow
> > warnings in the past:
> >
> > https://lore.kernel.org/all/20201026160006.3704027-1-arnd@xxxxxxxxxx/
>
> I think this is a correct change, but unfortunately it exposes a clang bug
> with -mregparm=3. Nick should be able to provide more details, I think
> he has a plan.

Interesting. I admittedly did not do extensive tests on clang
but I would have expected the Linux kernel bot to have warned me
on my previous patch.

I did research on mregparm and clang. I found this thread:
https://lore.kernel.org/r/20220208225350.1331628-9-keescook@xxxxxxxxxxxx

and the associated LLVM issue:
https://github.com/llvm/llvm-project/issues/53645

Those threads mention that some clang builtins become unusable
when combining -mregparm=3 and -m32. But I could not find a
bug reference about -mregparm=3 and -fno-builtin combination.

Could you just double confirm that you indeed saw the issue with
-fno-builtin? If that the case, I am really curious to get the
details :)


Yours sincerely,
Vincent Mailhol