bpftools: update, split off bpftool and libbpf packages
authorTony Ambardar <itugrok@yahoo.com>
Sun, 21 May 2023 09:14:37 +0000 (02:14 -0700)
committerNick Hainke <vincent@systemli.org>
Wed, 24 May 2023 19:17:20 +0000 (21:17 +0200)
My original bpftools package made "variant" builds of bpftool and libbpf
as a convenience, since both used the same local kernel sources with the
same versioning. This is no longer the case, since the commit below
switched to using an out-of-tree build mirror hosting repos for each.

Replace bpftools with separate bpftool and libbpf packages, each simplified
and correctly versioned. Also fix the broken libbpf ABI introduced in the
same commit. Existing build .config files are not impacted.

Fixes: 00cbf6f6ab1d ("bpftools: update to standalone bpftools + libbpf, use the latest version")
Signed-off-by: Tony Ambardar <itugrok@yahoo.com>
package/libs/libbpf/Makefile [new file with mode: 0644]
package/libs/libbpf/patches/001-cflags.patch [new file with mode: 0644]
package/network/utils/bpftool/Makefile [new file with mode: 0644]
package/network/utils/bpftool/patches/001-cflags.patch [new file with mode: 0644]
package/network/utils/bpftool/patches/002-includes.patch [new file with mode: 0644]
package/network/utils/bpftools/Makefile [deleted file]
package/network/utils/bpftools/patches/001-cflags.patch [deleted file]
package/network/utils/bpftools/patches/002-includes.patch [deleted file]

diff --git a/package/libs/libbpf/Makefile b/package/libs/libbpf/Makefile
new file mode 100644 (file)
index 0000000..ee7666f
--- /dev/null
@@ -0,0 +1,75 @@
+#
+# Copyright (C) 2020-2023 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:=libbpf
+PKG_VERSION:=1.2.0
+PKG_RELEASE:=1
+
+PKG_SOURCE_URL:=https://github.com/libbpf/libbpf
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_VERSION:=fbd60dbff51c870f5e80a17c4f2fd639eb80af90
+PKG_MIRROR_HASH:=80a80dfba71576e017b596fb28068e2a92de629e426f063e4b37314c8d576336
+PKG_ABI_VERSION:=$(firstword $(subst .,$(space),$(PKG_VERSION)))
+
+PKG_MAINTAINER:=Tony Ambardar <itugrok@yahoo.com>
+
+PKG_BUILD_FLAGS:=no-mips16
+PKG_BUILD_PARALLEL:=1
+PKG_INSTALL:=1
+
+include $(INCLUDE_DIR)/package.mk
+include $(INCLUDE_DIR)/nls.mk
+
+define Package/libbpf
+  SECTION:=libs
+  CATEGORY:=Libraries
+  TITLE:=libbpf - eBPF helper library
+  LICENSE:=LGPL-2.1 OR BSD-2-Clause
+  ABI_VERSION:=$(PKG_ABI_VERSION)
+  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
+
+MAKE_VARS = \
+       EXTRA_CFLAGS="$(TARGET_CFLAGS) $(TARGET_CPPFLAGS)" \
+       LDFLAGS="$(TARGET_LDFLAGS)"
+
+MAKE_FLAGS += \
+       $(if $(findstring c,$(OPENWRT_VERBOSE)),V=1,V='') \
+       LIBSUBDIR=lib
+
+MAKE_PATH = src
+
+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/libbpf.{a,so*} \
+               $(1)/usr/lib/
+       $(INSTALL_DIR) $(1)/usr/lib/pkgconfig
+       $(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/libbpf.pc \
+               $(1)/usr/lib/pkgconfig/
+       $(SED) 's,/usr/include,$$$${prefix}/include,g' \
+               $(1)/usr/lib/pkgconfig/libbpf.pc
+       $(SED) 's,/usr/lib,$$$${exec_prefix}/lib,g' \
+               $(1)/usr/lib/pkgconfig/libbpf.pc
+endef
+
+Build/InstallDev=$(Build/InstallDev/libbpf)
+
+define Package/libbpf/install
+       $(INSTALL_DIR) $(1)/usr/lib
+       $(CP) $(PKG_INSTALL_DIR)/usr/lib/libbpf.so.* $(1)/usr/lib/
+endef
+
+$(eval $(call BuildPackage,libbpf))
diff --git a/package/libs/libbpf/patches/001-cflags.patch b/package/libs/libbpf/patches/001-cflags.patch
new file mode 100644 (file)
index 0000000..d6ffc3f
--- /dev/null
@@ -0,0 +1,10 @@
+--- a/src/Makefile
++++ b/src/Makefile
+@@ -34,6 +34,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 $(EXTRA_CFLAGS)
+ ALL_LDFLAGS += $(LDFLAGS) $(EXTRA_LDFLAGS)
diff --git a/package/network/utils/bpftool/Makefile b/package/network/utils/bpftool/Makefile
new file mode 100644 (file)
index 0000000..cbbba2d
--- /dev/null
@@ -0,0 +1,99 @@
+#
+# Copyright (C) 2020-2023 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:=7.2.0
+PKG_RELEASE:=1
+
+PKG_SOURCE_URL:=https://github.com/libbpf/bpftool
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE_VERSION:=19ff0564980a7429e730f6987a0b0bf418b3c676
+PKG_MIRROR_HASH:=f9b9871f64986dd2e5dab7060bb919398256ba93964da49c62efaf0e6bc9bbc4
+
+PKG_MAINTAINER:=Tony Ambardar <itugrok@yahoo.com>
+
+PKG_BUILD_FLAGS:=no-mips16
+PKG_BUILD_PARALLEL:=1
+PKG_INSTALL:=1
+
+include $(INCLUDE_DIR)/package.mk
+include $(INCLUDE_DIR)/nls.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
+
+TARGET_CFLAGS += -ffunction-sections -fdata-sections -flto
+TARGET_LDFLAGS += -Wl,--gc-sections -flto
+
+ifeq ($(BUILD_VARIANT),full)
+  full:=1
+else
+  full:=0
+endif
+
+MAKE_VARS = \
+       EXTRA_CFLAGS="$(TARGET_CFLAGS) $(TARGET_CPPFLAGS)" \
+       LDFLAGS="$(TARGET_LDFLAGS)"
+
+MAKE_FLAGS += \
+       OUTPUT="$(PKG_BUILD_DIR)/" \
+       prefix="/usr" \
+       $(if $(findstring c,$(OPENWRT_VERBOSE)),V=1,V='') \
+       check_feat=0 \
+       feature-clang-bpf-co-re=0 \
+       feature-libbfd=$(full) \
+       feature-llvm=0 \
+       feature-libcap=0 \
+       feature-disassembler-four-args=1 \
+       feature-disassembler-init-styled=1
+
+MAKE_PATH = src
+
+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
+
+$(eval $(call BuildPackage,bpftool-full))
+$(eval $(call BuildPackage,bpftool-minimal))
diff --git a/package/network/utils/bpftool/patches/001-cflags.patch b/package/network/utils/bpftool/patches/001-cflags.patch
new file mode 100644 (file)
index 0000000..b06842a
--- /dev/null
@@ -0,0 +1,10 @@
+--- a/libbpf/src/Makefile
++++ b/libbpf/src/Makefile
+@@ -34,6 +34,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 $(EXTRA_CFLAGS)
+ ALL_LDFLAGS += $(LDFLAGS) $(EXTRA_LDFLAGS)
diff --git a/package/network/utils/bpftool/patches/002-includes.patch b/package/network/utils/bpftool/patches/002-includes.patch
new file mode 100644 (file)
index 0000000..ac1b5fc
--- /dev/null
@@ -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 <linux/types.h>
++
+ #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$(or $(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/Makefile b/package/network/utils/bpftools/Makefile
deleted file mode 100644 (file)
index 047d2a0..0000000
+++ /dev/null
@@ -1,149 +0,0 @@
-#
-# 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_RELEASE:=1
-
-PKG_SOURCE_URL:=https://github.com/libbpf/bpftool
-PKG_SOURCE_PROTO:=git
-PKG_SOURCE_DATE:=7.1.0
-PKG_SOURCE_VERSION:=b01941c8f7890489f09713348a7d89567538504b
-PKG_MIRROR_HASH:=641fb337342e25ae784a3efe72c71d8c88600a326300d8d5834e26be21547015
-PKG_ABI_VERSION:=$(call abi_version_str,$(PKG_SOURCE_DATE))
-
-PKG_MAINTAINER:=Tony Ambardar <itugrok@yahoo.com>
-
-PKG_BUILD_FLAGS:=no-mips16
-PKG_BUILD_PARALLEL:=1
-PKG_INSTALL:=1
-
-include $(INCLUDE_DIR)/package.mk
-include $(INCLUDE_DIR)/nls.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:=$(PKG_ABI_VERSION)
-  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 -flto
-endif
-
-ifeq ($(BUILD_VARIANT),full)
-  full:=1
-else
-  full:=0
-endif
-
-MAKE_VARS = \
-       EXTRA_CFLAGS="$(TARGET_CFLAGS) $(TARGET_CPPFLAGS)" \
-       LDFLAGS="$(TARGET_LDFLAGS)"
-
-MAKE_FLAGS += \
-       OUTPUT="$(PKG_BUILD_DIR)/" \
-       prefix="/usr" \
-       $(if $(findstring c,$(OPENWRT_VERBOSE)),V=1,V='') \
-       LIBSUBDIR=lib \
-       check_feat=0 \
-       feature-clang-bpf-co-re=0 \
-       feature-libbfd=$(full) \
-       feature-llvm=0 \
-       feature-libcap=0 \
-       feature-disassembler-four-args=1 \
-       feature-disassembler-init-styled=1
-
-ifeq ($(BUILD_VARIANT),lib)
-  MAKE_PATH = libbpf/src
-else
-  MAKE_PATH = src
-endif
-
-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/libbpf.{a,so*} \
-               $(1)/usr/lib/
-       $(INSTALL_DIR) $(1)/usr/lib/pkgconfig
-       $(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/libbpf.pc \
-               $(1)/usr/lib/pkgconfig/
-       $(SED) 's,/usr/include,$$$${prefix}/include,g' \
-               $(1)/usr/lib/pkgconfig/libbpf.pc
-       $(SED) 's,/usr/lib,$$$${exec_prefix}/lib,g' \
-               $(1)/usr/lib/pkgconfig/libbpf.pc
-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/libbpf.so.* $(1)/usr/lib/
-endef
-
-$(eval $(call BuildPackage,libbpf))
-$(eval $(call BuildPackage,bpftool-full))
-$(eval $(call BuildPackage,bpftool-minimal))
diff --git a/package/network/utils/bpftools/patches/001-cflags.patch b/package/network/utils/bpftools/patches/001-cflags.patch
deleted file mode 100644 (file)
index b06842a..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
---- a/libbpf/src/Makefile
-+++ b/libbpf/src/Makefile
-@@ -34,6 +34,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 $(EXTRA_CFLAGS)
- ALL_LDFLAGS += $(LDFLAGS) $(EXTRA_LDFLAGS)
diff --git a/package/network/utils/bpftools/patches/002-includes.patch b/package/network/utils/bpftools/patches/002-includes.patch
deleted file mode 100644 (file)
index ac1b5fc..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
---- 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 <linux/types.h>
-+
- #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$(or $(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