* [PATCH 1/9] perf libbfd: Fix the clang -Wthread-safety build failure
2026-09-16 6:12 [PATCH 0/9] perf build: Fix builds with clang and BUILD_NONDISTRO Ian Rogers
@ 2026-09-16 6:12 ` Ian Rogers
2026-09-16 6:12 ` [PATCH 2/9] perf symbol: Fix the build when demangling with libbfd Ian Rogers
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Ian Rogers @ 2026-09-16 6:12 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark,
Nathan Chancellor, Nick Desaulniers, Bill Wendling,
Thomas Richter, linux-perf-users, linux-kernel, llvm
perf_bfd_lock() and perf_bfd_unlock() are the callbacks given to
bfd_thread_init(), so by design they acquire and release the lock on
libbfd's behalf and the lock state differs between entry and exit.
clang's thread safety analysis, which perf builds with as an error,
flags both:
util/libbfd.c:56:1: error: mutex 'bfd_mutex' is still held at the end of function [-Werror,-Wthread-safety-analysis]
util/libbfd.c:60:2: error: releasing mutex 'bfd_mutex' that was not held [-Werror,-Wthread-safety-analysis]
Mark both functions NO_THREAD_SAFETY_ANALYSIS so that libbfd.c compiles
with "make CC=clang BUILD_NONDISTRO=1".
Fixes: b72b8132d8fd ("perf libbfd: Ensure libbfd is initialized prior to use")
Signed-off-by: Ian Rogers <irogers@google.com>
Assisted-by: Antigravity:gemini-3.1-pro
---
tools/perf/util/libbfd.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/libbfd.c b/tools/perf/util/libbfd.c
index 33dc6158b2b1..8ac6670a39aa 100644
--- a/tools/perf/util/libbfd.c
+++ b/tools/perf/util/libbfd.c
@@ -39,13 +39,13 @@ struct a2l_data {
asymbol **syms;
};
-static bool perf_bfd_lock(void *bfd_mutex)
+static bool perf_bfd_lock(void *bfd_mutex) NO_THREAD_SAFETY_ANALYSIS
{
mutex_lock(bfd_mutex);
return true;
}
-static bool perf_bfd_unlock(void *bfd_mutex)
+static bool perf_bfd_unlock(void *bfd_mutex) NO_THREAD_SAFETY_ANALYSIS
{
mutex_unlock(bfd_mutex);
return true;
--
2.55.0.1032.g73a4cd73de-goog
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH 2/9] perf symbol: Fix the build when demangling with libbfd
2026-09-16 6:12 [PATCH 0/9] perf build: Fix builds with clang and BUILD_NONDISTRO Ian Rogers
2026-09-16 6:12 ` [PATCH 1/9] perf libbfd: Fix the clang -Wthread-safety build failure Ian Rogers
@ 2026-09-16 6:12 ` Ian Rogers
2026-09-16 6:12 ` [PATCH 3/9] perf libbfd: Include the headers that are used Ian Rogers
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Ian Rogers @ 2026-09-16 6:12 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark,
Nathan Chancellor, Nick Desaulniers, Bill Wendling,
Thomas Richter, linux-perf-users, linux-kernel, llvm
cxx_demangle_sym() calls bfd_demangle() with the DMGL_PARAMS and
DMGL_ANSI flags, but nothing declares them. The
"#define PACKAGE 'perf'", "#include <bfd.h>" and the DMGL_ definitions
were left behind in symbol-elf.c when the demangling code moved to
symbol.c, and libiberty's demangle.h that defines the flags isn't
installed by every binutils package. The cplus_demangle() variant is
missing a declaration for the same reason.
The code is only built when the C++ ABI's __cxa_demangle() is
unavailable, so most builds never compile it:
$ make BUILD_NONDISTRO=1 NO_DEMANGLE=1
util/symbol.c:2714: error: 'DMGL_PARAMS' undeclared
util/symbol.c:2714: error: 'DMGL_ANSI' undeclared
util/symbol.c:2716: error: implicit declaration of 'bfd_demangle'
Move the libbfd demangling into libbfd.c, which already includes bfd.h,
and declare in symbol.c the libiberty interfaces the cplus_demangle()
variant needs.
Fixes: 4d9b5146f0d9 ("perf symbol: Move demangling code out of symbol-elf.c")
Signed-off-by: Ian Rogers <irogers@google.com>
Assisted-by: Antigravity:gemini-3.1-pro
---
tools/perf/util/libbfd.c | 17 +++++++++++++++++
tools/perf/util/libbfd.h | 9 +++++++++
tools/perf/util/symbol.c | 18 +++++++++++++++---
3 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/tools/perf/util/libbfd.c b/tools/perf/util/libbfd.c
index 8ac6670a39aa..131bfedf48cd 100644
--- a/tools/perf/util/libbfd.c
+++ b/tools/perf/util/libbfd.c
@@ -72,6 +72,23 @@ static void ensure_bfd_init(void)
pthread_once(&bfd_init_once, perf_bfd_init);
}
+/*
+ * Flags from libiberty's demangle.h. bfd.h declares bfd_demangle but not the
+ * flags to pass to it, and demangle.h isn't installed by every binutils
+ * package.
+ */
+#ifndef DMGL_PARAMS
+#define DMGL_PARAMS (1 << 0) /* Include function arguments. */
+#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc. */
+#endif
+
+char *libbfd__demangle_sym(const char *str, bool params, bool modifiers)
+{
+ int flags = (params ? DMGL_PARAMS : 0) | (modifiers ? DMGL_ANSI : 0);
+
+ return bfd_demangle(/*abfd=*/NULL, str, flags);
+}
+
static int bfd_error(const char *string)
{
const char *errmsg;
diff --git a/tools/perf/util/libbfd.h b/tools/perf/util/libbfd.h
index 953886f3d62f..14171db8b112 100644
--- a/tools/perf/util/libbfd.h
+++ b/tools/perf/util/libbfd.h
@@ -31,6 +31,8 @@ int libbfd_filename__read_debuglink(const char *filename, char *debuglink, size_
int symbol__disassemble_bpf_libbfd(struct symbol *sym, struct annotate_args *args);
+char *libbfd__demangle_sym(const char *str, bool params, bool modifiers);
+
#else // !defined(HAVE_LIBBFD_SUPPORT)
#include "annotate.h"
@@ -77,6 +79,13 @@ static inline int symbol__disassemble_bpf_libbfd(struct symbol *sym __always_unu
return SYMBOL_ANNOTATE_ERRNO__NO_LIBOPCODES_FOR_BPF;
}
+static inline char *libbfd__demangle_sym(const char *str __always_unused,
+ bool params __always_unused,
+ bool modifiers __always_unused)
+{
+ return NULL;
+}
+
#endif // defined(HAVE_LIBBFD_SUPPORT)
#endif /* __PERF_LIBBFD_H */
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 3587ad243159..3206929473a2 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -27,6 +27,7 @@
#include "dso.h"
#include "util.h" // lsdir()
#include "event.h"
+#include "libbfd.h"
#include "machine.h"
#include "map.h"
#include "symbol.h"
@@ -2707,13 +2708,24 @@ static bool want_demangle(bool is_kernel_sym)
* version.
*/
#ifndef HAVE_CXA_DEMANGLE_SUPPORT
+#ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
+/*
+ * Declarations from libiberty's demangle.h, the header isn't installed by
+ * every binutils package.
+ */
+#ifndef DMGL_PARAMS
+#define DMGL_PARAMS (1 << 0) /* Include function arguments. */
+#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc. */
+#endif
+
+char *cplus_demangle(const char *mangled, int options);
+#endif
+
char *cxx_demangle_sym(const char *str __maybe_unused, bool params __maybe_unused,
bool modifiers __maybe_unused)
{
#ifdef HAVE_LIBBFD_SUPPORT
- int flags = (params ? DMGL_PARAMS : 0) | (modifiers ? DMGL_ANSI : 0);
-
- return bfd_demangle(NULL, str, flags);
+ return libbfd__demangle_sym(str, params, modifiers);
#elif defined(HAVE_CPLUS_DEMANGLE_SUPPORT)
int flags = (params ? DMGL_PARAMS : 0) | (modifiers ? DMGL_ANSI : 0);
--
2.55.0.1032.g73a4cd73de-goog
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH 3/9] perf libbfd: Include the headers that are used
2026-09-16 6:12 [PATCH 0/9] perf build: Fix builds with clang and BUILD_NONDISTRO Ian Rogers
2026-09-16 6:12 ` [PATCH 1/9] perf libbfd: Fix the clang -Wthread-safety build failure Ian Rogers
2026-09-16 6:12 ` [PATCH 2/9] perf symbol: Fix the build when demangling with libbfd Ian Rogers
@ 2026-09-16 6:12 ` Ian Rogers
2026-09-16 6:12 ` [PATCH 4/9] perf pmu: " Ian Rogers
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Ian Rogers @ 2026-09-16 6:12 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark,
Nathan Chancellor, Nick Desaulniers, Bill Wendling,
Thomas Richter, linux-perf-users, linux-kernel, llvm
libbfd.c uses errno, PATH_MAX, strdup(), strlen(), strcmp(), memcpy()
and pthread_once() but relies on other headers to drag in <errno.h>,
<limits.h>, <string.h> and <pthread.h>. The BPF disassembly code needs
<inttypes.h> for PRIx64 and <stdint.h> for uintptr_t for the same
reason.
Include them directly and group the includes so that the system ones
come before perf's own.
No functional change.
Signed-off-by: Ian Rogers <irogers@google.com>
Assisted-by: Antigravity:gemini-3.1-pro
---
tools/perf/util/libbfd.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/tools/perf/util/libbfd.c b/tools/perf/util/libbfd.c
index 131bfedf48cd..1b23a261a9ce 100644
--- a/tools/perf/util/libbfd.c
+++ b/tools/perf/util/libbfd.c
@@ -1,5 +1,19 @@
// SPDX-License-Identifier: GPL-2.0
#include "libbfd.h"
+
+#include <errno.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <fcntl.h>
+#include <pthread.h>
+
+#include <tools/dis-asm-compat.h>
+
#include "annotate.h"
#include "bpf-event.h"
#include "bpf-utils.h"
@@ -11,15 +25,13 @@
#include "symbol.h"
#include "symbol_conf.h"
#include "util.h"
-#include <tools/dis-asm-compat.h>
+
#ifdef HAVE_LIBBPF_SUPPORT
#include <bpf/bpf.h>
#include <bpf/btf.h>
#include <bpf/libbpf.h>
#endif
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
+
#define PACKAGE "perf"
#include <bfd.h>
--
2.55.0.1032.g73a4cd73de-goog
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH 4/9] perf pmu: Include the headers that are used
2026-09-16 6:12 [PATCH 0/9] perf build: Fix builds with clang and BUILD_NONDISTRO Ian Rogers
` (2 preceding siblings ...)
2026-09-16 6:12 ` [PATCH 3/9] perf libbfd: Include the headers that are used Ian Rogers
@ 2026-09-16 6:12 ` Ian Rogers
2026-09-16 6:12 ` [PATCH 5/9] perf build: Only pass clang flags to CXX when CXX is clang Ian Rogers
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Ian Rogers @ 2026-09-16 6:12 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark,
Nathan Chancellor, Nick Desaulniers, Bill Wendling,
Thomas Richter, linux-perf-users, linux-kernel, llvm
pmu.c uses errno, free() and the str*() functions but declares none of
them directly. <string.h> arrives by way of <linux/string.h>, and
<errno.h> and <stdlib.h> come from whatever the other headers happen to
drag in, which is fragile and breaks on C libraries that don't nest
their headers the same way.
Include the three directly.
<ctype.h> is deliberately not added. The isdigit(), tolower() and
toupper() used here are the macros from <linux/ctype.h>, which is
included on purpose and documents that it doesn't handle EOF the way the
standard C library does, so pulling in <ctype.h> would change which
implementation is used.
size_t is left alone too, as <stdio.h> is already included directly and
declares it.
No functional change.
Signed-off-by: Ian Rogers <irogers@google.com>
Assisted-by: Antigravity:gemini-3.1-pro
---
tools/perf/util/pmu.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 836e3b5615cd..744e253e851f 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -8,8 +8,11 @@
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
-#include <stdio.h>
+#include <errno.h>
#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <dirent.h>
#include <api/fs/fs.h>
#include <api/io.h>
--
2.55.0.1032.g73a4cd73de-goog
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH 5/9] perf build: Only pass clang flags to CXX when CXX is clang
2026-09-16 6:12 [PATCH 0/9] perf build: Fix builds with clang and BUILD_NONDISTRO Ian Rogers
` (3 preceding siblings ...)
2026-09-16 6:12 ` [PATCH 4/9] perf pmu: " Ian Rogers
@ 2026-09-16 6:12 ` Ian Rogers
2026-09-16 6:12 ` [PATCH 6/9] perf build: Use the given CC rather than clang in clang builds Ian Rogers
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Ian Rogers @ 2026-09-16 6:12 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark,
Nathan Chancellor, Nick Desaulniers, Bill Wendling,
Thomas Richter, linux-perf-users, linux-kernel, llvm
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@google.com>
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
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH 6/9] perf build: Use the given CC rather than clang in clang builds
2026-09-16 6:12 [PATCH 0/9] perf build: Fix builds with clang and BUILD_NONDISTRO Ian Rogers
` (4 preceding siblings ...)
2026-09-16 6:12 ` [PATCH 5/9] perf build: Only pass clang flags to CXX when CXX is clang Ian Rogers
@ 2026-09-16 6:12 ` Ian Rogers
2026-09-16 6:12 ` [PATCH 7/9] perf build: Check the version of the compiler that is used Ian Rogers
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Ian Rogers @ 2026-09-16 6:12 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark,
Nathan Chancellor, Nick Desaulniers, Bill Wendling,
Thomas Richter, linux-perf-users, linux-kernel, llvm
The clang block is entered when CC_NO_CLANG has determined that CC is
clang, but it then ignores CC and hard codes $(CLANG), which defaults to
plain "clang". Building with a versioned compiler silently switches
compiler:
$ make CC=clang-19 # actually builds with "clang"
Worse, the target triple is probed with $(CLANG) too, so on a machine
that only has versioned binaries installed the probe produces nothing
and the build stops:
$ make CC=clang-19
*** Specify CROSS_COMPILE or add CLANG_TARGET_FLAGS for x86_64
Use $(CC) in both places. Within the block CC is known to be clang, and
for "make LLVM=1" CC is already $(CLANG), so nothing changes there.
$(CLANG) is left as it is for BPF skeletons, as bpf_skel.mak builds
those with "$(CLANG) --target=bpf" whatever CC happens to be.
Fixes: 4772e66cb45e ("perf build: Support build with clang")
Signed-off-by: Ian Rogers <irogers@google.com>
Assisted-by: Antigravity:gemini-3.1-pro
---
tools/perf/Makefile.config | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 31e4cbe192b9..dca62e155fb5 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -38,7 +38,7 @@ ifeq ($(CC_NO_CLANG), 0)
# Default to host architecture if ARCH is not explicitly given.
ifeq ($(ARCH), $(HOSTARCH))
- CLANG_TARGET_FLAGS := $(shell $(CLANG) -print-target-triple)
+ CLANG_TARGET_FLAGS := $(shell $(CC) -print-target-triple)
else
CLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(ARCH))
endif
@@ -53,7 +53,7 @@ ifeq ($(CC_NO_CLANG), 0)
CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
endif # CROSS_COMPILE
- CC := $(CLANG) $(CLANG_FLAGS) -fintegrated-as
+ CC := $(CC) $(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
--
2.55.0.1032.g73a4cd73de-goog
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH 7/9] perf build: Check the version of the compiler that is used
2026-09-16 6:12 [PATCH 0/9] perf build: Fix builds with clang and BUILD_NONDISTRO Ian Rogers
` (5 preceding siblings ...)
2026-09-16 6:12 ` [PATCH 6/9] perf build: Use the given CC rather than clang in clang builds Ian Rogers
@ 2026-09-16 6:12 ` Ian Rogers
2026-09-16 6:12 ` [PATCH 8/9] perf build: Remove leftovers of removed build options Ian Rogers
2026-09-16 6:12 ` [PATCH 9/9] perf test: Add build tests for clang and libbfd demangling Ian Rogers
8 siblings, 0 replies; 10+ messages in thread
From: Ian Rogers @ 2026-09-16 6:12 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark,
Nathan Chancellor, Nick Desaulniers, Bill Wendling,
Thomas Richter, linux-perf-users, linux-kernel, llvm
The flex and bison flags are adjusted for clang older than 13.0.0, which
doesn't grok -Wno-unused-but-set-variable. The test is reached because
CC_NO_CLANG says CC is clang, but the version comes from $(CLANG), which
defaults to plain "clang" and needn't be the compiler in use:
$ make CC=clang-19 CLANG=clang-12
version from $(CLANG) -> 12.0.0, flag stripped
version from $(CC) -> 19.1.7, flag kept
Dropping the flag lets the warnings it suppresses in the generated flex
and bison code through, and those are errors under -Werror.
Ask $(CC) instead, as that is what compiles the code.
Fixes: 878460e8d0ff ("perf build: Remove -Wno-unused-but-set-variable from the flex flags when building with clang < 13.0.0")
Signed-off-by: Ian Rogers <irogers@google.com>
Assisted-by: Antigravity:gemini-3.1-pro
---
tools/perf/util/Build | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index d08f2af7d970..a4618e4e4848 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -339,7 +339,7 @@ bison_flags := -DYYENABLE_NLS=0 -Wno-unused-but-set-variable
# Old clangs don't grok -Wno-unused-but-set-variable, remove it
ifeq ($(CC_NO_CLANG), 0)
- CLANG_VERSION := $(shell $(CLANG) --version | head -1 | sed 's/.*clang version \([[:digit:]]\+.[[:digit:]]\+.[[:digit:]]\+\).*/\1/g')
+ CLANG_VERSION := $(shell $(CC) --version | head -1 | sed 's/.*clang version \([[:digit:]]\+.[[:digit:]]\+.[[:digit:]]\+\).*/\1/g')
ifeq ($(call version-lt3,$(CLANG_VERSION),13.0.0),1)
bison_flags := $(subst -Wno-unused-but-set-variable,,$(bison_flags))
flex_flags := $(subst -Wno-unused-but-set-variable,,$(flex_flags))
--
2.55.0.1032.g73a4cd73de-goog
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH 8/9] perf build: Remove leftovers of removed build options
2026-09-16 6:12 [PATCH 0/9] perf build: Fix builds with clang and BUILD_NONDISTRO Ian Rogers
` (6 preceding siblings ...)
2026-09-16 6:12 ` [PATCH 7/9] perf build: Check the version of the compiler that is used Ian Rogers
@ 2026-09-16 6:12 ` Ian Rogers
2026-09-16 6:12 ` [PATCH 9/9] perf test: Add build tests for clang and libbfd demangling Ian Rogers
8 siblings, 0 replies; 10+ messages in thread
From: Ian Rogers @ 2026-09-16 6:12 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark,
Nathan Chancellor, Nick Desaulniers, Bill Wendling,
Thomas Richter, linux-perf-users, linux-kernel, llvm
NO_LIBDW_DWARF_UNWIND, NO_SYSCALL_TABLE and the embedded clang/LLVM
support were all removed, but each removal left the matching entry in
the build test suite behind:
run += make_no_libdw_dwarf_unwind
run += make_no_syscall_tbl
run += make_with_clangllvm
None of these have a make_* variable defining what to build, so $($@)
expands to nothing and each one silently repeats the plain "make_pure"
build. The suite therefore spends six builds, as every test is also run
with O=, appearing to cover options that no longer exist.
Remove them, along with the NO_LIBDW_DWARF_UNWIND comment that is still
in Makefile.perf.
Fixes: 2e9191573a69 ("perf build: Remove NO_LIBDW_DWARF_UNWIND option")
Fixes: 3cc550f5bbcf ("perf tools: Remove dependency on libaudit")
Fixes: 56b11a2126bf ("perf bpf: Remove support for embedding clang for compiling BPF events (-e foo.c)")
Signed-off-by: Ian Rogers <irogers@google.com>
Assisted-by: Antigravity:gemini-3.1-pro
---
tools/perf/Makefile.perf | 3 ---
tools/perf/tests/make | 3 ---
2 files changed, 6 deletions(-)
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 2438b40eaaec..53f538cc8e1a 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -64,9 +64,6 @@ include ../scripts/utilities.mak
#
# Define NO_LIBBIONIC if you do not want bionic support
#
-# Define NO_LIBDW_DWARF_UNWIND if you do not want libdw support
-# for dwarf backtrace post unwind.
-#
# Define NO_LIBTRACEEVENT=1 if you don't want libtraceevent to be linked,
# this will remove multiple features and tools, such as 'perf trace',
# that need it to read tracefs event format files, etc.
diff --git a/tools/perf/tests/make b/tools/perf/tests/make
index f879f8109072..608470ff9c10 100644
--- a/tools/perf/tests/make
+++ b/tools/perf/tests/make
@@ -157,7 +157,6 @@ run += make_no_demangle
run += make_no_libelf
run += make_no_libdw
run += make_libunwind
-run += make_no_libdw_dwarf_unwind
run += make_no_backtrace
run += make_no_libcapstone
run += make_libcapstone_dlopen
@@ -167,10 +166,8 @@ run += make_no_libbpf
run += make_no_libbpf_DEBUG
run += make_no_libllvm
run += make_no_sdt
-run += make_no_syscall_tbl
run += make_no_babeltrace2
run += make_with_coresight
-run += make_with_clangllvm
run += make_no_libpfm4
run += make_refcnt_check
run += make_help
--
2.55.0.1032.g73a4cd73de-goog
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH 9/9] perf test: Add build tests for clang and libbfd demangling
2026-09-16 6:12 [PATCH 0/9] perf build: Fix builds with clang and BUILD_NONDISTRO Ian Rogers
` (7 preceding siblings ...)
2026-09-16 6:12 ` [PATCH 8/9] perf build: Remove leftovers of removed build options Ian Rogers
@ 2026-09-16 6:12 ` Ian Rogers
8 siblings, 0 replies; 10+ messages in thread
From: Ian Rogers @ 2026-09-16 6:12 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Jiri Olsa, Ian Rogers, Adrian Hunter, James Clark,
Nathan Chancellor, Nick Desaulniers, Bill Wendling,
Thomas Richter, linux-perf-users, linux-kernel, llvm
Three build configurations broke recently without the build test suite
noticing, as none of them were covered:
- "CC=clang" on its own. CXX is only set to clang++ by "make LLVM=1",
so CXX stays as g++ and used to be passed clang's flags.
- "CC=clang BUILD_NONDISTRO=1", where libbfd.c failed clang's
-Wthread-safety analysis.
- "BUILD_NONDISTRO=1 NO_DEMANGLE=1", the only combination that
compiles the libbfd demangling in symbol.c, which referred to
identifiers nothing declared.
Add the three. The clang ones need clang installed, and the libbfd ones
reuse the existing binutils check.
Testing that perf was built isn't enough for the first one. Feature
tests are allowed to fail, so a broken C++ compiler command line doesn't
fail the build, it silently turns off every feature needing a C++
compiler and the build still produces a working perf. Check that libLLVM
is still built in, which is the C++ dependent feature perf can report
on, so the test fails instead of quietly producing a perf with less in
it than the default build has.
Only make that check when libLLVM can be built in the first place. The
llvm-perf feature test compiles and links against the llvm-devel/llvm-dev
headers and libraries and needs version 13 or newer, so the presence of
llvm-config on its own says nothing. Probe the same way the feature test
does and fall back to only testing that perf was built when the probe
fails, rather than turning a machine without the LLVM development files
into a spurious failure.
For the same reason the clang tests must not reuse a feature dump made
with the default compiler, so exclude them from REUSE_FEATURES_DUMP.
Signed-off-by: Ian Rogers <irogers@google.com>
Assisted-by: Antigravity:gemini-3.1-pro
---
tools/perf/tests/make | 47 +++++++++++++++++++++++++++++++++++++++++--
1 file changed, 45 insertions(+), 2 deletions(-)
diff --git a/tools/perf/tests/make b/tools/perf/tests/make
index 608470ff9c10..8e55ff1aecbd 100644
--- a/tools/perf/tests/make
+++ b/tools/perf/tests/make
@@ -71,6 +71,9 @@ make_clean_all := clean all
make_python_perf_so := $(python_perf_so)
make_debug := DEBUG=1
make_nondistro := BUILD_NONDISTRO=1
+make_nondistro_no_demangle := BUILD_NONDISTRO=1 NO_DEMANGLE=1
+make_clang := CC=clang
+make_clang_nondistro := CC=clang BUILD_NONDISTRO=1
make_extra_tests := EXTRA_TESTS=1
make_no_jevents := NO_JEVENTS=1
make_jevents_all := JEVENTS_ARCH=all
@@ -128,6 +131,18 @@ make_minimal += NO_CAPSTONE=1
# binutils 2_42 and newer have bfd_thread_init()
new_libbfd := $(shell echo '#include <bfd.h>' | $(CC) -E -x c - | grep bfd_thread_init)
+# Whether libLLVM can be built, which needs the llvm-devel/llvm-dev headers and
+# libraries of version 13 or newer, not just llvm-config. This mirrors the
+# llvm-perf feature test in tools/build/feature/test-llvm-perf.cpp so that
+# libLLVM is only asserted below when the default compiler can really build it.
+ifneq ($(call has,$(LLVM_CONFIG)),)
+have_libllvm := $(shell printf '#include <llvm/Support/ManagedStatic.h>\n#include <llvm/Support/raw_ostream.h>\n#if LLVM_VERSION_MAJOR < 13\n#error "llvm-devel/llvm-dev version 13 or greater is required"\n#endif\nint main(){llvm::errs()<<"";llvm::llvm_shutdown();return 0;}\n' | \
+ $(CXX) -x c++ -std=gnu++17 -I$(shell $(LLVM_CONFIG) --includedir 2>/dev/null) - -o /dev/null \
+ -L$(shell $(LLVM_CONFIG) --libdir 2>/dev/null) \
+ $(shell $(LLVM_CONFIG) --libs Core BPF 2>/dev/null) \
+ $(shell $(LLVM_CONFIG) --system-libs 2>/dev/null) >/dev/null 2>&1 && echo y)
+endif
+
# $(run) contains all available tests
run := make_pure
# Targets 'clean all' can be run together only through top level
@@ -143,6 +158,17 @@ run += make_python_perf_so
run += make_debug
ifneq ($(new_libbfd),)
run += make_nondistro
+# Demangling with libbfd is only built when the C++ ABI's __cxa_demangle
+# isn't available, so it needs a build of its own to be compiled at all.
+run += make_nondistro_no_demangle
+endif
+# CXX is only set to clang++ by LLVM=1, so a CC=clang build has to cope with
+# a C compiler and a C++ compiler that don't match.
+ifneq ($(call has,clang),)
+run += make_clang
+ifneq ($(new_libbfd),)
+run += make_clang_nondistro
+endif
endif
run += make_extra_tests
run += make_no_jevents
@@ -278,6 +304,17 @@ test_make_install_pdf_O := $(test_ok)
test_make_libbpf_dynamic := ldd $(PERF_O)/perf | grep -q libbpf
test_make_libbpf_dynamic_O := ldd $$TMP_O/perf | grep -q libbpf
+# Feature tests are allowed to fail, so a broken C++ compiler command line
+# doesn't fail the build, it just quietly turns off everything that needs a
+# C++ compiler. Check a feature that does, otherwise these tests would pass
+# while producing a perf with less in it than the default build has.
+ifneq ($(have_libllvm),)
+test_make_clang := test -x $(PERF_O)/perf && $(PERF_O)/perf check -q feature libLLVM
+test_make_clang_O := test -x $$TMP_O/perf && $$TMP_O/perf check -q feature libLLVM
+test_make_clang_nondistro := $(test_make_clang)
+test_make_clang_nondistro_O := $(test_make_clang_O)
+endif
+
test_make_python_perf_so_O := test -f $$TMP_O/python/perf.so
test_make_perf_o_O := test -f $$TMP_O/perf.o
test_make_util_map_o_O := test -f $$TMP_O/util/map.o
@@ -407,8 +444,14 @@ $(FEATURES_DUMP_FILE_STATIC):
echo "- $@: $$cmd" && echo $$cmd && \
( eval $$cmd ) > /dev/null 2>&1
+# The clang tests exist to run feature detection with a compiler other than
+# the default one, so they have to do their own and are left out of both the
+# dependency and the 'FEATURES_DUMP=' append below.
+no_features_dump := make_clang make_clang_nondistro
+no_features_dump += $(addsuffix _O,$(no_features_dump))
+
# Add feature dump dependency for run/run_O targets
-$(foreach t,$(run) $(run_O),$(eval \
+$(foreach t,$(filter-out $(no_features_dump),$(run) $(run_O)),$(eval \
$(t): $(if $(findstring make_static,$(t)),\
$(FEATURES_DUMP_FILE_STATIC),\
$(FEATURES_DUMP_FILE))))
@@ -416,7 +459,7 @@ $(foreach t,$(run) $(run_O),$(eval \
# Append 'FEATURES_DUMP=' option to all test cases. For example:
# make_no_libbpf: NO_LIBBPF=1 --> NO_LIBBPF=1 FEATURES_DUMP=/a/b/BUILD_TEST_FEATURE_DUMP
# make_static: LDFLAGS=-static --> LDFLAGS=-static FEATURES_DUMP=/a/b/BUILD_TEST_FEATURE_DUMP_STATIC
-$(foreach t,$(run),$(if $(findstring make_static,$(t)),\
+$(foreach t,$(filter-out $(no_features_dump),$(run)),$(if $(findstring make_static,$(t)),\
$(eval $(t) := $($(t)) FEATURES_DUMP=$(FEATURES_DUMP_FILE_STATIC)),\
$(eval $(t) := $($(t)) FEATURES_DUMP=$(FEATURES_DUMP_FILE))))
endif
--
2.55.0.1032.g73a4cd73de-goog
^ permalink raw reply [flat|nested] 10+ messages in thread