stddef: don't include compiler_types.h in the uAPI header
Subsystems (2)
Jakub Kicinski
maintainerPATCH 1/1 stddef: don't include compiler_types.h in the uAPI header
The uAPI stddef header includes compiler_types.h, a non-uAPI header. There is a hack in scripts/headers_install.sh which strips includes of compiler.h and compiler_types.h.
But AFAICT there is nothing in stddef.h which would need the include. The include dates back to when uAPI stddef.h was first created, back then the including of compiler.h was the only line in the file. So presumably stddef.h has been including compiler headers to retain some chain of dependency? Perhaps someone with more build system understanding knows what that chain would be, given kernel doesn't include uAPI stddef.h, and user space has the compiler headers stripped.
Since nothing needs this include, let's remove it. Builds pass on x86, arm64, csky, m68k, riscv32. The direct motivation for the change is that the includes of compiler.h and co. make it hard to include uAPI headers from tools/.
---
More than happy for someone else to take this via their tree, FWIW.
--- include/uapi/linux/stddef.h | 2 -- 1 file changed, 2 deletions(-)
include/uapi/linux/stddef.h +0 -2
@@ -2,8 +2,6 @@#ifndef _UAPI_LINUX_STDDEF_H#define _UAPI_LINUX_STDDEF_H -#include <linux/compiler_types.h> -#ifndef __always_inline#define __always_inline inline#endif
Signature · 1 line
2.50.1
Quoted 3 lines · Jakub Kicinski
[...]
header. There is a hack inscripts/headers_install.shwhich strips includes ofcompiler.handcompiler_types.h.
This looks like the last user of compiler_types.h in include/uapi, so it'd probably be best to also remove portion of the hack from scripts/headers_install.sh while you're at it.
Quoted 4 lines
[...]
understanding knows what that chain would be, given kernel doesn't include uAPIstddef.h, and user space has the compiler headers stripped.
Uh, yes it does:
$ git grep uapi/linux/stddef.h include/linux/stddef.h:#include <uapi/linux/stddef.h>
Quoted 2 lines
[...]
Since nothing needs this include, let's remove it.
But yes, nothing uses compiler_types.h via uapi/linux/stddef.h. That does seem to be true.
I find the change of subject between stddef.h ("nothing includes the uapi header") and compiler_types.h ("nothing needs this include") to be confusing in the commit log. :)
Quoted 7 lines
[...]
Builds pass on x86, arm64, csky, m68k, riscv32. The direct motivation for the change is that the includes ofcompiler.hand co. make it hard to include uAPI headers fromtools/.Signed-off-by Jakub Kicinski <[email protected]>
If you can clear that up and everything is building, then this change would be fine my me.
Signature · 1 line
Kees Cook
Jakub Kicinski
maintainerQuoted 4 lines · On Mon, 18 Aug 2025 21:06:10 -0700 Kees Cook wrote:
Quoted 1 line
Since nothing needs this include, let's remove it.
But yes, nothing uses
compiler_types.hviauapi/linux/stddef.h. That does seem to be true.
While staring at the kbuild bot report (which I can't repro :|) I realized this include is to give kernel's __counted_by and friends precedence over the empty uAPI-facing defines.
Not sure this is the most fortunate approach, personally I'd rather wrap our empty user-space-facing defines under ifndef __KERNEL__. I think it'd be better from "include what you need" perspective. Perhaps stddef pulling in compiler annotations is expected, dunno...
Would you be okay with:
scripts/headers_install.sh +1 -1
@@ -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 @
include/uapi/linux/stddef.h +2 -0
@@ -2,7 +2,9 @@#ifndef _UAPI_LINUX_STDDEF_H#define _UAPI_LINUX_STDDEF_H +#ifdef __KERNEL__#include <linux/compiler_types.h> +#endif
? As you pointed out compiler_types.h is only included under stddef.h so the special handling in the installation script is easily avoided.
Quoted 2 lines · Jakub Kicinski
I realized this include is to give kernel's
__counted_byand friends precedence over the empty uAPI-facing defines.
Right.
Quoted 4 lines
Not sure this is the most fortunate approach, personally I'd rather wrap our empty user-space-facing defines under ifndef
__KERNEL__. I think it'd be better from "include what you need" perspective. Perhaps stddef pulling in compiler annotations is expected, dunno...
I'm trying to leave the door open for userspace to start using these, if they defined them too.
Quoted 27 lines
Would you be okay with:
scripts/headers_install.sh +1
-1@@ -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 @include/uapi/linux/stddef.h +2
-0@@ -2,7 +2,9 @@#ifndef _UAPI_LINUX_STDDEF_H#define _UAPI_LINUX_STDDEF_H +#ifdef __KERNEL__#include <linux/compiler_types.h> +#endif
Quoted 2 lines
? As you pointed out
compiler_types.his only included understddef.hso the special handling in the installation script is easily avoided.
I think this should be fine, but something is itching at my mind that doing __KERNEL__ checks in uAPI is fragile. I can't substantiate this sensation, though. :P
Signature · 1 line
Kees Cook
Jakub Kicinski
maintainerQuoted 7 lines · On Mon, 25 Aug 2025 19:54:44 -0700 Kees Cook wrote:
Quoted 4 lines
Not sure this is the most fortunate approach, personally I'd rather wrap our empty user-space-facing defines under ifndef
__KERNEL__. I think it'd be better from "include what you need" perspective. Perhaps stddef pulling in compiler annotations is expected, dunno...I'm trying to leave the door open for userspace to start using these, if they defined them too.
Makes sense.
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Jakub,
kernel test robot noticed the following build errors:
[auto build test ERROR on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Jakub-Kicinski/stddef-don-t-include-compiler_types-h-in-the-uAPI-header/20250819-022023 base: net-next/main patch link: https://lore.kernel.org/r/20250818181848.799566-1-kuba%40kernel.org patch subject: [PATCH net-next] stddef: don't include compiler_types.h in the uAPI header config: arm64-allmodconfig (https://download.01.org/0day-ci/archive/20250819/[email protected]/config) compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250819/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All error/warnings (new ones prefixed by >>):
In file included from <built-in>:3:
In file included from lib/vdso/gettimeofday.c:5:
In file included from include/vdso/auxclock.h:5:
In file included from include/uapi/linux/time.h:5:
>> include/linux/types.h:265:21: error: field has incomplete type 'struct task_struct'
265 | struct task_struct __rcu *task;
| ^
include/linux/types.h:265:9: note: forward declaration of 'struct task_struct'
265 | struct task_struct __rcu *task;
| ^
>> include/linux/types.h:265:26: error: expected ';' at end of declaration list
265 | struct task_struct __rcu *task;
| ^
| ;
In file included from <built-in>:3:
In file included from lib/vdso/gettimeofday.c:6:
In file included from include/vdso/datapage.h:7:
In file included from include/linux/compiler.h:5:
In file included from include/linux/compiler_types.h:89:
>> include/linux/compiler_attributes.h:55:9: warning: '__always_inline' macro redefined [-Wmacro-redefined]
55 | #define __always_inline inline __attribute__((__In file included from arch/arm64/kernel/vdso32/note.c:11:
In file included from include/linux/elfnote.h:62:
In file included from include/uapi/linux/elf.h:5:
>> include/linux/types.h:265:21: error: field has incomplete type 'struct task_struct'
alw ays_inline__))
| ^
include/uapi/linux/stddef.h:6:9: note: previous definition is here
6 | #define __always_inline inline
| ^
265 | struct task_struct __rcu *task;
| ^
In file included from <built-in>:3:
In file included from lib/vdso/gettimeofday.c:6:
In file included from include/vdso/datapage.h:7:
In file included from include/linux/compiler.h:5:
>> include/linux/compiler_types.h:346:10: warning: '__counted_by' macro redefined [-Wmacro-redefined]
346 | # define __counted_by(member) __attribute__((__counted_by__(member)))
| ^
include/uapi/linux/stddef.h:60:9: note: previous definition is here
60 | #define __counted_by(m)
| ^
In file included from include/linux/types.h:265:9: note: forward declaration of 'struct task_struct'
265 | struct task_struct __rcu *task;
| ^
<built-in>:3:
In file included from lib/vdso/gettimeofday.c:6:
In file included from include/vdso/datapage.h:7:
In file included from include/linux/compiler.h:5:
>> include/linux/compiler_types.h:367include/linux/types.h:265:26: error: expected ';' at end of declaration list
: 265 | struct task_struct __rcu *task;
| ^
| ;
9: warning: '__counted_by_le' macro redefined [-Wmacro-redefined]
367 | #define __counted_by_le(member) __counted_by(member)
| ^
include/uapi/linux/stddef.h:64:9: note: previous definition is here
64 | #define __counted_by_le(m)
| ^
In file included from <built-in>:3:
In file included from lib/vdso/gettimeofday.c:6:
In file included from include/vdso/datapage.h:7:
In file included from include/linux/compiler.h:5:
>> include/linux/compiler_types.h:368:9: warning: '__counted_by_be' macro redefined [-Wmacro-redefined]
368 | #define __counted_by_be(member)
| ^
include/uapi/linux/stddef.h:68:9: note: previous definition is here
68 | #define __counted_by_be(m)
| ^
>> error: expected ';' after struct
>> arch/arm64/kernel/vdso32/note.c:14:1: error: unknown type name '_note_14'
14 | ELFNOTE32("Linux", 0, LINUX_VERSION_CODE);
| ^
include/linux/elfnote.h:95:37: note: expanded from macro 'ELFNOTE32'
95 | #define ELFNOTE32(name, type, desc) ELFNOTE(32, name, type, desc)
| ^
include/linux/elfnote.h:93:2: note: expanded from macro 'ELFNOTE'
93 | _ELFNOTE(size, name, __LINE__, type, desc)
| ^
include/linux/elfnote.h:79:4: note: expanded from macro '_ELFNOTE'
79 | } _ELFNOTE_PASTE(_note_, unique) \
| ^
include/linux/elfnote.h:71:29: note: expanded from macro '_ELFNOTE_PASTE'
71 | #define _ELFNOTE_PASTE(a,b) a##b
| ^
<scratch space>:11:1: note: expanded from here
11 | _note_14
| ^
>> error: expected ';' after struct
>> arch/arm64/kernel/vdso32/note.c:15:1: error: unknown type name '_note_15'
15 | BUILD_SALT;
| ^
include/linux/build-salt.h:16:8: note: expanded from macro 'BUILD_SALT'
16 | ELFNOTE32("Linux", LINUX_ELFNOTE_BUILD_SALT, CONFIG_BUILD_SALT)
| ^
include/linux/elfnote.h:95:37: note: expanded from macro 'ELFNOTE32'
95 | #define ELFNOTE32(name, type, desc) ELFNOTE(32, name, type, desc)
| ^
include/linux/elfnote.h:93:2: note: expanded from macro 'ELFNOTE'
93 | _ELFNOTE(size, name, __LINE__, type, desc)
| ^
include/linux/elfnote.h:79:4: note: expanded from macro '_ELFNOTE'
79 | } _ELFNOTE_PASTE(_note_, unique) \
| ^
include/linux/elfnote.h:71:29: note: expanded from macro '_ELFNOTE_PASTE'
71 | #define _ELFNOTE_PASTE(a,b) a##b
| ^
<scratch space>:21:1: note: expanded from here
21 | _note_15
| ^ 6 errors generated.
make[3]: *** [arch/arm64/kernel/vdso32/Makefile:144: arch/arm64/kernel/vdso32/note.o] Error 1 4 warnings and 2 errors generated.
make[3]: *** [arch/arm64/kernel/vdso32/Makefile:146: arch/arm64/kernel/vdso32/vgettimeofday.o] Error 1 make[3]: Target 'arch/arm64/kernel/vdso32/vdso.so' not remade because of errors. make[2]: *** [arch/arm64/Makefile:208: vdso_prepare] Error 2
make[2]: Target 'prepare' not remade because of errors.
make[1]: *** [Makefile:248: __sub-make] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:248: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.
vim +/__always_inline +55 include/linux/compiler_attributes.h
86cffecdeaa278 Kees Cook 2021-11-05 45 a3f8a30f3f0079 Miguel Ojeda 2018-08-30 46 /* a3f8a30f3f0079 Miguel Ojeda 2018-08-30 47 * Note: users of __always_inline currently do not write "inline" themselves, a3f8a30f3f0079 Miguel Ojeda 2018-08-30 48 * which seems to be required by gcc to apply the attribute according a3f8a30f3f0079 Miguel Ojeda 2018-08-30 49 * to its docs (and also "warning: always_inline function might not be a3f8a30f3f0079 Miguel Ojeda 2018-08-30 50 * inlinable [-Wattributes]" is emitted). a3f8a30f3f0079 Miguel Ojeda 2018-08-30 51 * a3f8a30f3f0079 Miguel Ojeda 2018-08-30 52 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-always_005finline-function-attribute a3f8a30f3f0079 Miguel Ojeda 2018-08-30 53 * clang: mentioned a3f8a30f3f0079 Miguel Ojeda 2018-08-30 54 */
a3f8a30f3f0079 Miguel Ojeda 2018-08-30 @55 #define __always_inline inline __attribute__((__always_inline__))a3f8a30f3f0079 Miguel Ojeda 2018-08-30 56
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki