mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: James Clark <james.clark@linaro.org>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	 Arnaldo Carvalho de Melo <acme@kernel.org>,
	 Namhyung Kim <namhyung@kernel.org>, Jiri Olsa <jolsa@kernel.org>,
	 Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>
Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	 James Clark <james.clark@linaro.org>
Subject: [PATCH] perf build: Only enable context analysis with Clang 23 or later
Date: Mon, 23 Nov 2026 16:46:38 +0000	[thread overview]
Message-ID: <20261123-james-perf-late-parse-attr-v1-1-cfebcd81a962@linaro.org> (raw)

Context analysis requires Clang 23 or later (see
Documentation/dev-tools/context-analysis.rst), 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);

Only enable it when the Clang version is supported. Leave the other
thread safety options enabled if they exist because they don't cause
build failures at the moment, and might provide benefits even without
-DWARN_CONTEXT_ANALYSIS.

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
---
 tools/perf/Makefile.config | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index aed2e952c8f3..f5adceee5589 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -65,11 +65,15 @@ ifeq ($(CC_NO_CLANG), 0)
     CXX := $(CXX) $(CLANG_FLAGS) -fintegrated-as
   endif
 
-  # Enable context analysis (linux/compiler-context-analysis.h gates its Clang
-  # attributes behind WARN_CONTEXT_ANALYSIS) and Clang thread-safety checks.
-  CFLAGS += -DWARN_CONTEXT_ANALYSIS -Wthread-safety
+  CFLAGS += -Wthread-safety
   CFLAGS += $(call cc-option,-Wthread-safety-pointer -Wthread-safety-beta)
-  CFLAGS += $(call cc-option,-fexperimental-late-parse-attributes)
+
+  # Enable context analysis (linux/compiler-context-analysis.h gates its Clang
+  # attributes behind WARN_CONTEXT_ANALYSIS). Requires Clang 23 or later.
+  CLANG_MAJOR := $(shell echo __clang_major__ | $(CC) -E -P -x c - 2>/dev/null)
+  ifeq ($(shell test "$(CLANG_MAJOR)" -ge 23 2>/dev/null && echo y),y)
+    CFLAGS += -DWARN_CONTEXT_ANALYSIS -fexperimental-late-parse-attributes
+  endif
 endif
 
 include $(srctree)/tools/scripts/Makefile.arch

---
base-commit: eb79d2fbc230d41b009e49f20671303c6efbd946
change-id: 20261123-james-perf-late-parse-attr-4e996381859f

Best regards,
--  
James Clark <james.clark@linaro.org>


             reply	other threads:[~2026-11-23 16:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 16:46 James Clark [this message]
2026-11-23 18:44 ` Ian Rogers
2026-11-23 19:55   ` Arnaldo Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261123-james-perf-late-parse-attr-v1-1-cfebcd81a962@linaro.org \
    --to=james.clark@linaro.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®