[PATCH 5/9] perf build: Only pass clang flags to CXX when CXX is clang

From: Ian Rogers

Date: Wed Sep 16 2026 - 02:15:40 EST


Building with "make CC=clang" appends clang's --target= and
-fintegrated-as to CXX, but CXX is only set to clang++ by "make LLVM=1".
With just CC=clang, CXX is still g++ and every C++ feature test dies:

g++: error: unrecognized command-line option '--target=...'
g++: error: unrecognized command-line option '-fintegrated-as'

The failures are silent, as feature tests are allowed to fail, so the
build quietly loses libllvm and C++ demangling support:

$ make CC=clang && grep LIBLLVM .config-detected
(nothing, whereas a gcc build reports CONFIG_LIBLLVM=y)

The block is entered when CC_NO_CLANG says CC is clang, which says
nothing about CXX. Probe CXX the same way tools/scripts/Makefile.include
probes CC, and only add the flags when CXX really is clang++.

Mixing a clang-built C with a g++-built C++ is fine here, the C++ code
is linked with -lstdc++ already.

Fixes: 4772e66cb45e ("perf build: Support build with clang")
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
Assisted-by: Antigravity:gemini-3.1-pro
---
tools/perf/Makefile.config | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 4ee7393a39f9..31e4cbe192b9 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -54,7 +54,14 @@ ifeq ($(CC_NO_CLANG), 0)
endif # CROSS_COMPILE

CC := $(CLANG) $(CLANG_FLAGS) -fintegrated-as
- CXX := $(CXX) $(CLANG_FLAGS) -fintegrated-as
+
+ # CC being clang says nothing about CXX: "make LLVM=1" overrides both, but
+ # "make CC=clang" leaves CXX as g++. Probe CXX the way Makefile.include
+ # probes CC rather than assuming the two match.
+ CXX_NO_CLANG := $(shell if command -v $(firstword $(CXX)) >/dev/null 2>&1; then $(CXX) -dM -E -x c++ /dev/null; fi | grep -Fq "__clang__"; echo $$?)
+ ifeq ($(CXX_NO_CLANG), 0)
+ CXX := $(CXX) $(CLANG_FLAGS) -fintegrated-as
+ endif

# Enabled Wthread-safety analysis for clang builds.
CFLAGS += -Wthread-safety
--
2.55.0.1032.g73a4cd73de-goog