Linux Perf Users
 help / color / mirror / Atom feed
* [PATCH v3] perf build: Stub out __guarded_by() on older Clang versions
@ 2026-11-24 11:33 James Clark
  2026-11-24 11:37 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: James Clark @ 2026-11-24 11:33 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 v3:
- Fix check-headers.sh diff warning (Sashiko)
- Link to v2: https://patch.msgid.link/20261124-james-perf-late-parse-attr-v2-1-cb8b00d904a7@linaro.org

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 ++++++++
 tools/perf/check-headers.sh                     | 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..b6619cdc295c 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 /* !(__clang_major__ < 19) */
 # 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 /* !(__clang_major__ < 19) */
 # 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 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

end of thread, other threads:[~2026-11-24 11:37 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:33 [PATCH v3] perf build: Stub out __guarded_by() on older Clang versions James Clark
2026-11-24 11:37 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox