diff options
author | Tony Ambardar <itugrok@yahoo.com> | 2020-08-20 11:46:50 -0700 |
---|---|---|
committer | Daniel Golle <daniel@makrotopia.org> | 2020-08-31 12:23:59 +0100 |
commit | 2f0d672088c39914ab9cd59b9de3d6f705cd6d5d (patch) | |
tree | ba3810d5384e7529d19f8f318c36d804e2354f96 /package/network/utils/bpftools/Makefile | |
parent | 735947229c0e89fd714b3cded1e76ea9093827ed (diff) | |
download | upstream-2f0d672088c39914ab9cd59b9de3d6f705cd6d5d.tar.gz upstream-2f0d672088c39914ab9cd59b9de3d6f705cd6d5d.tar.bz2 upstream-2f0d672088c39914ab9cd59b9de3d6f705cd6d5d.zip |
bpftools: add utility and library packages supporting eBPF usage
Add support for building bpftool and libbpf from the latest 5.8.3 kernel
sources, ensuring up-to-date functionality and fixes. Both are written to
be backwards compatible, which simplfies build and usage across different
OpenWRT image kernels.
'bpftool' is the primary userspace tool widely used for introspection and
manipulation of eBPF programs and maps. Two variants are built: a 'full'
version which supports object disassembly and depends on libbfd/libopcodes
(total ~500KB); and a 'minimal' version without disassembly functions and
dependencies. The default 'minimal' variant is otherwise fully functional,
and both are compiled using LTO for further (~30KB) size reductions.
'libbpf' provides shared/static libraries and dev files needed for building
userspace programs that perform eBPF interaction.
Several cross-compilation and build-failure problems are addressed by new
patches and ones backported from farther upstream:
* 001-libbpf-ensure-no-local-symbols-counted-in-ABI-check.patch
* 002-libbpf-fix-build-failure-from-uninitialized-variable.patch
* 003-bpftool-allow-passing-BPFTOOL_VERSION-to-make.patch
* 004-v5.9-bpftool-use-only-ftw-for-file-tree-parsing.patch
Signed-off-by: Tony Ambardar <itugrok@yahoo.com>
Diffstat (limited to 'package/network/utils/bpftools/Makefile')
-rw-r--r-- | package/network/utils/bpftools/Makefile | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/package/network/utils/bpftools/Makefile b/package/network/utils/bpftools/Makefile new file mode 100644 index 0000000000..156dc8a4fa --- /dev/null +++ b/package/network/utils/bpftools/Makefile @@ -0,0 +1,162 @@ +# +# Copyright (C) 2020 Tony Ambardar <itugrok@yahoo.com> +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=bpftools +PKG_VERSION:=5.8.3 +PKG_RELEASE:=1 + +PKG_SOURCE:=linux-$(PKG_VERSION).tar.xz +PKG_SOURCE_URL:=@KERNEL/linux/kernel/v5.x +PKG_HASH:=8ea27e1ed38981f772cc6d5f16ab8dbb8052c3800ba0494bd798fbb95dcc1779 + +PKG_MAINTAINER:=Tony Ambardar <itugrok@yahoo.com> + +PKG_USE_MIPS16:=0 +PKG_BUILD_PARALLEL:=1 +PKG_INSTALL:=1 + +LINUX_VERSION:=$(PKG_VERSION) +LINUX_TLD:=linux-$(LINUX_VERSION) + +BPF_FILES:= \ + kernel/bpf scripts tools/Makefile tools/bpf tools/perf/perf-sys.h \ + tools/arch tools/build tools/include tools/lib tools/scripts +TAR_OPTIONS+= \ + --transform="s;$(LINUX_TLD)/;$(PKG_NAME)-$(PKG_VERSION)/;" \ + $(addprefix $(LINUX_TLD)/,$(BPF_FILES)) + +include $(INCLUDE_DIR)/package.mk + +define Package/bpftool/Default + SECTION:=net + CATEGORY:=Network + TITLE:=bpftool - eBPF subsystem utility + LICENSE:=GPL-2.0-only OR BSD-2-Clause + URL:=http://www.kernel.org + DEPENDS:=+libelf +endef + +define Package/bpftool-minimal + $(call Package/bpftool/Default) + TITLE+= (Minimal) + VARIANT:=minimal + DEFAULT_VARIANT:=1 + PROVIDES:=bpftool + ALTERNATIVES:=200:/usr/sbin/bpftool:/usr/libexec/bpftool-minimal +endef + +define Package/bpftool-full + $(call Package/bpftool/Default) + TITLE+= (Full) + VARIANT:=full + PROVIDES:=bpftool + ALTERNATIVES:=300:/usr/sbin/bpftool:/usr/libexec/bpftool-full + DEPENDS+= +libbfd +libopcodes +endef + +define Package/bpftool-minimal/description + A tool for inspection and simple manipulation of eBPF programs and maps. +endef + +define Package/bpftool-full/description + A tool for inspection and simple manipulation of eBPF programs and maps. + This full version uses libbfd and libopcodes to support disassembly of + eBPF programs and jited code. +endef + +define Package/libbpf + SECTION:=libs + CATEGORY:=Libraries + TITLE:=libbpf - eBPF helper library + VARIANT:=lib + LICENSE:=LGPL-2.1 OR BSD-2-Clause + ABI_VERSION:=0 + URL:=http://www.kernel.org + DEPENDS:=+libelf +endef + +define Package/libbpf/description + libbpf is a library for loading eBPF programs and reading and manipulating eBPF objects from user-space. +endef + + +# LTO not compatible with DSO using PIC +ifneq ($(BUILD_VARIANT),lib) + TARGET_CFLAGS += -ffunction-sections -fdata-sections -flto + TARGET_LDFLAGS += -Wl,--gc-sections +endif + +MAKE_FLAGS += \ + EXTRA_CFLAGS="$(TARGET_CFLAGS) $(TARGET_CPPFLAGS)" \ + LDFLAGS="$(TARGET_LDFLAGS)" \ + BPFTOOL_VERSION="$(LINUX_VERSION)" \ + FEATURES_DUMP="$(PKG_BUILD_DIR)/FEATURE-DUMP.openwrt" \ + OUTPUT="$(PKG_BUILD_DIR)/" \ + prefix="/usr" \ + $(if $(findstring c,$(OPENWRT_VERBOSE)),V=1,V='') + +ifeq ($(BUILD_VARIANT),full) + HAVE_LIBBFD:=1 + HAVE_LIBCAP:=0 + HAVE_CLANG:=0 + MAKE_PATH:=tools/bpf/bpftool +else ifeq ($(BUILD_VARIANT),minimal) + HAVE_LIBBFD:=0 + HAVE_LIBCAP:=0 + HAVE_CLANG:=0 + MAKE_PATH:=tools/bpf/bpftool +else ifeq ($(BUILD_VARIANT),lib) + HAVE_LIBBFD:=0 + HAVE_LIBCAP:=0 + HAVE_CLANG:=0 + MAKE_PATH:=tools/lib/bpf +endif + +# Perform a "throw-away" make to create a FEATURE-DUMP.* file to edit later. +# The "//" in the make target is actually needed, very unPOSIXly. +define Build/Configure + +$(MAKE_VARS) $(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR)/tools/bpf/bpftool \ + $(MAKE_FLAGS) FEATURES_DUMP= $(PKG_BUILD_DIR)//libbpf/libbpf.a + (cd $(PKG_BUILD_DIR); cat FEATURE-DUMP.bpftool libbpf/FEATURE-DUMP.libbpf \ + | sort | uniq > FEATURE-DUMP.openwrt) + $(SED) 's/feature-libbfd=[01]/feature-libbfd=$(HAVE_LIBBFD)/' \ + -e 's/feature-libcap=[01]/feature-libcap=$(HAVE_LIBCAP)/' \ + -e 's/feature-clang-bpf-global-var=[01]/feature-clang-bpf-global-var=$(HAVE_CLANG)/' \ + $(PKG_BUILD_DIR)/FEATURE-DUMP.openwrt +endef + +define Build/InstallDev/libbpf + $(INSTALL_DIR) $(1)/usr/include/bpf + $(CP) $(PKG_INSTALL_DIR)/usr/include/bpf/*.h $(1)/usr/include/bpf/ + $(INSTALL_DIR) $(1)/usr/lib + $(CP) $(PKG_INSTALL_DIR)/usr/lib$(LIB_SUFFIX)/libbpf.{a,so*} \ + $(1)/usr/lib/ + $(INSTALL_DIR) $(1)/usr/lib/pkgconfig + $(CP) $(PKG_INSTALL_DIR)/usr/lib$(LIB_SUFFIX)/pkgconfig/libbpf.pc \ + $(1)/usr/lib/pkgconfig/ +endef + +ifeq ($(BUILD_VARIANT),lib) + Build/InstallDev=$(Build/InstallDev/libbpf) +endif + +define Package/bpftool-$(BUILD_VARIANT)/install + $(INSTALL_DIR) $(1)/usr/libexec + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/bpftool \ + $(1)/usr/libexec/bpftool-$(BUILD_VARIANT) +endef + +define Package/libbpf/install + $(INSTALL_DIR) $(1)/usr/lib + $(CP) $(PKG_INSTALL_DIR)/usr/lib$(LIB_SUFFIX)/libbpf.so.* $(1)/usr/lib/ +endef + +$(eval $(call BuildPackage,bpftool-full)) +$(eval $(call BuildPackage,bpftool-minimal)) +$(eval $(call BuildPackage,libbpf)) |