tools: Update context analysis macros in compiler_types.h
PATCH 1/1 tools: Update context analysis macros in compiler_types.h
In sync with the main kernel headers, include a stub version of compiler-context-analysis.h in tools/include/linux/compiler_types.h and remove the sparse context tracking definitions.
Since tools/ headers are generally self-contained, provide a standalone tools/include/linux/compiler-context-analysis.h with no-op stubs for now. Also clean up redundant stubs in tools/testing/shared/linux/kernel.h that are now redundant.
This fixes build errors in tools/testing/radix-tree/ where headers from include/linux/ (like cleanup.h) are used directly and expect these macros to be defined:
| cc -I../shared -I. -I../../include -I../../arch/x86/include -I../../../lib -g -Og -Wall -D_LGPL_SOURCE -fsanitize=address -fsanitize=undefined -c -o radix-tree.o radix-tree.c | In file included from ../shared/linux/cleanup.h:2, | from ../shared/linux/../../../../include/linux/idr.h:18, | from ../shared/linux/idr.h:5, | from radix-tree.c:18: | ../shared/linux/../../../../include/linux/idr.h: In function ‘class_idr_alloc_destructor’: | ../shared/linux/../../../../include/linux/cleanup.h:283:9: error: expected declaration specifiers before ‘__no_context_analysis’ | 283 | __no_context_analysis \ | | ^~~~~~~~~~~~~~~~~~~~~
--- .../include/linux/compiler-context-analysis.h | 42 +++++++++++++++++++ tools/include/linux/compiler_types.h | 16 +------ tools/testing/shared/linux/kernel.h | 4 -- 3 files changed, 43 insertions(+), 19 deletions(-) create mode 100644 tools/include/linux/compiler-context-analysis.h
tools/include/linux/compiler-context-analysis.h new file +42 -0
@@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _TOOLS_LINUX_COMPILER_CONTEXT_ANALYSIS_H +#define _TOOLS_LINUX_COMPILER_CONTEXT_ANALYSIS_H + +/* +* Macros and attributes for compiler-based static context analysis. +* No-op stubs for tools. +*/ + +#define __guarded_by (...) +#define __pt_guarded_by (...) + +#define context_lock_struct (name, ...) struct __VA_ARGS__ name + +#define __no_context_analysis +#define __context_unsafe (comment) +#define context_unsafe (...) ({ __VA_ARGS__; }) +#define context_unsafe_alias (p) +#define disable_context_analysis () +#define enable_context_analysis () + +#define __must_hold (...) +#define __must_not_hold (...) +#define __acquires (...) +#define __cond_acquires (ret, x) +#define __releases (...) +#define __acquire (x) (void)0 +#define __release (x) (void)0 + +#define __must_hold_shared (...) +#define __acquires_shared (...) +#define __cond_acquires_shared (ret, x) +#define __releases_shared (...) +#define __acquire_shared (x) (void)0 +#define __release_shared (x) (void)0 + +#define __acquire_ret (call, expr) (call) +#define __acquire_shared_ret (call, expr) (call) +#define __acquires_ret +#define __acquires_shared_ret + +#endif /* _TOOLS_LINUX_COMPILER_CONTEXT_ANALYSIS_H */
tools/include/linux/compiler_types.h +1 -15
@@ -13,21 +13,7 @@#define __has_builtin (x) (0)#endif -#ifdef __CHECKER__ -/* context/locking */ -# define __must_hold (x) __attribute__((context(x,1,1))) -# define __acquires (x) __attribute__((context(x,0,1))) -# define __releases (x) __attribute__((context(x,1,0))) -# define __acquire (x) __context__(x,1) -# define __release (x) __context__(x,-1) -#else /* __CHECKER__ */ -/* context/locking */ -# define __must_hold (x) -# define __acquires (x) -# define __releases (x) -# define __acquire (x) (void)0 -# define __release (x) (void)0 -#endif /* __CHECKER__ */ +#include <linux/compiler-context-analysis.h> /* Compiler specific macros. */ #ifdef __GNUC__
tools/testing/shared/linux/kernel.h +0 -4
@@ -21,9 +21,5 @@#define schedule ()#define PAGE_SHIFT 12 -#define __acquires (x) -#define __releases (x) -#define __must_hold (x) -#define EXPORT_PER_CPU_SYMBOL_GPL (x)#endif /* _KERNEL_H */
Signature · 1 line
2.52.0.457.g6b5491de43-goog
Quoted 23 lines · Marco Elver
In sync with the main kernel headers, include a stub version of
compiler-context-analysis.hintools/include/linux/compiler_types.hand remove the sparse context tracking definitions.Since
tools/headers are generally self-contained, provide a standalonetools/include/linux/compiler-context-analysis.hwith no-op stubs for now. Also clean up redundant stubs intools/testing/shared/linux/kernel.hthat are now redundant.This fixes build errors in
tools/testing/radix-tree/where headers frominclude/linux/(likecleanup.h) are used directly and expect these macros to be defined:| cc -I../shared -I. -I../../include -I../../arch/x86/include -I../../../lib -g -Og -Wall -D_LGPL_SOURCE -fsanitize=address -fsanitize=undefined -c -o radix-tree.o radix-tree.c | In file included from ../shared/linux/cleanup.h:2, | from ../shared/linux/../../../../include/linux/idr.h:18, | from ../shared/linux/idr.h:5, | from radix-tree.c:18: | ../shared/linux/../../../../include/linux/idr.h: In function ‘class_idr_alloc_destructor’: | ../shared/linux/../../../../include/linux/cleanup.h:283:9: error: expected declaration specifiers before ‘__no_context_analysis’ | 283 | __no_context_analysis \ | | ^~~~~~~~~~~~~~~~~~~~~
Quoted 5 lines
Reported-by kernel test robot <[email protected]>Signed-off-by Marco Elver <[email protected]>Cc Lorenzo Stoakes <[email protected]>Cc Sidhartha Kumar <[email protected]>
Thanks, I tested it locally and it fixes the issue for both radix-trees and the vma userland tests, so feel free to add:
Cheers, Lorenzo
Quoted 98 lines
--- .../include/linux/compiler-context-analysis.h | 42 +++++++++++++++++++ tools/include/linux/compiler_types.h | 16 +------ tools/testing/shared/linux/kernel.h | 4 -- 3 files changed, 43 insertions(+), 19 deletions(-) create mode 100644 tools/include/linux/compiler-context-analysis.htools/include/linux/compiler-context-analysis.h new file +42
-0@@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _TOOLS_LINUX_COMPILER_CONTEXT_ANALYSIS_H +#define _TOOLS_LINUX_COMPILER_CONTEXT_ANALYSIS_H + +/* +* Macros and attributes for compiler-based static context analysis. +* No-op stubs for tools. +*/ + +#define __guarded_by (...) +#define __pt_guarded_by (...) + +#define context_lock_struct (name, ...) struct __VA_ARGS__ name + +#define __no_context_analysis +#define __context_unsafe (comment) +#define context_unsafe (...) ({ __VA_ARGS__; }) +#define context_unsafe_alias (p) +#define disable_context_analysis () +#define enable_context_analysis () + +#define __must_hold (...) +#define __must_not_hold (...) +#define __acquires (...) +#define __cond_acquires (ret, x) +#define __releases (...) +#define __acquire (x) (void)0 +#define __release (x) (void)0 + +#define __must_hold_shared (...) +#define __acquires_shared (...) +#define __cond_acquires_shared (ret, x) +#define __releases_shared (...) +#define __acquire_shared (x) (void)0 +#define __release_shared (x) (void)0 + +#define __acquire_ret (call, expr) (call) +#define __acquire_shared_ret (call, expr) (call) +#define __acquires_ret +#define __acquires_shared_ret + +#endif /* _TOOLS_LINUX_COMPILER_CONTEXT_ANALYSIS_H */ tools/include/linux/compiler_types.h +1
-15@@ -13,21 +13,7 @@#define __has_builtin (x) (0)#endif -#ifdef __CHECKER__ -/* context/locking */ -# define __must_hold (x) __attribute__((context(x,1,1))) -# define __acquires (x) __attribute__((context(x,0,1))) -# define __releases (x) __attribute__((context(x,1,0))) -# define __acquire (x) __context__(x,1) -# define __release (x) __context__(x,-1) -#else /* __CHECKER__ */ -/* context/locking */ -# define __must_hold (x) -# define __acquires (x) -# define __releases (x) -# define __acquire (x) (void)0 -# define __release (x) (void)0 -#endif /* __CHECKER__ */ +#include <linux/compiler-context-analysis.h> /* Compiler specific macros. */ #ifdef __GNUC__tools/testing/shared/linux/kernel.h +0
-5@@ -21,9 +21,5 @@#define schedule ()#define PAGE_SHIFT 12 -#define __acquires (x) -#define __releases (x) -#define __must_hold (x) -#define EXPORT_PER_CPU_SYMBOL_GPL (x)#endif /* _KERNEL_H */ --2.52.0.457.g6b5491de43-goog
The following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 944e3f7562c55fa37ebcdd58e5f60f296c81a854 Gitweb: https://git.kernel.org/tip/944e3f7562c55fa37ebcdd58e5f60f296c81a854 Author: Marco Elver <[email protected]> AuthorDate: Tue, 27 Jan 2026 12:12:06 +01:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Wed, 28 Jan 2026 09:25:45 +01:00
tools: Update context analysis macros in compiler_types.h
In sync with the main kernel headers, include a stub version of compiler-context-analysis.h in tools/include/linux/compiler_types.h and remove the sparse context tracking definitions.
Since tools/ headers are generally self-contained, provide a standalone tools/include/linux/compiler-context-analysis.h with no-op stubs for now. Also clean up redundant stubs in tools/testing/shared/linux/kernel.h that are now redundant.
This fixes build errors in tools/testing/radix-tree/ where headers from include/linux/ (like cleanup.h) are used directly and expect these macros to be defined:
| cc -I../shared -I. -I../../include -I../../arch/x86/include -I../../../lib -g -Og -Wall -D_LGPL_SOURCE -fsanitize=address -fsanitize=undefined -c -o radix-tree.o radix-tree.c | In file included from ../shared/linux/cleanup.h:2, | from ../shared/linux/../../../../include/linux/idr.h:18, | from ../shared/linux/idr.h:5, | from radix-tree.c:18: | ../shared/linux/../../../../include/linux/idr.h: In function ‘class_idr_alloc_destructor’: | ../shared/linux/../../../../include/linux/cleanup.h:283:9: error: expected declaration specifiers before ‘__no_context_analysis’ | 283 | __no_context_analysis \ | | ^~~~~~~~~~~~~~~~~~~~~
--- tools/include/linux/compiler-context-analysis.h | 42 ++++++++++++++++- tools/include/linux/compiler_types.h | 16 +------ tools/testing/shared/linux/kernel.h | 4 +-- 3 files changed, 43 insertions(+), 19 deletions(-) create mode 100644 tools/include/linux/compiler-context-analysis.h
tools/include/linux/compiler-context-analysis.h new file +42 -0
@@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _TOOLS_LINUX_COMPILER_CONTEXT_ANALYSIS_H +#define _TOOLS_LINUX_COMPILER_CONTEXT_ANALYSIS_H + +/* +* Macros and attributes for compiler-based static context analysis. +* No-op stubs for tools. +*/ + +#define __guarded_by (...) +#define __pt_guarded_by (...) + +#define context_lock_struct (name, ...) struct __VA_ARGS__ name + +#define __no_context_analysis +#define __context_unsafe (comment) +#define context_unsafe (...) ({ __VA_ARGS__; }) +#define context_unsafe_alias (p) +#define disable_context_analysis () +#define enable_context_analysis () + +#define __must_hold (...) +#define __must_not_hold (...) +#define __acquires (...) +#define __cond_acquires (ret, x) +#define __releases (...) +#define __acquire (x) (void)0 +#define __release (x) (void)0 + +#define __must_hold_shared (...) +#define __acquires_shared (...) +#define __cond_acquires_shared (ret, x) +#define __releases_shared (...) +#define __acquire_shared (x) (void)0 +#define __release_shared (x) (void)0 + +#define __acquire_ret (call, expr) (call) +#define __acquire_shared_ret (call, expr) (call) +#define __acquires_ret +#define __acquires_shared_ret + +#endif /* _TOOLS_LINUX_COMPILER_CONTEXT_ANALYSIS_H */
tools/include/linux/compiler_types.h +1 -15
@@ -13,21 +13,7 @@#define __has_builtin (x) (0)#endif -#ifdef __CHECKER__ -/* context/locking */ -# define __must_hold (x) __attribute__((context(x,1,1))) -# define __acquires (x) __attribute__((context(x,0,1))) -# define __releases (x) __attribute__((context(x,1,0))) -# define __acquire (x) __context__(x,1) -# define __release (x) __context__(x,-1) -#else /* __CHECKER__ */ -/* context/locking */ -# define __must_hold (x) -# define __acquires (x) -# define __releases (x) -# define __acquire (x) (void)0 -# define __release (x) (void)0 -#endif /* __CHECKER__ */ +#include <linux/compiler-context-analysis.h> /* Compiler specific macros. */ #ifdef __GNUC__
tools/testing/shared/linux/kernel.h +0 -4
@@ -21,9 +21,5 @@#define schedule ()#define PAGE_SHIFT 12 -#define __acquires (x) -#define __releases (x) -#define __must_hold (x) -#define EXPORT_PER_CPU_SYMBOL_GPL (x)#endif /* _KERNEL_H */