summaryrefslogtreecommitdiffstats
path: root/usr/include
diff options
context:
space:
mode:
authorThomas Weißschuh <linux@weissschuh.net>2026-03-16 17:52:02 +0100
committerNicolas Schier <nsc@kernel.org>2026-03-25 13:24:42 +0100
commitdcc99abebfa1e9ca70f8af8695b6682ad7597bf2 (patch)
treea3fddee07fa902d300eda310074c9d722c6524ee /usr/include
parentb187c1a1a0513593663b1adee0340d41d833d16d (diff)
downloadlinux-dcc99abebfa1e9ca70f8af8695b6682ad7597bf2.tar.gz
linux-dcc99abebfa1e9ca70f8af8695b6682ad7597bf2.zip
kbuild: uapi: also test UAPI headers against C++ compilers
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> Reviewed-by: Nathan Chancellor <nathan@kernel.org> Link: https://patch.msgid.link/20260316-kbuild-uapi-c-v2-5-35d6d0ed863f@weissschuh.net Signed-off-by: Nicolas Schier <nsc@kernel.org>
Diffstat (limited to 'usr/include')
-rw-r--r--usr/include/Makefile28
1 files changed, 28 insertions, 0 deletions
diff --git a/usr/include/Makefile b/usr/include/Makefile
index edeaf9d778c4..ee69dd9d970e 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) $(CLANG_FLAGS) -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 $@