1 From a82db18ab34ba7f9d38319e8cc01ffe382e3e55e Mon Sep 17 00:00:00 2001
2 From: Andres Freund <andres@anarazel.de>
3 Date: Sun, 31 Jul 2022 18:38:33 -0700
4 Subject: [PATCH 5/5] tools bpftool: Fix compilation error with new binutils
6 binutils changed the signature of init_disassemble_info(), which now causes
7 compilation to fail for tools/bpf/bpftool/jit_disasm.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 bpftool can still disassemble bpf programs, both with an
18 old and new dis-asm.h API. There are no output changes for plain and json
19 formats. When comparing the output from old binutils (2.35)
20 to new bintuils with the patch (upstream snapshot) there are a few output
21 differences, but they are unrelated to this patch. An example hunk is:
31 Signed-off-by: Andres Freund <andres@anarazel.de>
32 Acked-by: Quentin Monnet <quentin@isovalent.com>
33 Cc: Alexei Starovoitov <ast@kernel.org>
34 Cc: Ben Hutchings <benh@debian.org>
35 Cc: Jiri Olsa <jolsa@kernel.org>
36 Cc: Quentin Monnet <quentin@isovalent.com>
37 Cc: Sedat Dilek <sedat.dilek@gmail.com>
38 Cc: bpf@vger.kernel.org
39 Link: http://lore.kernel.org/lkml/20220622181918.ykrs5rsnmx3og4sv@alap3.anarazel.de
40 Link: https://lore.kernel.org/r/20220801013834.156015-8-andres@anarazel.de
41 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
42 (cherry picked from commit 600b7b26c07a070d0153daa76b3806c1e52c9e00)
44 tools/bpf/bpftool/Makefile | 5 +++-
45 tools/bpf/bpftool/jit_disasm.c | 42 +++++++++++++++++++++++++++-------
46 2 files changed, 38 insertions(+), 9 deletions(-)
48 --- a/tools/bpf/bpftool/Makefile
49 +++ b/tools/bpf/bpftool/Makefile
50 @@ -76,7 +76,7 @@ INSTALL ?= install
53 FEATURE_USER = .bpftool
54 -FEATURE_TESTS = libbfd disassembler-four-args reallocarray zlib libcap \
55 +FEATURE_TESTS = libbfd disassembler-four-args disassembler-init-styled reallocarray zlib libcap \
57 FEATURE_DISPLAY = libbfd disassembler-four-args zlib libcap \
59 @@ -100,6 +100,9 @@ endif
60 ifeq ($(feature-disassembler-four-args), 1)
61 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
63 +ifeq ($(feature-disassembler-init-styled), 1)
64 + CFLAGS += -DDISASM_INIT_STYLED
67 ifeq ($(feature-reallocarray), 0)
68 CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
69 --- a/tools/bpf/bpftool/jit_disasm.c
70 +++ b/tools/bpf/bpftool/jit_disasm.c
74 #include <bpf/libbpf.h>
75 +#include <tools/dis-asm-compat.h>
77 #include "json_writer.h"
79 @@ -39,15 +40,12 @@ static void get_exec_path(char *tpath, s
82 static int oper_count;
83 -static int fprintf_json(void *out, const char *fmt, ...)
84 +static int printf_json(void *out, const char *fmt, va_list ap)
91 err = vasprintf(&s, fmt, ap);
96 @@ -73,6 +71,32 @@ static int fprintf_json(void *out, const
100 +static int fprintf_json(void *out, const char *fmt, ...)
106 + r = printf_json(out, fmt, ap);
112 +static int fprintf_json_styled(void *out,
113 + enum disassembler_style style __maybe_unused,
114 + const char *fmt, ...)
120 + r = printf_json(out, fmt, ap);
126 void disasm_print_insn(unsigned char *image, ssize_t len, int opcodes,
127 const char *arch, const char *disassembler_options,
128 const struct btf *btf,
129 @@ -99,11 +123,13 @@ void disasm_print_insn(unsigned char *im
130 assert(bfd_check_format(bfdf, bfd_object));
133 - init_disassemble_info(&info, stdout,
134 - (fprintf_ftype) fprintf_json);
135 + init_disassemble_info_compat(&info, stdout,
136 + (fprintf_ftype) fprintf_json,
137 + fprintf_json_styled);
139 - init_disassemble_info(&info, stdout,
140 - (fprintf_ftype) fprintf);
141 + init_disassemble_info_compat(&info, stdout,
142 + (fprintf_ftype) fprintf,
145 /* Update architecture info for offload. */