Skip to content

Commit a2af0f6

Browse files
captain5050acmel
authored andcommitted
perf build: Add system include paths to BPF builds
There are insufficient headers in tools/include to satisfy building BPF programs and their header dependencies. Add the system include paths from the non-BPF clang compile so that these headers can be found. This code was taken from: tools/testing/selftests/bpf/Makefile Committer notes: Had to adjust the '#ifndef NO_BPF_SKEL' to '#ifdef BUILD_BPF_SKEL' as reverted that build BPF skels by default. Also cope with the addition of -I$(srctree)/tools/include/uapi done by Yang Jihong so that we prefer using the kernel sources headers instead of older ones in the system. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Albert Ou <aou@eecs.berkeley.edu> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com> Cc: Ian Rogers <irogers@google.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Nathan Chancellor <nathan@kernel.org> Cc: Nick Desaulniers <ndesaulniers@google.com> Cc: Palmer Dabbelt <palmer@dabbelt.com> Cc: Paul Walmsley <paul.walmsley@sifive.com>, Cc: Peter Zijlstra <peterz@infradead.org> Cc: Song Liu <songliubraving@meta.com> Cc: Tom Rix <trix@redhat.com> Cc: Yang Jihong <yangjihong1@huawei.com> Link: https://lore.kernel.org/lkml/20230506021450.3499232-1-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 5be6cec commit a2af0f6

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

tools/perf/Makefile.perf

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,24 @@ $(SKEL_TMP_OUT) $(LIBAPI_OUTPUT) $(LIBBPF_OUTPUT) $(LIBPERF_OUTPUT) $(LIBSUBCMD_
10571057

10581058
ifdef BUILD_BPF_SKEL
10591059
BPFTOOL := $(SKEL_TMP_OUT)/bootstrap/bpftool
1060-
BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. -I$(LIBBPF_INCLUDE)
1060+
# Get Clang's default includes on this system, as opposed to those seen by
1061+
# '-target bpf'. This fixes "missing" files on some architectures/distros,
1062+
# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
1063+
#
1064+
# Use '-idirafter': Don't interfere with include mechanics except where the
1065+
# build would have failed anyways.
1066+
define get_sys_includes
1067+
$(shell $(1) $(2) -v -E - </dev/null 2>&1 \
1068+
| sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \
1069+
$(shell $(1) $(2) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}')
1070+
endef
1071+
1072+
ifneq ($(CROSS_COMPILE),)
1073+
CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%))
1074+
endif
1075+
1076+
CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH))
1077+
BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. -I$(LIBBPF_INCLUDE) $(CLANG_SYS_INCLUDES)
10611078
TOOLS_UAPI_INCLUDE := -I$(srctree)/tools/include/uapi
10621079

10631080
$(BPFTOOL): | $(SKEL_TMP_OUT)

0 commit comments

Comments
 (0)