Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Pass target triple to get_sys_includes macro

When cross-compiling [1], the get_sys_includes make macro should use
the target system include path, and not the build hosts system include
path.

Make clang honor the CROSS_COMPILE triple.

[1] e.g. "ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- make"

Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Tested-by: Anders Roxell <anders.roxell@linaro.org>
Link: https://lore.kernel.org/bpf/20221115182051.582962-2-bjorn@kernel.org

authored by

Björn Töpel and committed by
Andrii Nakryiko
98b2afc8 c4525f05

+8 -4
+8 -4
tools/testing/selftests/bpf/Makefile
··· 310 310 # Use '-idirafter': Don't interfere with include mechanics except where the 311 311 # build would have failed anyways. 312 312 define get_sys_includes 313 - $(shell $(1) -v -E - </dev/null 2>&1 \ 313 + $(shell $(1) $(2) -v -E - </dev/null 2>&1 \ 314 314 | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \ 315 - $(shell $(1) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}') 315 + $(shell $(1) $(2) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}') 316 316 endef 317 317 318 318 # Determine target endianness. ··· 320 320 grep 'define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__') 321 321 MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian) 322 322 323 - CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG)) 323 + ifneq ($(CROSS_COMPILE),) 324 + CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%)) 325 + endif 326 + 327 + CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH)) 324 328 BPF_CFLAGS = -g -Werror -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \ 325 329 -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) \ 326 330 -I$(abspath $(OUTPUT)/../usr/include) ··· 546 542 # Define test_progs BPF-GCC-flavored test runner. 547 543 ifneq ($(BPF_GCC),) 548 544 TRUNNER_BPF_BUILD_RULE := GCC_BPF_BUILD_RULE 549 - TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(call get_sys_includes,gcc) 545 + TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(call get_sys_includes,gcc,) 550 546 $(eval $(call DEFINE_TEST_RUNNER,test_progs,bpf_gcc)) 551 547 endif 552 548