* [PATCH v2] perf build: Stub out __guarded_by() on older Clang versions
@ 2026-11-24 11:20 James Clark
2026-11-24 11:26 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: James Clark @ 2026-11-24 11:20 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Jiri Olsa, Ian Rogers, Adrian Hunter
Cc: linux-perf-users, linux-kernel, James Clark
__guarded_by() annotations that reference struct members require Clang
19 or later [1], otherwise the build fails on older versions, e.g. Clang
18:
util/env.h:142:39: error: use of undeclared identifier 'lock'
142 | struct rb_root infos __guarded_by(&lock);
Stub out __guarded_by() and __pt_guarded_by() on older versions, but
keep the rest of the context analysis enabled. Add an exception to
check-headers.sh for the tools only change.
[1]: https://github.com/llvm/llvm-project/pull/95455
Fixes: 321967859933 ("perf build: Enable context analysis and Clang thread-safety flags")
Signed-off-by: James Clark <james.clark@linaro.org>
---
Assisted by Claude Opus 5.5
---
Changes in v2:
- Only stub out __guarded_by() on < Clang 19 so all the other working
checks remain on all other compiler versions.
- Change summary from "perf build: Only enable context analysis with Clang 23 or later"
- Link to v1: https://patch.msgid.link/20261123-james-perf-late-parse-attr-v1-1-cfebcd81a962@linaro.org
---
tools/include/linux/compiler-context-analysis.h | 8 ++++++++
| 2 +-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/tools/include/linux/compiler-context-analysis.h b/tools/include/linux/compiler-context-analysis.h
index 024e303188ad..2806fb5f79d3 100644
--- a/tools/include/linux/compiler-context-analysis.h
+++ b/tools/include/linux/compiler-context-analysis.h
@@ -60,7 +60,11 @@
* long counter __guarded_by(&lock1, &lock2);
* };
*/
+#if defined(__clang__) && __clang_major__ < 19
+# define __guarded_by(...)
+#else
# define __guarded_by(...) __attribute__((guarded_by(__VA_ARGS__)))
+#endif /* __clang_major__ < 19 */
/**
* __pt_guarded_by() - struct member and globals attribute, declares pointed-to
@@ -85,7 +89,11 @@
* long *counter __pt_guarded_by(&lock1, &lock2);
* };
*/
+#if defined(__clang__) && __clang_major__ < 19
+# define __pt_guarded_by(...)
+#else
# define __pt_guarded_by(...) __attribute__((pt_guarded_by(__VA_ARGS__)))
+#endif /* __clang_major__ < 19 */
/**
* context_lock_struct() - declare or define a context lock struct
--git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh
index c6b2ecadf9b1..caa7ab26968c 100755
--- a/tools/perf/check-headers.sh
+++ b/tools/perf/check-headers.sh
@@ -23,7 +23,6 @@ declare -a FILES=(
"include/linux/bits.h"
"include/vdso/bits.h"
"include/linux/cfi_types.h"
- "include/linux/compiler-context-analysis.h"
"include/linux/const.h"
"include/vdso/const.h"
"include/vdso/unaligned.h"
@@ -193,6 +192,7 @@ check include/uapi/asm-generic/mman.h '-I "^#include <\(uapi/\)*asm-generic/mman
check include/uapi/linux/mman.h '-I "^#include <\(uapi/\)*asm/mman.h>"'
check include/linux/build_bug.h '-I "^#\(ifndef\|endif\)\( \/\/\)* static_assert$"'
check include/linux/ctype.h '-I "isdigit("'
+check include/linux/compiler-context-analysis.h '-I "__clang_major__ < 19" -I "^# define __\(pt_\)*guarded_by(...)$"'
check lib/ctype.c '-I "^EXPORT_SYMBOL" -I "^#include <linux/export.h>" -B'
# diff non-symmetric files
---
base-commit: eb79d2fbc230d41b009e49f20671303c6efbd946
change-id: 20261123-james-perf-late-parse-attr-4e996381859f
Best regards,
--
James Clark <james.clark@linaro.org>
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v2] perf build: Stub out __guarded_by() on older Clang versions
2026-11-24 11:20 [PATCH v2] perf build: Stub out __guarded_by() on older Clang versions James Clark
@ 2026-11-24 11:26 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-24 11:26 UTC (permalink / raw)
To: James Clark; +Cc: linux-perf-users
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] perf build: check-headers.sh ignore regex misses #else lines
--
commit 0ea3202ffc7513d3010799640980ebb7d00cf374
Author: James Clark <james.clark@linaro.org>
perf build: Stub out __guarded_by() on older Clang versions
This commit stubs out __guarded_by() and __pt_guarded_by() in
tools/include/linux/compiler-context-analysis.h on Clang versions older
than 19, and updates tools/perf/check-headers.sh to ignore the difference
from the kernel header.
> diff --git a/tools/include/linux/compiler-context-analysis.h b/tools/include/linux/compiler-context-analysis.h
> index 024e303188ad3..2806fb5f79d3a 100644
> --- a/tools/include/linux/compiler-context-analysis.h
> +++ b/tools/include/linux/compiler-context-analysis.h
> @@ -60,7 +60,11 @@
> * long counter __guarded_by(&lock1, &lock2);
> * };
> */
> +#if defined(__clang__) && __clang_major__ < 19
> +# define __guarded_by(...)
> +#else
> # define __guarded_by(...) __attribute__((guarded_by(__VA_ARGS__)))
> +#endif /* __clang_major__ < 19 */
>
> /**
> * __pt_guarded_by() - struct member and globals attribute, declares pointed-to
> @@ -85,7 +89,11 @@
> * long *counter __pt_guarded_by(&lock1, &lock2);
> * };
> */
> +#if defined(__clang__) && __clang_major__ < 19
> +# define __pt_guarded_by(...)
> +#else
> # define __pt_guarded_by(...) __attribute__((pt_guarded_by(__VA_ARGS__)))
> +#endif /* __clang_major__ < 19 */
>
> /**
> * context_lock_struct() - declare or define a context lock struct
> diff --git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh
> index c6b2ecadf9b12..caa7ab26968ce 100755
> --- a/tools/perf/check-headers.sh
> +++ b/tools/perf/check-headers.sh
> @@ -23,7 +23,6 @@ declare -a FILES=(
> "include/linux/bits.h"
> "include/vdso/bits.h"
> "include/linux/cfi_types.h"
> - "include/linux/compiler-context-analysis.h"
> "include/linux/const.h"
> "include/vdso/const.h"
> "include/vdso/unaligned.h"
> @@ -193,6 +192,7 @@ check include/uapi/asm-generic/mman.h '-I "^#include <\(uapi/\)*asm-generic/mman
> check include/uapi/linux/mman.h '-I "^#include <\(uapi/\)*asm/mman.h>"'
> check include/linux/build_bug.h '-I "^#\(ifndef\|endif\)\( \/\/\)* static_assert$"'
> check include/linux/ctype.h '-I "isdigit("'
> +check include/linux/compiler-context-analysis.h '-I "__clang_major__ < 19" -I "^# define __\(pt_\)*guarded_by(...)$"'
[Severity: Low]
Does this diff -I filter miss the bare #else lines added in
tools/include/linux/compiler-context-analysis.h?
diff -I only ignores a difference hunk when every changed line in that
hunk matches an -I pattern. Because the #else lines are part of the
3-line insertion hunks with #if and # define but match neither regex,
tools/perf/check-headers.sh still reports a header difference warning for
compiler-context-analysis.h. Adding the /* __clang_major__ < 19 */
comment to the two #else lines (or matching #else in the -I filter) lets
diff ignore the hunks.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-james-perf-late-parse-attr-v2-1-cb8b00d904a7@linaro.org?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-24 11:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 11:20 [PATCH v2] perf build: Stub out __guarded_by() on older Clang versions James Clark
2026-11-24 11:26 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox