diff mbox series

[23.05] xdp-tools: build with target toolchain headers

Message ID 20241005195523.85314-2-git@oliver-kaestner.de
State New
Headers show
Series [23.05] xdp-tools: build with target toolchain headers | expand

Commit Message

Oliver Kästner Oct. 5, 2024, 7:55 p.m. UTC
Fix build to lookup headers from the target toolchain instead of the
host's. This removes the need for workarounds to make asm/types.h
available in the host os, e.g. by installing gcc-multilib.
For this, include two cherry-picked commits from upstream.

Add a workaround required for the gcc 12.3.0 toolchain to prevent a
macro redefinition error of `offsetof`.
Also fix building for MIPSEL by defining `__MIPSEL__` like Debian
does.

Closes: https://github.com/openwrt/openwrt/issues/12239
Signed-off-by: Oliver Kästner <git@oliver-kaestner.de>
---
 package/network/utils/xdp-tools/Makefile      |  3 +
 .../011-libxdp-bpf-cflags-arch-includes.patch | 24 ++++++++
 .../012-configure-fix-arch-includes.patch     | 56 +++++++++++++++++++
 ...030-xdp-filter-offsetof-redefinition.patch | 23 ++++++++
 4 files changed, 106 insertions(+)
 create mode 100644 package/network/utils/xdp-tools/patches/011-libxdp-bpf-cflags-arch-includes.patch
 create mode 100644 package/network/utils/xdp-tools/patches/012-configure-fix-arch-includes.patch
 create mode 100644 package/network/utils/xdp-tools/patches/030-xdp-filter-offsetof-redefinition.patch
diff mbox series

Patch

diff --git a/package/network/utils/xdp-tools/Makefile b/package/network/utils/xdp-tools/Makefile
index 3cc7980cf6..9f9a20b10b 100644
--- a/package/network/utils/xdp-tools/Makefile
+++ b/package/network/utils/xdp-tools/Makefile
@@ -95,6 +95,9 @@  MAKE_VARS += \
 define Build/Configure
 	$(call Build/Configure/Default)
 	echo "BPF_CFLAGS += -I$(BPF_HEADERS_DIR)/tools/lib" >> $(PKG_BUILD_DIR)/config.mk
+ifeq ($(ARCH),mipsel)
+	echo "BPF_CFLAGS += -D__MIPSEL__" >> $(PKG_BUILD_DIR)/config.mk
+endif
 endef
 
 define Build/InstallDev
diff --git a/package/network/utils/xdp-tools/patches/011-libxdp-bpf-cflags-arch-includes.patch b/package/network/utils/xdp-tools/patches/011-libxdp-bpf-cflags-arch-includes.patch
new file mode 100644
index 0000000000..234bd0a414
--- /dev/null
+++ b/package/network/utils/xdp-tools/patches/011-libxdp-bpf-cflags-arch-includes.patch
@@ -0,0 +1,24 @@ 
+From 11356006dff4f902de0a493455ec94461bdd8dbc Mon Sep 17 00:00:00 2001
+From: ami-GS <1991.daiki@gmail.com>
+Date: Fri, 22 Mar 2024 16:58:42 -0700
+Subject: [PATCH] Fix include path of libxdp for each arch
+
+Signed-off-by: ami-GS <1991.daiki@gmail.com>
+---
+ lib/libxdp/Makefile | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/lib/libxdp/Makefile b/lib/libxdp/Makefile
+index cf0afa49..403d5a6e 100644
+--- a/lib/libxdp/Makefile
++++ b/lib/libxdp/Makefile
+@@ -28,7 +28,7 @@ PC_FILE := $(OBJDIR)/libxdp.pc
+ TEMPLATED_SOURCES := xdp-dispatcher.c
+ 
+ CFLAGS += -I$(HEADER_DIR)
+-BPF_CFLAGS += -I$(HEADER_DIR)
++BPF_CFLAGS += -I$(HEADER_DIR) $(ARCH_INCLUDES)
+ 
+ 
+ ifndef BUILD_STATIC_ONLY
+
diff --git a/package/network/utils/xdp-tools/patches/012-configure-fix-arch-includes.patch b/package/network/utils/xdp-tools/patches/012-configure-fix-arch-includes.patch
new file mode 100644
index 0000000000..61b2d2066a
--- /dev/null
+++ b/package/network/utils/xdp-tools/patches/012-configure-fix-arch-includes.patch
@@ -0,0 +1,56 @@ 
+From 6ce30637951949212344f1968c3fd5e5adf1ffc3 Mon Sep 17 00:00:00 2001
+From: Sachin Tiptur <coolsachints@gmail.com>
+Date: Wed, 13 Sep 2023 12:47:31 +0000
+Subject: [PATCH] Fix build on arm64
+
+Fix the arm64 build by adding arch specific header files to
+CFLAGS and BPF_CFLAGS. Also, use `gcc -print-multiarch` to get
+arch name instead of `uname -m` which is not the right way.
+
+Signed-off-by: Sachin Tiptur <coolsachints@gmail.com>
+---
+ configure      | 7 +++++--
+ lib/defines.mk | 4 ++--
+ 2 files changed, 7 insertions(+), 4 deletions(-)
+
+--- a/configure
++++ b/configure
+@@ -65,6 +65,7 @@ check_toolchain()
+     : ${M4=m4}
+     : ${EMACS=emacs}
+     : ${ARCH_INCLUDES=}
++    : ${ARCH_NAME=}
+ 
+     CLANG=$(find_tool clang "$CLANG")
+     LLC=$(find_tool llc "$LLC")
+@@ -76,6 +77,8 @@ check_toolchain()
+         fi;
+     done
+ 
++    ARCH_NAME=$($CC -print-multiarch 2>/dev/null)
++
+     clang_version=$($CLANG --version | grep -Po '(?<=clang version )[[:digit:]]+')
+     if [ "$?" -ne "0" ]; then
+         echo "*** ERROR: Couldn't execute '$CLANG --version'"
+@@ -109,7 +112,7 @@ check_toolchain()
+     if [ -z "$ARCH_INCLUDES" ]; then
+         for dir in $(echo | $CC -Wp,-v -E - 2>&1 | grep '^ '); do
+             local idir
+-            idir="${dir}/$(uname -m)-linux-gnu/"
++            idir="${dir}/${ARCH_NAME}/"
+             [ -d "$idir" ] && ARCH_INCLUDES="-I${idir} $ARCH_INCLUDES"
+         done
+     fi
+--- a/lib/defines.mk
++++ b/lib/defines.mk
+@@ -40,8 +40,8 @@ endif
+ 
+ DEFINES += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
+ 
+-CFLAGS += -std=gnu11 -Wextra -Werror $(DEFINES)
+-BPF_CFLAGS += $(DEFINES) $(filter -ffile-prefix-map=%,$(CFLAGS))
++CFLAGS += -std=gnu11 -Wextra -Werror $(DEFINES) $(ARCH_INCLUDES)
++BPF_CFLAGS += $(DEFINES) $(filter -ffile-prefix-map=%,$(CFLAGS)) $(ARCH_INCLUDES)
+ 
+ CONFIGMK := $(LIB_DIR)/../config.mk
+ LIBMK := Makefile $(CONFIGMK) $(LIB_DIR)/defines.mk $(LIB_DIR)/common.mk $(LIB_DIR)/../version.mk
diff --git a/package/network/utils/xdp-tools/patches/030-xdp-filter-offsetof-redefinition.patch b/package/network/utils/xdp-tools/patches/030-xdp-filter-offsetof-redefinition.patch
new file mode 100644
index 0000000000..4546c1538c
--- /dev/null
+++ b/package/network/utils/xdp-tools/patches/030-xdp-filter-offsetof-redefinition.patch
@@ -0,0 +1,23 @@ 
+From 70422c175abc240b0050f39fe57fab5277d3612a Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Oliver=20K=C3=A4stner?= <git@oliver-kaestner.de>
+Date: Sun, 29 Sep 2024 21:02:03 +0200
+Subject: [PATCH] xdp-filter: fix offsetof redefinition error with gcc 12.3.0
+
+This is fixed in gcc 13.2.0
+---
+ xdp-filter/xdpfilt_prog.h | 4 ++++
+ 1 file changed, 4 insertions(+)
+
+--- a/xdp-filter/xdpfilt_prog.h
++++ b/xdp-filter/xdpfilt_prog.h
+@@ -18,6 +18,10 @@
+ 
+ /* Defines xdp_stats_map */
+ #include "xdp/xdp_stats_kern.h"
++/* offsetof is already defined in bpf/bpf_helpers.h,
++ * and including stddef.h of gcc 12.3.0 would fail.
++ */
++#undef offsetof
+ #include "xdp/parsing_helpers.h"
+ 
+ #ifdef FILT_MODE_DENY