diff options
author | Stanislav Fomichev <sdf@google.com> | 2018-11-12 16:44:10 -0500 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2018-11-16 23:45:01 -0500 |
commit | 29a9c10e4110e368443f0b606d71557edee7f2cc (patch) | |
tree | 0c3025388dcfa6221044a9ad532775ff30bf077b | |
parent | ae9435f696035894a57987ba25396818c756eeaf (diff) |
bpftool: make libbfd optional
Make it possible to build bpftool without libbfd. libbfd and libopcodes are
typically provided in dev/dbg packages (binutils-dev in debian) which we
usually don't have installed on the fleet machines and we'd like a way to have
bpftool version that works without installing any additional packages.
This excludes support for disassembling jit-ted code and prints an error if
the user tries to use these features.
Tested by:
cat > FEATURES_DUMP.bpftool <<EOF
feature-libbfd=0
feature-disassembler-four-args=1
feature-reallocarray=0
feature-libelf=1
feature-libelf-mmap=1
feature-bpf=1
EOF
FEATURES_DUMP=$PWD/FEATURES_DUMP.bpftool make
ldd bpftool | grep libbfd
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
-rw-r--r-- | tools/bpf/bpftool/Makefile | 13 | ||||
-rw-r--r-- | tools/bpf/bpftool/jit_disasm.c | 8 | ||||
-rw-r--r-- | tools/bpf/bpftool/main.c | 3 | ||||
-rw-r--r-- | tools/bpf/bpftool/main.h | 14 | ||||
-rw-r--r-- | tools/bpf/bpftool/prog.c | 3 |
5 files changed, 35 insertions, 6 deletions
diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile index dac7eff4c7e5..1bea6b979082 100644 --- a/tools/bpf/bpftool/Makefile +++ b/tools/bpf/bpftool/Makefile | |||
@@ -53,7 +53,7 @@ ifneq ($(EXTRA_LDFLAGS),) | |||
53 | LDFLAGS += $(EXTRA_LDFLAGS) | 53 | LDFLAGS += $(EXTRA_LDFLAGS) |
54 | endif | 54 | endif |
55 | 55 | ||
56 | LIBS = -lelf -lbfd -lopcodes $(LIBBPF) | 56 | LIBS = -lelf $(LIBBPF) |
57 | 57 | ||
58 | INSTALL ?= install | 58 | INSTALL ?= install |
59 | RM ?= rm -f | 59 | RM ?= rm -f |
@@ -90,7 +90,16 @@ include $(wildcard $(OUTPUT)*.d) | |||
90 | 90 | ||
91 | all: $(OUTPUT)bpftool | 91 | all: $(OUTPUT)bpftool |
92 | 92 | ||
93 | SRCS = $(wildcard *.c) | 93 | BFD_SRCS = jit_disasm.c |
94 | |||
95 | SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c)) | ||
96 | |||
97 | ifeq ($(feature-libbfd),1) | ||
98 | CFLAGS += -DHAVE_LIBBFD_SUPPORT | ||
99 | SRCS += $(BFD_SRCS) | ||
100 | LIBS += -lbfd -lopcodes | ||
101 | endif | ||
102 | |||
94 | OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o | 103 | OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o |
95 | 104 | ||
96 | $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c | 105 | $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c |
diff --git a/tools/bpf/bpftool/jit_disasm.c b/tools/bpf/bpftool/jit_disasm.c index c75ffd9ce2bb..b2ed5ee1af5f 100644 --- a/tools/bpf/bpftool/jit_disasm.c +++ b/tools/bpf/bpftool/jit_disasm.c | |||
@@ -109,7 +109,7 @@ void disasm_print_insn(unsigned char *image, ssize_t len, int opcodes, | |||
109 | if (inf) { | 109 | if (inf) { |
110 | bfdf->arch_info = inf; | 110 | bfdf->arch_info = inf; |
111 | } else { | 111 | } else { |
112 | p_err("No libfd support for %s", arch); | 112 | p_err("No libbfd support for %s", arch); |
113 | return; | 113 | return; |
114 | } | 114 | } |
115 | } | 115 | } |
@@ -183,3 +183,9 @@ void disasm_print_insn(unsigned char *image, ssize_t len, int opcodes, | |||
183 | 183 | ||
184 | bfd_close(bfdf); | 184 | bfd_close(bfdf); |
185 | } | 185 | } |
186 | |||
187 | int disasm_init(void) | ||
188 | { | ||
189 | bfd_init(); | ||
190 | return 0; | ||
191 | } | ||
diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c index 75a3296dc0bc..5c4c1cd5a7ba 100644 --- a/tools/bpf/bpftool/main.c +++ b/tools/bpf/bpftool/main.c | |||
@@ -31,7 +31,6 @@ | |||
31 | * SOFTWARE. | 31 | * SOFTWARE. |
32 | */ | 32 | */ |
33 | 33 | ||
34 | #include <bfd.h> | ||
35 | #include <ctype.h> | 34 | #include <ctype.h> |
36 | #include <errno.h> | 35 | #include <errno.h> |
37 | #include <getopt.h> | 36 | #include <getopt.h> |
@@ -399,8 +398,6 @@ int main(int argc, char **argv) | |||
399 | if (argc < 0) | 398 | if (argc < 0) |
400 | usage(); | 399 | usage(); |
401 | 400 | ||
402 | bfd_init(); | ||
403 | |||
404 | ret = cmd_select(cmds, argc, argv, do_help); | 401 | ret = cmd_select(cmds, argc, argv, do_help); |
405 | 402 | ||
406 | if (json_output) | 403 | if (json_output) |
diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h index 61d82020af58..10c6c16fae29 100644 --- a/tools/bpf/bpftool/main.h +++ b/tools/bpf/bpftool/main.h | |||
@@ -147,8 +147,22 @@ int prog_parse_fd(int *argc, char ***argv); | |||
147 | int map_parse_fd(int *argc, char ***argv); | 147 | int map_parse_fd(int *argc, char ***argv); |
148 | int map_parse_fd_and_info(int *argc, char ***argv, void *info, __u32 *info_len); | 148 | int map_parse_fd_and_info(int *argc, char ***argv, void *info, __u32 *info_len); |
149 | 149 | ||
150 | #ifdef HAVE_LIBBFD_SUPPORT | ||
150 | void disasm_print_insn(unsigned char *image, ssize_t len, int opcodes, | 151 | void disasm_print_insn(unsigned char *image, ssize_t len, int opcodes, |
151 | const char *arch, const char *disassembler_options); | 152 | const char *arch, const char *disassembler_options); |
153 | int disasm_init(void); | ||
154 | #else | ||
155 | static inline | ||
156 | void disasm_print_insn(unsigned char *image, ssize_t len, int opcodes, | ||
157 | const char *arch, const char *disassembler_options) | ||
158 | { | ||
159 | } | ||
160 | static inline int disasm_init(void) | ||
161 | { | ||
162 | p_err("No libbfd support"); | ||
163 | return -1; | ||
164 | } | ||
165 | #endif | ||
152 | void print_data_json(uint8_t *data, size_t len); | 166 | void print_data_json(uint8_t *data, size_t len); |
153 | void print_hex_data_json(uint8_t *data, size_t len); | 167 | void print_hex_data_json(uint8_t *data, size_t len); |
154 | 168 | ||
diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c index 5ff5544596e7..c176e1aa66fe 100644 --- a/tools/bpf/bpftool/prog.c +++ b/tools/bpf/bpftool/prog.c | |||
@@ -467,6 +467,9 @@ static int do_dump(int argc, char **argv) | |||
467 | int fd; | 467 | int fd; |
468 | 468 | ||
469 | if (is_prefix(*argv, "jited")) { | 469 | if (is_prefix(*argv, "jited")) { |
470 | if (disasm_init()) | ||
471 | return -1; | ||
472 | |||
470 | member_len = &info.jited_prog_len; | 473 | member_len = &info.jited_prog_len; |
471 | member_ptr = &info.jited_prog_insns; | 474 | member_ptr = &info.jited_prog_insns; |
472 | } else if (is_prefix(*argv, "xlated")) { | 475 | } else if (is_prefix(*argv, "xlated")) { |