Commit c3f8644c authored by Steinar H. Gunderson's avatar Steinar H. Gunderson Committed by Arnaldo Carvalho de Melo
Browse files

perf report: Support LLVM for addr2line()



In addition to the existing support for libbfd and calling out to
an external addr2line command, add support for using libllvm directly.

This is both faster than libbfd, and can be enabled in distro builds
(the LLVM license has an explicit provision for GPLv2 compatibility).

Thus, it is set as the primary choice if available.

As an example, running 'perf report' on a medium-size profile with
DWARF-based backtraces took 58 seconds with LLVM, 78 seconds with
libbfd, 153 seconds with external llvm-addr2line, and I got tired and
aborted the test after waiting for 55 minutes with external bfd
addr2line (which is the default for perf as compiled by distributions
today).

Evidently, for this case, the bfd addr2line process needs 18 seconds (on
a 5.2 GHz Zen 3) to load the .debug ELF in question, hits the 1-second
timeout and gets killed during initialization, getting restarted anew
every time. Having an in-process addr2line makes this much more robust.

As future extensions, libllvm can be used in many other places where
we currently use libbfd or other libraries:

 - Symbol enumeration (in particular, for PE binaries).
 - Demangling (including non-Itanium demangling, e.g. Microsoft
   or Rust).
 - Disassembling (perf annotate).

However, these are much less pressing; most people don't profile PE
binaries, and perf has non-bfd paths for ELF. The same with demangling;
the default _cxa_demangle path works fine for most users, and while bfd
objdump can be slow on large binaries, it is possible to use
--objdump=llvm-objdump to get the speed benefits.  (It appears
LLVM-based demangling is very simple, should we want that.)

Tested with LLVM 14, 15, 16, 18 and 19. For some reason, LLVM 12 was not
correctly detected using feature_check, and thus was not tested.

Committer notes:

 Added the name and a __maybe_unused to address:

   1    13.50 almalinux:8                   : FAIL gcc version 8.5.0 20210514 (Red Hat 8.5.0-22) (GCC)
    util/srcline.c: In function 'dso__free_a2l':
    util/srcline.c:184:20: error: parameter name omitted
     void dso__free_a2l(struct dso *)
                        ^~~~~~~~~~~~
    make[3]: *** [/git/perf-6.11.0-rc3/tools/build/Makefile.build:158: util] Error 2

Signed-off-by: default avatarSteinar H. Gunderson <sesse@google.com>
Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Cc: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20240803152008.2818485-1-sesse@google.com


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 0e7eb236
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -136,6 +136,7 @@ FEATURE_DISPLAY ?= \
         libunwind              \
         libdw-dwarf-unwind     \
         libcapstone            \
         llvm                   \
         zlib                   \
         lzma                   \
         get_cpuid              \
+17 −0
Original line number Diff line number Diff line
@@ -980,6 +980,23 @@ ifdef BUILD_NONDISTRO
  endif
endif

ifndef NO_LIBLLVM
  $(call feature_check,llvm)
  ifeq ($(feature-llvm), 1)
    CFLAGS += -DHAVE_LIBLLVM_SUPPORT
    CFLAGS += $(shell $(LLVM_CONFIG) --cflags)
    CXXFLAGS += -DHAVE_LIBLLVM_SUPPORT
    CXXFLAGS += $(shell $(LLVM_CONFIG) --cxxflags)
    LIBLLVM = $(shell $(LLVM_CONFIG) --libs all) $(shell $(LLVM_CONFIG) --system-libs)
    EXTLIBS += -L$(shell $(LLVM_CONFIG) --libdir) $(LIBLLVM)
    EXTLIBS += -lstdc++
    $(call detected,CONFIG_LIBLLVM)
  else
    $(warning No libllvm found, slower source file resolution, please install llvm-devel/llvm-dev)
    NO_LIBLLVM := 1
  endif
endif

ifndef NO_DEMANGLE
  $(call feature_check,cxa-demangle)
  ifeq ($(feature-cxa-demangle), 1)
+1 −0
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ static void library_status(void)
	STATUS(HAVE_LIBBFD_SUPPORT, libbfd);
	STATUS(HAVE_DEBUGINFOD_SUPPORT, debuginfod);
	STATUS(HAVE_LIBELF_SUPPORT, libelf);
	STATUS(HAVE_LIBLLVM_SUPPORT, libllvm);
	STATUS(HAVE_LIBNUMA_SUPPORT, libnuma);
	STATUS(HAVE_LIBNUMA_SUPPORT, numa_num_possible_cpus);
	STATUS(HAVE_LIBPERL_SUPPORT, libperl);
+2 −0
Original line number Diff line number Diff line
@@ -93,6 +93,7 @@ make_no_libbpf := NO_LIBBPF=1
make_libbpf_dynamic := LIBBPF_DYNAMIC=1
make_no_libbpf_DEBUG := NO_LIBBPF=1 DEBUG=1
make_no_libcrypto   := NO_LIBCRYPTO=1
make_no_libllvm     := NO_LIBLLVM=1
make_with_babeltrace:= LIBBABELTRACE=1
make_with_coresight := CORESIGHT=1
make_no_sdt	    := NO_SDT=1
@@ -163,6 +164,7 @@ run += make_no_auxtrace
run += make_no_libbpf
run += make_no_libbpf_DEBUG
run += make_no_libcrypto
run += make_no_libllvm
run += make_no_sdt
run += make_no_syscall_tbl
run += make_with_babeltrace
+1 −0
Original line number Diff line number Diff line
@@ -229,6 +229,7 @@ perf-util-$(CONFIG_CXX_DEMANGLE) += demangle-cxx.o
perf-util-y += demangle-ocaml.o
perf-util-y += demangle-java.o
perf-util-y += demangle-rust.o
perf-util-$(CONFIG_LIBLLVM) += llvm-c-helpers.o

ifdef CONFIG_JITDUMP
perf-util-$(CONFIG_LIBELF) += jitdump.o
Loading