Skip to contentSkip to conversation

selftests/bpf: Makefile: add includes to fix broken test build

PATCH Superseded Sirio Balmelli 2 participants 2 messages Apr 30, 2018

Subsystems (5)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 selftests/bpf: Makefile: add includes to fix broken test build

Build fails with missing 'asm/bitsperlong.h'.

Include this from tools/arch/[arch]/include/uapi
using an architecture-specific include sourced from 'Module.symvers' (is this legitimate? another idea was to do a uname -p but what if caller was cross-compiling?)

Once the arch-specific include is fixed, a lack of 'asm/byteorder.h' now rears its ugly head.
The only sane (ie: will not pull in kernel headers) place I can find it is in $(ROOT)/usr/include - add this to the include.

Note that $(ROOT)/usr/include is generated on kernel build, hence my assumption that 'Module.symvers' will also be present.

This highlights a philosophical issue - should these tests build:

1. Against the kernel tree only?
In this case I likely did the right thing here.

2. Against the local machine?
Then the proper handling is to source 'arch' from eg uname -p and include /usr/include/x86_64-linux-gnu/asm/byteorder.h instead of $(ROOT)/usr/include.

---
 tools/testing/selftests/bpf/Makefile | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/Makefile +8 -2
index 9d76218..a19c6af 100644
@@ -84,8 +84,14 @@ else
   CPU ?= generic
 endif
 
-CLANG_FLAGS = -I. -I./include/uapi -I../../../include/uapi \
-	      -Wno-compare-distinct-pointer-types
+# Assume caller has compiled the kernel; get compilation architecture from Module.symvers
+TOOLS :=../../..
+ROOT :=../../../..
+ARCH := $(shell sed -rne 's|.*(arch/[^/]+).*|\1|p' $(ROOT)/Module.symvers | head -n 1)
+CLANG_FLAGS = -I. -I./include/uapi \
+	-I$(TOOLS)/include/uapi -I$(TOOLS)/$(ARCH)/include/uapi \
+	-I$(ROOT)/usr/include \
+	-Wno-compare-distinct-pointer-types
 
 $(OUTPUT)/test_l4lb_noinline.o: CLANG_FLAGS += -fno-inline
 $(OUTPUT)/test_xdp_noinline.o: CLANG_FLAGS += -fno-inline
Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 6 lines · Sirio Balmelli

Build fails with missing 'asm/bitsperlong.h'.

Include this from tools/arch/[arch]/include/uapi
using an architecture-specific include sourced from 'Module.symvers' (is this legitimate? another idea was to do a uname -p but what if caller was cross-compiling?)

To point to an arch specific include, the way this works under tools can be seen e.g. in barrier.h, see tools/include/asm/barrier.h. This will then pull in one of the tools/arch/*/include/asm/barrier.h. We would need to do something similar for tools/arch/*/include/uapi/asm/bitsperlong.h

Then you also don't need the Module.symvers hack to derive the underlying arch. See 720f228e8d31 ("bpf: fix broken BPF selftest build") for another, similar example we had in the past.

Quoted 4 lines

Once the arch-specific include is fixed, a lack of 'asm/byteorder.h' now rears its ugly head.
The only sane (ie: will not pull in kernel headers) place I can find it is in $(ROOT)/usr/include - add this to the include.

Why it doesn't work adding a new file tools/include/uapi/asm/byteorder.h that points to one present in tools/arch/*/include/uapi/asm/bitsperlong.h or tools/include/uapi/asm-generic/bitsperlong.h otherwise?

Quoted 2 lines

Note that $(ROOT)/usr/include is generated on kernel build, hence my assumption that 'Module.symvers' will also be present.

The problem with this approach is that you need to do 'make header_install' in order to resolve this dependency, whereas tools infrastructure has no such dependency. Here's some more background context on the tools infra that perhaps helps why it's done this way:

https://www.spinics.net/lists/netdev/msg487309.html

Please see to add a tools/include/uapi/asm/byteorder.h to fix the issue.

Thanks a lot,
Daniel