kbuild: uapi: remove usage of toolchain headers
Subsystems (2)
cover kbuild: uapi: remove usage of toolchain headers
Currently the test compilation of some UAPI headers requires a toolchain libc headers. Remove that dependency.
---
Thomas Weißschuh (9):
hexagon: uapi: Fix structure alignment attribute
kbuild: uapi: test linux/bpf_perf_event.h on powerpc
kbuild: uapi: deduplicate linux/bpf_perf_event.h exclusions
kbuild: uapi: completely exclude linux/bpf_perf_event.h on nios2
kbuild: uapi: only use dummy-include for headers which use libc
kbuild: uapi: provide stub includes for some libc headers
kbuild: uapi: use custom stub headers instead of libc ones
kbuild: uapi: simplify libc dependency logic
kbuild: uapi: remove now unneeded guard headers
arch/hexagon/include/uapi/asm/sigcontext.h | 2 +- usr/dummy-include/endian.h | 0 usr/dummy-include/limits.h | 8 ++++++++ usr/dummy-include/netinet/if_ether.h | 0 usr/dummy-include/netinet/in.h | 0 usr/dummy-include/stdbool.h | 7 ------- usr/dummy-include/stddef.h | 8 ++++++++ usr/dummy-include/stdint.h | 17 +++++++++++++++++ usr/dummy-include/stdlib.h | 7 ------- usr/dummy-include/string.h | 12 ++++++++++++ usr/dummy-include/sys/ioctl.h | 0 usr/dummy-include/sys/socket.h | 12 ++++++++++++ usr/dummy-include/sys/time.h | 3 +++ usr/dummy-include/sys/types.h | 0 usr/dummy-include/time.h | 0 usr/dummy-include/unistd.h | 0 usr/include/Makefile | 24 +++++------------------- 17 files changed, 66 insertions(+), 34 deletions(-)
---
base-commit: 93e7204d4b0e7b69ebbceee0dc09092e975cece3
change-id: 20260124-kbuild-uapi-libc-896f152c81d6
Best regards,
Signature · 1 line
Thomas Weißschuh <[email protected]>
PATCH 1/9 hexagon: uapi: Fix structure alignment attribute
From: Thomas Weißschuh <[email protected]>
__aligned() is a kernel macro, which is not available in UAPI headers.
Use the compiler-provided alignment attribute directly.
--- arch/hexagon/include/uapi/asm/sigcontext.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/hexagon/include/uapi/asm/sigcontext.h +1 -1
@@ -29,6 +29,6 @@*/ struct sigcontext {struct user_regs_struct sc_regs; -}__aligned(8) ; +} __attribute__((aligned (8 )));#endif
Signature · 1 line
2.53.0
PATCH 2/9 kbuild: uapi: test linux/bpf_perf_event.h on powerpc
In reply to Thomas WeißschuhThis header works now, so test it.
--- usr/include/Makefile | 4 ---- 1 file changed, 4 deletions(-)
usr/include/Makefile +0 -4
@@ -56,10 +56,6 @@ ifeq ($(SRCARCH),openrisc) no-header-test += linux/bpf_perf_event.h endif -ifeq ($(SRCARCH),powerpc) -no-header-test += linux/bpf_perf_event.h -endif - ifeq ($(SRCARCH),sparc) no-header-test += asm/uctx.h no-header-test += asm/fbio.h
Signature · 1 line
2.53.0
PATCH 3/9 kbuild: uapi: deduplicate linux/bpf_perf_event.h exclusions
In reply to Thomas WeißschuhThis header is excluded for multiple architectures. Use a single exclusion for all of them.
--- usr/include/Makefile | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
usr/include/Makefile +1 -9
@@ -48,11 +48,7 @@ no-header-test += xen/privcmd.h # More headers are broken in some architectures -ifeq ($(SRCARCH),arc) -no-header-test += linux/bpf_perf_event.h -endif - -ifeq ($(SRCARCH),openrisc) +ifneq ($(filter arc openrisc xtensa, $(SRCARCH)),) no-header-test += linux/bpf_perf_event.h endif
@@ -61,10 +57,6 @@ no-header-test += asm/uctx.h no-header-test += asm/fbio.h endif -ifeq ($(SRCARCH),xtensa) -no-header-test += linux/bpf_perf_event.h -endif - # asm-generic/*.h is used by asm/*.h, and should not be included directly no-header-test += asm-generic/%
Signature · 1 line
2.53.0
PATCH 4/9 kbuild: uapi: completely exclude linux/bpf_perf_event.h on nios2
In reply to Thomas WeißschuhThis header is actually not buildable on nios. As nobody built nios2 with CONFIG_CC_CAN_LINK=y so far, this produced no errors.
--- usr/include/Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
usr/include/Makefile +1 -2
@@ -48,7 +48,7 @@ no-header-test += xen/privcmd.h # More headers are broken in some architectures -ifneq ($(filter arc openrisc xtensa, $(SRCARCH)),) +ifneq ($(filter arc openrisc xtensa nios2, $(SRCARCH)),) no-header-test += linux/bpf_perf_event.h endif
@@ -128,7 +128,6 @@ endif ifeq ($(SRCARCH),nios2) uses-libc += asm/ptrace.h -uses-libc += linux/bpf_perf_event.h endif ifeq ($(SRCARCH),s390)
Signature · 1 line
2.53.0
PATCH 5/9 kbuild: uapi: only use dummy-include for headers which use libc
In reply to Thomas WeißschuhThe headers which do not rely on libc are using built using -nostdinc. For them the dummy headers are pointless.
--- usr/include/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
usr/include/Makefile +2 -2
@@ -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) -I $(srctree)/usr/dummy-include +override c_flags = $(KBUILD_USERCFLAGS) $(UAPI_CFLAGS) -Wp,-MMD,$(depfile) -I $(obj) # The following are excluded for now because they fail to build. #
@@ -145,7 +145,7 @@ target-can-compile = $(and $(filter-out $(no-header-test), $*.h), \ quiet_cmd_hdrtest = HDRTEST $< cmd_hdrtest = \ $(CC) $(c_flags) -fsyntax-only -Werror -x c /dev/null \ - $(if $(target-no-libc), -nostdinc) \ + $(if $(target-no-libc), -nostdinc, -I $(srctree)/usr/dummy-include) \ $(if $(target-can-compile), -include $< -include $<); \ $(PERL) $(src)/headers_check.pl $(obj) $<; \ touch $@
Signature · 1 line
2.53.0
PATCH 6/9 kbuild: uapi: provide stub includes for some libc headers
In reply to Thomas WeißschuhSome UAPI headers incorrectly use libc headers. To compile-test these UAPI headers, their respective libc dependencies need to be present. Not all kernel toolchains provide these headers, reducing test coverage.
Introduce some stub headers which provide just enough symbols to test all UAPI headers. Most headers are empty anyways, as their symbols are only used in macros which are not actually evaluated.
As these headers are only ever used with newer kernel toolchains, they can defer to compiler builtins in many cases.
As more UAPI headers are cleaned up to not require these stubs anymore, they can be removed again.
--- usr/dummy-include/endian.h | 0 usr/dummy-include/limits.h | 8 ++++++++ usr/dummy-include/netinet/if_ether.h | 0 usr/dummy-include/netinet/in.h | 0 usr/dummy-include/stddef.h | 8 ++++++++ usr/dummy-include/stdint.h | 17 +++++++++++++++++ usr/dummy-include/string.h | 12 ++++++++++++ usr/dummy-include/sys/ioctl.h | 0 usr/dummy-include/sys/socket.h | 12 ++++++++++++ usr/dummy-include/sys/time.h | 3 +++ usr/dummy-include/sys/types.h | 0 usr/dummy-include/time.h | 0 usr/dummy-include/unistd.h | 0 13 files changed, 60 insertions(+)
usr/dummy-include/endian.h new file +0 -0
usr/dummy-include/limits.h new file +8 -0
@@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _DUMMY_LIMITS_H +#define _DUMMY_LIMITS_H + +#define INT_MAX ((int)(~0U >> 1)) +#define INT_MIN (-INT_MAX - 1) + +#endif /* _DUMMY_LIMITS_H */
usr/dummy-include/netinet/if_ether.h new file +0 -0
usr/dummy-include/netinet/in.h new file +0 -0
usr/dummy-include/stddef.h new file +8 -0
@@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _DUMMY_STDDEF_H +#define _DUMMY_STDDEF_H + +#define offsetof (TYPE ,MEMBER ) __builtin_offsetof(TYPE, MEMBER) +#define NULL ((void *)0) + +#endif /* _DUMMY_STDDEF_H */
usr/dummy-include/stdint.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _DUMMY_STDINT_H +#define _DUMMY_STDINT_H + +#include <linux/types.h> + +typedef __u64 uint64_t ; +typedef __u32 uint32_t ; +typedef __u16 uint16_t ; +typedef __u8 uint8_t ; + +typedef __s64 int64_t ; +typedef __s32 int32_t ; +typedef __s16 int16_t ; +typedef __s8 int8_t ; + +#endif /* _DUMMY_STDINT_H */
usr/dummy-include/string.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _DUMMY_STRING_H +#define _DUMMY_STRING_H + +#include <stddef.h> + +#define memset (_s, _c, _n) __builtin_memset(_s, _c, _n) +#define memcpy (_dest, _src, _n) __builtin_memcpy(_dest, _src, _n) + +#define strlen (_s) __builtin_strlen(_s) + +#endif /* _DUMMY_STRING_H */
usr/dummy-include/sys/ioctl.h new file +0 -0
usr/dummy-include/sys/socket.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _DUMMY_SYS_SOCKET_H +#define _DUMMY_SYS_SOCKET_H + +#include <linux/socket.h> + +struct sockaddr { +__kernel_sa_family_t sa_family;/* address family, AF_xxx */ +char sa_data[14 ];/* 14 bytes of protocol address */ +}; + +#endif /* _DUMMY_SYS_SOCKET_H */
usr/dummy-include/sys/time.h new file +3 -0
@@ -0,0 +1,3 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <linux/time.h>
usr/dummy-include/sys/types.h new file +0 -0
usr/dummy-include/time.h new file +0 -0
usr/dummy-include/unistd.h new file +0 -0
Signature · 1 line
2.53.0
PATCH 7/9 kbuild: uapi: use custom stub headers instead of libc ones
In reply to Thomas WeißschuhNow that custom stub headers are provided for all libc headers used from the UAPI headers, the dependency on the toolchain libc can be dropped.
--- usr/include/Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
usr/include/Makefile +2 -3
@@ -138,14 +138,13 @@ endif always-y := $(patsubst $(obj)/%.h,%.hdrtest, $(shell find $(obj) -name '*.h' 2>/dev/null)) target-no-libc = $(filter-out $(uses-libc), $*.h) -target-can-compile = $(and $(filter-out $(no-header-test), $*.h), \ - $(or $(CONFIG_CC_CAN_LINK), $(target-no-libc))) +target-can-compile = $(filter-out $(no-header-test), $*.h) # 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 \ - $(if $(target-no-libc), -nostdinc, -I $(srctree)/usr/dummy-include) \ + -nostdinc $(if $(target-no-libc), , -I $(srctree)/usr/dummy-include) \ $(if $(target-can-compile), -include $< -include $<); \ $(PERL) $(src)/headers_check.pl $(obj) $<; \ touch $@
Signature · 1 line
2.53.0
PATCH 8/9 kbuild: uapi: simplify libc dependency logic
In reply to Thomas WeißschuhThe only left user of the condition inverts it.
Invert the condition completely and simplify its user.
--- usr/include/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
usr/include/Makefile +2 -2
@@ -137,14 +137,14 @@ endif always-y := $(patsubst $(obj)/%.h,%.hdrtest, $(shell find $(obj) -name '*.h' 2>/dev/null)) -target-no-libc = $(filter-out $(uses-libc), $*.h) +target-libc = $(filter $(uses-libc), $*.h) target-can-compile = $(filter-out $(no-header-test), $*.h) # 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-no-libc), , -I $(srctree)/usr/dummy-include) \ + -nostdinc $(if $(target-libc), -I $(srctree)/usr/dummy-include) \ $(if $(target-can-compile), -include $< -include $<); \ $(PERL) $(src)/headers_check.pl $(obj) $<; \ touch $@
Signature · 1 line
2.53.0
PATCH 9/9 kbuild: uapi: remove now unneeded guard headers
In reply to Thomas WeißschuhThe test compilation does not allow usage of the toolchain headers anymore, so these dummy headers are not needed anymore.
--- usr/dummy-include/stdbool.h | 7 ------- usr/dummy-include/stdlib.h | 7 ------- 2 files changed, 14 deletions(-)
usr/dummy-include/stdbool.h deleted +0 -7
@@ -1,7 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef _STDBOOL_H -#define _STDBOOL_H - -#error "Please do not include <stdbool.h> from exported headers" - -#endif /* _STDBOOL_H */
usr/dummy-include/stdlib.h deleted +0 -7
@@ -1,7 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef _STDLIB_H -#define _STDLIB_H - -#error "Please do not include <stdlib.h> from exported headers" - -#endif /* _STDLIB_H */
Signature · 1 line
2.53.0
Quoted 4 lines · Thomas Weißschuh
Currently the test compilation of some UAPI headers requires a toolchain libc headers. Remove that dependency.
Signed-off-by Thomas Weißschuh <[email protected]>
Nice work!
I had toyed around with a similar series, using a slightly different approach of always using the in-kernel nolibc headers, and making those compile across all architectures (using empty stubs for those that are missing syscall entry functions).
I don't care much which way we do this as long as we can build test the headers, but I wonder what your reason was for picking this approach over the other.
Arnd
Quoted 10 lines · Arnd Bergmann
Quoted 4 lines · Thomas Weißschuh
Currently the test compilation of some UAPI headers requires a toolchain libc headers. Remove that dependency.
Signed-off-by Thomas Weißschuh <[email protected]>Nice work!
Acked-by Arnd Bergmann <[email protected]>
Quoted 8 lines
I had toyed around with a similar series, using a slightly different approach of always using the in-kernel nolibc headers, and making those compile across all architectures (using empty stubs for those that are missing syscall entry functions).
I don't care much which way we do this as long as we can build test the headers, but I wonder what your reason was for picking this approach over the other.
My goal is to reduce the reliance of the UAPI headers on libc ones. Hopefully we can remove libc usages from the UAPI headers and then also drop the compatibility bits from the stub headers. If we use the full nolibc the message to UAPI authors would not be clear and new dependencies may be introduced again.
Thomas
Quoted 12 lines · Thomas Weißschuh
Quoted 10 lines · Arnd Bergmann
On Fri, Feb 27, 2026, at 07:37, Thomas Weißschuh wrote:
I had toyed around with a similar series, using a slightly different approach of always using the in-kernel nolibc headers, and making those compile across all architectures (using empty stubs for those that are missing syscall entry functions).
I don't care much which way we do this as long as we can build test the headers, but I wonder what your reason was for picking this approach over the other.
Quoted 5 lines
My goal is to reduce the reliance of the UAPI headers on libc ones. Hopefully we can remove libc usages from the UAPI headers and then also drop the compatibility bits from the stub headers. If we use the full nolibc the message to UAPI authors would not be clear and new dependencies may be introduced again.
Good point, thanks for the clarification!
Arnd
Quoted 2 lines · Thomas Weißschuh
Currently the test compilation of some UAPI headers requires a toolchain libc headers. Remove that dependency.
Thanks a lot for the highly appreciated clean up! Having -nostdinc in UAPI header tests is good thing!
Kind regards,
Nicolas
Signature · 1 line
Nicolas
Quoted 4 lines · Thomas Weißschuh
Currently the test compilation of some UAPI headers requires a toolchain libc headers. Remove that dependency.
Signed-off-by Thomas Weißschuh <[email protected]>
Quoted 11 lines
---
Thomas Weißschuh (9):
hexagon: uapi: Fix structure alignment attribute
kbuild: uapi: testlinux/bpf_perf_event.hon powerpc
kbuild: uapi: deduplicatelinux/bpf_perf_event.hexclusions
kbuild: uapi: completely excludelinux/bpf_perf_event.hon nios2
kbuild: uapi: only use dummy-include for headers which use libc
kbuild: uapi: provide stub includes for some libc headers
kbuild: uapi: use custom stub headers instead of libc ones
kbuild: uapi: simplify libc dependency logic
kbuild: uapi: remove now unneeded guard headers
This is nice! For the series:
Cheers,
Nathan
Nicolas Schier
maintainerQuoted 2 lines · Thomas Weißschuh
Currently the test compilation of some UAPI headers requires a toolchain libc headers. Remove that dependency.
Applied to kbuild/kbuild-next.git (kbuild-next), thanks!
[1/9] hexagon: uapi: Fix structure alignment attribute
https://git.kernel.org/kbuild/c/47bca1cb [2/9] kbuild: uapi: test linux/bpf_perf_event.h on powerpc https://git.kernel.org/kbuild/c/a8c9d3cc [3/9] kbuild: uapi: deduplicate linux/bpf_perf_event.h exclusions https://git.kernel.org/kbuild/c/45bd8643 [4/9] kbuild: uapi: completely exclude linux/bpf_perf_event.h on nios2 https://git.kernel.org/kbuild/c/60a16bee [5/9] kbuild: uapi: only use dummy-include for headers which use libc https://git.kernel.org/kbuild/c/0ef1b7a6 [6/9] kbuild: uapi: provide stub includes for some libc headers https://git.kernel.org/kbuild/c/aad94ba6 [7/9] kbuild: uapi: use custom stub headers instead of libc ones https://git.kernel.org/kbuild/c/579f103f [8/9] kbuild: uapi: simplify libc dependency logic https://git.kernel.org/kbuild/c/510c7a57 [9/9] kbuild: uapi: remove now unneeded guard headers https://git.kernel.org/kbuild/c/febb5c81
Please look out for regression or issue reports or other follow up comments, as they may result in the patch/series getting dropped, reverted or modified (e.g. trailers).
Best regards,
Signature · 1 line
Nicolas