2022-03-07 06:13:51

by Vincent MAILHOL

[permalink] [raw]
Subject: [RFC PATCH v1] x86/build: add -fno-builtin flag to prevent shadowing

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 <[email protected]>
---
FYI, I tested this patch on a "make allyesconfig" for both x86_32 and
x86_64.

arch/x86/Makefile.um already adds the -fno-builtin but
does not get included in arch/x86/Makefile (the only consumer of
Makefile.um is arch/um/Makefile). I do not understand what is the role
of Makefile.um here.

Because of my lack of confidence on this Makefile.um, and because it
is the first time for me to send a patch for x86/build I am sending
this as an RFC.

Regarless, this patch is my best shot on this issue. I hope I did not
miss anything obvious.
---
arch/x86/Makefile | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index e84cdd409b64..5ff7b6571dd2 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -53,6 +53,8 @@ export REALMODE_CFLAGS
# e.g.: obj-y += foo_$(BITS).o
export BITS

+KBUILD_CFLAGS += -fno-builtin
+
#
# Prevent GCC from generating any FP code by mistake.
#
--
2.34.1


2022-05-09 08:21:17

by Vincent MAILHOL

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

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 <[email protected]>
---
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/[email protected]/
---
arch/x86/Makefile | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index e84cdd409b64..5ff7b6571dd2 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -53,6 +53,8 @@ export REALMODE_CFLAGS
# e.g.: obj-y += foo_$(BITS).o
export BITS

+KBUILD_CFLAGS += -fno-builtin
+
#
# Prevent GCC from generating any FP code by mistake.
#
--
2.34.1


2022-05-09 11:35:56

by Arnd Bergmann

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

On Sun, May 8, 2022 at 12:09 PM Vincent Mailhol
<[email protected]> 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 <[email protected]>
> ---
> 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/[email protected]/

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.

> ---
> arch/x86/Makefile | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/arch/x86/Makefile b/arch/x86/Makefile
> index e84cdd409b64..5ff7b6571dd2 100644
> --- a/arch/x86/Makefile
> +++ b/arch/x86/Makefile
> @@ -53,6 +53,8 @@ export REALMODE_CFLAGS
> # e.g.: obj-y += foo_$(BITS).o
> export BITS
>
> +KBUILD_CFLAGS += -fno-builtin
> +
> #
> # Prevent GCC from generating any FP code by mistake.
> #
> --
> 2.34.1
>