Skip to content

Commit fb98266

Browse files
rgushchinborkmann
authored andcommitted
tools/bpftool: fix bpftool build with bintutils >= 2.9
Bpftool build is broken with binutils version 2.29 and later. The cause is commit 003ca0fd2286 ("Refactor disassembler selection") in the binutils repo, which changed the disassembler() function signature. Fix this by adding a new "feature" to the tools/build/features infrastructure and make it responsible for decision which disassembler() function signature to use. Signed-off-by: Roman Gushchin <guro@fb.com> Cc: Jakub Kicinski <jakub.kicinski@netronome.com> Cc: Alexei Starovoitov <ast@kernel.org> Cc: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent 4bfe3bd commit fb98266

File tree

6 files changed

+86
-0
lines changed

6 files changed

+86
-0
lines changed

tools/bpf/Makefile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,35 @@ MAKE = make
99
CFLAGS += -Wall -O2
1010
CFLAGS += -D__EXPORTED_HEADERS__ -I../../include/uapi -I../../include
1111

12+
ifeq ($(srctree),)
13+
srctree := $(patsubst %/,%,$(dir $(CURDIR)))
14+
srctree := $(patsubst %/,%,$(dir $(srctree)))
15+
endif
16+
17+
FEATURE_USER = .bpf
18+
FEATURE_TESTS = libbfd disassembler-four-args
19+
FEATURE_DISPLAY = libbfd disassembler-four-args
20+
21+
check_feat := 1
22+
NON_CHECK_FEAT_TARGETS := clean bpftool_clean
23+
ifdef MAKECMDGOALS
24+
ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
25+
check_feat := 0
26+
endif
27+
endif
28+
29+
ifeq ($(check_feat),1)
30+
ifeq ($(FEATURES_DUMP),)
31+
include $(srctree)/tools/build/Makefile.feature
32+
else
33+
include $(FEATURES_DUMP)
34+
endif
35+
endif
36+
37+
ifeq ($(feature-disassembler-four-args), 1)
38+
CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
39+
endif
40+
1241
%.yacc.c: %.y
1342
$(YACC) -o $@ -d $<
1443

tools/bpf/bpf_jit_disasm.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,14 @@ static void get_asm_insns(uint8_t *image, size_t len, int opcodes)
7272

7373
disassemble_init_for_target(&info);
7474

75+
#ifdef DISASM_FOUR_ARGS_SIGNATURE
76+
disassemble = disassembler(info.arch,
77+
bfd_big_endian(bfdf),
78+
info.mach,
79+
bfdf);
80+
#else
7581
disassemble = disassembler(bfdf);
82+
#endif
7683
assert(disassemble);
7784

7885
do {

tools/bpf/bpftool/Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,30 @@ LIBS = -lelf -lbfd -lopcodes $(LIBBPF)
4646
INSTALL ?= install
4747
RM ?= rm -f
4848

49+
FEATURE_USER = .bpftool
50+
FEATURE_TESTS = libbfd disassembler-four-args
51+
FEATURE_DISPLAY = libbfd disassembler-four-args
52+
53+
check_feat := 1
54+
NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall
55+
ifdef MAKECMDGOALS
56+
ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
57+
check_feat := 0
58+
endif
59+
endif
60+
61+
ifeq ($(check_feat),1)
62+
ifeq ($(FEATURES_DUMP),)
63+
include $(srctree)/tools/build/Makefile.feature
64+
else
65+
include $(FEATURES_DUMP)
66+
endif
67+
endif
68+
69+
ifeq ($(feature-disassembler-four-args), 1)
70+
CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
71+
endif
72+
4973
include $(wildcard *.d)
5074

5175
all: $(OUTPUT)bpftool

tools/bpf/bpftool/jit_disasm.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,14 @@ void disasm_print_insn(unsigned char *image, ssize_t len, int opcodes)
107107

108108
disassemble_init_for_target(&info);
109109

110+
#ifdef DISASM_FOUR_ARGS_SIGNATURE
111+
disassemble = disassembler(info.arch,
112+
bfd_big_endian(bfdf),
113+
info.mach,
114+
bfdf);
115+
#else
110116
disassemble = disassembler(bfdf);
117+
#endif
111118
assert(disassemble);
112119

113120
if (json_output)

tools/build/feature/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ FILES= \
1313
test-hello.bin \
1414
test-libaudit.bin \
1515
test-libbfd.bin \
16+
test-disassembler-four-args.bin \
1617
test-liberty.bin \
1718
test-liberty-z.bin \
1819
test-cplus-demangle.bin \
@@ -188,6 +189,9 @@ $(OUTPUT)test-libpython-version.bin:
188189
$(OUTPUT)test-libbfd.bin:
189190
$(BUILD) -DPACKAGE='"perf"' -lbfd -lz -liberty -ldl
190191

192+
$(OUTPUT)test-disassembler-four-args.bin:
193+
$(BUILD) -lbfd -lopcodes
194+
191195
$(OUTPUT)test-liberty.bin:
192196
$(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty
193197

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#include <bfd.h>
3+
#include <dis-asm.h>
4+
5+
int main(void)
6+
{
7+
bfd *abfd = bfd_openr(NULL, NULL);
8+
9+
disassembler(bfd_get_arch(abfd),
10+
bfd_big_endian(abfd),
11+
bfd_get_mach(abfd),
12+
abfd);
13+
14+
return 0;
15+
}

0 commit comments

Comments
 (0)