Commit c5a2c734 authored by Daniel Borkmann's avatar Daniel Borkmann
Browse files

Merge branch 'bpf-bpftool-build-improvements'

Quentin Monnet says:

====================
This set attempts to make it easier to build bpftool, in particular when
passing a specific output directory. This is a follow-up to the
conversation held last month by Lorenz, Ilya and Jakub [0].

The first patch is a minor fix to bpftool's Makefile, regarding the
retrieval of kernel version (which currently prints a non-relevant make
warning on some invocations).

Second patch improves the Makefile commands to support more "make"
invocations, or to fix building with custom output directory. On Jakub's
suggestion, a script is also added to BPF selftests in order to keep track
of the supported build variants.

Building bpftool with "make tools/bpf" from the top of the repository
generates files in "libbpf/" and "feature/" directories under tools/bpf/
and tools/bpf/bpftool/. The third patch ensures such directories are taken
care of on "make clean", and add them to the relevant .gitignore files.

At last, fourth patch is a sligthly modified version of Ilya's fix
regarding libbpf.a appearing twice on the linking command for bpftool.

[0] https://lore.kernel.org/bpf/CACAyw9-CWRHVH3TJ=Tke2x8YiLsH47sLCijdp=V+5M836R9aAA@mail.gmail.com/



v2:
- Return error from check script if one of the make invocations returns
  non-zero (even if binary is successfully produced).
- Run "make clean" from bpf/ and not only bpf/bpftool/ in that same script,
  when relevant.
- Add a patch to clean up generated "feature/" and "libbpf/" directories.
====================

Acked-by: default avatarIlya Leoshkevich <iii@linux.ibm.com>
Tested-by: default avatarIlya Leoshkevich <iii@linux.ibm.com>
Cc: Lorenz Bauer <lmb@cloudflare.com>
Cc: Ilya Leoshkevich <iii@linux.ibm.com>
Cc: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parents 1c8f9b91 5b84ad2e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
FEATURE-DUMP.bpf
feature
bpf_asm
bpf_dbg
bpf_exp.yacc.*
+3 −2
Original line number Diff line number Diff line
@@ -81,10 +81,11 @@ $(OUTPUT)bpf_exp.lex.o: $(OUTPUT)bpf_exp.lex.c

clean: bpftool_clean
	$(call QUIET_CLEAN, bpf-progs)
	$(Q)rm -rf $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \
	$(Q)$(RM) -r -- $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \
	       $(OUTPUT)bpf_asm $(OUTPUT)bpf_exp.yacc.* $(OUTPUT)bpf_exp.lex.*
	$(call QUIET_CLEAN, core-gen)
	$(Q)rm -f $(OUTPUT)FEATURE-DUMP.bpf
	$(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpf
	$(Q)$(RM) -r -- $(OUTPUT)feature

install: $(PROGS) bpftool_install
	$(call QUIET_INSTALL, bpf_jit_disasm)
+2 −0
Original line number Diff line number Diff line
@@ -3,3 +3,5 @@
bpftool*.8
bpf-helpers.*
FEATURE-DUMP.bpftool
feature
libbpf
+16 −12
Original line number Diff line number Diff line
@@ -17,21 +17,23 @@ endif
BPF_DIR = $(srctree)/tools/lib/bpf/

ifneq ($(OUTPUT),)
  BPF_PATH = $(OUTPUT)
  LIBBPF_OUTPUT = $(OUTPUT)/libbpf/
  LIBBPF_PATH = $(LIBBPF_OUTPUT)
else
  BPF_PATH = $(BPF_DIR)
  LIBBPF_PATH = $(BPF_DIR)
endif

LIBBPF = $(BPF_PATH)libbpf.a
LIBBPF = $(LIBBPF_PATH)libbpf.a

BPFTOOL_VERSION := $(shell make --no-print-directory -sC ../../.. kernelversion)
BPFTOOL_VERSION := $(shell make -rR --no-print-directory -sC ../../.. kernelversion)

$(LIBBPF): FORCE
	$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) $(OUTPUT)libbpf.a
	$(if $(LIBBPF_OUTPUT),@mkdir -p $(LIBBPF_OUTPUT))
	$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) $(LIBBPF_OUTPUT)libbpf.a

$(LIBBPF)-clean:
	$(call QUIET_CLEAN, libbpf)
	$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) clean >/dev/null
	$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) clean >/dev/null

prefix ?= /usr/local
bash_compdir ?= /usr/share/bash-completion/completions
@@ -53,7 +55,7 @@ ifneq ($(EXTRA_LDFLAGS),)
LDFLAGS += $(EXTRA_LDFLAGS)
endif

LIBS = -lelf -lz $(LIBBPF)
LIBS = $(LIBBPF) -lelf -lz

INSTALL ?= install
RM ?= rm -f
@@ -115,16 +117,18 @@ $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
$(OUTPUT)feature.o: | zdep

$(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)

$(OUTPUT)%.o: %.c
	$(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<

clean: $(LIBBPF)-clean
	$(call QUIET_CLEAN, bpftool)
	$(Q)$(RM) $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
	$(Q)$(RM) -- $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
	$(Q)$(RM) -r -- $(OUTPUT)libbpf/
	$(call QUIET_CLEAN, core-gen)
	$(Q)$(RM) $(OUTPUT)FEATURE-DUMP.bpftool
	$(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpftool
	$(Q)$(RM) -r -- $(OUTPUT)feature/

install: $(OUTPUT)bpftool
	$(call QUIET_INSTALL, bpftool)
@@ -135,8 +139,8 @@ install: $(OUTPUT)bpftool

uninstall:
	$(call QUIET_UNINST, bpftool)
	$(Q)$(RM) $(DESTDIR)$(prefix)/sbin/bpftool
	$(Q)$(RM) $(DESTDIR)$(bash_compdir)/bpftool
	$(Q)$(RM) -- $(DESTDIR)$(prefix)/sbin/bpftool
	$(Q)$(RM) -- $(DESTDIR)$(bash_compdir)/bpftool

doc:
	$(call descend,Documentation)
+2 −1
Original line number Diff line number Diff line
@@ -63,7 +63,8 @@ TEST_PROGS := test_kmod.sh \
	test_tcp_check_syncookie.sh \
	test_tc_tunnel.sh \
	test_tc_edt.sh \
	test_xdping.sh
	test_xdping.sh \
	test_bpftool_build.sh

TEST_PROGS_EXTENDED := with_addr.sh \
	with_tunnels.sh \
Loading