[PATCH v2] selftests/bpf: fix the compilation errors caused by larchintrin.h

Zhang Xi posted 1 patch 9 months ago
samples/bpf/Makefile | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
[PATCH v2] selftests/bpf: fix the compilation errors caused by larchintrin.h
Posted by Zhang Xi 9 months ago
From: zhangxi <zhangxi@kylinos.cn>

On the LoongArch platform, the header file 'larchintrin.h' is provided by
the package clang-libs, and it is necessary to add CLANG_SYS_INCLUDES to
the compilation command.

make M=samples/bpf, compilation errors:

In file included from sockex2_kern.c:2:
In file included from /root/work/src/github/linux/include/uapi/linux/in.h:25:
In file included from /root/work/src/github/linux/include/linux/socket.h:8:
In file included from /root/work/src/github/linux/include/linux/uio.h:9:
In file included from /root/work/src/github/linux/include/linux/thread_info.h:60:
In file included from /root/work/src/github/linux/arch/loongarch/include/asm/thread_info.h:15:
In file included from /root/work/src/github/linux/arch/loongarch/include/asm/processor.h:13:
In file included from /root/work/src/github/linux/arch/loongarch/include/asm/cpu-info.h:11:
/root/work/src/github/linux/arch/loongarch/include/asm/loongarch.h:13:10: fatal error: 'larchintrin.h' file not found
   13 | #include <larchintrin.h>

Signed-off-by: zhangxi <zhangxi@kylinos.cn>
---
 samples/bpf/Makefile | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index dd9944a97b7e..f459360c99bc 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -337,6 +337,10 @@ endef
 
 CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG))
 
+ifeq ($(ARCH), loongarch)
+CLANG_CFLAGS = $(CLANG_SYS_INCLUDES)
+endif
+
 $(obj)/xdp_router_ipv4.bpf.o: $(obj)/xdp_sample.bpf.o
 
 $(obj)/%.bpf.o: $(src)/%.bpf.c $(obj)/vmlinux.h $(src)/xdp_sample.bpf.h $(src)/xdp_sample_shared.h
@@ -376,7 +380,7 @@ $(obj)/%.o: $(src)/%.c
 	@echo "  CLANG-bpf " $@
 	$(Q)$(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(BPF_EXTRA_CFLAGS) \
 		-I$(obj) -I$(srctree)/tools/testing/selftests/bpf/ \
-		-I$(LIBBPF_INCLUDE) \
+		-I$(LIBBPF_INCLUDE) $(CLANG_CFLAGS)\
 		-D__KERNEL__ -D__BPF_TRACING__ -Wno-unused-value -Wno-pointer-sign \
 		-D__TARGET_ARCH_$(SRCARCH) -Wno-compare-distinct-pointer-types \
 		-Wno-gnu-variable-sized-type-not-at-end \
-- 
2.25.1