perf build: Fix builds with clang and BUILD_NONDISTRO
Ian Rogers
reviewercover perf build: Fix builds with clang and BUILD_NONDISTRO
Several perf build configurations are broken, and stayed broken because the build test suite doesn't cover them.
Three of them fail outright:
$ make CC=clang BUILD_NONDISTRO=1 util/libbfd.c:56:1: error: mutex 'bfd_mutex' is still held at the end of function [-Werror,-Wthread-safety-analysis]
$ make BUILD_NONDISTRO=1 NO_DEMANGLE=1 util/symbol.c:2714: error: 'DMGL_PARAMS' undeclared
$ make CC=clang-19 *** Specify CROSS_COMPILE or add CLANG_TARGET_FLAGS for x86_64
A fourth is worse for being silent. "make CC=clang" appends clang's --target= and -fintegrated-as to CXX, but CXX is only set to clang++ by "make LLVM=1", so it is still g++ and rejects both. Feature tests are allowed to fail, so nothing is reported: the build succeeds and just quietly drops libllvm and C++ demangling support.
$ make CC=clang && grep LIBLLVM .config-detected (nothing, whereas a gcc build reports CONFIG_LIBLLVM=y)
The patches are grouped as:
1-2 Fix the two build failures, in libbfd.c and symbol.c. 3-4 Include the headers that are used directly rather than relying
on other headers to drag them in. No functional change.
5-7 Fix the clang handling in Makefile.config: don't give clang's
flags to a non-clang CXX, and use the CC that was asked for instead of hard coding "clang" when picking the target triple and when testing the compiler version.
8 Remove three build test entries left behind by the removal of
the options they tested. None of them define what to build, so each silently repeats "make_pure" and the suite spends six builds appearing to cover options that no longer exist.
9 Add build tests for the configurations above, so they don't
break again. As a build that loses a feature still succeeds, the clang tests also check that libLLVM is still built in.
Testing:
- 13 build configurations (gcc, clang, versioned clang, LLVM=1, BUILD_NONDISTRO, NO_DEMANGLE, NO_LIBDW, NO_LIBELF, DEBUG, asan, refcount checking) pass, where two failed before the series.
- Every patch builds on its own, so the series stays bisectable.
- Each fix was confirmed by reintroducing the bug and checking that the test added in patch 9 fails:
CXX flags given to g++ make_clang fails on libLLVM
libbfd thread safety make_clang_nondistro fails to compile
symbol.c demangling make_nondistro_no_demangle likewiseIan Rogers (9):
perf libbfd: Fix the clang -Wthread-safety build failure perf symbol: Fix the build when demangling with libbfd perf libbfd: Include the headers that are used
perf pmu: Include the headers that are used
perf build: Only pass clang flags to CXX when CXX is clang perf build: Use the given CC rather than clang in clang builds perf build: Check the version of the compiler that is used perf build: Remove leftovers of removed build options perf test: Add build tests for clang and libbfd demangling
tools/perf/Makefile.config | 13 +++++++--- tools/perf/Makefile.perf | 3 --- tools/perf/tests/make | 50 ++++++++++++++++++++++++++++++++++---- tools/perf/util/Build | 2 +- tools/perf/util/libbfd.c | 41 ++++++++++++++++++++++++++----- tools/perf/util/libbfd.h | 9 +++++++ tools/perf/util/pmu.c | 5 +++- tools/perf/util/symbol.c | 18 +++++++++++--- 8 files changed, 119 insertions(+), 22 deletions(-)
base-commit: 91b0782fc9e9d2f0a40b5256146e014802fdbb36
Signature · 1 line
2.55.0.1032.g73a4cd73de-goog
Ian Rogers
reviewerPATCH 1/9 perf libbfd: Fix the clang -Wthread-safety build failure
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".
--- tools/perf/util/libbfd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/libbfd.c +2 -2
@@ -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;
Signature · 1 line
2.55.0.1032.g73a4cd73de-goog
[email protected]
AI reviewRe: [PATCH 1/9] perf libbfd: Fix the clang -Wthread-safety build failure
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines
perf_bfd_lock()andperf_bfd_unlock()are the callbacks given tobfd_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:
Quoted 8 lines
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_ANALYSISso thatlibbfd.ccompiles with "make CC=clang BUILD_NONDISTRO=1".Fixes b72b8132d8fd ("perf libbfd: Ensure libbfd is initialized prior to use")Signed-off-by Ian Rogers <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Ian Rogers
reviewerPATCH 2/9 perf symbol: Fix the build when demangling with libbfd
In reply to Ian Rogerscxx_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.
--- 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(-)
tools/perf/util/libbfd.c +17 -0
@@ -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;
tools/perf/util/libbfd.h +9 -0
@@ -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_unureturn 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 */
tools/perf/util/symbol.c +15 -3
@@ -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 );
Signature · 1 line
2.55.0.1032.g73a4cd73de-goog
[email protected]
AI reviewRe: [PATCH 2/9] perf symbol: Fix the build when demangling with libbfd
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 16 lines
cxx_demangle_sym()callsbfd_demangle()with theDMGL_PARAMSandDMGL_ANSIflags, but nothing declares them. The
"#define PACKAGE 'perf'", "#include <bfd.h>" and theDMGL_definitions were left behind insymbol-elf.cwhen the demangling code moved tosymbol.c, and libiberty'sdemangle.hthat defines the flags isn't installed by every binutils package. Thecplus_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'
Quoted 6 lines
Move the libbfd demangling into
libbfd.c, which already includesbfd.h, and declare insymbol.cthe libiberty interfaces thecplus_demangle()variant needs.Fixes 4d9b5146f0d9 ("perf symbol: Move demangling code out of symbol-elf.c")Signed-off-by Ian Rogers <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Ian Rogers
reviewerPATCH 3/9 perf libbfd: Include the headers that are used
In reply to Ian Rogerslibbfd.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.
--- tools/perf/util/libbfd.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
tools/perf/util/libbfd.c +16 -4
@@ -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>
Signature · 1 line
2.55.0.1032.g73a4cd73de-goog
[email protected]
AI reviewRe: [PATCH 3/9] perf libbfd: Include the headers that are used
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] perf libbfd: build failure on musl due to missing <stdarg.h> --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] perf libbfd: build failure on musl due to missing <stdarg.h>
--
commit b4b64b7fbd73cf480fc5aaa2ad17802e8f46fbcc
Author: Ian Rogers <[email protected]>
perf libbfd: Include the headers that are used
This patch explicitly includes several POSIX headers directly into libbfd.c instead of relying on indirect inclusions. It also reorders the includes to group system headers before perf's own headers.
Quoted 10 lines
tools/perf/util/libbfd.c +3
-0@@ -1,5 +1,19 @@// SPDX-License-Identifier: GPL-2.0 #include "libbfd.h" + +#include <errno.h> +#include <inttypes.h>
tools/perf/util/libbfd.c line 15
Quoted 10 lines
tools/perf/util/libbfd.c +10
-0+#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>
[Severity: Low]
Does this inclusion order break the build on musl libc?
Because <tools/dis-asm-compat.h> uses va_start and va_end in an inline function, it strictly requires <stdarg.h>. Previously, this requirement was satisfied implicitly because it was included later in the file, after other headers provided the necessary declarations.
Moving <tools/dis-asm-compat.h> higher up in the file exposes this missing dependency, which will cause va_start and va_end to be undeclared in strict environments like musl.
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Ian Rogers
reviewerRe: [PATCH 3/9] perf libbfd: Include the headers that are used
Quoted 43 lines · On Tue, Sep 15, 2026 at 11:22 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] perf libbfd: build failure on musl due to missing <stdarg.h>
--commit
b4b64b7fbd73cf480fc5aaa2ad17802e8f46fbcc
Author: Ian Rogers <[email protected]>perf libbfd: Include the headers that are used
This patch explicitly includes several POSIX headers directly into
libbfd.cinstead of relying on indirect inclusions. It also reorders the includes to group system headers before perf's own headers.Quoted 10 lines
tools/perf/util/libbfd.c +3
-0@@ -1,5 +1,19 @@// SPDX-License-Identifier: GPL-2.0 #include "libbfd.h" + +#include <errno.h> +#include <inttypes.h> tools/perf/util/libbfd.c line 15
Quoted 10 lines
tools/perf/util/libbfd.c +10
-0+#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> [Severity: Low]
Does this inclusion order break the build on musl libc?Because <
tools/dis-asm-compat.h> usesva_startandva_endin an inline function, it strictly requires <stdarg.h>. Previously, this requirement was satisfied implicitly because it was included later in the file, after other headers provided the necessary declarations.
Quoted 5 lines
Moving <
tools/dis-asm-compat.h> higher up in the file exposes this missing dependency, which will causeva_startandva_endto be undeclared in strict environments like musl.[ ... ]
I don't plan to fix this as the issue is minor and relates to an include, not the code itself. The series has no other Sashiko feedback.
https://sashiko.dev/#/patchset/20260916061218.3061216-1-irogers%40google.com
Thanks,
Ian
Quoted 2 lines
--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Namhyung Kim
maintainerRe: [PATCH 3/9] perf libbfd: Include the headers that are used
Quoted 48 lines · Ian Rogers
Quoted 47 lines · On Tue, Sep 15, 2026 at 11:22 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] perf libbfd: build failure on musl due to missing <stdarg.h>
--commit
b4b64b7fbd73cf480fc5aaa2ad17802e8f46fbcc
Author: Ian Rogers <[email protected]>perf libbfd: Include the headers that are used
This patch explicitly includes several POSIX headers directly into
libbfd.cinstead of relying on indirect inclusions. It also reorders the includes to group system headers before perf's own headers.Quoted 10 lines
tools/perf/util/libbfd.c +3
-0@@ -1,5 +1,19 @@// SPDX-License-Identifier: GPL-2.0 #include "libbfd.h" + +#include <errno.h> +#include <inttypes.h> tools/perf/util/libbfd.c line 15
Quoted 10 lines
tools/perf/util/libbfd.c +10
-0+#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> [Severity: Low]
Does this inclusion order break the build on musl libc?Because <
tools/dis-asm-compat.h> usesva_startandva_endin an inline function, it strictly requires <stdarg.h>. Previously, this requirement was satisfied implicitly because it was included later in the file, after other headers provided the necessary declarations.Moving <
tools/dis-asm-compat.h> higher up in the file exposes this missing dependency, which will causeva_startandva_endto be undeclared in strict environments like musl.
Quoted 6 lines
Quoted 1 line
[ ... ]
I don't plan to fix this as the issue is minor and relates to an include, not the code itself. The series has no other Sashiko feedback.
https://sashiko.dev/#/patchset/20260916061218.3061216-1-irogers%40google.com
I think <stdarg.h> should be included by <tools/dis-asm-compat.h> then. But it looks like a separate issue.
Thanks,
Namhyung
Ian Rogers
reviewerPATCH 4/9 perf pmu: Include the headers that are used
In reply to Ian Rogerspmu.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.
--- tools/perf/util/pmu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/pmu.c +4 -1
@@ -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>
Signature · 1 line
2.55.0.1032.g73a4cd73de-goog
[email protected]
AI reviewRe: [PATCH 4/9] perf pmu: Include the headers that are used
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 14 lines
pmu.cuses 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. Theisdigit(),tolower()andtoupper()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.
Quoted 6 lines
size_tis left alone too, as <stdio.h> is already included directly and declares it.No functional change.
Signed-off-by Ian Rogers <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Ian Rogers
reviewerPATCH 5/9 perf build: Only pass clang flags to CXX when CXX is clang
In reply to Ian RogersBuilding 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.
--- tools/perf/Makefile.config | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
tools/perf/Makefile.config +8 -1
@@ -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
Signature · 1 line
2.55.0.1032.g73a4cd73de-goog
[email protected]
AI reviewRe: [PATCH 5/9] perf build: Only pass clang flags to CXX when CXX is clang
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 17 lines
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_CLANGsays CC is clang, which says nothing about CXX. Probe CXX the same waytools/scripts/Makefile.includeprobes CC, and only add the flags when CXX really is clang++.
Quoted 5 lines
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 <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Ian Rogers
reviewerPATCH 6/9 perf build: Use the given CC rather than clang in clang builds
In reply to Ian RogersThe 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.
--- tools/perf/Makefile.config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/Makefile.config +2 -2
@@ -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
Signature · 1 line
2.55.0.1032.g73a4cd73de-goog
[email protected]
AI reviewRe: [PATCH 6/9] perf build: Use the given CC rather than clang in clang builds
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 14 lines
The clang block is entered when
CC_NO_CLANGhas 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
Quoted 8 lines
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 <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Ian Rogers
reviewerPATCH 7/9 perf build: Check the version of the compiler that is used
In reply to Ian RogersThe 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.
--- tools/perf/util/Build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/Build +1 -1
@@ -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))
Signature · 1 line
2.55.0.1032.g73a4cd73de-goog
[email protected]
AI reviewRe: [PATCH 7/9] perf build: Check the version of the compiler that is used
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines
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_CLANGsays 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
Quoted 7 lines
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 <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Ian Rogers
reviewerPATCH 8/9 perf build: Remove leftovers of removed build options
In reply to Ian RogersNO_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.
--- tools/perf/Makefile.perf | 3 --- tools/perf/tests/make | 3 --- 2 files changed, 6 deletions(-)
tools/perf/Makefile.perf +0 -3
@@ -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.
tools/perf/tests/make +0 -3
@@ -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
Signature · 1 line
2.55.0.1032.g73a4cd73de-goog
[email protected]
AI reviewRe: [PATCH 8/9] perf build: Remove leftovers of removed build options
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 13 lines
NO_LIBDW_DWARF_UNWIND,NO_SYSCALL_TABLEand 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_clangllvmNone 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.
Quoted 7 lines
Remove them, along with the
NO_LIBDW_DWARF_UNWINDcomment 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 <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Ian Rogers
reviewerPATCH 9/9 perf test: Add build tests for clang and libbfd demangling
In reply to Ian RogersThree 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.
--- tools/perf/tests/make | 47 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-)
tools/perf/tests/make +45 -2
@@ -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
Signature · 1 line
2.55.0.1032.g73a4cd73de-goog
[email protected]
AI reviewRe: [PATCH 9/9] perf test: Add build tests for clang and libbfd demangling
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 14 lines
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", wherelibbfd.cfailed clang's -Wthread-safety analysis.
- "BUILD_NONDISTRO=1 NO_DEMANGLE=1", the only combination that compiles the libbfd demangling insymbol.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.
Quoted 7 lines
Testing that perf was built isn't enough for the first one. Feature [ ... ]
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 <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
Quoted 54 lines · Ian Rogers
Several perf build configurations are broken, and stayed broken because the build test suite doesn't cover them.
Three of them fail outright:
$ make CC=clang BUILD_NONDISTRO=1 util/libbfd.c:56:1: error: mutex 'bfd_mutex' is still held at the end of function [-Werror,-Wthread-safety-analysis]$ make BUILD_NONDISTRO=1 NO_DEMANGLE=1 util/symbol.c:2714: error: 'DMGL_PARAMS' undeclared$ make CC=clang-19 *** Specify CROSS_COMPILE or add CLANG_TARGET_FLAGS for x86_64A fourth is worse for being silent. "make CC=clang" appends clang's --target= and -fintegrated-as to CXX, but CXX is only set to clang++ by "make LLVM=1", so it is still g++ and rejects both. Feature tests are allowed to fail, so nothing is reported: the build succeeds and just quietly drops libllvm and C++ demangling support.
$ make CC=clang && grep LIBLLVM .config-detected (nothing, whereas a gcc build reports CONFIG_LIBLLVM=y)The patches are grouped as:
1-2 Fix the two build failures, in
libbfd.candsymbol.c. 3-4 Include the headers that are used directly rather than relying
on other headers to drag them in. No functional change.
5-7 Fix the clang handling in Makefile.config: don't give clang's
flags to a non-clang CXX, and use the CC that was asked for instead of hard coding "clang" when picking the target triple and when testing the compiler version.
8 Remove three build test entries left behind by the removal of
the options they tested. None of them define what to build, so each silently repeats "make_pure" and the suite spends six builds appearing to cover options that no longer exist.
9 Add build tests for the configurations above, so they don't
break again. As a build that loses a feature still succeeds, the clang tests also check that libLLVM is still built in.Testing:
- 13 build configurations (gcc, clang, versioned clang, LLVM=1,
BUILD_NONDISTRO,NO_DEMANGLE,NO_LIBDW,NO_LIBELF, DEBUG, asan, refcount checking) pass, where two failed before the series.
- Every patch builds on its own, so the series stays bisectable.
- Each fix was confirmed by reintroducing the bug and checking that the test added in patch 9 fails:CXX flags given to g++ make_clang fails on libLLVM libbfd thread safety make_clang_nondistro fails to compile symbol.c demangling make_nondistro_no_demangle likewise
Quoted 10 lines
Ian Rogers (9):
perf libbfd: Fix the clang -Wthread-safety build failure perf symbol: Fix the build when demangling with libbfd perf libbfd: Include the headers that are used
perf pmu: Include the headers that are used
perf build: Only pass clang flags to CXX when CXX is clang perf build: Use the given CC rather than clang in clang builds perf build: Check the version of the compiler that is used perf build: Remove leftovers of removed build options perf test: Add build tests for clang and libbfd demangling
Thanks,
Namhyung
Quoted 16 lines
tools/perf/Makefile.config | 13 +++++++--- tools/perf/Makefile.perf | 3 --- tools/perf/tests/make | 50 ++++++++++++++++++++++++++++++++++---- tools/perf/util/Build | 2 +- tools/perf/util/libbfd.c | 41 ++++++++++++++++++++++++++----- tools/perf/util/libbfd.h | 9 +++++++ tools/perf/util/pmu.c | 5 +++- tools/perf/util/symbol.c | 18 +++++++++++--- 8 files changed, 119 insertions(+), 22 deletions(-)base-commit:
91b0782fc9e9d2f0a40b5256146e014802fdbb36Signature · 1 line
2.55.0.1032.g73a4cd73de-goog
Quoted 14 lines · Namhyung Kim
Quoted 4 lines · Ian Rogers
Several perf build configurations are broken, and stayed broken because the build test suite doesn't cover them.
Ian Rogers (9):
perf libbfd: Fix the clang -Wthread-safety build failureQuoted 8 lines
perf symbol: Fix the build when demangling with libbfd perf libbfd: Include the headers that are used
perf pmu: Include the headers that are used
perf build: Only pass clang flags to CXX when CXX is clang perf build: Use the given CC rather than clang in clang builds perf build: Check the version of the compiler that is used perf build: Remove leftovers of removed build options perf test: Add build tests for clang and libbfd demangling
Quoted 1 line
Acked-by Namhyung Kim <[email protected]>
Thanks, applied to perf-tools-next, for v7.4.
- Arnaldo