1 From 3bc373152a3a00742750dbbe974d541af78231e6 Mon Sep 17 00:00:00 2001
2 From: Andres Freund <andres@anarazel.de>
3 Date: Sun, 31 Jul 2022 18:38:30 -0700
4 Subject: [PATCH 3/5] tools perf: Fix compilation error with new binutils
6 binutils changed the signature of init_disassemble_info(), which now causes
7 compilation failures for tools/perf/util/annotate.c, e.g. on debian
10 Relevant binutils commit:
12 https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=60a3da00bd5407f07
14 Wire up the feature test and switch to init_disassemble_info_compat(),
15 which were introduced in prior commits, fixing the compilation failure.
17 I verified that perf can still disassemble bpf programs by using bpftrace
18 under load, recording a perf trace, and then annotating the bpf "function"
19 with and without the changes. With old binutils there's no change in output
20 before/after this patch. When comparing the output from old binutils (2.35)
21 to new bintuils with the patch (upstream snapshot) there are a few output
22 differences, but they are unrelated to this patch. An example hunk is:
24 1.15 : 55:mov %rbp,%rdx
25 0.00 : 58:add $0xfffffffffffffff8,%rdx
26 0.00 : 5c:xor %ecx,%ecx
27 - 1.03 : 5e:callq 0xffffffffe12aca3c
28 + 1.03 : 5e:call 0xffffffffe12aca3c
29 0.00 : 63:xor %eax,%eax
35 Signed-off-by: Andres Freund <andres@anarazel.de>
36 Acked-by: Quentin Monnet <quentin@isovalent.com>
37 Cc: Alexei Starovoitov <ast@kernel.org>
38 Cc: Ben Hutchings <benh@debian.org>
39 Cc: Jiri Olsa <jolsa@kernel.org>
40 Cc: Sedat Dilek <sedat.dilek@gmail.com>
41 Cc: bpf@vger.kernel.org
42 Link: http://lore.kernel.org/lkml/20220622181918.ykrs5rsnmx3og4sv@alap3.anarazel.de
43 Link: https://lore.kernel.org/r/20220801013834.156015-5-andres@anarazel.de
44 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
45 (cherry picked from commit 83aa0120487e8bc3f231e72c460add783f71f17c)
47 tools/perf/Makefile.config | 8 ++++++++
48 tools/perf/util/annotate.c | 7 ++++---
49 2 files changed, 12 insertions(+), 3 deletions(-)
51 --- a/tools/perf/Makefile.config
52 +++ b/tools/perf/Makefile.config
53 @@ -296,6 +296,7 @@ FEATURE_CHECK_LDFLAGS-libpython := $(PYT
54 FEATURE_CHECK_LDFLAGS-libaio = -lrt
56 FEATURE_CHECK_LDFLAGS-disassembler-four-args = -lbfd -lopcodes -ldl
57 +FEATURE_CHECK_LDFLAGS-disassembler-init-styled = -lbfd -lopcodes -ldl
59 CORE_CFLAGS += -fno-omit-frame-pointer
61 @@ -872,13 +873,16 @@ ifndef NO_LIBBFD
62 ifeq ($(feature-libbfd-liberty), 1)
63 EXTLIBS += -lbfd -lopcodes -liberty
64 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -ldl
65 + FEATURE_CHECK_LDFLAGS-disassembler-init-styled += -liberty -ldl
67 ifeq ($(feature-libbfd-liberty-z), 1)
68 EXTLIBS += -lbfd -lopcodes -liberty -lz
69 FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -lz -ldl
70 + FEATURE_CHECK_LDFLAGS-disassembler-init-styled += -liberty -lz -ldl
73 $(call feature_check,disassembler-four-args)
74 + $(call feature_check,disassembler-init-styled)
77 ifeq ($(feature-libbfd-buildid), 1)
78 @@ -992,6 +996,10 @@ ifeq ($(feature-disassembler-four-args),
79 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
82 +ifeq ($(feature-disassembler-init-styled), 1)
83 + CFLAGS += -DDISASM_INIT_STYLED
86 ifeq (${IS_64_BIT}, 1)
87 ifndef NO_PERF_READ_VDSO32
88 $(call feature_check,compile-32)
89 --- a/tools/perf/util/annotate.c
90 +++ b/tools/perf/util/annotate.c
91 @@ -1694,6 +1694,7 @@ fallback:
93 #include <bpf/libbpf.h>
94 #include <linux/btf.h>
95 +#include <tools/dis-asm-compat.h>
97 static int symbol__disassemble_bpf(struct symbol *sym,
98 struct annotate_args *args)
99 @@ -1736,9 +1737,9 @@ static int symbol__disassemble_bpf(struc
103 - init_disassemble_info(&info, s,
104 - (fprintf_ftype) fprintf);
106 + init_disassemble_info_compat(&info, s,
107 + (fprintf_ftype) fprintf,
109 info.arch = bfd_get_arch(bfdf);
110 info.mach = bfd_get_mach(bfdf);