mirror of
https://github.com/openwrt/openwrt.git
synced 2024-12-21 14:37:57 +00:00
xdp-tools: fix compilation wrongly using host header
Currently it's needed to have gcc-multilib on the host to correctly compile xdp-tools. This is wrong and means that we are using host header to compile a tool. By some searching in how the makefile works it was discovered that BPF_CFLAGS were not used and required to be appended to config.mk Only one single header was added but we should include each BPF_CFLAGS from bpf.mk. To make this some patching to bpf-header were required and some patches to xdp-tools were required. Also it's needed to pass the correct target to BPF_CFLAGS. With the following changes xdp-tools can correctly compile with each header from bpf-headers and should not use any host header. Co-Developed-by: Andre Heider <a.heider@gmail.com> Signed-off-by: Andre Heider <a.heider@gmail.com> Link: https://github.com/openwrt/openwrt/pull/11825 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
This commit is contained in:
parent
dfcc0ff5d2
commit
5acc4f919c
@ -85,8 +85,13 @@ CONFIGURE_VARS += \
|
||||
CFLAGS="$(TARGET_CFLAGS)" \
|
||||
LDFLAGS="$(TARGET_LDFLAGS)" \
|
||||
CLANG="$(CLANG)" \
|
||||
BPF_TARGET="$(BPF_TARGET)" \
|
||||
LLC="$(LLVM_LLC)"
|
||||
BPF_TARGET="$(BPF_ARCH)-linux-gnu" \
|
||||
LLC="$(LLVM_LLC)" \
|
||||
BPF_LDFLAGS="-march=$(BPF_TARGET) -mcpu=v3"
|
||||
|
||||
ifneq ($(findstring c,$(OPENWRT_VERBOSE)),)
|
||||
MAKE_FLAGS+=V=1
|
||||
endif
|
||||
|
||||
MAKE_VARS += \
|
||||
PREFIX=/usr \
|
||||
@ -94,7 +99,7 @@ MAKE_VARS += \
|
||||
|
||||
define Build/Configure
|
||||
$(call Build/Configure/Default)
|
||||
echo "BPF_CFLAGS += -I$(BPF_HEADERS_DIR)/tools/lib -fno-stack-protector" >> $(PKG_BUILD_DIR)/config.mk
|
||||
echo "BPF_CFLAGS += $(BPF_CFLAGS) -Wno-error -fno-stack-protector" >> $(PKG_BUILD_DIR)/config.mk
|
||||
endef
|
||||
|
||||
define Build/InstallDev
|
||||
|
@ -1,6 +1,6 @@
|
||||
--- a/configure
|
||||
+++ b/configure
|
||||
@@ -174,7 +174,7 @@ int main(int argc, char **argv) {
|
||||
@@ -176,7 +176,7 @@ int main(int argc, char **argv) {
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
@ -9,7 +9,7 @@
|
||||
if [ "$?" -eq "0" ]; then
|
||||
echo "HAVE_PCAP:=y" >>$CONFIG
|
||||
[ -n "$LIBPCAP_CFLAGS" ] && echo 'CFLAGS += ' $LIBPCAP_CFLAGS >> $CONFIG
|
||||
@@ -222,7 +222,7 @@ int main(int argc, char **argv) {
|
||||
@@ -224,7 +224,7 @@ int main(int argc, char **argv) {
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
@ -18,7 +18,7 @@
|
||||
if [ "$?" -eq "0" ]; then
|
||||
echo "HAVE_FEATURES+=${config_var}" >>"$CONFIG"
|
||||
echo "yes"
|
||||
@@ -289,7 +289,7 @@ int main(int argc, char **argv) {
|
||||
@@ -291,7 +291,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
EOF
|
||||
|
||||
|
@ -0,0 +1,49 @@
|
||||
From 1f160c287c14b4300c4248752e20da5981c9763e Mon Sep 17 00:00:00 2001
|
||||
From: Christian Marangi <ansuelsmth@gmail.com>
|
||||
Date: Wed, 18 Jan 2023 19:00:54 +0100
|
||||
Subject: [PATCH] libxdp: Use __noinline__ reserved attribute for XDP
|
||||
dispatcher
|
||||
|
||||
The use of noinline is wrong as noline is not a reserved attribute and
|
||||
with gcc12 this became an error. Use the reserved __noinline__ attribute
|
||||
to fix compilation error.
|
||||
|
||||
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
|
||||
[a.heider: adapt lib/libxdp/protocol.org too]
|
||||
Signed-off-by: Andre Heider <a.heider@gmail.com>
|
||||
---
|
||||
lib/libxdp/protocol.org | 2 +-
|
||||
lib/libxdp/xdp-dispatcher.c.in | 4 ++--
|
||||
2 files changed, 3 insertions(+), 3 deletions(-)
|
||||
|
||||
--- a/lib/libxdp/protocol.org
|
||||
+++ b/lib/libxdp/protocol.org
|
||||
@@ -54,7 +54,7 @@ static volatile const struct xdp_dispatc
|
||||
/* The volatile return value prevents the compiler from assuming it knows the
|
||||
* return value and optimising based on that.
|
||||
*/
|
||||
-__attribute__ ((noinline))
|
||||
+__attribute__ ((__noinline__))
|
||||
int prog0(struct xdp_md *ctx) {
|
||||
volatile int ret = XDP_DISPATCHER_RETVAL;
|
||||
|
||||
--- a/lib/libxdp/xdp-dispatcher.c.in
|
||||
+++ b/lib/libxdp/xdp-dispatcher.c.in
|
||||
@@ -30,7 +30,7 @@ static volatile const struct xdp_dispatc
|
||||
* return value and optimising based on that.
|
||||
*/
|
||||
forloop(`i', `0', NUM_PROGS,
|
||||
-`__attribute__ ((noinline))
|
||||
+`__attribute__ ((__noinline__))
|
||||
int format(`prog%d', i)(struct xdp_md *ctx) {
|
||||
volatile int ret = XDP_DISPATCHER_RETVAL;
|
||||
|
||||
@@ -40,7 +40,7 @@ int format(`prog%d', i)(struct xdp_md *c
|
||||
}
|
||||
')
|
||||
|
||||
-__attribute__ ((noinline))
|
||||
+__attribute__ ((__noinline__))
|
||||
int compat_test(struct xdp_md *ctx) {
|
||||
volatile int ret = XDP_DISPATCHER_RETVAL;
|
||||
|
@ -0,0 +1,31 @@
|
||||
From bc2a11227b5bed29d33926d5ff7e707228db9e87 Mon Sep 17 00:00:00 2001
|
||||
From: Christian Marangi <ansuelsmth@gmail.com>
|
||||
Date: Wed, 18 Jan 2023 20:07:58 +0100
|
||||
Subject: [PATCH] headers: xdp: drop vlan_hdr as already defined
|
||||
|
||||
Drop vlan_hdr as already defined by bpf headers.
|
||||
|
||||
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
|
||||
---
|
||||
headers/xdp/parsing_helpers.h | 10 ----------
|
||||
1 file changed, 10 deletions(-)
|
||||
|
||||
--- a/headers/xdp/parsing_helpers.h
|
||||
+++ b/headers/xdp/parsing_helpers.h
|
||||
@@ -33,16 +33,6 @@ struct hdr_cursor {
|
||||
};
|
||||
|
||||
/*
|
||||
- * struct vlan_hdr - vlan header
|
||||
- * @h_vlan_TCI: priority and VLAN ID
|
||||
- * @h_vlan_encapsulated_proto: packet type ID or len
|
||||
- */
|
||||
-struct vlan_hdr {
|
||||
- __be16 h_vlan_TCI;
|
||||
- __be16 h_vlan_encapsulated_proto;
|
||||
-};
|
||||
-
|
||||
-/*
|
||||
* Struct icmphdr_common represents the common part of the icmphdr and icmp6hdr
|
||||
* structures.
|
||||
*/
|
@ -0,0 +1,34 @@
|
||||
From 0388d7447de027e0d2369d6b8a9c58ea0f8f027c Mon Sep 17 00:00:00 2001
|
||||
From: Christian Marangi <ansuelsmth@gmail.com>
|
||||
Date: Wed, 18 Jan 2023 20:37:12 +0100
|
||||
Subject: [PATCH] xdp-dump: add missing perf_event include for bpf and xdp
|
||||
|
||||
Add missing perf_event include needed for struct perf_event_header for
|
||||
bpf and xdp.
|
||||
|
||||
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
|
||||
---
|
||||
xdp-dump/xdpdump_bpf.c | 1 +
|
||||
xdp-dump/xdpdump_xdp.c | 1 +
|
||||
2 files changed, 2 insertions(+)
|
||||
|
||||
--- a/xdp-dump/xdpdump_bpf.c
|
||||
+++ b/xdp-dump/xdpdump_bpf.c
|
||||
@@ -4,6 +4,7 @@
|
||||
* Include files
|
||||
*****************************************************************************/
|
||||
#include <stdbool.h>
|
||||
+#include <linux/perf_event.h>
|
||||
#include <linux/bpf.h>
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include <bpf/bpf_trace_helpers.h>
|
||||
--- a/xdp-dump/xdpdump_xdp.c
|
||||
+++ b/xdp-dump/xdpdump_xdp.c
|
||||
@@ -4,6 +4,7 @@
|
||||
* Include files
|
||||
*****************************************************************************/
|
||||
#include <stdbool.h>
|
||||
+#include <linux/perf_event.h>
|
||||
#include <linux/bpf.h>
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include <bpf/bpf_trace_helpers.h>
|
@ -0,0 +1,30 @@
|
||||
From cb1ef3322671a67e2050a3eee18b49cdb4ed4bed Mon Sep 17 00:00:00 2001
|
||||
From: Andre Heider <a.heider@gmail.com>
|
||||
Date: Wed, 18 Jan 2023 20:54:41 +0100
|
||||
Subject: [PATCH] libxdp: fix compilation on multiarch systems
|
||||
|
||||
Multiarch systems require an additional include path, which is covered
|
||||
by ARCH_INCLUDES here. Just as lib/util, add it to BPF_CFLAGS.
|
||||
|
||||
Fixes compilation on debian:
|
||||
|
||||
In file included from xdp-dispatcher.c:3:
|
||||
In file included from ../../headers/linux/bpf.h:11:
|
||||
/usr/include/linux/types.h:5:10: fatal error: 'asm/types.h' file not found
|
||||
|
||||
Signed-off-by: Andre Heider <a.heider@gmail.com>
|
||||
---
|
||||
lib/libxdp/Makefile | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
--- a/lib/libxdp/Makefile
|
||||
+++ b/lib/libxdp/Makefile
|
||||
@@ -30,7 +30,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
|
@ -0,0 +1,49 @@
|
||||
From e2d8eae9477f6ba41ab75ad77202f235e34c04f7 Mon Sep 17 00:00:00 2001
|
||||
From: Andre Heider <a.heider@gmail.com>
|
||||
Date: Wed, 18 Jan 2023 22:30:23 +0100
|
||||
Subject: [PATCH] lib: allow overwriting -W* flags via BPF_CFLAGS
|
||||
|
||||
The bpf header file situation is a mess, and the default warning
|
||||
compiler flags may not be suitable everywhere, especially with -Werror
|
||||
in the mix.
|
||||
|
||||
Move BPF_CFLAGS further down, so these can be overwritten by builders.
|
||||
|
||||
Signed-off-by: Andre Heider <a.heider@gmail.com>
|
||||
---
|
||||
lib/common.mk | 2 +-
|
||||
lib/libxdp/Makefile | 2 +-
|
||||
2 files changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
--- a/lib/common.mk
|
||||
+++ b/lib/common.mk
|
||||
@@ -108,12 +108,12 @@ $(XDP_OBJ): %.o: %.c $(KERN_USER_H) $(EX
|
||||
$(QUIET_CLANG)$(CLANG) -S \
|
||||
-target $(BPF_TARGET) \
|
||||
-D __BPF_TRACING__ \
|
||||
- $(BPF_CFLAGS) \
|
||||
-Wall \
|
||||
-Wno-unused-value \
|
||||
-Wno-pointer-sign \
|
||||
-Wno-compare-distinct-pointer-types \
|
||||
-Werror \
|
||||
+ $(BPF_CFLAGS) \
|
||||
-O2 -emit-llvm -c -g -o ${@:.o=.ll} $<
|
||||
$(QUIET_LLC)$(LLC) -march=$(BPF_TARGET) -filetype=obj -o $@ ${@:.o=.ll}
|
||||
|
||||
--- a/lib/libxdp/Makefile
|
||||
+++ b/lib/libxdp/Makefile
|
||||
@@ -139,12 +139,12 @@ $(XDP_OBJS): %.o: %.c $(BPF_HEADERS) $(L
|
||||
$(QUIET_CLANG)$(CLANG) -S \
|
||||
-target $(BPF_TARGET) \
|
||||
-D __BPF_TRACING__ \
|
||||
- $(BPF_CFLAGS) \
|
||||
-Wall \
|
||||
-Wno-unused-value \
|
||||
-Wno-pointer-sign \
|
||||
-Wno-compare-distinct-pointer-types \
|
||||
-Werror \
|
||||
+ $(BPF_CFLAGS) \
|
||||
-O2 -emit-llvm -c -g -o ${@:.o=.ll} $<
|
||||
$(QUIET_LLC)$(LLC) -march=$(BPF_TARGET) -filetype=obj -o $@ ${@:.o=.ll}
|
||||
|
@ -0,0 +1,55 @@
|
||||
From 7b00d4a90af1d7bff50833ffe1216cf59592353a Mon Sep 17 00:00:00 2001
|
||||
From: Andre Heider <a.heider@gmail.com>
|
||||
Date: Wed, 18 Jan 2023 22:42:28 +0100
|
||||
Subject: [PATCH] Add BPF_LDFLAGS to allow overwriting llc's -march argument
|
||||
|
||||
The argument to clang's -target isn't necessarily the same as to
|
||||
llc's -march.
|
||||
|
||||
Analogue to BPF_CFLAGS, introduce BPF_LDFLAGS to allow e.g.:
|
||||
BPF_TARGET="mipsel-linux-gnu" BPF_LDFLAGS="-march=bpfel -mcpu=v3"
|
||||
|
||||
Signed-off-by: Andre Heider <a.heider@gmail.com>
|
||||
---
|
||||
configure | 2 ++
|
||||
lib/common.mk | 2 +-
|
||||
lib/libxdp/Makefile | 2 +-
|
||||
3 files changed, 4 insertions(+), 2 deletions(-)
|
||||
|
||||
--- a/configure
|
||||
+++ b/configure
|
||||
@@ -17,10 +17,12 @@ check_opts()
|
||||
: ${DYNAMIC_LIBXDP:=0}
|
||||
: ${MAX_DISPATCHER_ACTIONS:=10}
|
||||
: ${BPF_TARGET:=bpf}
|
||||
+ : ${BPF_LDFLAGS:=-march=$(BPF_TARGET)}
|
||||
echo "PRODUCTION:=${PRODUCTION}" >>$CONFIG
|
||||
echo "DYNAMIC_LIBXDP:=${DYNAMIC_LIBXDP}" >>$CONFIG
|
||||
echo "MAX_DISPATCHER_ACTIONS:=${MAX_DISPATCHER_ACTIONS}" >>$CONFIG
|
||||
echo "BPF_TARGET:=${BPF_TARGET}" >>$CONFIG
|
||||
+ echo "BPF_LDFLAGS:=${BPF_LDFLAGS}" >>$CONFIG
|
||||
}
|
||||
|
||||
find_tool()
|
||||
--- a/lib/common.mk
|
||||
+++ b/lib/common.mk
|
||||
@@ -115,7 +115,7 @@ $(XDP_OBJ): %.o: %.c $(KERN_USER_H) $(EX
|
||||
-Werror \
|
||||
$(BPF_CFLAGS) \
|
||||
-O2 -emit-llvm -c -g -o ${@:.o=.ll} $<
|
||||
- $(QUIET_LLC)$(LLC) -march=$(BPF_TARGET) -filetype=obj -o $@ ${@:.o=.ll}
|
||||
+ $(QUIET_LLC)$(LLC) $(BPF_LDFLAGS) -filetype=obj -o $@ ${@:.o=.ll}
|
||||
|
||||
.PHONY: man
|
||||
ifeq ($(EMACS),)
|
||||
--- a/lib/libxdp/Makefile
|
||||
+++ b/lib/libxdp/Makefile
|
||||
@@ -146,7 +146,7 @@ $(XDP_OBJS): %.o: %.c $(BPF_HEADERS) $(L
|
||||
-Werror \
|
||||
$(BPF_CFLAGS) \
|
||||
-O2 -emit-llvm -c -g -o ${@:.o=.ll} $<
|
||||
- $(QUIET_LLC)$(LLC) -march=$(BPF_TARGET) -filetype=obj -o $@ ${@:.o=.ll}
|
||||
+ $(QUIET_LLC)$(LLC) $(BPF_LDFLAGS) -filetype=obj -o $@ ${@:.o=.ll}
|
||||
|
||||
.PHONY: man
|
||||
ifeq ($(EMACS),)
|
Loading…
Reference in New Issue
Block a user