Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

uapi: wrap compiler_types.h in an ifdef instead of the implicit strip

The uAPI stddef header includes compiler_types.h, a kernel-only
header, to make sure that kernel definitions of annotations
like __counted_by() take precedence.

There is a hack in scripts/headers_install.sh which strips includes
of compiler.h and compiler_types.h when installing uAPI headers.
While explicit handling makes sense for compiler.h, which is included
all over the uAPI, compiler_types.h is only included by stddef.h
(within the uAPI, obviously it's included in kernel code a lot).

Remove the stripping from scripts/headers_install.sh and wrap
the include of compiler_types.h in #ifdef __KERNEL__ instead.
This should be equivalent functionally, but is easier to understand
to a casual reader of the code. It also makes it easier to work
with kernel headers directly from under tools/

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20250825201828.2370083-1-kuba@kernel.org
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Jakub Kicinski and committed by
Paolo Abeni
c2a75689 d4854be4

+3 -1
+2
include/uapi/linux/stddef.h
··· 2 2 #ifndef _UAPI_LINUX_STDDEF_H 3 3 #define _UAPI_LINUX_STDDEF_H 4 4 5 + #ifdef __KERNEL__ 5 6 #include <linux/compiler_types.h> 7 + #endif 6 8 7 9 #ifndef __always_inline 8 10 #define __always_inline inline
+1 -1
scripts/headers_install.sh
··· 32 32 sed -E -e ' 33 33 s/([[:space:](])(__user|__force|__iomem)[[:space:]]/\1/g 34 34 s/__attribute_const__([[:space:]]|$)/\1/g 35 - s@^#include <linux/compiler(|_types).h>@@ 35 + s@^#include <linux/compiler.h>@@ 36 36 s/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g 37 37 s/(^|[[:space:](])(inline|asm|volatile)([[:space:](]|$)/\1__\2__\3/g 38 38 s@#(ifndef|define|endif[[:space:]]*/[*])[[:space:]]*_UAPI@#\1 @