Skip to content

Commit 65cd8e5

Browse files
captain5050acmel
authored andcommitted
perf build: Don't compile demangle-cxx.cpp if not necessary
demangle-cxx.cpp requires a C++ compiler, but feature checks may fail because of the absence of this. Add a CONFIG_CXX_DEMANGLE so that the source isn't built if not supported. Copy libbfd and cplus demangle variants to a weak symbol-elf.c version so they aren't dependent on C++. These variants are only built with the build option BUILD_NONDISTRO=1. Committer note: This also handles this build break when a C++ compiler isn't available: CXX /tmp/build/perf/util/demangle-cxx.o /bin/sh: g++: command not found Signed-off-by: Ian Rogers <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Leo Yan <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Qi Liu <[email protected]> Cc: Ravi Bangoria <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent a0c2f92 commit 65cd8e5

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

tools/perf/Makefile.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,7 @@ ifndef NO_DEMANGLE
927927
EXTLIBS += -lstdc++
928928
CFLAGS += -DHAVE_CXA_DEMANGLE_SUPPORT
929929
CXXFLAGS += -DHAVE_CXA_DEMANGLE_SUPPORT
930+
$(call detected,CONFIG_CXX_DEMANGLE)
930931
endif
931932
ifdef BUILD_NONDISTRO
932933
ifeq ($(filter -liberty,$(EXTLIBS)),)

tools/perf/util/Build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ perf-$(CONFIG_ZSTD) += zstd.o
214214

215215
perf-$(CONFIG_LIBCAP) += cap.o
216216

217-
perf-y += demangle-cxx.o
217+
perf-$(CONFIG_CXX_DEMANGLE) += demangle-cxx.o
218218
perf-y += demangle-ocaml.o
219219
perf-y += demangle-java.o
220220
perf-y += demangle-rust.o

tools/perf/util/symbol-elf.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@
3131
#include <bfd.h>
3232
#endif
3333

34+
#if defined(HAVE_LIBBFD_SUPPORT) || defined(HAVE_CPLUS_DEMANGLE_SUPPORT)
35+
#ifndef DMGL_PARAMS
36+
#define DMGL_PARAMS (1 << 0) /* Include function args */
37+
#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
38+
#endif
39+
#endif
40+
3441
#ifndef EM_AARCH64
3542
#define EM_AARCH64 183 /* ARM 64 bit */
3643
#endif
@@ -271,6 +278,26 @@ static bool want_demangle(bool is_kernel_sym)
271278
return is_kernel_sym ? symbol_conf.demangle_kernel : symbol_conf.demangle;
272279
}
273280

281+
/*
282+
* Demangle C++ function signature, typically replaced by demangle-cxx.cpp
283+
* version.
284+
*/
285+
__weak char *cxx_demangle_sym(const char *str __maybe_unused, bool params __maybe_unused,
286+
bool modifiers __maybe_unused)
287+
{
288+
#ifdef HAVE_LIBBFD_SUPPORT
289+
int flags = (params ? DMGL_PARAMS : 0) | (modifiers ? DMGL_ANSI : 0);
290+
291+
return bfd_demangle(NULL, str, flags);
292+
#elif defined(HAVE_CPLUS_DEMANGLE_SUPPORT)
293+
int flags = (params ? DMGL_PARAMS : 0) | (modifiers ? DMGL_ANSI : 0);
294+
295+
return cplus_demangle(str, flags);
296+
#else
297+
return NULL;
298+
#endif
299+
}
300+
274301
static char *demangle_sym(struct dso *dso, int kmodule, const char *elf_name)
275302
{
276303
char *demangled = NULL;

0 commit comments

Comments
 (0)