* [PATCH RFC 1/5] kbuild: uapi: move some compiler arguments out of the command definition
2026-03-08 21:24 [PATCH RFC 0/5] kbuild: uapi: also test UAPI headers against C++ compilers Thomas Weißschuh
@ 2026-03-08 21:24 ` Thomas Weißschuh
2026-03-08 21:24 ` [PATCH RFC 2/5] kbuild: uapi: move all include path flags together Thomas Weißschuh
` (4 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2026-03-08 21:24 UTC (permalink / raw)
To: Arnd Bergmann, Nathan Chancellor, Nicolas Schier
Cc: linux-kbuild, linux-kernel, David Howells, Thomas Weißschuh
Simplify the definition of cmd_hdrtest by moving some of it to a new
variable. This will both enable the upcoming reuse of those flags
and also the extension of cmd_hdrtest.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
usr/include/Makefile | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/usr/include/Makefile b/usr/include/Makefile
index 845d06b63c2b..0b1c9a4b0477 100644
--- a/usr/include/Makefile
+++ b/usr/include/Makefile
@@ -140,11 +140,13 @@ always-y := $(patsubst $(obj)/%.h,%.hdrtest, $(shell find $(obj) -name '*.h' 2>/
target-libc = $(filter $(uses-libc), $*.h)
target-can-compile = $(filter-out $(no-header-test), $*.h)
+hdrtest-flags = -fsyntax-only -Werror \
+ -nostdinc $(if $(target-libc), -I $(srctree)/usr/dummy-include)
+
# Include the header twice to detect missing include guard.
quiet_cmd_hdrtest = HDRTEST $<
cmd_hdrtest = \
- $(CC) $(c_flags) -fsyntax-only -Werror -x c /dev/null \
- -nostdinc $(if $(target-libc), -I $(srctree)/usr/dummy-include) \
+ $(CC) $(c_flags) $(hdrtest-flags) -x c /dev/null \
$(if $(target-can-compile), -include $< -include $<); \
$(PERL) $(src)/headers_check.pl $(obj) $<; \
touch $@
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH RFC 2/5] kbuild: uapi: move all include path flags together
2026-03-08 21:24 [PATCH RFC 0/5] kbuild: uapi: also test UAPI headers against C++ compilers Thomas Weißschuh
2026-03-08 21:24 ` [PATCH RFC 1/5] kbuild: uapi: move some compiler arguments out of the command definition Thomas Weißschuh
@ 2026-03-08 21:24 ` Thomas Weißschuh
2026-03-08 21:24 ` [PATCH RFC 3/5] kbuild: uapi: handle UML in architecture-specific exclusion lists Thomas Weißschuh
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2026-03-08 21:24 UTC (permalink / raw)
To: Arnd Bergmann, Nathan Chancellor, Nicolas Schier
Cc: linux-kbuild, linux-kernel, David Howells, Thomas Weißschuh
The argument to add the root of the UAPI header tree to the include path
is separated from the other arguments concerning the include path.
Move all include path arguments together for more consistency and
balanced line lengths.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
usr/include/Makefile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/usr/include/Makefile b/usr/include/Makefile
index 0b1c9a4b0477..74f5ba24bb29 100644
--- a/usr/include/Makefile
+++ b/usr/include/Makefile
@@ -8,7 +8,7 @@
# We cannot go as far as adding -Wpedantic since it emits too many warnings.
UAPI_CFLAGS := -std=c90 -Werror=implicit-function-declaration
-override c_flags = $(KBUILD_USERCFLAGS) $(UAPI_CFLAGS) -Wp,-MMD,$(depfile) -I $(obj)
+override c_flags = $(KBUILD_USERCFLAGS) $(UAPI_CFLAGS) -Wp,-MMD,$(depfile)
# The following are excluded for now because they fail to build.
#
@@ -141,7 +141,7 @@ target-libc = $(filter $(uses-libc), $*.h)
target-can-compile = $(filter-out $(no-header-test), $*.h)
hdrtest-flags = -fsyntax-only -Werror \
- -nostdinc $(if $(target-libc), -I $(srctree)/usr/dummy-include)
+ -nostdinc -I $(obj) $(if $(target-libc), -I $(srctree)/usr/dummy-include)
# Include the header twice to detect missing include guard.
quiet_cmd_hdrtest = HDRTEST $<
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH RFC 3/5] kbuild: uapi: handle UML in architecture-specific exclusion lists
2026-03-08 21:24 [PATCH RFC 0/5] kbuild: uapi: also test UAPI headers against C++ compilers Thomas Weißschuh
2026-03-08 21:24 ` [PATCH RFC 1/5] kbuild: uapi: move some compiler arguments out of the command definition Thomas Weißschuh
2026-03-08 21:24 ` [PATCH RFC 2/5] kbuild: uapi: move all include path flags together Thomas Weißschuh
@ 2026-03-08 21:24 ` Thomas Weißschuh
2026-03-08 21:24 ` [PATCH RFC 4/5] kbuild: uapi: provide a C++ compatible dummy definition of NULL Thomas Weißschuh
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2026-03-08 21:24 UTC (permalink / raw)
To: Arnd Bergmann, Nathan Chancellor, Nicolas Schier
Cc: linux-kbuild, linux-kernel, David Howells, Thomas Weißschuh
When building User Mode Linux SRCARCH is set to 'um', while the actual
underlying architecture is provided in HEADER_ARCH.
Allow the exclusion lists to work on UML by comparing against
HEADER_ARCH when that is available.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
usr/include/Makefile | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/usr/include/Makefile b/usr/include/Makefile
index 74f5ba24bb29..edeaf9d778c4 100644
--- a/usr/include/Makefile
+++ b/usr/include/Makefile
@@ -7,6 +7,7 @@
# -std=c90 (equivalent to -ansi) catches the violation of those.
# We cannot go as far as adding -Wpedantic since it emits too many warnings.
UAPI_CFLAGS := -std=c90 -Werror=implicit-function-declaration
+UAPI_ARCH := $(or $(HEADER_ARCH),$(SRCARCH))
override c_flags = $(KBUILD_USERCFLAGS) $(UAPI_CFLAGS) -Wp,-MMD,$(depfile)
@@ -48,11 +49,11 @@ no-header-test += xen/privcmd.h
# More headers are broken in some architectures
-ifneq ($(filter arc openrisc xtensa nios2, $(SRCARCH)),)
+ifneq ($(filter arc openrisc xtensa nios2, $(UAPI_ARCH)),)
no-header-test += linux/bpf_perf_event.h
endif
-ifeq ($(SRCARCH),sparc)
+ifeq ($(UAPI_ARCH),sparc)
no-header-test += asm/uctx.h
no-header-test += asm/fbio.h
endif
@@ -122,15 +123,15 @@ uses-libc += linux/wireless.h
uses-libc += regulator/regulator.h
uses-libc += scsi/fc/fc_els.h
-ifeq ($(SRCARCH),hexagon)
+ifeq ($(UAPI_ARCH),hexagon)
uses-libc += asm/sigcontext.h
endif
-ifeq ($(SRCARCH),nios2)
+ifeq ($(UAPI_ARCH),nios2)
uses-libc += asm/ptrace.h
endif
-ifeq ($(SRCARCH),s390)
+ifeq ($(UAPI_ARCH),s390)
uses-libc += asm/chpid.h
uses-libc += asm/chsc.h
endif
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH RFC 4/5] kbuild: uapi: provide a C++ compatible dummy definition of NULL
2026-03-08 21:24 [PATCH RFC 0/5] kbuild: uapi: also test UAPI headers against C++ compilers Thomas Weißschuh
` (2 preceding siblings ...)
2026-03-08 21:24 ` [PATCH RFC 3/5] kbuild: uapi: handle UML in architecture-specific exclusion lists Thomas Weißschuh
@ 2026-03-08 21:24 ` Thomas Weißschuh
2026-03-08 21:24 ` [PATCH RFC 5/5] kbuild: uapi: also test UAPI headers against C++ compilers Thomas Weißschuh
2026-03-12 8:16 ` [PATCH RFC 0/5] " Nathan Chancellor
5 siblings, 0 replies; 8+ messages in thread
From: Thomas Weißschuh @ 2026-03-08 21:24 UTC (permalink / raw)
To: Arnd Bergmann, Nathan Chancellor, Nicolas Schier
Cc: linux-kbuild, linux-kernel, David Howells, Thomas Weißschuh
NULL works differently in C++ compared to C.
To allow testing the UAPI headers against C++ compilers, provide
a variant of NULL which works with those.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
usr/dummy-include/stddef.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/usr/dummy-include/stddef.h b/usr/dummy-include/stddef.h
index a61703d1c896..525489daffe2 100644
--- a/usr/dummy-include/stddef.h
+++ b/usr/dummy-include/stddef.h
@@ -3,6 +3,11 @@
#define _DUMMY_STDDEF_H
#define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER)
+
+#ifdef __cplusplus
+#define NULL 0
+#else
#define NULL ((void *)0)
+#endif
#endif /* _DUMMY_STDDEF_H */
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH RFC 5/5] kbuild: uapi: also test UAPI headers against C++ compilers
2026-03-08 21:24 [PATCH RFC 0/5] kbuild: uapi: also test UAPI headers against C++ compilers Thomas Weißschuh
` (3 preceding siblings ...)
2026-03-08 21:24 ` [PATCH RFC 4/5] kbuild: uapi: provide a C++ compatible dummy definition of NULL Thomas Weißschuh
@ 2026-03-08 21:24 ` Thomas Weißschuh
2026-03-12 8:15 ` Nathan Chancellor
2026-03-12 8:16 ` [PATCH RFC 0/5] " Nathan Chancellor
5 siblings, 1 reply; 8+ messages in thread
From: Thomas Weißschuh @ 2026-03-08 21:24 UTC (permalink / raw)
To: Arnd Bergmann, Nathan Chancellor, Nicolas Schier
Cc: linux-kbuild, linux-kernel, David Howells, Thomas Weißschuh
C++ language requirements differ from those of C.
Also test the headers against C++ compilers to make sure no errors
creep in accidentally.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
usr/include/Makefile | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/usr/include/Makefile b/usr/include/Makefile
index edeaf9d778c4..0e23aeace410 100644
--- a/usr/include/Makefile
+++ b/usr/include/Makefile
@@ -10,6 +10,7 @@ UAPI_CFLAGS := -std=c90 -Werror=implicit-function-declaration
UAPI_ARCH := $(or $(HEADER_ARCH),$(SRCARCH))
override c_flags = $(KBUILD_USERCFLAGS) $(UAPI_CFLAGS) -Wp,-MMD,$(depfile)
+cxx_flags = $(filter-out -Wmissing-prototypes -Wstrict-prototypes -std=%, $(KBUILD_USERCFLAGS)) -std=c++98
# The following are excluded for now because they fail to build.
#
@@ -61,6 +62,27 @@ endif
# asm-generic/*.h is used by asm/*.h, and should not be included directly
no-header-test += asm-generic/%
+# The following are not compatible with C++.
+#
+# Do not add a new header to the list without legitimate reason.
+# Please consider to fix the header first.
+#
+# Sorted alphabetically.
+no-header-test-cxx += linux/auto_dev-ioctl.h
+no-header-test-cxx += linux/map_to_14segment.h
+no-header-test-cxx += linux/map_to_7segment.h
+no-header-test-cxx += linux/netfilter/xt_sctp.h
+no-header-test-cxx += linux/target_core_user.h
+no-header-test-cxx += linux/vhost.h
+no-header-test-cxx += linux/vhost_types.h
+no-header-test-cxx += linux/virtio_net.h
+no-header-test-cxx += linux/virtio_ring.h
+no-header-test-cxx += scsi/fc/fc_els.h
+
+ifeq ($(UAPI_ARCH),x86)
+no-header-test-cxx += asm/elf.h
+endif
+
# The following are using libc header and types.
#
# Do not add a new header to the list without legitimate reason.
@@ -138,8 +160,12 @@ endif
always-y := $(patsubst $(obj)/%.h,%.hdrtest, $(shell find $(obj) -name '*.h' 2>/dev/null))
+# $(cc-option) forces '-x c' which breaks '-x c++' detection.
+cc-can-compile-cxx := $(call try-run,$(CC) -c -x c++ /dev/null -o "$$TMP", 1)
+
target-libc = $(filter $(uses-libc), $*.h)
target-can-compile = $(filter-out $(no-header-test), $*.h)
+target-can-compile-cxx = $(and $(cc-can-compile-cxx), $(target-can-compile), $(filter-out $(no-header-test-cxx), $*.h))
hdrtest-flags = -fsyntax-only -Werror \
-nostdinc -I $(obj) $(if $(target-libc), -I $(srctree)/usr/dummy-include)
@@ -149,6 +175,8 @@ quiet_cmd_hdrtest = HDRTEST $<
cmd_hdrtest = \
$(CC) $(c_flags) $(hdrtest-flags) -x c /dev/null \
$(if $(target-can-compile), -include $< -include $<); \
+ $(if $(target-can-compile-cxx), \
+ $(CC) $(cxx_flags) $(hdrtest-flags) -x c++ /dev/null -include $<;) \
$(PERL) $(src)/headers_check.pl $(obj) $<; \
touch $@
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH RFC 5/5] kbuild: uapi: also test UAPI headers against C++ compilers
2026-03-08 21:24 ` [PATCH RFC 5/5] kbuild: uapi: also test UAPI headers against C++ compilers Thomas Weißschuh
@ 2026-03-12 8:15 ` Nathan Chancellor
0 siblings, 0 replies; 8+ messages in thread
From: Nathan Chancellor @ 2026-03-12 8:15 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Arnd Bergmann, Nicolas Schier, linux-kbuild, linux-kernel,
David Howells
On Sun, Mar 08, 2026 at 10:24:05PM +0100, Thomas Weißschuh wrote:
> C++ language requirements differ from those of C.
>
> Also test the headers against C++ compilers to make sure no errors
> creep in accidentally.
>
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
> usr/include/Makefile | 28 ++++++++++++++++++++++++++++
> 1 file changed, 28 insertions(+)
>
> diff --git a/usr/include/Makefile b/usr/include/Makefile
> index edeaf9d778c4..0e23aeace410 100644
> --- a/usr/include/Makefile
> +++ b/usr/include/Makefile
> @@ -10,6 +10,7 @@ UAPI_CFLAGS := -std=c90 -Werror=implicit-function-declaration
> UAPI_ARCH := $(or $(HEADER_ARCH),$(SRCARCH))
>
> override c_flags = $(KBUILD_USERCFLAGS) $(UAPI_CFLAGS) -Wp,-MMD,$(depfile)
> +cxx_flags = $(filter-out -Wmissing-prototypes -Wstrict-prototypes -std=%, $(KBUILD_USERCFLAGS)) -std=c++98
>
> # The following are excluded for now because they fail to build.
> #
> @@ -61,6 +62,27 @@ endif
> # asm-generic/*.h is used by asm/*.h, and should not be included directly
> no-header-test += asm-generic/%
>
> +# The following are not compatible with C++.
> +#
> +# Do not add a new header to the list without legitimate reason.
> +# Please consider to fix the header first.
> +#
> +# Sorted alphabetically.
> +no-header-test-cxx += linux/auto_dev-ioctl.h
> +no-header-test-cxx += linux/map_to_14segment.h
> +no-header-test-cxx += linux/map_to_7segment.h
> +no-header-test-cxx += linux/netfilter/xt_sctp.h
> +no-header-test-cxx += linux/target_core_user.h
> +no-header-test-cxx += linux/vhost.h
> +no-header-test-cxx += linux/vhost_types.h
> +no-header-test-cxx += linux/virtio_net.h
> +no-header-test-cxx += linux/virtio_ring.h
> +no-header-test-cxx += scsi/fc/fc_els.h
> +
> +ifeq ($(UAPI_ARCH),x86)
> +no-header-test-cxx += asm/elf.h
> +endif
> +
> # The following are using libc header and types.
> #
> # Do not add a new header to the list without legitimate reason.
> @@ -138,8 +160,12 @@ endif
>
> always-y := $(patsubst $(obj)/%.h,%.hdrtest, $(shell find $(obj) -name '*.h' 2>/dev/null))
>
> +# $(cc-option) forces '-x c' which breaks '-x c++' detection.
> +cc-can-compile-cxx := $(call try-run,$(CC) -c -x c++ /dev/null -o "$$TMP", 1)
Include $(CLANG_FLAGS) here just in case clang cannot generate code for
the host target (I know, sounds weird, but I have seen people build
LLVM only targeting arm/arm64 with an x86_64 host...).
> +
> target-libc = $(filter $(uses-libc), $*.h)
> target-can-compile = $(filter-out $(no-header-test), $*.h)
> +target-can-compile-cxx = $(and $(cc-can-compile-cxx), $(target-can-compile), $(filter-out $(no-header-test-cxx), $*.h))
>
> hdrtest-flags = -fsyntax-only -Werror \
> -nostdinc -I $(obj) $(if $(target-libc), -I $(srctree)/usr/dummy-include)
> @@ -149,6 +175,8 @@ quiet_cmd_hdrtest = HDRTEST $<
> cmd_hdrtest = \
> $(CC) $(c_flags) $(hdrtest-flags) -x c /dev/null \
> $(if $(target-can-compile), -include $< -include $<); \
> + $(if $(target-can-compile-cxx), \
> + $(CC) $(cxx_flags) $(hdrtest-flags) -x c++ /dev/null -include $<;) \
> $(PERL) $(src)/headers_check.pl $(obj) $<; \
> touch $@
>
>
> --
> 2.53.0
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH RFC 0/5] kbuild: uapi: also test UAPI headers against C++ compilers
2026-03-08 21:24 [PATCH RFC 0/5] kbuild: uapi: also test UAPI headers against C++ compilers Thomas Weißschuh
` (4 preceding siblings ...)
2026-03-08 21:24 ` [PATCH RFC 5/5] kbuild: uapi: also test UAPI headers against C++ compilers Thomas Weißschuh
@ 2026-03-12 8:16 ` Nathan Chancellor
5 siblings, 0 replies; 8+ messages in thread
From: Nathan Chancellor @ 2026-03-12 8:16 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Arnd Bergmann, Nicolas Schier, linux-kbuild, linux-kernel,
David Howells
On Sun, Mar 08, 2026 at 10:24:00PM +0100, Thomas Weißschuh wrote:
> C++ language requirements differ from those of C.
>
> Also test the headers against C++ compilers to make sure no errors
> creep in accidentally.
>
> There was a previous attempt by David Howells[0], but today with the
> existing UAPI testing infrastructure the implementation is a bit nicer.
> This series does not derive from David's, as I found it only after
> writing my patches.
>
> [0] https://lore.kernel.org/lkml/nycvar.YFH.7.76.1809052120510.24932@n3.vanv.qr/
>
> This depends on my other series "kbuild: uapi: remove usage of toolchain
> headers", which is currently in kbuild-next-unstable.
>
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
> Thomas Weißschuh (5):
> kbuild: uapi: move some compiler arguments out of the command definition
> kbuild: uapi: move all include path flags together
> kbuild: uapi: handle UML in architecture-specific exclusion lists
> kbuild: uapi: provide a C++ compatible dummy definition of NULL
> kbuild: uapi: also test UAPI headers against C++ compilers
Aside from my comment on patch 5, this seems reasonable to me.
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Cheers,
Nathan
^ permalink raw reply [flat|nested] 8+ messages in thread