2019-05-19 20:07:45 +08:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-only
|
2017-10-05 11:10:04 +08:00
|
|
|
include ../../scripts/Makefile.include
|
|
|
|
include ../../scripts/utilities.mak
|
|
|
|
|
|
|
|
ifeq ($(srctree),)
|
|
|
|
srctree := $(patsubst %/,%,$(dir $(CURDIR)))
|
|
|
|
srctree := $(patsubst %/,%,$(dir $(srctree)))
|
|
|
|
srctree := $(patsubst %/,%,$(dir $(srctree)))
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(V),1)
|
|
|
|
Q =
|
|
|
|
else
|
|
|
|
Q = @
|
|
|
|
endif
|
|
|
|
|
2017-12-08 07:00:17 +08:00
|
|
|
BPF_DIR = $(srctree)/tools/lib/bpf/
|
2017-10-05 11:10:04 +08:00
|
|
|
|
|
|
|
ifneq ($(OUTPUT),)
|
tools: bpftool: improve and check builds for different make invocations
There are a number of alternative "make" invocations that can be used to
compile bpftool. The following invocations are expected to work:
- through the kbuild system, from the top of the repository
(make tools/bpf)
- by telling make to change to the bpftool directory
(make -C tools/bpf/bpftool)
- by building the BPF tools from tools/
(cd tools && make bpf)
- by running make from bpftool directory
(cd tools/bpf/bpftool && make)
Additionally, setting the O or OUTPUT variables should tell the build
system to use a custom output path, for each of these alternatives.
The following patch fixes the following invocations:
$ make tools/bpf
$ make tools/bpf O=<dir>
$ make -C tools/bpf/bpftool OUTPUT=<dir>
$ make -C tools/bpf/bpftool O=<dir>
$ cd tools/ && make bpf O=<dir>
$ cd tools/bpf/bpftool && make OUTPUT=<dir>
$ cd tools/bpf/bpftool && make O=<dir>
After this commit, the build still fails for two variants when passing
the OUTPUT variable:
$ make tools/bpf OUTPUT=<dir>
$ cd tools/ && make bpf OUTPUT=<dir>
In order to remember and check what make invocations are supposed to
work, and to document the ones which do not, a new script is added to
the BPF selftests. Note that some invocations require the kernel to be
configured, so the script skips them if no .config file is found.
v2:
- In make_and_clean(), set $ERROR to 1 when "make" returns non-zero,
even if the binary was produced.
- Run "make clean" from the correct directory (bpf/ instead of bpftool/,
when relevant).
Reported-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-08-30 19:00:38 +08:00
|
|
|
LIBBPF_OUTPUT = $(OUTPUT)/libbpf/
|
|
|
|
LIBBPF_PATH = $(LIBBPF_OUTPUT)
|
2017-10-05 11:10:04 +08:00
|
|
|
else
|
tools: bpftool: improve and check builds for different make invocations
There are a number of alternative "make" invocations that can be used to
compile bpftool. The following invocations are expected to work:
- through the kbuild system, from the top of the repository
(make tools/bpf)
- by telling make to change to the bpftool directory
(make -C tools/bpf/bpftool)
- by building the BPF tools from tools/
(cd tools && make bpf)
- by running make from bpftool directory
(cd tools/bpf/bpftool && make)
Additionally, setting the O or OUTPUT variables should tell the build
system to use a custom output path, for each of these alternatives.
The following patch fixes the following invocations:
$ make tools/bpf
$ make tools/bpf O=<dir>
$ make -C tools/bpf/bpftool OUTPUT=<dir>
$ make -C tools/bpf/bpftool O=<dir>
$ cd tools/ && make bpf O=<dir>
$ cd tools/bpf/bpftool && make OUTPUT=<dir>
$ cd tools/bpf/bpftool && make O=<dir>
After this commit, the build still fails for two variants when passing
the OUTPUT variable:
$ make tools/bpf OUTPUT=<dir>
$ cd tools/ && make bpf OUTPUT=<dir>
In order to remember and check what make invocations are supposed to
work, and to document the ones which do not, a new script is added to
the BPF selftests. Note that some invocations require the kernel to be
configured, so the script skips them if no .config file is found.
v2:
- In make_and_clean(), set $ERROR to 1 when "make" returns non-zero,
even if the binary was produced.
- Run "make clean" from the correct directory (bpf/ instead of bpftool/,
when relevant).
Reported-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-08-30 19:00:38 +08:00
|
|
|
LIBBPF_PATH = $(BPF_DIR)
|
2017-10-05 11:10:04 +08:00
|
|
|
endif
|
|
|
|
|
tools: bpftool: improve and check builds for different make invocations
There are a number of alternative "make" invocations that can be used to
compile bpftool. The following invocations are expected to work:
- through the kbuild system, from the top of the repository
(make tools/bpf)
- by telling make to change to the bpftool directory
(make -C tools/bpf/bpftool)
- by building the BPF tools from tools/
(cd tools && make bpf)
- by running make from bpftool directory
(cd tools/bpf/bpftool && make)
Additionally, setting the O or OUTPUT variables should tell the build
system to use a custom output path, for each of these alternatives.
The following patch fixes the following invocations:
$ make tools/bpf
$ make tools/bpf O=<dir>
$ make -C tools/bpf/bpftool OUTPUT=<dir>
$ make -C tools/bpf/bpftool O=<dir>
$ cd tools/ && make bpf O=<dir>
$ cd tools/bpf/bpftool && make OUTPUT=<dir>
$ cd tools/bpf/bpftool && make O=<dir>
After this commit, the build still fails for two variants when passing
the OUTPUT variable:
$ make tools/bpf OUTPUT=<dir>
$ cd tools/ && make bpf OUTPUT=<dir>
In order to remember and check what make invocations are supposed to
work, and to document the ones which do not, a new script is added to
the BPF selftests. Note that some invocations require the kernel to be
configured, so the script skips them if no .config file is found.
v2:
- In make_and_clean(), set $ERROR to 1 when "make" returns non-zero,
even if the binary was produced.
- Run "make clean" from the correct directory (bpf/ instead of bpftool/,
when relevant).
Reported-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-08-30 19:00:38 +08:00
|
|
|
LIBBPF = $(LIBBPF_PATH)libbpf.a
|
2017-10-05 11:10:04 +08:00
|
|
|
|
2020-09-17 19:58:33 +08:00
|
|
|
BPFTOOL_VERSION ?= $(shell make -rR --no-print-directory -sC ../../.. kernelversion)
|
2017-12-28 03:16:28 +08:00
|
|
|
|
2017-10-05 11:10:04 +08:00
|
|
|
$(LIBBPF): FORCE
|
tools: bpftool: improve and check builds for different make invocations
There are a number of alternative "make" invocations that can be used to
compile bpftool. The following invocations are expected to work:
- through the kbuild system, from the top of the repository
(make tools/bpf)
- by telling make to change to the bpftool directory
(make -C tools/bpf/bpftool)
- by building the BPF tools from tools/
(cd tools && make bpf)
- by running make from bpftool directory
(cd tools/bpf/bpftool && make)
Additionally, setting the O or OUTPUT variables should tell the build
system to use a custom output path, for each of these alternatives.
The following patch fixes the following invocations:
$ make tools/bpf
$ make tools/bpf O=<dir>
$ make -C tools/bpf/bpftool OUTPUT=<dir>
$ make -C tools/bpf/bpftool O=<dir>
$ cd tools/ && make bpf O=<dir>
$ cd tools/bpf/bpftool && make OUTPUT=<dir>
$ cd tools/bpf/bpftool && make O=<dir>
After this commit, the build still fails for two variants when passing
the OUTPUT variable:
$ make tools/bpf OUTPUT=<dir>
$ cd tools/ && make bpf OUTPUT=<dir>
In order to remember and check what make invocations are supposed to
work, and to document the ones which do not, a new script is added to
the BPF selftests. Note that some invocations require the kernel to be
configured, so the script skips them if no .config file is found.
v2:
- In make_and_clean(), set $ERROR to 1 when "make" returns non-zero,
even if the binary was produced.
- Run "make clean" from the correct directory (bpf/ instead of bpftool/,
when relevant).
Reported-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-08-30 19:00:38 +08:00
|
|
|
$(if $(LIBBPF_OUTPUT),@mkdir -p $(LIBBPF_OUTPUT))
|
|
|
|
$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) $(LIBBPF_OUTPUT)libbpf.a
|
2017-10-05 11:10:04 +08:00
|
|
|
|
|
|
|
$(LIBBPF)-clean:
|
|
|
|
$(call QUIET_CLEAN, libbpf)
|
tools: bpftool: improve and check builds for different make invocations
There are a number of alternative "make" invocations that can be used to
compile bpftool. The following invocations are expected to work:
- through the kbuild system, from the top of the repository
(make tools/bpf)
- by telling make to change to the bpftool directory
(make -C tools/bpf/bpftool)
- by building the BPF tools from tools/
(cd tools && make bpf)
- by running make from bpftool directory
(cd tools/bpf/bpftool && make)
Additionally, setting the O or OUTPUT variables should tell the build
system to use a custom output path, for each of these alternatives.
The following patch fixes the following invocations:
$ make tools/bpf
$ make tools/bpf O=<dir>
$ make -C tools/bpf/bpftool OUTPUT=<dir>
$ make -C tools/bpf/bpftool O=<dir>
$ cd tools/ && make bpf O=<dir>
$ cd tools/bpf/bpftool && make OUTPUT=<dir>
$ cd tools/bpf/bpftool && make O=<dir>
After this commit, the build still fails for two variants when passing
the OUTPUT variable:
$ make tools/bpf OUTPUT=<dir>
$ cd tools/ && make bpf OUTPUT=<dir>
In order to remember and check what make invocations are supposed to
work, and to document the ones which do not, a new script is added to
the BPF selftests. Note that some invocations require the kernel to be
configured, so the script skips them if no .config file is found.
v2:
- In make_and_clean(), set $ERROR to 1 when "make" returns non-zero,
even if the binary was produced.
- Run "make clean" from the correct directory (bpf/ instead of bpftool/,
when relevant).
Reported-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-08-30 19:00:38 +08:00
|
|
|
$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) clean >/dev/null
|
2017-10-05 11:10:04 +08:00
|
|
|
|
2017-12-08 07:00:17 +08:00
|
|
|
prefix ?= /usr/local
|
tools: bpftool: unify installation directories
Programs and documentation not managed by package manager are generally
installed under /usr/local/, instead of the user's home directory. In
particular, `man` is generally able to find manual pages under
`/usr/local/share/man`.
bpftool generally follows perf's example, and perf installs to home
directory. However bpftool requires root credentials, so it seems
sensible to follow the more common convention of installing files under
/usr/local instead. So, make /usr/local the default prefix for
installing the binary with `make install`, and the documentation with
`make doc-install`. Also, create /usr/local/sbin if it does not exist.
Note that the bash-completion file, however, is still installed under
/usr/share/bash-completion/completions, as the default setup for bash
does not attempt to load completion files under /usr/local/.
Reported-by: David Beckett <david.beckett@netronome.com>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2017-11-29 09:44:32 +08:00
|
|
|
bash_compdir ?= /usr/share/bash-completion/completions
|
2017-10-05 11:10:04 +08:00
|
|
|
|
|
|
|
CFLAGS += -O2
|
2019-08-14 19:37:24 +08:00
|
|
|
CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers
|
tools/bpftool: Turn off -Wnested-externs warning
Turn off -Wnested-externs to avoid annoying warnings in BUILD_BUG_ON macro when
compiling bpftool:
In file included from /data/users/andriin/linux/tools/include/linux/build_bug.h:5,
from /data/users/andriin/linux/tools/include/linux/kernel.h:8,
from /data/users/andriin/linux/kernel/bpf/disasm.h:10,
from /data/users/andriin/linux/kernel/bpf/disasm.c:8:
/data/users/andriin/linux/kernel/bpf/disasm.c: In function ‘__func_get_name’:
/data/users/andriin/linux/tools/include/linux/compiler.h:37:38: warning: nested extern declaration of ‘__compiletime_assert_0’ [-Wnested-externs]
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
^~~~~~~~~~~~~~~~~~~~~
/data/users/andriin/linux/tools/include/linux/compiler.h:16:15: note: in definition of macro ‘__compiletime_assert’
extern void prefix ## suffix(void) __compiletime_error(msg); \
^~~~~~
/data/users/andriin/linux/tools/include/linux/compiler.h:37:2: note: in expansion of macro ‘_compiletime_assert’
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
^~~~~~~~~~~~~~~~~~~
/data/users/andriin/linux/tools/include/linux/build_bug.h:39:37: note: in expansion of macro ‘compiletime_assert’
#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
^~~~~~~~~~~~~~~~~~
/data/users/andriin/linux/tools/include/linux/build_bug.h:50:2: note: in expansion of macro ‘BUILD_BUG_ON_MSG’
BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
^~~~~~~~~~~~~~~~
/data/users/andriin/linux/kernel/bpf/disasm.c:20:2: note: in expansion of macro ‘BUILD_BUG_ON’
BUILD_BUG_ON(ARRAY_SIZE(func_id_str) != __BPF_FUNC_MAX_ID);
^~~~~~~~~~~~
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20200701212816.2072340-1-andriin@fb.com
2020-07-02 05:28:16 +08:00
|
|
|
CFLAGS += $(filter-out -Wswitch-enum -Wnested-externs,$(EXTRA_WARNINGS))
|
2018-05-04 09:37:16 +08:00
|
|
|
CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \
|
2020-06-20 07:17:00 +08:00
|
|
|
-I$(if $(OUTPUT),$(OUTPUT),.) \
|
2018-05-04 09:37:16 +08:00
|
|
|
-I$(srctree)/kernel/bpf/ \
|
|
|
|
-I$(srctree)/tools/include \
|
|
|
|
-I$(srctree)/tools/include/uapi \
|
2020-01-20 21:06:46 +08:00
|
|
|
-I$(srctree)/tools/lib \
|
2018-05-04 09:37:16 +08:00
|
|
|
-I$(srctree)/tools/perf
|
2017-12-28 03:16:28 +08:00
|
|
|
CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"'
|
2018-10-08 16:22:58 +08:00
|
|
|
ifneq ($(EXTRA_CFLAGS),)
|
|
|
|
CFLAGS += $(EXTRA_CFLAGS)
|
|
|
|
endif
|
2018-10-08 16:22:59 +08:00
|
|
|
ifneq ($(EXTRA_LDFLAGS),)
|
|
|
|
LDFLAGS += $(EXTRA_LDFLAGS)
|
|
|
|
endif
|
2018-10-08 16:22:58 +08:00
|
|
|
|
2017-12-08 07:00:17 +08:00
|
|
|
INSTALL ?= install
|
|
|
|
RM ?= rm -f
|
2020-03-10 01:32:15 +08:00
|
|
|
CLANG ?= clang
|
2020-07-22 12:38:04 +08:00
|
|
|
LLVM_STRIP ?= llvm-strip
|
2017-12-08 07:00:17 +08:00
|
|
|
|
2017-12-28 03:16:29 +08:00
|
|
|
FEATURE_USER = .bpftool
|
2020-04-29 22:45:06 +08:00
|
|
|
FEATURE_TESTS = libbfd disassembler-four-args reallocarray zlib libcap \
|
2020-06-20 07:17:00 +08:00
|
|
|
clang-bpf-co-re
|
2020-04-29 22:45:06 +08:00
|
|
|
FEATURE_DISPLAY = libbfd disassembler-four-args zlib libcap \
|
2020-06-20 07:17:00 +08:00
|
|
|
clang-bpf-co-re
|
2017-12-28 03:16:29 +08:00
|
|
|
|
|
|
|
check_feat := 1
|
|
|
|
NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall
|
|
|
|
ifdef MAKECMDGOALS
|
|
|
|
ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),)
|
|
|
|
check_feat := 0
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(check_feat),1)
|
|
|
|
ifeq ($(FEATURES_DUMP),)
|
|
|
|
include $(srctree)/tools/build/Makefile.feature
|
|
|
|
else
|
|
|
|
include $(FEATURES_DUMP)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(feature-disassembler-four-args), 1)
|
|
|
|
CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
|
|
|
|
endif
|
|
|
|
|
2018-07-11 05:43:05 +08:00
|
|
|
ifeq ($(feature-reallocarray), 0)
|
|
|
|
CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
|
|
|
|
endif
|
|
|
|
|
2020-04-29 22:45:06 +08:00
|
|
|
LIBS = $(LIBBPF) -lelf -lz
|
|
|
|
ifeq ($(feature-libcap), 1)
|
|
|
|
CFLAGS += -DUSE_LIBCAP
|
|
|
|
LIBS += -lcap
|
|
|
|
endif
|
|
|
|
|
2018-03-16 14:26:14 +08:00
|
|
|
include $(wildcard $(OUTPUT)*.d)
|
2017-10-05 11:10:04 +08:00
|
|
|
|
|
|
|
all: $(OUTPUT)bpftool
|
|
|
|
|
2018-11-13 05:44:10 +08:00
|
|
|
BFD_SRCS = jit_disasm.c
|
|
|
|
|
|
|
|
SRCS = $(filter-out $(BFD_SRCS),$(wildcard *.c))
|
|
|
|
|
|
|
|
ifeq ($(feature-libbfd),1)
|
2019-01-16 06:03:27 +08:00
|
|
|
LIBS += -lbfd -ldl -lopcodes
|
|
|
|
else ifeq ($(feature-libbfd-liberty),1)
|
|
|
|
LIBS += -lbfd -ldl -lopcodes -liberty
|
|
|
|
else ifeq ($(feature-libbfd-liberty-z),1)
|
|
|
|
LIBS += -lbfd -ldl -lopcodes -liberty -lz
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq ($(filter -lbfd,$(LIBS)),)
|
2018-11-13 05:44:10 +08:00
|
|
|
CFLAGS += -DHAVE_LIBBFD_SUPPORT
|
|
|
|
SRCS += $(BFD_SRCS)
|
|
|
|
endif
|
|
|
|
|
2020-06-20 07:16:59 +08:00
|
|
|
BPFTOOL_BOOTSTRAP := $(if $(OUTPUT),$(OUTPUT)bpftool-bootstrap,./bpftool-bootstrap)
|
|
|
|
|
|
|
|
BOOTSTRAP_OBJS = $(addprefix $(OUTPUT),main.o common.o json_writer.o gen.o btf.o)
|
2017-12-08 07:00:17 +08:00
|
|
|
OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
|
2020-03-10 01:32:15 +08:00
|
|
|
|
2020-06-30 08:47:58 +08:00
|
|
|
VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \
|
2020-06-20 07:17:00 +08:00
|
|
|
$(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \
|
|
|
|
../../../vmlinux \
|
|
|
|
/sys/kernel/btf/vmlinux \
|
|
|
|
/boot/vmlinux-$(shell uname -r)
|
2020-06-30 08:47:58 +08:00
|
|
|
VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS))))
|
2020-06-20 07:17:00 +08:00
|
|
|
|
2020-06-30 08:47:58 +08:00
|
|
|
ifneq ($(VMLINUX_BTF)$(VMLINUX_H),)
|
2020-06-20 07:17:00 +08:00
|
|
|
ifeq ($(feature-clang-bpf-co-re),1)
|
|
|
|
|
|
|
|
BUILD_BPF_SKELS := 1
|
|
|
|
|
|
|
|
$(OUTPUT)vmlinux.h: $(VMLINUX_BTF) $(BPFTOOL_BOOTSTRAP)
|
2020-06-30 08:47:58 +08:00
|
|
|
ifeq ($(VMLINUX_H),)
|
2020-06-20 07:17:00 +08:00
|
|
|
$(QUIET_GEN)$(BPFTOOL_BOOTSTRAP) btf dump file $< format c > $@
|
2020-06-30 08:47:58 +08:00
|
|
|
else
|
|
|
|
$(Q)cp "$(VMLINUX_H)" $@
|
|
|
|
endif
|
2020-03-13 02:23:30 +08:00
|
|
|
|
2020-06-20 07:17:00 +08:00
|
|
|
$(OUTPUT)%.bpf.o: skeleton/%.bpf.c $(OUTPUT)vmlinux.h $(LIBBPF)
|
2020-03-12 21:03:30 +08:00
|
|
|
$(QUIET_CLANG)$(CLANG) \
|
2020-06-20 07:17:00 +08:00
|
|
|
-I$(if $(OUTPUT),$(OUTPUT),.) \
|
2020-03-12 21:03:30 +08:00
|
|
|
-I$(srctree)/tools/include/uapi/ \
|
2020-06-20 07:17:00 +08:00
|
|
|
-I$(LIBBPF_PATH) \
|
|
|
|
-I$(srctree)/tools/lib \
|
2020-07-22 12:38:04 +08:00
|
|
|
-g -O2 -target bpf -c $< -o $@ && $(LLVM_STRIP) -g $@
|
2020-03-10 01:32:15 +08:00
|
|
|
|
2020-06-20 07:17:00 +08:00
|
|
|
$(OUTPUT)%.skel.h: $(OUTPUT)%.bpf.o $(BPFTOOL_BOOTSTRAP)
|
|
|
|
$(QUIET_GEN)$(BPFTOOL_BOOTSTRAP) gen skeleton $< > $@
|
|
|
|
|
|
|
|
$(OUTPUT)prog.o: $(OUTPUT)profiler.skel.h
|
|
|
|
|
tools/bpftool: Show info for processes holding BPF map/prog/link/btf FDs
Add bpf_iter-based way to find all the processes that hold open FDs against
BPF object (map, prog, link, btf). bpftool always attempts to discover this,
but will silently give up if kernel doesn't yet support bpf_iter BPF programs.
Process name and PID are emitted for each process (task group).
Sample output for each of 4 BPF objects:
$ sudo ./bpftool prog show
2694: cgroup_device tag 8c42dee26e8cd4c2 gpl
loaded_at 2020-06-16T15:34:32-0700 uid 0
xlated 648B jited 409B memlock 4096B
pids systemd(1)
2907: cgroup_skb name egress tag 9ad187367cf2b9e8 gpl
loaded_at 2020-06-16T18:06:54-0700 uid 0
xlated 48B jited 59B memlock 4096B map_ids 2436
btf_id 1202
pids test_progs(2238417), test_progs(2238445)
$ sudo ./bpftool map show
2436: array name test_cgr.bss flags 0x400
key 4B value 8B max_entries 1 memlock 8192B
btf_id 1202
pids test_progs(2238417), test_progs(2238445)
2445: array name pid_iter.rodata flags 0x480
key 4B value 4B max_entries 1 memlock 8192B
btf_id 1214 frozen
pids bpftool(2239612)
$ sudo ./bpftool link show
61: cgroup prog 2908
cgroup_id 375301 attach_type egress
pids test_progs(2238417), test_progs(2238445)
62: cgroup prog 2908
cgroup_id 375344 attach_type egress
pids test_progs(2238417), test_progs(2238445)
$ sudo ./bpftool btf show
1202: size 1527B prog_ids 2908,2907 map_ids 2436
pids test_progs(2238417), test_progs(2238445)
1242: size 34684B
pids bpftool(2258892)
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Reviewed-by: Quentin Monnet <quentin@isovalent.com>
Link: https://lore.kernel.org/bpf/20200619231703.738941-9-andriin@fb.com
2020-06-20 07:17:02 +08:00
|
|
|
$(OUTPUT)pids.o: $(OUTPUT)pid_iter.skel.h
|
|
|
|
|
2020-06-20 07:17:00 +08:00
|
|
|
endif
|
|
|
|
endif
|
2020-03-10 01:32:15 +08:00
|
|
|
|
2020-06-23 18:37:10 +08:00
|
|
|
CFLAGS += $(if $(BUILD_BPF_SKELS),,-DBPFTOOL_WITHOUT_SKELETONS)
|
2017-10-10 01:30:13 +08:00
|
|
|
|
|
|
|
$(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
|
2020-06-03 01:56:48 +08:00
|
|
|
$(QUIET_CC)$(CC) $(CFLAGS) -c -MMD -o $@ $<
|
2017-10-05 11:10:04 +08:00
|
|
|
|
2019-08-13 08:38:33 +08:00
|
|
|
$(OUTPUT)feature.o: | zdep
|
|
|
|
|
2020-06-20 07:16:59 +08:00
|
|
|
$(BPFTOOL_BOOTSTRAP): $(BOOTSTRAP_OBJS) $(LIBBPF)
|
|
|
|
$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(BOOTSTRAP_OBJS) $(LIBS)
|
|
|
|
|
|
|
|
$(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
|
|
|
|
$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
|
2017-10-05 11:10:04 +08:00
|
|
|
|
|
|
|
$(OUTPUT)%.o: %.c
|
2020-06-03 01:56:48 +08:00
|
|
|
$(QUIET_CC)$(CC) $(CFLAGS) -c -MMD -o $@ $<
|
2017-10-05 11:10:04 +08:00
|
|
|
|
2020-08-27 16:53:36 +08:00
|
|
|
feature-detect-clean:
|
|
|
|
$(call QUIET_CLEAN, feature-detect)
|
|
|
|
$(Q)$(MAKE) -C $(srctree)/tools/build/feature/ clean >/dev/null
|
|
|
|
|
|
|
|
clean: $(LIBBPF)-clean feature-detect-clean
|
2017-10-05 11:10:04 +08:00
|
|
|
$(call QUIET_CLEAN, bpftool)
|
2019-08-30 19:00:39 +08:00
|
|
|
$(Q)$(RM) -- $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
|
2020-06-20 07:17:00 +08:00
|
|
|
$(Q)$(RM) -- $(BPFTOOL_BOOTSTRAP) $(OUTPUT)*.skel.h $(OUTPUT)vmlinux.h
|
2019-08-30 19:00:39 +08:00
|
|
|
$(Q)$(RM) -r -- $(OUTPUT)libbpf/
|
2018-03-16 14:26:17 +08:00
|
|
|
$(call QUIET_CLEAN, core-gen)
|
2019-08-30 19:00:39 +08:00
|
|
|
$(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpftool
|
|
|
|
$(Q)$(RM) -r -- $(OUTPUT)feature/
|
2017-10-05 11:10:04 +08:00
|
|
|
|
2017-12-08 07:00:17 +08:00
|
|
|
install: $(OUTPUT)bpftool
|
|
|
|
$(call QUIET_INSTALL, bpftool)
|
|
|
|
$(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/sbin
|
|
|
|
$(Q)$(INSTALL) $(OUTPUT)bpftool $(DESTDIR)$(prefix)/sbin/bpftool
|
|
|
|
$(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(bash_compdir)
|
|
|
|
$(Q)$(INSTALL) -m 0644 bash-completion/bpftool $(DESTDIR)$(bash_compdir)
|
2017-10-05 11:10:04 +08:00
|
|
|
|
2017-12-08 07:00:18 +08:00
|
|
|
uninstall:
|
|
|
|
$(call QUIET_UNINST, bpftool)
|
2019-08-30 19:00:39 +08:00
|
|
|
$(Q)$(RM) -- $(DESTDIR)$(prefix)/sbin/bpftool
|
|
|
|
$(Q)$(RM) -- $(DESTDIR)$(bash_compdir)/bpftool
|
2017-12-08 07:00:18 +08:00
|
|
|
|
2017-10-05 11:10:05 +08:00
|
|
|
doc:
|
2017-12-08 07:00:17 +08:00
|
|
|
$(call descend,Documentation)
|
|
|
|
|
|
|
|
doc-clean:
|
|
|
|
$(call descend,Documentation,clean)
|
2017-10-05 11:10:05 +08:00
|
|
|
|
|
|
|
doc-install:
|
2017-12-08 07:00:17 +08:00
|
|
|
$(call descend,Documentation,install)
|
2017-10-05 11:10:05 +08:00
|
|
|
|
2017-12-08 07:00:18 +08:00
|
|
|
doc-uninstall:
|
|
|
|
$(call descend,Documentation,uninstall)
|
|
|
|
|
2017-10-05 11:10:04 +08:00
|
|
|
FORCE:
|
|
|
|
|
2019-08-13 08:38:33 +08:00
|
|
|
zdep:
|
|
|
|
@if [ "$(feature-zlib)" != "1" ]; then echo "No zlib found"; exit 1 ; fi
|
|
|
|
|
2020-06-20 07:17:00 +08:00
|
|
|
.SECONDARY:
|
2019-08-13 08:38:33 +08:00
|
|
|
.PHONY: all FORCE clean install uninstall zdep
|
2017-12-08 07:00:18 +08:00
|
|
|
.PHONY: doc doc-clean doc-install doc-uninstall
|
2017-10-05 11:10:04 +08:00
|
|
|
.DEFAULT_GOAL := all
|