Skip to contentSkip to conversation

selftests/bpf: enforce no-ALU32 for test_progs-no_alu32

PATCH Applied Andrii Nakryiko 3 participants 3 messages Nov 20, 2019

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/bpf: enforce no-ALU32 for test_progs-no_alu32

With the most recent Clang, alu32 is enabled by default if -mcpu=probe or -mcpu=v3 is specified. Use a separate build rule with -mcpu=v2 to enforce no ALU32 mode.

---
 tools/testing/selftests/bpf/Makefile | 7 +++++++
 1 file changed, 7 insertions(+)
tools/testing/selftests/bpf/Makefile +7 -0
index d4400fbe6634..4fe4aec0367c 100644
@@ -163,6 +163,12 @@ define CLANG_BPF_BUILD_RULE
 		-c $1 -o - || echo "BPF obj compilation failed") | 	\
 	$(LLC) -march=bpf -mcpu=probe $4 -filetype=obj -o $2
 endef
+# Similar to CLANG_BPF_BUILD_RULE, but with disabled alu32
+define CLANG_NOALU32_BPF_BUILD_RULE
+	($(CLANG) $3 -O2 -target bpf -emit-llvm				\
+		-c $1 -o - || echo "BPF obj compilation failed") | 	\
+	$(LLC) -march=bpf -mcpu=v2 $4 -filetype=obj -o $2
+endef
 # Similar to CLANG_BPF_BUILD_RULE, but using native Clang and bpf LLC
 define CLANG_NATIVE_BPF_BUILD_RULE
 	($(CLANG) $3 -O2 -emit-llvm					\
@@ -275,6 +281,7 @@ TRUNNER_BPF_LDFLAGS := -mattr=+alu32
 $(eval $(call DEFINE_TEST_RUNNER,test_progs))
 
 # Define test_progs-no_alu32 test runner.
+TRUNNER_BPF_BUILD_RULE := CLANG_NOALU32_BPF_BUILD_RULE
 TRUNNER_BPF_LDFLAGS :=
 $(eval $(call DEFINE_TEST_RUNNER,test_progs,no_alu32))
 
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw
Quoted 2 lines · Andrii Nakryiko

With the most recent Clang, alu32 is enabled by default if -mcpu=probe or -mcpu=v3 is specified. Use a separate build rule with -mcpu=v2 to enforce no

A little bit clarification -mcpu=probe may not enable alu32 for old kernels. alu32 enabled with -mcpu=probe only if kernel supports jmp32, which is merged in January this year.

Quoted 4 lines

ALU32 mode.

With the above nit,

#2 lore raw
Quoted 11 lines · Yonghong Song
Quoted 2 lines · Andrii Nakryiko

With the most recent Clang, alu32 is enabled by default if -mcpu=probe or -mcpu=v3 is specified. Use a separate build rule with -mcpu=v2 to enforce no

A little bit clarification -mcpu=probe may not enable alu32 for old kernels. alu32 enabled with -mcpu=probe only if kernel supports jmp32, which is merged in January this year.

Quoted 7 lines
Quoted 4 lines

ALU32 mode.

With the above nit,

Applied. Thanks for the fix.