]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
perf build: Autodetect minimum required llvm-dev version
authorJames Clark <james.clark@linaro.org>
Tue, 10 Sep 2024 14:04:00 +0000 (15:04 +0100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 10 Sep 2024 20:32:46 +0000 (17:32 -0300)
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>
tools/build/Makefile.feature
tools/build/feature/Makefile
tools/build/feature/test-llvm-perf.cpp [new file with mode: 0644]
tools/perf/Makefile.config

index 0717e96d6a0ee927b7d974f0dbc07fe678e81d12..427a9389e26cd203b46511844b9a2992eb5c7dca 100644 (file)
@@ -136,7 +136,7 @@ FEATURE_DISPLAY ?=              \
          libunwind              \
          libdw-dwarf-unwind     \
          libcapstone            \
-         llvm                   \
+         llvm-perf              \
          zlib                   \
          lzma                   \
          get_cpuid              \
index 12796808f07a8c0d21d1ebdeddba8d6cf688c25a..d6a98b3854f8216647b87da56e26dabd834c7283 100644 (file)
@@ -73,6 +73,7 @@ FILES=                                          \
          test-libopencsd.bin                   \
          test-clang.bin                                \
          test-llvm.bin                         \
+         test-llvm-perf.bin   \
          test-llvm-version.bin                 \
          test-libaio.bin                       \
          test-libzstd.bin                      \
@@ -388,6 +389,14 @@ $(OUTPUT)test-llvm.bin:
                $(shell $(LLVM_CONFIG) --system-libs)           \
                > $(@:.bin=.make.output) 2>&1
 
+$(OUTPUT)test-llvm-perf.bin:
+       $(BUILDXX) -std=gnu++17                                 \
+               -I$(shell $(LLVM_CONFIG) --includedir)          \
+               -L$(shell $(LLVM_CONFIG) --libdir)              \
+               $(shell $(LLVM_CONFIG) --libs Core BPF)         \
+               $(shell $(LLVM_CONFIG) --system-libs)           \
+               > $(@:.bin=.make.output) 2>&1
+
 $(OUTPUT)test-llvm-version.bin:
        $(BUILDXX) -std=gnu++17                                 \
                -I$(shell $(LLVM_CONFIG) --includedir)          \
diff --git a/tools/build/feature/test-llvm-perf.cpp b/tools/build/feature/test-llvm-perf.cpp
new file mode 100644 (file)
index 0000000..a8cbb67
--- /dev/null
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/raw_ostream.h"
+
+#if LLVM_VERSION_MAJOR < 13
+# error "Perf requires llvm-devel/llvm-dev version 13 or greater"
+#endif
+
+int main()
+{
+       llvm::errs() << "Hello World!\n";
+       llvm::llvm_shutdown();
+       return 0;
+}
index 7888c932b1b47694c514ed5fc7ea728900b8410e..37e3eee2986e580a92f27aabdaef33905ddb23cb 100644 (file)
@@ -981,8 +981,8 @@ ifdef BUILD_NONDISTRO
 endif
 
 ifndef NO_LIBLLVM
-  $(call feature_check,llvm)
-  ifeq ($(feature-llvm), 1)
+  $(call feature_check,llvm-perf)
+  ifeq ($(feature-llvm-perf), 1)
     CFLAGS += -DHAVE_LIBLLVM_SUPPORT
     CFLAGS += $(shell $(LLVM_CONFIG) --cflags)
     CXXFLAGS += -DHAVE_LIBLLVM_SUPPORT
@@ -992,7 +992,7 @@ ifndef NO_LIBLLVM
     EXTLIBS += -lstdc++
     $(call detected,CONFIG_LIBLLVM)
   else
-    $(warning No libllvm found, slower source file resolution, please install llvm-devel/llvm-dev)
+    $(warning No libllvm 13+ found, slower source file resolution, please install llvm-devel/llvm-dev)
     NO_LIBLLVM := 1
   endif
 endif