Skip to content

Commit 2ea4d86

Browse files
qmonnetAlexei Starovoitov
authored andcommitted
bpftool: Group libbfd defs in Makefile, only pass them if we use libbfd
Bpftool uses libbfd for disassembling JIT-ed programs. But the feature is optional, and the tool can be compiled without libbfd support. The Makefile sets the relevant variables accordingly. It also sets variables related to libbfd's interface, given that it has changed over time. Group all those libbfd-related definitions so that it's easier to understand what we are testing for, and only use variables related to libbfd's interface if we need libbfd in the first place. In addition to make the Makefile clearer, grouping the definitions related to disassembling JIT-ed programs will help support alternatives to libbfd. Signed-off-by: Quentin Monnet <[email protected]> Tested-by: Niklas Söderlund <[email protected]> Acked-by: Song Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 108326d commit 2ea4d86

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

tools/bpf/bpftool/Makefile

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,6 @@ include $(FEATURES_DUMP)
124124
endif
125125
endif
126126

127-
ifeq ($(feature-disassembler-four-args), 1)
128-
CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
129-
endif
130-
ifeq ($(feature-disassembler-init-styled), 1)
131-
CFLAGS += -DDISASM_INIT_STYLED
132-
endif
133-
134127
LIBS = $(LIBBPF) -lelf -lz
135128
LIBS_BOOTSTRAP = $(LIBBPF_BOOTSTRAP) -lelf -lz
136129
ifeq ($(feature-libcap), 1)
@@ -142,9 +135,7 @@ include $(wildcard $(OUTPUT)*.d)
142135

143136
all: $(OUTPUT)bpftool
144137

145-
BFD_SRCS = jit_disasm.c
146-
147-
SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c))
138+
SRCS := $(wildcard *.c)
148139

149140
ifeq ($(feature-libbfd),1)
150141
LIBS += -lbfd -ldl -lopcodes
@@ -154,9 +145,21 @@ else ifeq ($(feature-libbfd-liberty-z),1)
154145
LIBS += -lbfd -ldl -lopcodes -liberty -lz
155146
endif
156147

148+
# If one of the above feature combinations is set, we support libbfd
157149
ifneq ($(filter -lbfd,$(LIBS)),)
158-
CFLAGS += -DHAVE_LIBBFD_SUPPORT
159-
SRCS += $(BFD_SRCS)
150+
CFLAGS += -DHAVE_LIBBFD_SUPPORT
151+
152+
# Libbfd interface changed over time, figure out what we need
153+
ifeq ($(feature-disassembler-four-args), 1)
154+
CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
155+
endif
156+
ifeq ($(feature-disassembler-init-styled), 1)
157+
CFLAGS += -DDISASM_INIT_STYLED
158+
endif
159+
endif
160+
ifeq ($(filter -DHAVE_LIBBFD_SUPPORT,$(CFLAGS)),)
161+
# No support for JIT disassembly
162+
SRCS := $(filter-out jit_disasm.c,$(SRCS))
160163
endif
161164

162165
HOST_CFLAGS = $(subst -I$(LIBBPF_INCLUDE),-I$(LIBBPF_BOOTSTRAP_INCLUDE),\

0 commit comments

Comments
 (0)