Skip to content

Commit 944e3f7

Browse files
melverPeter Zijlstra
authored andcommitted
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 \ | | ^~~~~~~~~~~~~~~~~~~~~ Closes: https://lore.kernel.org/oe-lkp/202601261546.d7ae2447-lkp@intel.com Reported-by: kernel test robot <oliver.sang@intel.com> Signed-off-by: Marco Elver <elver@google.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Tested-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Link: https://patch.msgid.link/20260127111428.3747328-1-elver@google.com
1 parent e6de072 commit 944e3f7

3 files changed

Lines changed: 43 additions & 19 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _TOOLS_LINUX_COMPILER_CONTEXT_ANALYSIS_H
3+
#define _TOOLS_LINUX_COMPILER_CONTEXT_ANALYSIS_H
4+
5+
/*
6+
* Macros and attributes for compiler-based static context analysis.
7+
* No-op stubs for tools.
8+
*/
9+
10+
#define __guarded_by(...)
11+
#define __pt_guarded_by(...)
12+
13+
#define context_lock_struct(name, ...) struct __VA_ARGS__ name
14+
15+
#define __no_context_analysis
16+
#define __context_unsafe(comment)
17+
#define context_unsafe(...) ({ __VA_ARGS__; })
18+
#define context_unsafe_alias(p)
19+
#define disable_context_analysis()
20+
#define enable_context_analysis()
21+
22+
#define __must_hold(...)
23+
#define __must_not_hold(...)
24+
#define __acquires(...)
25+
#define __cond_acquires(ret, x)
26+
#define __releases(...)
27+
#define __acquire(x) (void)0
28+
#define __release(x) (void)0
29+
30+
#define __must_hold_shared(...)
31+
#define __acquires_shared(...)
32+
#define __cond_acquires_shared(ret, x)
33+
#define __releases_shared(...)
34+
#define __acquire_shared(x) (void)0
35+
#define __release_shared(x) (void)0
36+
37+
#define __acquire_ret(call, expr) (call)
38+
#define __acquire_shared_ret(call, expr) (call)
39+
#define __acquires_ret
40+
#define __acquires_shared_ret
41+
42+
#endif /* _TOOLS_LINUX_COMPILER_CONTEXT_ANALYSIS_H */

tools/include/linux/compiler_types.h

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,7 @@
1313
#define __has_builtin(x) (0)
1414
#endif
1515

16-
#ifdef __CHECKER__
17-
/* context/locking */
18-
# define __must_hold(x) __attribute__((context(x,1,1)))
19-
# define __acquires(x) __attribute__((context(x,0,1)))
20-
# define __releases(x) __attribute__((context(x,1,0)))
21-
# define __acquire(x) __context__(x,1)
22-
# define __release(x) __context__(x,-1)
23-
#else /* __CHECKER__ */
24-
/* context/locking */
25-
# define __must_hold(x)
26-
# define __acquires(x)
27-
# define __releases(x)
28-
# define __acquire(x) (void)0
29-
# define __release(x) (void)0
30-
#endif /* __CHECKER__ */
16+
#include <linux/compiler-context-analysis.h>
3117

3218
/* Compiler specific macros. */
3319
#ifdef __GNUC__

tools/testing/shared/linux/kernel.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,5 @@
2121
#define schedule()
2222
#define PAGE_SHIFT 12
2323

24-
#define __acquires(x)
25-
#define __releases(x)
26-
#define __must_hold(x)
27-
2824
#define EXPORT_PER_CPU_SYMBOL_GPL(x)
2925
#endif /* _KERNEL_H */

0 commit comments

Comments
 (0)