f8f5bcc6b801d9af3f8cd41d57d235ecc46d401c
[openwrt/staging/wigyori.git] /
1 From 042e7f11769adac0736d77d76262912b90724d7d Mon Sep 17 00:00:00 2001
2 From: Andres Freund <andres@anarazel.de>
3 Date: Sun, 31 Jul 2022 18:38:31 -0700
4 Subject: [PATCH 4/5] tools bpf_jit_disasm: Fix compilation error with new
5 binutils
6
7 binutils changed the signature of init_disassemble_info(), which now causes
8 compilation to fail for tools/bpf/bpf_jit_disasm.c, e.g. on debian
9 unstable.
10
11 Relevant binutils commit:
12
13 https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=60a3da00bd5407f07
14
15 Wire up the feature test and switch to init_disassemble_info_compat(),
16 which were introduced in prior commits, fixing the compilation failure.
17
18 I verified that bpf_jit_disasm can still disassemble bpf programs, both
19 with the old and new dis-asm.h API. With old binutils there's no change in
20 output before/after this patch. When comparing the output from old
21 binutils (2.35) to new bintuils with the patch (upstream snapshot) there
22 are a few output differences, but they are unrelated to this patch. An
23 example hunk is:
24
25 f4: mov %r14,%rsi
26 f7: mov %r15,%rdx
27 fa: mov $0x2a,%ecx
28 - ff: callq 0xffffffffea8c4988
29 + ff: call 0xffffffffea8c4988
30 104: test %rax,%rax
31 107: jge 0x0000000000000110
32 109: xor %eax,%eax
33 - 10b: jmpq 0x0000000000000073
34 + 10b: jmp 0x0000000000000073
35 110: cmp $0x16,%rax
36
37 However, I had to use an older kernel to generate the bpf_jit_enabled =
38 2 output, as that has been broken since 5.18 / 1022a5498f6f745c ("bpf,
39 x86_64: Use bpf_jit_binary_pack_alloc").
40
41 https://lore.kernel.org/20220703030210.pmjft7qc2eajzi6c@alap3.anarazel.de
42
43 Signed-off-by: Andres Freund <andres@anarazel.de>
44 Acked-by: Quentin Monnet <quentin@isovalent.com>
45 Cc: Alexei Starovoitov <ast@kernel.org>
46 Cc: Ben Hutchings <benh@debian.org>
47 Cc: Daniel Borkmann <daniel@iogearbox.net>
48 Cc: Jiri Olsa <jolsa@kernel.org>
49 Cc: Quentin Monnet <quentin@isovalent.com>
50 Cc: Sedat Dilek <sedat.dilek@gmail.com>
51 Cc: bpf@vger.kernel.org
52 Link: http://lore.kernel.org/lkml/20220622181918.ykrs5rsnmx3og4sv@alap3.anarazel.de
53 Link: https://lore.kernel.org/r/20220801013834.156015-6-andres@anarazel.de
54 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
55 (cherry picked from commit 96ed066054abf11c7d3e106e3011a51f3f1227a3)
56 ---
57 tools/bpf/Makefile | 5 ++++-
58 tools/bpf/bpf_jit_disasm.c | 5 ++++-
59 2 files changed, 8 insertions(+), 2 deletions(-)
60
61 --- a/tools/bpf/Makefile
62 +++ b/tools/bpf/Makefile
63 @@ -34,7 +34,7 @@ else
64 endif
65
66 FEATURE_USER = .bpf
67 -FEATURE_TESTS = libbfd disassembler-four-args
68 +FEATURE_TESTS = libbfd disassembler-four-args disassembler-init-styled
69 FEATURE_DISPLAY = libbfd disassembler-four-args
70
71 check_feat := 1
72 @@ -56,6 +56,9 @@ endif
73 ifeq ($(feature-disassembler-four-args), 1)
74 CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
75 endif
76 +ifeq ($(feature-disassembler-init-styled), 1)
77 +CFLAGS += -DDISASM_INIT_STYLED
78 +endif
79
80 $(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y
81 $(QUIET_BISON)$(YACC) -o $@ -d $<
82 --- a/tools/bpf/bpf_jit_disasm.c
83 +++ b/tools/bpf/bpf_jit_disasm.c
84 @@ -28,6 +28,7 @@
85 #include <sys/types.h>
86 #include <sys/stat.h>
87 #include <limits.h>
88 +#include <tools/dis-asm-compat.h>
89
90 #define CMD_ACTION_SIZE_BUFFER 10
91 #define CMD_ACTION_READ_ALL 3
92 @@ -64,7 +65,9 @@ static void get_asm_insns(uint8_t *image
93 assert(bfdf);
94 assert(bfd_check_format(bfdf, bfd_object));
95
96 - init_disassemble_info(&info, stdout, (fprintf_ftype) fprintf);
97 + init_disassemble_info_compat(&info, stdout,
98 + (fprintf_ftype) fprintf,
99 + fprintf_styled);
100 info.arch = bfd_get_arch(bfdf);
101 info.mach = bfd_get_mach(bfdf);
102 info.buffer = image;