[PATCH net-next v2] uapi: wrap compiler_types.h in an ifdef instead of the implicit strip

Subsystems: the rest

STALE400d

3 messages, 3 authors, 2025-08-28 · open the first message on its own page

[PATCH net-next v2] uapi: wrap compiler_types.h in an ifdef instead of the implicit strip

From: Jakub Kicinski <kuba@kernel.org>
Date: 2025-08-25 20:18:41

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>
---
v2:
 - remove the hack from scripts/headers_install.sh
 - wrap in __KERNEL__ instead of removing
v1: https://lore.kernel.org/20250818181848.799566-1-kuba@kernel.org

CC: dhowells@redhat.com
CC: kees@kernel.org
CC: gustavoars@kernel.org
CC: aleksander.lobakin@intel.com
CC: tstruk@gigaio.com
---
 scripts/headers_install.sh  | 2 +-
 include/uapi/linux/stddef.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
index 6bbccb43f7e7..4c20c62c4faf 100755
--- a/scripts/headers_install.sh
+++ b/scripts/headers_install.sh
@@ -32,7 +32,7 @@ fi
 sed -E -e '
 	s/([[:space:](])(__user|__force|__iomem)[[:space:]]/\1/g
 	s/__attribute_const__([[:space:]]|$)/\1/g
-	s@^#include <linux/compiler(|_types).h>@@
+	s@^#include <linux/compiler.h>@@
 	s/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g
 	s/(^|[[:space:](])(inline|asm|volatile)([[:space:](]|$)/\1__\2__\3/g
 	s@#(ifndef|define|endif[[:space:]]*/[*])[[:space:]]*_UAPI@#\1 @
diff --git a/include/uapi/linux/stddef.h b/include/uapi/linux/stddef.h
index b87df1b485c2..9a28f7d9a334 100644
--- a/include/uapi/linux/stddef.h
+++ b/include/uapi/linux/stddef.h
@@ -2,7 +2,9 @@
 #ifndef _UAPI_LINUX_STDDEF_H
 #define _UAPI_LINUX_STDDEF_H
 
+#ifdef __KERNEL__
 #include <linux/compiler_types.h>
+#endif
 
 #ifndef __always_inline
 #define __always_inline inline
-- 
2.51.0

Re: [PATCH net-next v2] uapi: wrap compiler_types.h in an ifdef instead of the implicit strip

From: Simon Horman <horms@kernel.org>
Date: 2025-08-27 15:52:28

On Mon, Aug 25, 2025 at 01:18:28PM -0700, Jakub Kicinski wrote:
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>
---
v2:
 - remove the hack from scripts/headers_install.sh
 - wrap in __KERNEL__ instead of removing
v1: https://lore.kernel.org/20250818181848.799566-1-kuba@kernel.org
Reviewed-by: Simon Horman <horms@kernel.org>

Re: [PATCH net-next v2] uapi: wrap compiler_types.h in an ifdef instead of the implicit strip

From: patchwork-bot+netdevbpf@kernel.org
Date: 2025-08-28 11:19:58

Hello:

This patch was applied to netdev/net-next.git (main)
by Paolo Abeni [off-list ref]:

On Mon, 25 Aug 2025 13:18:28 -0700 you wrote:
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).

[...]
Here is the summary with links:
  - [net-next,v2] uapi: wrap compiler_types.h in an ifdef instead of the implicit strip
    https://git.kernel.org/netdev/net-next/c/c2a756891bb4

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help