diff mbox series

[v3,1/2] kbuild: move -Werror from KBUILD_CFLAGS to KBUILD_CPPFLAGS

Message ID 20221012180118.331005-1-masahiroy@kernel.org (mailing list archive)
State New, archived
Headers show
Series [v3,1/2] kbuild: move -Werror from KBUILD_CFLAGS to KBUILD_CPPFLAGS | expand

Commit Message

Masahiro Yamada Oct. 12, 2022, 6:01 p.m. UTC
CONFIG_WERROR turns warnings into errors, which  happens only for *.c
files because -Werror is added to KBUILD_CFLAGS.

Adding it to KBUILD_CPPFLAGS makes more sense because preprocessors
understand the -Werror option.

For example, you can put a #warning directive in any preprocessed code.

    warning: #warning "this is a warning message" [-Wcpp]

If -Werror is added, it is promoted to an error.

    error: #warning "this is a warning message" [-Werror=cpp]

This commit moves -Werror to KBUILD_CPPFLAGS so it works in the same way
for *.c, *.S, *.lds.S or whatever needs preprocessing.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
---

(no changes since v1)

 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Nathan Chancellor Oct. 14, 2022, 4:03 p.m. UTC | #1
On Thu, Oct 13, 2022 at 03:01:17AM +0900, Masahiro Yamada wrote:
> CONFIG_WERROR turns warnings into errors, which  happens only for *.c
> files because -Werror is added to KBUILD_CFLAGS.
> 
> Adding it to KBUILD_CPPFLAGS makes more sense because preprocessors
> understand the -Werror option.
> 
> For example, you can put a #warning directive in any preprocessed code.
> 
>     warning: #warning "this is a warning message" [-Wcpp]
> 
> If -Werror is added, it is promoted to an error.
> 
>     error: #warning "this is a warning message" [-Werror=cpp]
> 
> This commit moves -Werror to KBUILD_CPPFLAGS so it works in the same way
> for *.c, *.S, *.lds.S or whatever needs preprocessing.
> 
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
> 
> (no changes since v1)
> 
>  Makefile | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/Makefile b/Makefile
> index 85a63a1d29b3..790760d26ea0 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -859,7 +859,8 @@ stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG)      := -fstack-protector-strong
>  
>  KBUILD_CFLAGS += $(stackp-flags-y)
>  
> -KBUILD_CFLAGS-$(CONFIG_WERROR) += -Werror
> +KBUILD_CPPFLAGS-$(CONFIG_WERROR) += -Werror
> +KBUILD_CPPFLAGS += $(KBUILD_CPPFLAGS-y)
>  KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds
>  
>  KBUILD_RUSTFLAGS-$(CONFIG_WERROR) += -Dwarnings
> -- 
> 2.34.1
> 
> 

For what it's worth, this is going to break 32-bit ARM builds with clang
plus the integrated assembler due to
https://github.com/ClangBuiltLinux/linux/issues/1315:

clang-16: error: argument unused during compilation: '-march=armv7-a' [-Werror,-Wunused-command-line-argument]

Ultimately, I want -Wunused-command-line-argument to be an error anyways
(https://github.com/ClangBuiltLinux/linux/issues/1587) but it would be
nice to get these cleaned up before this goes in.

Cheers,
Nathan
Nick Desaulniers Oct. 14, 2022, 8:19 p.m. UTC | #2
On Fri, Oct 14, 2022 at 9:03 AM Nathan Chancellor <nathan@kernel.org> wrote:
>
> On Thu, Oct 13, 2022 at 03:01:17AM +0900, Masahiro Yamada wrote:
> > CONFIG_WERROR turns warnings into errors, which  happens only for *.c
> > files because -Werror is added to KBUILD_CFLAGS.
> >
> > Adding it to KBUILD_CPPFLAGS makes more sense because preprocessors
> > understand the -Werror option.
> >
> For what it's worth, this is going to break 32-bit ARM builds with clang
> plus the integrated assembler due to
> https://github.com/ClangBuiltLinux/linux/issues/1315:
>
> clang-16: error: argument unused during compilation: '-march=armv7-a' [-Werror,-Wunused-command-line-argument]

Ah, sorry, I should have finished off that series back then. I've
rebased the series and sent a v4.
https://lore.kernel.org/llvm/20221014201354.3190007-1-ndesaulniers@google.com/

You mentioned to me on IRC
https://lore.kernel.org/linux-next/CAK7LNARg8OpqLR_71PJV3ZoLuDV8+mz9mphg=CzEeEEMY0G3rw@mail.gmail.com/
maybe will be a conflict.

>
> Ultimately, I want -Wunused-command-line-argument to be an error anyways
> (https://github.com/ClangBuiltLinux/linux/issues/1587) but it would be
> nice to get these cleaned up before this goes in.
>
> Cheers,
> Nathan
Masahiro Yamada Oct. 14, 2022, 8:21 p.m. UTC | #3
On Sat, Oct 15, 2022 at 1:03 AM Nathan Chancellor <nathan@kernel.org> wrote:
>
> On Thu, Oct 13, 2022 at 03:01:17AM +0900, Masahiro Yamada wrote:
> > CONFIG_WERROR turns warnings into errors, which  happens only for *.c
> > files because -Werror is added to KBUILD_CFLAGS.
> >
> > Adding it to KBUILD_CPPFLAGS makes more sense because preprocessors
> > understand the -Werror option.
> >
> > For example, you can put a #warning directive in any preprocessed code.
> >
> >     warning: #warning "this is a warning message" [-Wcpp]
> >
> > If -Werror is added, it is promoted to an error.
> >
> >     error: #warning "this is a warning message" [-Werror=cpp]
> >
> > This commit moves -Werror to KBUILD_CPPFLAGS so it works in the same way
> > for *.c, *.S, *.lds.S or whatever needs preprocessing.
> >
> > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> > Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> > ---
> >
> > (no changes since v1)
> >
> >  Makefile | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/Makefile b/Makefile
> > index 85a63a1d29b3..790760d26ea0 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -859,7 +859,8 @@ stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG)      := -fstack-protector-strong
> >
> >  KBUILD_CFLAGS += $(stackp-flags-y)
> >
> > -KBUILD_CFLAGS-$(CONFIG_WERROR) += -Werror
> > +KBUILD_CPPFLAGS-$(CONFIG_WERROR) += -Werror
> > +KBUILD_CPPFLAGS += $(KBUILD_CPPFLAGS-y)
> >  KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds
> >
> >  KBUILD_RUSTFLAGS-$(CONFIG_WERROR) += -Dwarnings
> > --
> > 2.34.1
> >
> >
>
> For what it's worth, this is going to break 32-bit ARM builds with clang
> plus the integrated assembler due to
> https://github.com/ClangBuiltLinux/linux/issues/1315:
>
> clang-16: error: argument unused during compilation: '-march=armv7-a' [-Werror,-Wunused-command-line-argument]
>
> Ultimately, I want -Wunused-command-line-argument to be an error anyways
> (https://github.com/ClangBuiltLinux/linux/issues/1587) but it would be
> nice to get these cleaned up before this goes in.
>
> Cheers,
> Nathan


OK, I will postpone this patch.
Thanks.
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 85a63a1d29b3..790760d26ea0 100644
--- a/Makefile
+++ b/Makefile
@@ -859,7 +859,8 @@  stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG)      := -fstack-protector-strong
 
 KBUILD_CFLAGS += $(stackp-flags-y)
 
-KBUILD_CFLAGS-$(CONFIG_WERROR) += -Werror
+KBUILD_CPPFLAGS-$(CONFIG_WERROR) += -Werror
+KBUILD_CPPFLAGS += $(KBUILD_CPPFLAGS-y)
 KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds
 
 KBUILD_RUSTFLAGS-$(CONFIG_WERROR) += -Dwarnings