Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11128471420 for ; Tue, 21 Jul 2026 19:41:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784662908; cv=none; b=pSQxFxotrYi17SFFbLGAMEZgYi9XRsHp6cCb7rhnbSeC5478S+GrSI9cPQmm+3RqGIEqgq+SoiKaR9HJ6Z6Z9zKVyRkyFpScpj2LwmhbBlI/GwK1zqjOciYube1/vKlXh71KbqIbgyXlfFQm9Y32hKPvi5XPCm3lAZ02KDTEXck= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784662908; c=relaxed/simple; bh=TWRemLoRUWVzkpIBGVURUxUC5yK/LjnnoMUf2KznhiE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z9Dw4WC87CwnNMkp+hqpnrN+NG6R+KpifmmoEbr+U0Fpgm36SJR8YVw/e+LGFF6fSDW8i1nwEyeUlbvQQF8tOJeoCbjVlztlVQzhrO6cpI3uEjBNV2jO9U1qLX0Ch6Lg+1t+JUSxGKHYXhsiHh10c2elH6fDXTXawDxdepGfPxA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=byGtIezY; arc=none smtp.client-ip=209.85.210.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="byGtIezY" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-84a2dcec51cso10984479b3a.3 for ; Tue, 21 Jul 2026 12:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784662904; x=1785267704; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=IjbhZyZjesTQjJvGusSsm++BaVFrjfrUsyQyH5Zpgas=; b=byGtIezYq4jVEG1D8/DDllf366SWyfJrKKePRhiyeilMNVUvJ+RVQJKFIBSNcO9KLv DSTyEHL4wuJHCMjItN0CEhfxaJErRKWORZrkYethBIhuamzVRBFm9F37wIRaymVT25/l 3JnL3GEZ1ABcRVih4KWtrqTZa9bQQSRb0Vp8zedOlGv9FQexRvEYff3oc160X+Z9ySgx ufaqevrXcV3JFY1YqsfO5ldChJzGn5Cv38ZCIu+aXaou45zfJMGVk/v87JSaTnQlGLUw Y3F1Ca0FvkNzwZugvyALyqmV3oxOWfKOc27Qb4Mp489SstH4c3dH9ngwBBtE02x9w57D 1uLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784662904; x=1785267704; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=IjbhZyZjesTQjJvGusSsm++BaVFrjfrUsyQyH5Zpgas=; b=mojn9EhxAzPSq43huLbpWT4L+0lq7cPx/W99klc0V2mzZeTaRh4cz/pD3qfRCYjpIX pxMAP9NjaCZmzWk/iFTHc2++MK7tEfMXJvYMOb4KJvACCfPIlZnTAylAvkIeXgoP0JKX iXkdE+pHy419qyxetYZKTZfW3OTumCH3RiCrSw6awOtdeJvhnkRy1kltAswFdLxsW7Ox 1XGmXND4JDKN6W5ewYydLVRcQB9GUFtmT4mIBybzKcgAdVymeiHLZxmxic4oMKhsezxk V0pn2SUbl+qtg6YPCitaf+jkYqk32bAVqU4h4vUBUdcwfFIXtSGkhE2B0uBywU38jLMX PaBw== X-Gm-Message-State: AOJu0YwSJU+gOTa13W0j7MIe0/40fA6Vgni/WeOTaxUUEEPtv6k/on97 STg1mAAZ82ZzD20ajTcOwTMIqUeTI0QjCgOHFEiyziTbRWCBCLk2Y5IVnTjIOD82 X-Gm-Gg: AR+sD13QrfeG4B+mun0MPt9Lq6OMUzkQrhCfJqGhs2sK/g5I1kjEIVgGBrVuXPR6ry0 vOReNm448GyOQjw4a3UO3k/KO4VmNUb4MjdMVSu1VBk1kkWH+WBl+0Y708FkgdNyGBIVRGl3hrB a79SWf7HjOeSRVre77pc08yON8EI0Lb2O7vuPo1bDhE+jbON/r3B6+dmFrFBHghpMw8pKdjcK7s KXqC3o33lu9siC5cT7evtQrttWqlz+fLwAuTHTP7IsRifU4+X2AAmluV0MOB6qO+gZP+fa9jrHb nBqq7xI/yKJkfuZFFuFUral4aXMZlHHQmxr7HgC1+XH8vfOBSArwI3nUYG0WmwVjhqOeErX42cc ybxb57IgweiMQK5snTY4kU01QqDxowW9y2US8rWga3y0yIInbbTekUtcfVylKvIpSv7K4Yypjiw k0yK8e3z/0fOYaa530IYIWn8F5 X-Received: by 2002:a05:6a00:4614:b0:847:82db:9046 with SMTP id d2e1a72fcca58-84c29289482mr20658727b3a.26.1784662904012; Tue, 21 Jul 2026 12:41:44 -0700 (PDT) Received: from powertower.localdomain ([64.180.35.234]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84e17237761sm214934b3a.4.2026.07.21.12.41.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2026 12:41:43 -0700 (PDT) From: Mykola Lysenko To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, eddyz87@gmail.com, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org, memxor@gmail.com, Mykola Lysenko Subject: [RFC PATCH bpf-next v2 2/3] selftests/bpf: move shared build definitions into Makefile.buildvars Date: Tue, 21 Jul 2026 12:41:10 -0700 Message-ID: <20260721194111.334795-3-nickolay.lysenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260721194111.334795-1-nickolay.lysenko@gmail.com> References: <20260721194111.334795-1-nickolay.lysenko@gmail.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Move the toolchain, path, flag, probe and knob definitions that are not rules into Makefile.buildvars: output-tree layout, libbpf/bpftool binary locations, BPF_CFLAGS/COMMON_CFLAGS assembly, libelf/libpcap probes, endianness and clang feature detection, the vmlinux BTF search list, signing key paths, permissive-mode knob and the libarena skeleton names. This is preparation for building each test runner instance in its own sub-make: the definitions become includable by more than one makefile. No rules or recipes are changed. One deliberate nuance: the include sits after ../lib.mk, so CFLAGS is now assembled by *prepending* COMMON_CFLAGS (keeping the include-search order identical to before, where the definitions preceded lib.mk's additions). Build artifacts are byte-identical before and after this change. Suggested-by: Eduard Zingerman Assisted-by: Claude:claude-fable-5 shellcheck Signed-off-by: Mykola Lysenko --- tools/testing/selftests/bpf/Makefile | 165 +-------------- .../testing/selftests/bpf/Makefile.buildvars | 196 ++++++++++++++++++ 2 files changed, 203 insertions(+), 158 deletions(-) create mode 100644 tools/testing/selftests/bpf/Makefile.buildvars diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index 09e5be201..2ddcb812d 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -3,93 +3,24 @@ include ../../../build/Build.include include ../../../scripts/Makefile.arch include ../../../scripts/Makefile.include -CXX ?= $(CROSS_COMPILE)g++ -OBJCOPY ?= $(CROSS_COMPILE)objcopy - -CURDIR := $(abspath .) -TOOLSDIR := $(abspath ../../..) -LIBDIR := $(TOOLSDIR)/lib -BPFDIR := $(LIBDIR)/bpf -TOOLSINCDIR := $(TOOLSDIR)/include -TOOLSARCHINCDIR := $(TOOLSDIR)/arch/$(SRCARCH)/include -BPFTOOLDIR := $(TOOLSDIR)/bpf/bpftool -APIDIR := $(TOOLSINCDIR)/uapi -ifneq ($(O),) -GENDIR := $(O)/include/generated -else -GENDIR := $(abspath ../../../../include/generated) -endif -GENHDR := $(GENDIR)/autoconf.h -PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config -ifneq ($(wildcard $(GENHDR)),) - GENFLAGS := -DHAVE_GENHDR +# These probes gate the flavor list, which must be final before lib.mk is +# included; keep values consistent with Makefile.buildvars. +ifeq ($(origin BPF_GCC),undefined) +BPF_GCC := $(shell command -v bpf-gcc;) endif -BPF_GCC ?= $(shell command -v bpf-gcc;) -ifdef ASAN -SAN_CFLAGS ?= -fsanitize=address -fno-omit-frame-pointer -else -SAN_CFLAGS ?= -endif -SAN_LDFLAGS ?= $(SAN_CFLAGS) -RELEASE ?= -OPT_FLAGS ?= $(if $(RELEASE),-O2,-O0) - -LIBELF_CFLAGS := $(shell $(PKG_CONFIG) libelf --cflags 2>/dev/null) -LIBELF_LIBS := $(shell $(PKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf) - -SKIP_DOCS ?= -SKIP_LLVM ?= -SKIP_LIBBFD ?= -SKIP_CRYPTO ?= - -# When BPF_STRICT_BUILD is 1, any BPF object, skeleton, test object, or -# benchmark compilation failure is fatal. Set to 0 to tolerate failures -# and continue building the remaining tests. -BPF_STRICT_BUILD ?= 1 -PERMISSIVE := $(filter 0,$(BPF_STRICT_BUILD)) - -ifeq ($(srctree),) -srctree := $(patsubst %/,%,$(dir $(CURDIR))) -srctree := $(patsubst %/,%,$(dir $(srctree))) -srctree := $(patsubst %/,%,$(dir $(srctree))) -srctree := $(patsubst %/,%,$(dir $(srctree))) -endif -COMMON_CFLAGS = -g $(OPT_FLAGS) -rdynamic -std=gnu11 \ - -Wall -Werror -fno-omit-frame-pointer \ - -Wno-unused-but-set-variable \ - $(GENFLAGS) $(SAN_CFLAGS) $(LIBELF_CFLAGS) \ - -I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \ - -I$(TOOLSINCDIR) -I$(TOOLSARCHINCDIR) -I$(APIDIR) -I$(OUTPUT) \ - -I$(CURDIR)/libarena/include -LDFLAGS += $(SAN_LDFLAGS) -LDLIBS += $(LIBELF_LIBS) -lz -lrt -lpthread - -PCAP_CFLAGS := $(shell $(PKG_CONFIG) --cflags libpcap 2>/dev/null && echo "-DTRAFFIC_MONITOR=1") -PCAP_LIBS := $(shell $(PKG_CONFIG) --libs libpcap 2>/dev/null) -LDLIBS += $(PCAP_LIBS) -CFLAGS += $(COMMON_CFLAGS) $(PCAP_CFLAGS) # Some utility functions use LLVM libraries jit_disasm_helpers.c-CFLAGS = $(LLVM_CFLAGS) -ifneq ($(LLVM),) -# Silence some warnings when compiled with clang -CFLAGS += -Wno-unused-command-line-argument -endif # Check whether bpf cpu=v4 is supported or not by clang ifneq ($(shell $(CLANG) --target=bpf -mcpu=help 2>&1 | grep 'v4'),) CLANG_CPUV4 := 1 endif -# Check whether clang supports BPF address sanitizer (requires LLVM 22+) -CLANG_HAS_ARENA_ASAN := $(shell echo 'int x;' | \ - $(CLANG) --target=bpf -fsanitize=kernel-address \ - -mllvm -asan-shadow-addr-space=1 \ - -x c -c - -o /dev/null 2>/dev/null && echo 1) # Order correspond to 'make run_tests' order TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_progs \ @@ -132,9 +63,8 @@ TEST_PROGS := test_kmod.sh \ TEST_PROGS_EXTENDED := \ ima_setup.sh verify_sig_setup.sh -TEST_KMODS := bpf_testmod.ko bpf_test_no_cfi.ko bpf_test_modorder_x.ko \ +TEST_KMODS ?= bpf_testmod.ko bpf_test_no_cfi.ko bpf_test_modorder_x.ko \ bpf_test_modorder_y.ko bpf_test_rqspinlock.ko -TEST_KMOD_TARGETS = $(addprefix $(OUTPUT)/,$(TEST_KMODS)) # Compile but not part of 'make run_tests' TEST_GEN_PROGS_EXTENDED = \ @@ -150,9 +80,6 @@ TEST_GEN_PROGS_EXTENDED = \ TEST_GEN_FILES += $(TEST_KMODS) liburandom_read.so urandom_read sign-file uprobe_multi -ifneq ($(V),1) -submake_extras := feature_display=0 -endif # override lib.mk's default rules OVERRIDE_TARGETS := 1 @@ -188,6 +115,8 @@ override OUTPUT := $(patsubst %/,%,$(OUTPUT)) endif endif +include Makefile.buildvars + ifneq ($(SKIP_LLVM),1) ifeq ($(feature-llvm),1) LLVM_CFLAGS += -DHAVE_LLVM_SUPPORT @@ -213,30 +142,6 @@ ifeq ($(feature-llvm),1) endif endif -SCRATCH_DIR := $(OUTPUT)/tools -BUILD_DIR := $(SCRATCH_DIR)/build -INCLUDE_DIR := $(SCRATCH_DIR)/include -BPFOBJ := $(BUILD_DIR)/libbpf/libbpf.a -ifneq ($(CROSS_COMPILE),) -HOST_BUILD_DIR := $(BUILD_DIR)/host -HOST_SCRATCH_DIR := $(OUTPUT)/host-tools -HOST_INCLUDE_DIR := $(HOST_SCRATCH_DIR)/include -else -HOST_BUILD_DIR := $(BUILD_DIR) -HOST_SCRATCH_DIR := $(SCRATCH_DIR) -HOST_INCLUDE_DIR := $(INCLUDE_DIR) -endif -HOST_BPFOBJ := $(HOST_BUILD_DIR)/libbpf/libbpf.a -RESOLVE_BTFIDS := $(HOST_BUILD_DIR)/resolve_btfids/resolve_btfids -VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \ - $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \ - ../../../../vmlinux \ - /sys/kernel/btf/vmlinux \ - /boot/vmlinux-$(shell uname -r) -VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS)))) -ifeq ($(VMLINUX_BTF),) -$(error Cannot find a vmlinux for VMLINUX_BTF at any of "$(VMLINUX_BTF_PATHS)") -endif # Define simple and short `make test_progs`, `make test_maps`, etc targets # to build individual tests. @@ -314,15 +219,6 @@ $(TEST_KMOD_TARGETS): $(addprefix test_kmods/,$(TEST_KMODS)) $(Q)$(if $(PERMISSIVE),if [ -f test_kmods/$(@F) ]; then )cp test_kmods/$(@F) $@$(if $(PERMISSIVE),; fi) -DEFAULT_BPFTOOL := $(HOST_SCRATCH_DIR)/sbin/bpftool -ifneq ($(CROSS_COMPILE),) -CROSS_BPFTOOL := $(SCRATCH_DIR)/sbin/bpftool -TRUNNER_BPFTOOL := $(CROSS_BPFTOOL) -USE_BOOTSTRAP := "" -else -TRUNNER_BPFTOOL := $(DEFAULT_BPFTOOL) -USE_BOOTSTRAP := "bootstrap/" -endif $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED): $(BPFOBJ) @@ -344,7 +240,6 @@ $(OUTPUT)/test_maps: $(TESTING_HELPERS) $(OUTPUT)/test_verifier: $(TESTING_HELPERS) $(CAP_HELPERS) $(UNPRIV_HELPERS) $(OUTPUT)/xsk.o: $(BPFOBJ) -BPFTOOL ?= $(DEFAULT_BPFTOOL) $(DEFAULT_BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) \ $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/bpftool $(Q)$(MAKE) $(submake_extras) -C $(BPFTOOLDIR) \ @@ -437,45 +332,6 @@ $(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/resolve_btfids \ HOSTPKG_CONFIG='$(PKG_CONFIG)' \ OUTPUT=$(HOST_BUILD_DIR)/resolve_btfids/ BPFOBJ=$(HOST_BPFOBJ) -# Get Clang's default includes on this system, as opposed to those seen by -# '--target=bpf'. This fixes "missing" files on some architectures/distros, -# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc. -# -# Use '-idirafter': Don't interfere with include mechanics except where the -# build would have failed anyways. -define get_sys_includes -$(shell $(1) $(2) -v -E - &1 \ - | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \ -$(shell $(1) $(2) -dM -E - /dev/null) +LIBELF_LIBS := $(shell $(PKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf) + +SKIP_DOCS ?= +SKIP_LLVM ?= +SKIP_LIBBFD ?= +SKIP_CRYPTO ?= + +# When BPF_STRICT_BUILD is 1, any BPF object, skeleton, test object, or +# benchmark compilation failure is fatal. Set to 0 to tolerate failures +# and continue building the remaining tests. +BPF_STRICT_BUILD ?= 1 +PERMISSIVE := $(filter 0,$(BPF_STRICT_BUILD)) + +# Kernel test modules; TEST_KMODS= on the command line disables them. +TEST_KMODS ?= bpf_testmod.ko bpf_test_no_cfi.ko bpf_test_modorder_x.ko \ + bpf_test_modorder_y.ko bpf_test_rqspinlock.ko +TEST_KMOD_TARGETS = $(addprefix $(OUTPUT)/,$(TEST_KMODS)) + +# Output-tree layout. Defined before COMMON_CFLAGS on purpose: CFLAGS +# below is expanded immediately and references $(INCLUDE_DIR). +SCRATCH_DIR := $(OUTPUT)/tools +BUILD_DIR := $(SCRATCH_DIR)/build +INCLUDE_DIR := $(SCRATCH_DIR)/include +BPFOBJ := $(BUILD_DIR)/libbpf/libbpf.a +ifneq ($(CROSS_COMPILE),) +HOST_BUILD_DIR := $(BUILD_DIR)/host +HOST_SCRATCH_DIR := $(OUTPUT)/host-tools +HOST_INCLUDE_DIR := $(HOST_SCRATCH_DIR)/include +else +HOST_BUILD_DIR := $(BUILD_DIR) +HOST_SCRATCH_DIR := $(SCRATCH_DIR) +HOST_INCLUDE_DIR := $(INCLUDE_DIR) +endif +HOST_BPFOBJ := $(HOST_BUILD_DIR)/libbpf/libbpf.a +RESOLVE_BTFIDS := $(HOST_BUILD_DIR)/resolve_btfids/resolve_btfids + +DEFAULT_BPFTOOL := $(HOST_SCRATCH_DIR)/sbin/bpftool +ifneq ($(CROSS_COMPILE),) +CROSS_BPFTOOL := $(SCRATCH_DIR)/sbin/bpftool +TRUNNER_BPFTOOL := $(CROSS_BPFTOOL) +USE_BOOTSTRAP := +else +TRUNNER_BPFTOOL := $(DEFAULT_BPFTOOL) +USE_BOOTSTRAP := bootstrap/ +endif +BPFTOOL ?= $(DEFAULT_BPFTOOL) + +COMMON_CFLAGS = -g $(OPT_FLAGS) -rdynamic -std=gnu11 \ + -Wall -Werror -fno-omit-frame-pointer \ + -Wno-unused-but-set-variable \ + $(GENFLAGS) $(SAN_CFLAGS) $(LIBELF_CFLAGS) \ + -I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \ + -I$(TOOLSINCDIR) -I$(TOOLSARCHINCDIR) -I$(APIDIR) -I$(OUTPUT) \ + -I$(CURDIR)/libarena/include +LDFLAGS += $(SAN_LDFLAGS) +LDLIBS += $(LIBELF_LIBS) -lz -lrt -lpthread + +PCAP_CFLAGS := $(shell $(PKG_CONFIG) --cflags libpcap 2>/dev/null && echo "-DTRAFFIC_MONITOR=1") +PCAP_LIBS := $(shell $(PKG_CONFIG) --libs libpcap 2>/dev/null) +LDLIBS += $(PCAP_LIBS) +# Prepend rather than append: the include-search order must stay +# "$(COMMON_CFLAGS) first, lib.mk additions after" regardless of whether +# lib.mk was included before this file (top level) or not at all (runner). +CFLAGS := $(COMMON_CFLAGS) $(PCAP_CFLAGS) $(CFLAGS) + +ifneq ($(LLVM),) +# Silence some warnings when compiled with clang +CFLAGS += -Wno-unused-command-line-argument +endif + +# Check whether clang supports BPF address sanitizer (requires LLVM 22+) +CLANG_HAS_ARENA_ASAN := $(shell echo 'int x;' | \ + $(CLANG) --target=bpf -fsanitize=kernel-address \ + -mllvm -asan-shadow-addr-space=1 \ + -x c -c - -o /dev/null 2>/dev/null && echo 1) +ifneq ($(CLANG_HAS_ARENA_ASAN),) +CFLAGS += -DHAS_BPF_ARENA_ASAN +endif + +VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \ + $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \ + ../../../../vmlinux \ + /sys/kernel/btf/vmlinux \ + /boot/vmlinux-$(shell uname -r) +VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS)))) +ifeq ($(VMLINUX_BTF),) +$(error Cannot find a vmlinux for VMLINUX_BTF at any of "$(VMLINUX_BTF_PATHS)") +endif + +# Get Clang's default includes on this system, as opposed to those seen by +# '--target=bpf'. This fixes "missing" files on some architectures/distros, +# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc. +# +# Use '-idirafter': Don't interfere with include mechanics except where the +# build would have failed anyways. +define get_sys_includes +$(shell $(1) $(2) -v -E - &1 \ + | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \ +$(shell $(1) $(2) -dM -E -