Skip to contentSkip to conversation

selftest/bpf: Use -m{little,big}-endian for clang

PATCH Superseded Ilya Leoshkevich 2 participants 2 messages Oct 24, 2019 – Oct 25, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftest/bpf: Use -m{little,big}-endian for clang

When cross-compiling tests from x86 to s390, the resulting BPF objects fail to load due to endianness mismatch.

Fix by using BPF-GCC endianness check for clang as well.

---
 tools/testing/selftests/bpf/Makefile | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
tools/testing/selftests/bpf/Makefile +8 -6
index 11ff34e7311b..59b93a5667c8 100644
@@ -131,10 +131,16 @@ $(shell $(1) -v -E - </dev/null 2>&1 \
 	| sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }')
 endef
 
+# Determine target endianness.
+IS_LITTLE_ENDIAN = $(shell $(CC) -dM -E - </dev/null | \
+			grep 'define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__')
+MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian)
+
 CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG))
 BPF_CFLAGS = -g -D__TARGET_ARCH_$(SRCARCH) 				\
 	     -I. -I./include/uapi -I$(APIDIR)				\
-	     -I$(BPFDIR) -I$(abspath $(OUTPUT)/../usr/include)
+	     -I$(BPFDIR) -I$(abspath $(OUTPUT)/../usr/include)		\
+	     $(MENDIAN)
 
 CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) \
 	       -Wno-compare-distinct-pointer-types
@@ -271,12 +277,8 @@ $(eval $(call DEFINE_TEST_RUNNER,test_progs,no_alu32))
 
 # Define test_progs BPF-GCC-flavored test runner.
 ifneq ($(BPF_GCC),)
-IS_LITTLE_ENDIAN = $(shell $(CC) -dM -E - </dev/null | \
-			grep 'define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__')
-MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian)
-
 TRUNNER_BPF_BUILD_RULE := GCC_BPF_BUILD_RULE
-TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(call get_sys_includes,gcc) $(MENDIAN)
+TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(call get_sys_includes,gcc)
 TRUNNER_BPF_LDFLAGS :=
 $(eval $(call DEFINE_TEST_RUNNER,test_progs,bpf_gcc))
 endif
Signature · 1 line
2.23.0
Acked-by on v1 1/1
#1 lore raw
Quoted 20 lines · Ilya Leoshkevich

When cross-compiling tests from x86 to s390, the resulting BPF objects fail to load due to endianness mismatch.

Fix by using BPF-GCC endianness check for clang as well.

---
 tools/testing/selftests/bpf/Makefile | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
tools/testing/selftests/bpf/Makefile +1 -0
index 11ff34e7311b..59b93a5667c8 100644
@@ -131,10 +131,16 @@ $(shell $(1) -v -E - </dev/null 2>&1 \
        | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }')
 endef
 
+# Determine target endianness.

tools/testing/selftests/bpf/Makefile $(shell $(1) -v -E - </dev/null 2>&1 \ · line 143

Quoted 10 lines
tools/testing/selftests/bpf/Makefile +6 -1
+IS_LITTLE_ENDIAN = $(shell $(CC) -dM -E - </dev/null | \
+                       grep 'define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__')
+MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian)
+
 CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG))
 BPF_CFLAGS = -g -D__TARGET_ARCH_$(SRCARCH)                             \
             -I. -I./include/uapi -I$(APIDIR)                           \
-            -I$(BPFDIR) -I$(abspath $(OUTPUT)/../usr/include)
+            -I$(BPFDIR) -I$(abspath $(OUTPUT)/../usr/include)          \
+            $(MENDIAN)

minor nit: I'd put $(MENDIAN) next to -g and -D__TARGET_ARCH stuff and keep a list of -Is at the end.

But besides that:

Quoted 20 lines
tools/testing/selftests/bpf/Makefile +1 -6
 CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) \
               -Wno-compare-distinct-pointer-types
@@ -271,12 +277,8 @@ $(eval $(call DEFINE_TEST_RUNNER,test_progs,no_alu32))
 
 # Define test_progs BPF-GCC-flavored test runner.
 ifneq ($(BPF_GCC),)
-IS_LITTLE_ENDIAN = $(shell $(CC) -dM -E - </dev/null | \
-                       grep 'define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__')
-MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian)
-
 TRUNNER_BPF_BUILD_RULE := GCC_BPF_BUILD_RULE
-TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(call get_sys_includes,gcc) $(MENDIAN)
+TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(call get_sys_includes,gcc)
 TRUNNER_BPF_LDFLAGS :=
 $(eval $(call DEFINE_TEST_RUNNER,test_progs,bpf_gcc))
 endif
--

2.23.0