From 00cbf6f6ab1d5c45a40c68167af897c9526542e8 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 15 Mar 2022 14:33:59 +0100 Subject: [PATCH] bpftools: update to standalone bpftools + libbpf, use the latest version Signed-off-by: Felix Fietkau --- package/network/config/qosify/Makefile | 2 + package/network/utils/bpftools/Makefile | 72 +++++++------------ .../utils/bpftools/patches/001-cflags.patch | 10 +++ .../utils/bpftools/patches/002-includes.patch | 26 +++++++ ...pc-fix-EDEADLOCK-redefinition-errors.patch | 51 ------------- .../utils/bpftools/patches/006-musl-120.patch | 20 ------ 6 files changed, 64 insertions(+), 117 deletions(-) create mode 100644 package/network/utils/bpftools/patches/001-cflags.patch create mode 100644 package/network/utils/bpftools/patches/002-includes.patch delete mode 100644 package/network/utils/bpftools/patches/005-tools-arch-powerpc-fix-EDEADLOCK-redefinition-errors.patch delete mode 100644 package/network/utils/bpftools/patches/006-musl-120.patch diff --git a/package/network/config/qosify/Makefile b/package/network/config/qosify/Makefile index 881d429613c..7aac759bcb2 100644 --- a/package/network/config/qosify/Makefile +++ b/package/network/config/qosify/Makefile @@ -34,6 +34,8 @@ define Package/qosify DEPENDS:=+libbpf +libubox +libubus +kmod-sched-cake +kmod-sched-bpf +kmod-ifb +tc-full $(BPF_DEPENDS) endef +TARGET_CFLAGS += -Wno-error=deprecated-declarations + define Build/Compile $(call CompileBPF,$(PKG_BUILD_DIR)/qosify-bpf.c) $(Build/Compile/Default) diff --git a/package/network/utils/bpftools/Makefile b/package/network/utils/bpftools/Makefile index f044cc81f85..406481d784b 100644 --- a/package/network/utils/bpftools/Makefile +++ b/package/network/utils/bpftools/Makefile @@ -8,12 +8,14 @@ include $(TOPDIR)/rules.mk PKG_NAME:=bpftools -PKG_VERSION:=5.11.16 PKG_RELEASE:=1 -PKG_SOURCE:=linux-$(PKG_VERSION).tar.xz -PKG_SOURCE_URL:=@KERNEL/linux/kernel/v5.x -PKG_HASH:=21163681d130cbce5a6be39019e2c69e44f284855ddd70b1a3bd039249540f43 +PKG_SOURCE_URL:=https://github.com/libbpf/bpftool +PKG_SOURCE_PROTO:=git +PKG_SOURCE_DATE:=2022-03-08 +PKG_SOURCE_VERSION:=04c465fd1f561f67796dc68bbfe1aa7cfa956c3c +PKG_MIRROR_HASH:=e22a954cd186f43228a96586bbdc120b11e6c87360ab88ae96ba37afb9c7cb58 +PKG_ABI_VERSION:=$(call abi_version_str,$(PKG_SOURCE_DATE)) PKG_MAINTAINER:=Tony Ambardar @@ -21,16 +23,6 @@ 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 include $(INCLUDE_DIR)/nls.mk @@ -77,7 +69,7 @@ define Package/libbpf TITLE:=libbpf - eBPF helper library VARIANT:=lib LICENSE:=LGPL-2.1 OR BSD-2-Clause - ABI_VERSION:=0 + ABI_VERSION:=$(PKG_ABI_VERSION) URL:=http://www.kernel.org DEPENDS:=+libelf endef @@ -93,47 +85,35 @@ ifneq ($(BUILD_VARIANT),lib) TARGET_LDFLAGS += -Wl,--gc-sections endif +ifeq ($(BUILD_VARIANT),full) + full:=1 +else + full:=0 +endif + MAKE_VARS = \ EXTRA_CFLAGS="$(TARGET_CFLAGS) $(TARGET_CPPFLAGS)" \ LDFLAGS="$(TARGET_LDFLAGS)" MAKE_FLAGS += \ - 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='') + $(if $(findstring c,$(OPENWRT_VERBOSE)),V=1,V='') \ + LIBSUBDIR=lib \ + check_feat=0 \ + feature-clang-bpf-co-re=0 \ + feature-reallocarray=1 \ + feature-zlib=1 \ + feature-libbfd=$(full) \ + feature-libcap=0 \ + feature-disassembler-four-args=$(full) -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 +ifeq ($(BUILD_VARIANT),lib) + MAKE_PATH = libbpf/src +else + MAKE_PATH = src 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=1/feature-libbfd=$(HAVE_LIBBFD)/' \ - -e 's/feature-libcap=1/feature-libcap=$(HAVE_LIBCAP)/' \ - -e 's/feature-clang-bpf-co-re=1/feature-clang-bpf-co-re=$(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/ diff --git a/package/network/utils/bpftools/patches/001-cflags.patch b/package/network/utils/bpftools/patches/001-cflags.patch new file mode 100644 index 00000000000..48617e302bd --- /dev/null +++ b/package/network/utils/bpftools/patches/001-cflags.patch @@ -0,0 +1,10 @@ +--- a/libbpf/src/Makefile ++++ b/libbpf/src/Makefile +@@ -25,6 +25,7 @@ ALL_CFLAGS := $(INCLUDES) + + SHARED_CFLAGS += -fPIC -fvisibility=hidden -DSHARED + ++CFLAGS = $(EXTRA_CFLAGS) + CFLAGS ?= -g -O2 -Werror -Wall -std=gnu89 + ALL_CFLAGS += $(CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 + ALL_LDFLAGS += $(LDFLAGS) diff --git a/package/network/utils/bpftools/patches/002-includes.patch b/package/network/utils/bpftools/patches/002-includes.patch new file mode 100644 index 00000000000..589d71c31e7 --- /dev/null +++ b/package/network/utils/bpftools/patches/002-includes.patch @@ -0,0 +1,26 @@ +--- a/libbpf/include/linux/list.h ++++ b/libbpf/include/linux/list.h +@@ -3,6 +3,8 @@ + #ifndef __LINUX_LIST_H + #define __LINUX_LIST_H + ++#include ++ + #define LIST_HEAD_INIT(name) { &(name), &(name) } + #define LIST_HEAD(name) \ + struct list_head name = LIST_HEAD_INIT(name) +--- a/src/Makefile ++++ b/src/Makefile +@@ -73,10 +73,10 @@ CFLAGS += -W -Wall -Wextra -Wno-unused-p + CFLAGS += $(filter-out -Wswitch-enum -Wnested-externs,$(EXTRA_WARNINGS)) + CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \ + -I$(if $(OUTPUT),$(OUTPUT),.) \ +- -I$(LIBBPF_INCLUDE) \ + -I$(srctree)/src/kernel/bpf/ \ + -I$(srctree)/include \ +- -I$(srctree)/include/uapi ++ -I$(srctree)/include/uapi \ ++ -I$(LIBBPF_INCLUDE) + ifneq ($(BPFTOOL_VERSION),) + CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"' + endif diff --git a/package/network/utils/bpftools/patches/005-tools-arch-powerpc-fix-EDEADLOCK-redefinition-errors.patch b/package/network/utils/bpftools/patches/005-tools-arch-powerpc-fix-EDEADLOCK-redefinition-errors.patch deleted file mode 100644 index 996ffc43ee5..00000000000 --- a/package/network/utils/bpftools/patches/005-tools-arch-powerpc-fix-EDEADLOCK-redefinition-errors.patch +++ /dev/null @@ -1,51 +0,0 @@ -From afe3f4c765b17ced23811fe652c7f7adf7a0c0cf Mon Sep 17 00:00:00 2001 -From: Tony Ambardar -Date: Mon, 14 Sep 2020 23:05:26 -0700 -Subject: [PATCH] tools/arch/powerpc: fix EDEADLOCK redefinition errors in - errno.h - -A few archs like powerpc have different errno.h values for macros -EDEADLOCK and EDEADLK. In code including both libc and linux versions of -errno.h, this can result in multiple definitions of EDEADLOCK in the -include chain. Definitions to the same value (e.g. seen with mips) do -not raise warnings, but on powerpc there are redefinitions changing the -value, which raise warnings and errors (with "-Werror"). - -Guard against these redefinitions to avoid build errors like the following, -first seen cross-compiling libbpf v5.8.9 for powerpc using GCC 8.4.0 with -musl 1.1.24: - - In file included from ../../arch/powerpc/include/uapi/asm/errno.h:5, - from ../../include/linux/err.h:8, - from libbpf.c:29: - ../../include/uapi/asm-generic/errno.h:40: error: "EDEADLOCK" redefined [-Werror] - #define EDEADLOCK EDEADLK - - In file included from toolchain-powerpc_8540_gcc-8.4.0_musl/include/errno.h:10, - from libbpf.c:26: - toolchain-powerpc_8540_gcc-8.4.0_musl/include/bits/errno.h:58: note: this is the location of the previous definition - #define EDEADLOCK 58 - - cc1: all warnings being treated as errors - make[5]: *** [target-powerpc_8540_musl/bpftools-5.8.9/tools/build/Makefile.build:97: /home/kodidev/openwrt-project/build_dir/target-powerpc_8540_musl/bpftools-minimal/bpftools-5.8.9//libbpf/staticobjs/libbpf.o] Error 1 - -Fixes: 95f28190aa01 ("tools include arch: Grab a copy of errno.h for arch's - supported by perf") -Fixes: c3617f72036c ("UAPI: (Scripted) Disintegrate arch/powerpc/include/asm") - -Reported-by: Rosen Penev -Signed-off-by: Tony Ambardar ---- - tools/arch/powerpc/include/uapi/asm/errno.h | 1 + - 1 file changed, 1 insertion(+) - ---- a/tools/arch/powerpc/include/uapi/asm/errno.h -+++ b/tools/arch/powerpc/include/uapi/asm/errno.h -@@ -2,6 +2,7 @@ - #ifndef _ASM_POWERPC_ERRNO_H - #define _ASM_POWERPC_ERRNO_H - -+#undef EDEADLOCK - #include - - #undef EDEADLOCK diff --git a/package/network/utils/bpftools/patches/006-musl-120.patch b/package/network/utils/bpftools/patches/006-musl-120.patch deleted file mode 100644 index 53be466f0bb..00000000000 --- a/package/network/utils/bpftools/patches/006-musl-120.patch +++ /dev/null @@ -1,20 +0,0 @@ ---- a/tools/bpf/bpftool/btf_dumper.c -+++ b/tools/bpf/bpftool/btf_dumper.c -@@ -5,6 +5,7 @@ - #include /* for (FILE *) used by json_writer */ - #include - #include -+#include - #include - #include - #include ---- a/tools/bpf/bpftool/map_perf_ring.c -+++ b/tools/bpf/bpftool/map_perf_ring.c -@@ -16,6 +16,7 @@ - #include - #include - #include -+#include - #include - #include - #include -- 2.30.2