[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240827133959.1269178-3-yikai.lin@vivo.com>
Date: Tue, 27 Aug 2024 21:39:59 +0800
From: Lin Yikai <yikai.lin@...o.com>
To: Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>,
Martin KaFai Lau <martin.lau@...ux.dev>,
Eduard Zingerman <eddyz87@...il.com>,
Song Liu <song@...nel.org>,
Yonghong Song <yonghong.song@...ux.dev>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>,
Stanislav Fomichev <sdf@...ichev.me>,
Hao Luo <haoluo@...gle.com>,
Jiri Olsa <jolsa@...nel.org>,
Mykola Lysenko <mykolal@...com>,
Shuah Khan <shuah@...nel.org>,
Nick Terrell <terrelln@...com>,
bpf@...r.kernel.org,
linux-kselftest@...r.kernel.org,
linux-kernel@...r.kernel.org
Cc: opensource.kernel@...o.com,
yikai.lin@...o.com
Subject: [PATCH bpf-next v1 2/2] selftests/bpf: Fix cross-compile issue for some files and a static compile issue for "-lzstd"
1. Fix cross-compile issue for some files:
[Issue]
When cross-compiling bpf selftests for arm64 on x86_64 host, the following error occurs:
progs/loop2.c:20:7: error: incomplete definition of type 'struct user_pt_regs'
20 | if (PT_REGS_RC(ctx) & 1)
| ^~~~~~~~~~~~~~~
There are same error in files: loop1.c, loop2.c, loop3.c, loop6.c ???
[Reason]
On arm64, in file bpf_tracing.h, we use userspace's user_pt_regs,
which is defined in "linux/ptrace.h".
We include the header file by adding "-idirafter /usr/include" for "CLANG_CFLAGS".
However, during cross-compiling, "linux/ptrace.h" is based on x86_64
and has no definition of "struct user_pt_regs".
[Fix]
Thus, to fix this issue, we include the Linux source tree's header file directory.
2. Fix static compile issue for "-lzstd":
[Issue]
By running the command "LDLIBS=-static LDFLAGS=--sysroot=/aarch64-linux-gnu/libc ./vmtest.sh -s -- ./test_progs",
during static cross-compiling, an error occurs:
/aarch64-linux-gnu/bin/ld: aarch64-linux-gnu/libc/usr/lib/libelf.a(elf_compress.o): in function `__libelf_compress':
(.text+0xec): undefined reference to `ZSTD_createCCtx'
/aarch64-linux-gnu/bin/ld: (.text+0xf0): undefined reference to `ZSTD_createCCtx'
...
[Fix]
For static compile, add "LDLIBS += -lzstd".
Signed-off-by: Lin Yikai <yikai.lin@...o.com>
---
tools/testing/selftests/bpf/Makefile | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index ec7d425c4022..5b725bc890d2 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -48,6 +48,10 @@ CFLAGS += -g $(OPT_FLAGS) -rdynamic \
LDFLAGS += $(SAN_LDFLAGS)
LDLIBS += $(LIBELF_LIBS) -lz -lrt -lpthread
+ifneq (,$(findstring -static,$(LDLIBS)))
+LDLIBS += -lzstd
+endif
+
LDLIBS += $(shell $(PKG_CONFIG) --libs libpcap 2>/dev/null)
CFLAGS += $(shell $(PKG_CONFIG) --cflags libpcap 2>/dev/null)
CFLAGS += $(shell $(PKG_CONFIG) --exists libpcap 2>/dev/null && echo "-DTRAFFIC_MONITOR=1")
@@ -443,13 +447,19 @@ CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%))
endif
CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH))
+CLANG_CFLAGS = $(CLANG_SYS_INCLUDES)
+
BPF_CFLAGS = -g -Wall -Werror -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \
-I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) \
-I$(abspath $(OUTPUT)/../usr/include) \
-Wno-compare-distinct-pointer-types
# TODO: enable me -Wsign-compare
-CLANG_CFLAGS = $(CLANG_SYS_INCLUDES)
+#"make headers_install" at first
+ifneq ($(CROSS_COMPILE),)
+src_uapi_dir := $(srctree)/usr/include
+BPF_CFLAGS += -I$(src_uapi_dir)
+endif
$(OUTPUT)/test_l4lb_noinline.o: BPF_CFLAGS += -fno-inline
$(OUTPUT)/test_xdp_noinline.o: BPF_CFLAGS += -fno-inline
--
2.34.1
Powered by blists - more mailing lists