[PATCH v15 05/23] perf build: Enable context analysis and Clang thread-safety flags
From: Ian Rogers
Date: Sat Nov 21 2026 - 01:59:01 EST
Define -DWARN_CONTEXT_ANALYSIS for Clang builds so the context analysis
attributes in linux/compiler-context-analysis.h expand to Clang's
thread-safety attributes rather than no-ops, matching the kernel's
scripts/Makefile.context-analysis.
Also include tools/build/Build.include (updating TMPOUT to place
temporary probe directories under $(OUTPUT) when set) and use cc-option
to enable -Wthread-safety-pointer, -Wthread-safety-beta, and
-fexperimental-late-parse-attributes when supported by Clang.
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/build/Build.include | 4 ++--
tools/perf/Makefile.config | 9 +++++++--
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/tools/build/Build.include b/tools/build/Build.include
index cd0baa7a168d..cce5e4673ba6 100644
--- a/tools/build/Build.include
+++ b/tools/build/Build.include
@@ -113,7 +113,7 @@ rust_flags = $(filter-out $(RUST_FLAGS_REMOVE_$(obj)), $(rust_flags_2))
host_c_flags = -Wp,-MD,$(depfile) -Wp,-MT,$@ $(HOSTCFLAGS) -D"BUILD_STR(s)=\#s" $(HOSTCFLAGS_$(basetarget).o) $(HOSTCFLAGS_$(obj))
# output directory for tests below
-TMPOUT = .tmp_$$$$
+TMPOUT = $(if $(OUTPUT),$(OUTPUT)/,).tmp_$$$$
# try-run
# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise)
@@ -121,8 +121,8 @@ TMPOUT = .tmp_$$$$
# automatically cleaned up.
try-run = $(shell set -e; \
TMP=$(TMPOUT)/tmp; \
- mkdir -p $(TMPOUT); \
trap "rm -rf $(TMPOUT)" EXIT; \
+ mkdir -p $(TMPOUT); \
if ($(1)) >/dev/null 2>&1; \
then echo "$(2)"; \
else echo "$(3)"; \
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 1cee80c531ab..aed2e952c8f3 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -12,6 +12,8 @@ ifneq ($(obj-perf),)
obj-perf := $(abspath $(obj-perf))/
endif
+include $(srctree)/tools/build/Build.include
+
$(shell printf "" > $(OUTPUT).config-detected)
detected = $(shell echo "$(1)=y" >> $(OUTPUT).config-detected)
detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected)
@@ -63,8 +65,11 @@ ifeq ($(CC_NO_CLANG), 0)
CXX := $(CXX) $(CLANG_FLAGS) -fintegrated-as
endif
- # Enabled Wthread-safety analysis for clang builds.
- CFLAGS += -Wthread-safety
+ # 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 += $(call cc-option,-Wthread-safety-pointer -Wthread-safety-beta)
+ CFLAGS += $(call cc-option,-fexperimental-late-parse-attributes)
endif
include $(srctree)/tools/scripts/Makefile.arch
--
2.56.1.750.gf70dc682cf-goog