rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] kbuild: enable CONFIG_WERROR for more build steps
@ 2025-08-12  5:31 Thomas Weißschuh
  2025-08-12  5:31 ` [PATCH 1/2] kbuild: move existing CONFIG_WERROR flags into dedicated Makefile Thomas Weißschuh
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Thomas Weißschuh @ 2025-08-12  5:31 UTC (permalink / raw)
  To: Nathan Chancellor, Nicolas Schier, Miguel Ojeda, Alex Gaynor,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich
  Cc: linux-kbuild, linux-kernel, rust-for-linux, Thomas Weißschuh

CONFIG_WERROR is useful for all build steps, not only compilation of C and
Rust sources linked into the kernel.

Also enable it for assembler and linker invocations, userprogs, as well as
C and Rust hostprogs.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
Thomas Weißschuh (2):
      kbuild: move existing CONFIG_WERROR flags into dedicated Makefile
      kbuild: enable CONFIG_WERROR for more build steps

 Makefile                   |  4 +---
 scripts/Makefile.extrawarn |  2 --
 scripts/Makefile.werror    | 18 ++++++++++++++++++
 3 files changed, 19 insertions(+), 5 deletions(-)
---
base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
change-id: 20250801-kbuild-werror-081f72fee1de

Best regards,
-- 
Thomas Weißschuh <thomas.weissschuh@linutronix.de>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] kbuild: move existing CONFIG_WERROR flags into dedicated Makefile
  2025-08-12  5:31 [PATCH 0/2] kbuild: enable CONFIG_WERROR for more build steps Thomas Weißschuh
@ 2025-08-12  5:31 ` Thomas Weißschuh
  2025-08-12  5:31 ` [PATCH 2/2] kbuild: enable CONFIG_WERROR for more build steps Thomas Weißschuh
  2025-08-12  9:21 ` [PATCH 0/2] " Miguel Ojeda
  2 siblings, 0 replies; 7+ messages in thread
From: Thomas Weißschuh @ 2025-08-12  5:31 UTC (permalink / raw)
  To: Nathan Chancellor, Nicolas Schier, Miguel Ojeda, Alex Gaynor,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich
  Cc: linux-kbuild, linux-kernel, rust-for-linux, Thomas Weißschuh

CONFIG_WERROR is about to be enabled for more build steps.
To avoid spreading similar flags into multiple locations, create a
dedicated, shared file for them.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
 Makefile                   |  4 +---
 scripts/Makefile.extrawarn |  2 --
 scripts/Makefile.werror    | 11 +++++++++++
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index 6bfe776bf3c5ff0cf187dc6719dd5817cd4af2ca..4ffa40e98b1517e1f2a7a155641fa9a3c784f625 100644
--- a/Makefile
+++ b/Makefile
@@ -901,9 +901,6 @@ stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG)      := -fstack-protector-strong
 
 KBUILD_CFLAGS += $(stackp-flags-y)
 
-KBUILD_RUSTFLAGS-$(CONFIG_WERROR) += -Dwarnings
-KBUILD_RUSTFLAGS += $(KBUILD_RUSTFLAGS-y)
-
 ifdef CONFIG_FRAME_POINTER
 KBUILD_CFLAGS	+= -fno-omit-frame-pointer -fno-optimize-sibling-calls
 KBUILD_RUSTFLAGS += -Cforce-frame-pointers=y
@@ -1085,6 +1082,7 @@ endif
 
 # include additional Makefiles when needed
 include-y			:= scripts/Makefile.extrawarn
+include-$(CONFIG_WERROR)	+= scripts/Makefile.werror
 include-$(CONFIG_DEBUG_INFO)	+= scripts/Makefile.debug
 include-$(CONFIG_DEBUG_INFO_BTF)+= scripts/Makefile.btf
 include-$(CONFIG_KASAN)		+= scripts/Makefile.kasan
diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
index dca175fffcabeb2d942814f0a096a7efbf8bc819..2d8201395002dace78b875a6d25d1fd33b1691fd 100644
--- a/scripts/Makefile.extrawarn
+++ b/scripts/Makefile.extrawarn
@@ -25,8 +25,6 @@ ifneq ($(CONFIG_FRAME_WARN),0)
 KBUILD_CFLAGS += -Wframe-larger-than=$(CONFIG_FRAME_WARN)
 endif
 
-KBUILD_CPPFLAGS-$(CONFIG_WERROR) += -Werror
-KBUILD_CPPFLAGS += $(KBUILD_CPPFLAGS-y)
 KBUILD_CFLAGS-$(CONFIG_CC_NO_ARRAY_BOUNDS) += -Wno-array-bounds
 
 ifdef CONFIG_CC_IS_CLANG
diff --git a/scripts/Makefile.werror b/scripts/Makefile.werror
new file mode 100644
index 0000000000000000000000000000000000000000..db14b5490ba83444be39a18109f103cabc5b95e9
--- /dev/null
+++ b/scripts/Makefile.werror
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0
+# ==========================================================================
+# Warning flags enabled by CONFIG_WERROR
+#
+# Different parts of the build require different flags to transform warnings
+# into errors. These are handled by the entries below.
+# ==========================================================================
+
+KBUILD_CPPFLAGS		+= -Werror
+
+KBUILD_RUSTFLAGS	+= -Dwarnings

-- 
2.50.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] kbuild: enable CONFIG_WERROR for more build steps
  2025-08-12  5:31 [PATCH 0/2] kbuild: enable CONFIG_WERROR for more build steps Thomas Weißschuh
  2025-08-12  5:31 ` [PATCH 1/2] kbuild: move existing CONFIG_WERROR flags into dedicated Makefile Thomas Weißschuh
@ 2025-08-12  5:31 ` Thomas Weißschuh
  2025-08-12  9:21 ` [PATCH 0/2] " Miguel Ojeda
  2 siblings, 0 replies; 7+ messages in thread
From: Thomas Weißschuh @ 2025-08-12  5:31 UTC (permalink / raw)
  To: Nathan Chancellor, Nicolas Schier, Miguel Ojeda, Alex Gaynor,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich
  Cc: linux-kbuild, linux-kernel, rust-for-linux, Thomas Weißschuh

CONFIG_WERROR is useful for all build steps, not only compilation of C and
Rust sources linked into the kernel.

Also enable it for assembler and linker invocations, userprogs, as well as
C and Rust hostprogs.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
 scripts/Makefile.werror | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/scripts/Makefile.werror b/scripts/Makefile.werror
index db14b5490ba83444be39a18109f103cabc5b95e9..e741ae45757c7864f5132d37f39fa3fea5b9d247 100644
--- a/scripts/Makefile.werror
+++ b/scripts/Makefile.werror
@@ -7,5 +7,12 @@
 # ==========================================================================
 
 KBUILD_CPPFLAGS		+= -Werror
+KBUILD_AFLAGS		+= -Wa,--fatal-warnings
+KBUILD_LDFLAGS		+= --fatal-warnings
+KBUILD_USERCFLAGS	+= -Werror
+KBUILD_USERLDFLAGS	+= -Wl,--fatal-warnings
+KBUILD_HOSTCFLAGS	+= -Werror
+KBUILD_HOSTLDFLAGS	+= -Wl,--fatal-warnings
 
 KBUILD_RUSTFLAGS	+= -Dwarnings
+KBUILD_HOSTRUSTFLAGS	+= -Dwarnings

-- 
2.50.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/2] kbuild: enable CONFIG_WERROR for more build steps
  2025-08-12  5:31 [PATCH 0/2] kbuild: enable CONFIG_WERROR for more build steps Thomas Weißschuh
  2025-08-12  5:31 ` [PATCH 1/2] kbuild: move existing CONFIG_WERROR flags into dedicated Makefile Thomas Weißschuh
  2025-08-12  5:31 ` [PATCH 2/2] kbuild: enable CONFIG_WERROR for more build steps Thomas Weißschuh
@ 2025-08-12  9:21 ` Miguel Ojeda
  2025-08-12 10:25   ` Thomas Weißschuh
  2 siblings, 1 reply; 7+ messages in thread
From: Miguel Ojeda @ 2025-08-12  9:21 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Nathan Chancellor, Nicolas Schier, Miguel Ojeda, Alex Gaynor,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	linux-kbuild, linux-kernel, rust-for-linux

On Tue, Aug 12, 2025 at 7:31 AM Thomas Weißschuh
<thomas.weissschuh@linutronix.de> wrote:
>
> CONFIG_WERROR is useful for all build steps, not only compilation of C and
> Rust sources linked into the kernel.
>
> Also enable it for assembler and linker invocations, userprogs, as well as
> C and Rust hostprogs.
>
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>

The Rust part is:

    https://lore.kernel.org/rust-for-linux/20240519211235.589325-1-ojeda@kernel.org/

However, Masahiro back then mentioned that we shouldn't make the C
host flags depend on `WERROR` since `HOSTCC` builds Kconfig and, for
consistency, not for Rust host progs either:

    https://lore.kernel.org/rust-for-linux/CAK7LNATPx2wTEM=KDmGtcH8vVTB4suOhh-CUQKP54F8wtPWDiw@mail.gmail.com/

Perhaps it could make sense to explicitly exclude certain bits, like
Kconfig, from `WERROR`, and apply it for everything else instead.

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/2] kbuild: enable CONFIG_WERROR for more build steps
  2025-08-12  9:21 ` [PATCH 0/2] " Miguel Ojeda
@ 2025-08-12 10:25   ` Thomas Weißschuh
  2025-08-12 10:50     ` Miguel Ojeda
  0 siblings, 1 reply; 7+ messages in thread
From: Thomas Weißschuh @ 2025-08-12 10:25 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Nathan Chancellor, Nicolas Schier, Miguel Ojeda, Alex Gaynor,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	linux-kbuild, linux-kernel, rust-for-linux

Hi Miguel,

On Tue, Aug 12, 2025 at 11:21:24AM +0200, Miguel Ojeda wrote:
> On Tue, Aug 12, 2025 at 7:31 AM Thomas Weißschuh
> <thomas.weissschuh@linutronix.de> wrote:
> >
> > CONFIG_WERROR is useful for all build steps, not only compilation of C and
> > Rust sources linked into the kernel.
> >
> > Also enable it for assembler and linker invocations, userprogs, as well as
> > C and Rust hostprogs.
> >
> > Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> 
> The Rust part is:
> 
>     https://lore.kernel.org/rust-for-linux/20240519211235.589325-1-ojeda@kernel.org/

Thanks for the pointer. We can keep the logic in Makefile.extrawarn.
But adding FLAGS-y machinery for all of the flags will be a bit noisy.
Having one ifdef CONFIG_WERROR around everything is much easier to read.

> However, Masahiro back then mentioned that we shouldn't make the C
> host flags depend on `WERROR` since `HOSTCC` builds Kconfig and, for
> consistency, not for Rust host progs either:
> 
>     https://lore.kernel.org/rust-for-linux/CAK7LNATPx2wTEM=KDmGtcH8vVTB4suOhh-CUQKP54F8wtPWDiw@mail.gmail.com/

That does make sense.

> Perhaps it could make sense to explicitly exclude certain bits, like
> Kconfig, from `WERROR`, and apply it for everything else instead.

The users will still pass -Werror explicitly, we can't filter that out.

Let's skip hostprogs for now. Another possibility would be to use -Werror
for hostprogs unconditionally. Various tools/ are doing that for example.


Thomas

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/2] kbuild: enable CONFIG_WERROR for more build steps
  2025-08-12 10:25   ` Thomas Weißschuh
@ 2025-08-12 10:50     ` Miguel Ojeda
  2025-08-12 20:56       ` Nathan Chancellor
  0 siblings, 1 reply; 7+ messages in thread
From: Miguel Ojeda @ 2025-08-12 10:50 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Nathan Chancellor, Nicolas Schier, Miguel Ojeda, Alex Gaynor,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	linux-kbuild, linux-kernel, rust-for-linux

On Tue, Aug 12, 2025 at 12:25 PM Thomas Weißschuh
<thomas.weissschuh@linutronix.de> wrote:
>
> The users will still pass -Werror explicitly, we can't filter that out.

You mean the user passing them when calling `make`, right? I guess we
could perhaps try to be smart there, but yeah, it gets annoying.

Another option could be to have a new `NOCONFIGCC` that gets used only
for Kconfig and that defaults to `HOSTCC`.

> Let's skip hostprogs for now.

Sounds good, thanks!

> Another possibility would be to use -Werror
> for hostprogs unconditionally. Various tools/ are doing that for example.

Not sure what Kbuild thinks about that -- we have a small risk of
breaking things with newer compilers, but that may be not too bad for
just hostprogs (unlike when it was attempted to make it default `y`).

(For Rust, the rate of new releases is very high compared to GCC or
LLVM, but on the other hand it is easy to test them in advance, and
what I have done so far for other things is just clean them as they
appear -- so that should be fine, but it does make it way more urgent
if they are errors every time, though, since it blocks other testing
too).

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/2] kbuild: enable CONFIG_WERROR for more build steps
  2025-08-12 10:50     ` Miguel Ojeda
@ 2025-08-12 20:56       ` Nathan Chancellor
  0 siblings, 0 replies; 7+ messages in thread
From: Nathan Chancellor @ 2025-08-12 20:56 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Thomas Weißschuh, Nicolas Schier, Miguel Ojeda, Alex Gaynor,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	linux-kbuild, linux-kernel, rust-for-linux

On Tue, Aug 12, 2025 at 12:50:44PM +0200, Miguel Ojeda wrote:
> On Tue, Aug 12, 2025 at 12:25 PM Thomas Weißschuh
> > Another possibility would be to use -Werror
> > for hostprogs unconditionally. Various tools/ are doing that for example.
> 
> Not sure what Kbuild thinks about that -- we have a small risk of
> breaking things with newer compilers, but that may be not too bad for
> just hostprogs (unlike when it was attempted to make it default `y`).
...
> appear -- so that should be fine, but it does make it way more urgent
> if they are errors every time, though, since it blocks other testing
> too).

Yeah I am conflicted. On the one hand, KBUILD_HOSTCFLAGS only has -Wall
and a couple of extra warnings so the risk of new warnings breaking the
build is pretty low. You can see the rate at which warnings get added or
removed from -Wall in clang in the warning-wall.c test:

  https://github.com/llvm/llvm-project/commits/main/clang/test/Misc/warning-wall.c

I'm obviously on top of testing upstream LLVM against hostprogs because
LLVM= makes it easy to set HOSTCC. I suspect that GCC trunk sees less
testing against the hostprogs unless the user has it in their PATH
somehow.

On the other hand, the recent changes to -Wuninitialized and the
addition of -Wuninitialized-const-pointer were extremely disruptive only
because of -Werror... I would have no problems with fast tracking fixes
for hostprogs -Werror usage but I am not sure all maintainers will. This
would also impact vendored host programs like dtc, which may be harder
to update.

We could try it for a development cycle in -next to see if anything gets
noticed. Always easy to back out retrospectively as well. Alternatively,
we could just recommend people use HOSTCFLAGS=-Werror if they desire it.

Cheers,
Nathan

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-08-12 20:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-12  5:31 [PATCH 0/2] kbuild: enable CONFIG_WERROR for more build steps Thomas Weißschuh
2025-08-12  5:31 ` [PATCH 1/2] kbuild: move existing CONFIG_WERROR flags into dedicated Makefile Thomas Weißschuh
2025-08-12  5:31 ` [PATCH 2/2] kbuild: enable CONFIG_WERROR for more build steps Thomas Weißschuh
2025-08-12  9:21 ` [PATCH 0/2] " Miguel Ojeda
2025-08-12 10:25   ` Thomas Weißschuh
2025-08-12 10:50     ` Miguel Ojeda
2025-08-12 20:56       ` Nathan Chancellor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).