selftests/bpf: Fix cross compiling error when using userspace pt_regs
Subsystems (5)
PATCH v2 1/1 selftests/bpf: Fix cross compiling error when using userspace pt_regs
When cross compiling arm64 bpf selftests in x86_64 host, the following error occur:
progs/loop2.c:20:7: error: incomplete definition of type 'struct user_pt_regs'
Some archs, like arm64 and riscv, use userspace pt_regs in bpf_tracing.h. When arm64 bpf selftests cross compiling in x86_64 host, clang cannot find the arch specific uapi ptrace.h. We can add arch specific header file directory to fix this issue.
---v1->v2:
- use vmlinux.h directly might lead to verifier fail.
- use source arch header file directory suggested by Andrii Nakryiko.
tools/testing/selftests/bpf/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/Makefile +3 -1
@@ -12,6 +12,7 @@ BPFDIR := $(LIBDIR)/bpf TOOLSINCDIR := $(TOOLSDIR)/include BPFTOOLDIR := $(TOOLSDIR)/bpf/bpftool APIDIR := $(TOOLSINCDIR)/uapi +ARCH_APIDIR := $(abspath ../../../../arch/$(SRCARCH)/include/uapi) GENDIR := $(abspath ../../../../include/generated) GENHDR := $(GENDIR)/autoconf.h
@@ -294,7 +295,8 @@ MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian) CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG)) BPF_CFLAGS = -g -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \ -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) \ - -I$(abspath $(OUTPUT)/../usr/include) + -I$(abspath $(OUTPUT)/../usr/include) \ + -I$(ARCH_APIDIR) CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) \ -Wno-compare-distinct-pointer-types
Signature · 1 line
2.25.1
Quoted 34 lines · Pu Lehui
When cross compiling arm64 bpf selftests in
x86_64host, the following error occur:
progs/loop2.c:20:7: error: incomplete definition of type 'structuser_pt_regs'Some archs, like arm64 and riscv, use userspace
pt_regsinbpf_tracing.h. When arm64 bpf selftests cross compiling inx86_64host, clang cannot find the arch specific uapiptrace.h. We can add arch specific header file directory to fix this issue.Signed-off-by Pu Lehui <[email protected]>---
v1->v2:
- usevmlinux.hdirectly might lead to verifier fail.
- use source arch header file directory suggested by Andrii Nakryiko.tools/testing/selftests/bpf/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)tools/testing/selftests/bpf/Makefile +1
-0@@ -12,6 +12,7 @@ BPFDIR := $(LIBDIR)/bpf TOOLSINCDIR := $(TOOLSDIR)/include BPFTOOLDIR := $(TOOLSDIR)/bpf/bpftool APIDIR := $(TOOLSINCDIR)/uapi +ARCH_APIDIR := $(abspath ../../../../arch/$(SRCARCH)/include/uapi) GENDIR := $(abspath ../../../../include/generated) GENHDR := $(GENDIR)/autoconf.h
tools/testing/selftests/bpf/Makefile MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian) · line 300
Quoted 7 lines
tools/testing/selftests/bpf/Makefile +2
-1@@ -294,7 +295,8 @@ MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian) CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG)) BPF_CFLAGS = -g -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \ -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) \ - -I$(abspath $(OUTPUT)/../usr/include) + -I$(abspath $(OUTPUT)/../usr/include) \ + -I$(ARCH_APIDIR)
This causes compilation error, see [0]. I think we'll have to wait for my patch ([1]) to land and then add kernel-side variants for accessing pt_regs.
[0] https://github.com/kernel-patches/bpf/runs/4614606900?check_suite_focus=true
[1] https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
Quoted 5 lines
tools/testing/selftests/bpf/Makefile +0
-1CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) \ -Wno-compare-distinct-pointer-types --2.25.1
Quoted 47 lines · Andrii Nakryiko
Quoted 34 lines · Pu Lehui
When cross compiling arm64 bpf selftests in
x86_64host, the following error occur:
progs/loop2.c:20:7: error: incomplete definition of type 'structuser_pt_regs'Some archs, like arm64 and riscv, use userspace
pt_regsinbpf_tracing.h. When arm64 bpf selftests cross compiling inx86_64host, clang cannot find the arch specific uapiptrace.h. We can add arch specific header file directory to fix this issue.Signed-off-by Pu Lehui <[email protected]>---
v1->v2:
- usevmlinux.hdirectly might lead to verifier fail.
- use source arch header file directory suggested by Andrii Nakryiko.tools/testing/selftests/bpf/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)tools/testing/selftests/bpf/Makefile +1
-0@@ -12,6 +12,7 @@ BPFDIR := $(LIBDIR)/bpf TOOLSINCDIR := $(TOOLSDIR)/include BPFTOOLDIR := $(TOOLSDIR)/bpf/bpftool APIDIR := $(TOOLSINCDIR)/uapi +ARCH_APIDIR := $(abspath ../../../../arch/$(SRCARCH)/include/uapi) GENDIR := $(abspath ../../../../include/generated) GENHDR := $(GENDIR)/autoconf.htools/testing/selftests/bpf/Makefile MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian) · line 300
Quoted 7 lines
tools/testing/selftests/bpf/Makefile +2
-1@@ -294,7 +295,8 @@ MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian) CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG)) BPF_CFLAGS = -g -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \ -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) \ - -I$(abspath $(OUTPUT)/../usr/include) + -I$(abspath $(OUTPUT)/../usr/include) \ + -I$(ARCH_APIDIR)This causes compilation error, see [0]. I think we'll have to wait for my patch ([1]) to land and then add kernel-side variants for accessing
pt_regs.
Quoted 4 lines
[0] https://github.com/kernel-patches/bpf/runs/4614606900?check_suite_focus=true [1] https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
OK, I'll keep follow it.
Quoted 7 lines
Quoted 5 lines
tools/testing/selftests/bpf/Makefile +0
-1CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) \ -Wno-compare-distinct-pointer-types --2.25.1
.