Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf build: Autodetect minimum required llvm-dev version

The new LLVM addr2line feature requires a minimum version of 13 to
compile. Add a feature check for the version so that NO_LLVM=1 doesn't
need to be explicitly added. Leave the existing llvm feature check
intact because it's used by tools other than Perf.

This fixes the following compilation error when the llvm-dev version
doesn't match:

util/llvm-c-helpers.cpp: In function 'char* llvm_name_for_code(dso*, const char*, u64)':
util/llvm-c-helpers.cpp:178:21: error: 'std::remove_reference_t<llvm::DILineInfo>' {aka 'struct llvm::DILineInfo'} has no member named 'StartAddress'
178 | addr, res_or_err->StartAddress ? *res_or_err->StartAddress : 0);

Fixes: c3f8644c21df9b7d ("perf report: Support LLVM for addr2line()")
Signed-off-by: James Clark <james.clark@linaro.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Bill Wendling <morbo@google.com>
Cc: Changbin Du <changbin.du@huawei.com>
Cc: Guilherme Amadio <amadio@gentoo.org>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Justin Stitt <justinstitt@google.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@arm.com>
Cc: Manu Bretelle <chantr4@gmail.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Quentin Monnet <qmo@kernel.org>
Cc: Steinar H. Gunderson <sesse@google.com>
Link: https://lore.kernel.org/r/20240910140405.568791-1-james.clark@linaro.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

James Clark and committed by
Arnaldo Carvalho de Melo
206dcfca 375f9262

+27 -4
+1 -1
tools/build/Makefile.feature
··· 136 136 libunwind \ 137 137 libdw-dwarf-unwind \ 138 138 libcapstone \ 139 - llvm \ 139 + llvm-perf \ 140 140 zlib \ 141 141 lzma \ 142 142 get_cpuid \
+9
tools/build/feature/Makefile
··· 73 73 test-libopencsd.bin \ 74 74 test-clang.bin \ 75 75 test-llvm.bin \ 76 + test-llvm-perf.bin \ 76 77 test-llvm-version.bin \ 77 78 test-libaio.bin \ 78 79 test-libzstd.bin \ ··· 382 381 $(BUILD) 383 382 384 383 $(OUTPUT)test-llvm.bin: 384 + $(BUILDXX) -std=gnu++17 \ 385 + -I$(shell $(LLVM_CONFIG) --includedir) \ 386 + -L$(shell $(LLVM_CONFIG) --libdir) \ 387 + $(shell $(LLVM_CONFIG) --libs Core BPF) \ 388 + $(shell $(LLVM_CONFIG) --system-libs) \ 389 + > $(@:.bin=.make.output) 2>&1 390 + 391 + $(OUTPUT)test-llvm-perf.bin: 385 392 $(BUILDXX) -std=gnu++17 \ 386 393 -I$(shell $(LLVM_CONFIG) --includedir) \ 387 394 -L$(shell $(LLVM_CONFIG) --libdir) \
+14
tools/build/feature/test-llvm-perf.cpp
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + #include "llvm/Support/ManagedStatic.h" 3 + #include "llvm/Support/raw_ostream.h" 4 + 5 + #if LLVM_VERSION_MAJOR < 13 6 + # error "Perf requires llvm-devel/llvm-dev version 13 or greater" 7 + #endif 8 + 9 + int main() 10 + { 11 + llvm::errs() << "Hello World!\n"; 12 + llvm::llvm_shutdown(); 13 + return 0; 14 + }
+3 -3
tools/perf/Makefile.config
··· 981 981 endif 982 982 983 983 ifndef NO_LIBLLVM 984 - $(call feature_check,llvm) 985 - ifeq ($(feature-llvm), 1) 984 + $(call feature_check,llvm-perf) 985 + ifeq ($(feature-llvm-perf), 1) 986 986 CFLAGS += -DHAVE_LIBLLVM_SUPPORT 987 987 CFLAGS += $(shell $(LLVM_CONFIG) --cflags) 988 988 CXXFLAGS += -DHAVE_LIBLLVM_SUPPORT ··· 992 992 EXTLIBS += -lstdc++ 993 993 $(call detected,CONFIG_LIBLLVM) 994 994 else 995 - $(warning No libllvm found, slower source file resolution, please install llvm-devel/llvm-dev) 995 + $(warning No libllvm 13+ found, slower source file resolution, please install llvm-devel/llvm-dev) 996 996 NO_LIBLLVM := 1 997 997 endif 998 998 endif