All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Mykola Lysenko <nickolay.lysenko@gmail.com>, bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	martin.lau@linux.dev, 	song@kernel.org, yonghong.song@linux.dev,
	jolsa@kernel.org, memxor@gmail.com
Subject: Re: [RFC PATCH bpf-next v5 8/8] selftests/bpf: build each test runner instance in its own sub-make
Date: Thu, 06 Aug 2026 01:02:35 -0700	[thread overview]
Message-ID: <8da8aa48afa6ef52c22f976793af75b334b189a1.camel@gmail.com> (raw)
In-Reply-To: <20260804170156.1709916-9-nickolay.lysenko@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 9872 bytes --]

On Tue, 2026-08-04 at 10:01 -0700, Mykola Lysenko wrote:

...

> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index 58c567a22..af3709d51 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile

...

> @@ -262,6 +249,35 @@ $(OUTPUT)/test_maps: $(TESTING_HELPERS)
>  $(OUTPUT)/test_verifier: $(TESTING_HELPERS) $(CAP_HELPERS) $(UNPRIV_HELPERS)
>  $(OUTPUT)/xsk.o: $(BPFOBJ)
>
> +# All helper objects a runner instance links, pre-built here so runner
> +# sub-makes sharing $(OUTPUT) never compile them concurrently.
> +HELPER_OBJS := $(TESTING_HELPERS) $(CGROUP_HELPERS) $(UNPRIV_HELPERS)	\
> +	       $(TRACE_HELPERS) $(JSON_WRITER) $(CAP_HELPERS)		\
> +	       $(NETWORK_HELPERS) $(OUTPUT)/usdt_1.o $(OUTPUT)/usdt_2.o	\
> +	       $(OUTPUT)/xsk.o
> +
> +# $(BPFTOOL) is a prerequisite because its sub-make is what installs
> +# libbpf's internal headers (bpf/hashmap.h, bpf/libbpf_internal.h) into
> +# $(INCLUDE_DIR); without it, helpers including those headers race the
> +# install and can silently pick up the source-tree copies instead.
> +#
> +# Invariant: this list must be a superset of every prerequisite the
> +# runner's EXTRA_OBJS rule attaches to these same objects (EXTRA_HDRS,
> +# both tests.h flavors, $(BPFOBJ)). It guarantees the helpers built
> +# here are never older than a runner-side prerequisite, so the
> +# unflavored test_progs and test_maps sub-makes, which share $(OUTPUT),
> +# treat them as up to date instead of both recompiling the same object
> +# file concurrently.
> +$(HELPER_OBJS): flow_dissector_load.h ip_check_defrag_frags.h		\
> +		$(VERIFY_SIG_HDR) $(LIBARENA_SKEL) $(LIBARENA_ASAN_SKEL)\
> +		prog_tests/tests.h map_tests/tests.h $(BPFOBJ) $(BPFTOOL)
> +

Tbh, I don't understand what this comment is attempting to convey and
maintaining the invariant would be taxing going forward. LLM is also
trying to convince me that several dependencies are missing from the
list:

  test_progs.o btf_helpers.o sysctl_helpers.o netlink_helpers.o
  jit_disasm_helpers.o io_helpers.o test_loader.o disasm.o
  disasm_helpers.o bpftool_helpers.o find_bit.o

Which would form a race when compiling test_progs and test_maps that
both share the same $(OUTPUT) directory. This seem plausible.

How about a change as in the attached patch? (squashed with this patch).
It sidesteps a previously discussed constraint to keep refactoring to
the minimum, but HELPER_OBJS is just too ugly to pass.

> +$(OUTPUT)/flow_dissector_load: flow_dissector_load.h
> +
> +# Tool sub-builds: bpftool, libbpf (host and, when cross-compiling,
> +# target variants) and resolve_btfids. Deliberate asymmetry: the host
> +# libbpf builds without sanitizers and with the host toolchain.

Nit: is this comment necessary?

>  $(DEFAULT_BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile)    \
>  		    $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/bpftool
>  	$(Q)$(MAKE) $(submake_extras)  -C $(BPFTOOLDIR)			       \

...

> @@ -672,81 +413,125 @@ $(LIBARENA_ASAN_SKEL): $(INCLUDE_DIR)/vmlinux.h $(BPFOBJ) $(LIBARENA_BPF_DEPS)

...

> +# Everything a runner instance references but does not know how to build.
> +RUNNER_PREREQS := $(INCLUDE_DIR)/vmlinux.h $(BPFOBJ) $(BPFTOOL)		\
> +		  $(TRUNNER_BPFTOOL) $(RESOLVE_BTFIDS)			\
> +		  $(OUTPUT)/veristat					\
> +		  $(VERIFY_SIG_HDR) $(PRIVATE_KEY) $(VERIFICATION_CERT)	\
> +		  $(LIBARENA_SKEL) $(LIBARENA_ASAN_SKEL)		\
> +		  prog_tests/tests.h map_tests/tests.h			\
> +		  $(HELPER_OBJS)					\
> +		  $(OUTPUT)/urandom_read $(OUTPUT)/liburandom_read.so	\
> +		  $(OUTPUT)/xdp_synproxy $(OUTPUT)/sign-file		\
> +		  $(OUTPUT)/uprobe_multi $(TEST_KMOD_TARGETS)
> +
> +FORCE:

Nit: please drop a line here, saying that the main makefile does not
     know if $(OUTPUT)/test_progs is stale, hence FORCE to force
     delegation to Makefile.runner.

> +
> +# The default flavor's skeletons are also inputs of bench, test_maps,
> +# xskxceiver, xdp_* and test_cpp; "default-skels" builds just those
> +# without the test_progs test objects and binary.
> +.PHONY: default-skels
> +default-skels: $(RUNNER_PREREQS)
> +	+$(Q)$(RUNNER_MAKE) RUNNER=test_progs FLAVOR= TESTS_DIR=prog_tests \
> +		BPF_CC='$(CLANG)' BPF_CC_MSG=CLNG-BPF BPF_SYS_INCLUDES='$(CLANG_SYS_INCLUDES)'	\
> +		BPF_CC_FLAGS='-O2 $(BPF_TARGET_ENDIAN) -mcpu=v3'		\
> +		BPF_DEFINES=-DENABLE_ATOMICS_TESTS skels
> +
> +$(OUTPUT)/test_progs: $(RUNNER_PREREQS) default-skels FORCE
> +	+$(Q)$(RUNNER_MAKE) RUNNER=test_progs FLAVOR= TESTS_DIR=prog_tests \
> +		BPF_CC='$(CLANG)' BPF_CC_MSG=CLNG-BPF BPF_SYS_INCLUDES='$(CLANG_SYS_INCLUDES)'	\
> +		BPF_CC_FLAGS='-O2 $(BPF_TARGET_ENDIAN) -mcpu=v3'		\
> +		BPF_DEFINES=-DENABLE_ATOMICS_TESTS

Is there a way to reduce copy-paste between default-skels and
test_progs? Why does test_progs depend on default-skels?

> +
> +$(OUTPUT)/test_progs-no_alu32: $(RUNNER_PREREQS) FORCE
> +	+$(Q)$(RUNNER_MAKE) RUNNER=test_progs FLAVOR=no_alu32 TESTS_DIR=prog_tests \
> +		BPF_CC='$(CLANG)' BPF_CC_MSG=CLNG-BPF BPF_SYS_INCLUDES='$(CLANG_SYS_INCLUDES)'	\
> +		BPF_CC_FLAGS='-O2 $(BPF_TARGET_ENDIAN) -mcpu=v2'
> +
>  ifneq ($(CLANG_CPUV4),)
> -TRUNNER_BPF_BUILD_RULE := CLANG_CPUV4_BPF_BUILD_RULE
> -TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS) -DENABLE_ATOMICS_TESTS
> -$(eval $(call DEFINE_TEST_RUNNER,test_progs,cpuv4))
> +$(OUTPUT)/test_progs-cpuv4: $(RUNNER_PREREQS) FORCE
> +	+$(Q)$(RUNNER_MAKE) RUNNER=test_progs FLAVOR=cpuv4 TESTS_DIR=prog_tests \
> +		BPF_CC='$(CLANG)' BPF_CC_MSG=CLNG-BPF BPF_SYS_INCLUDES='$(CLANG_SYS_INCLUDES)'	\
> +		BPF_CC_FLAGS='-O2 $(BPF_TARGET_ENDIAN) -mcpu=v4'		\
> +		BPF_DEFINES=-DENABLE_ATOMICS_TESTS
>  endif
>
> -# Define test_progs BPF-GCC-flavored test runner.
>  ifneq ($(BPF_GCC),)
> -TRUNNER_BPF_BUILD_RULE := GCC_BPF_BUILD_RULE
> -TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(call get_sys_includes,gcc,)
> -$(eval $(call DEFINE_TEST_RUNNER,test_progs,bpf_gcc))
> +# Sys includes come from the *host* gcc, not $(BPF_GCC) - bpf-gcc's own
> +# search path lacks the host's asm-generic/ headers.
> +GCC_SYS_INCLUDES := $(call get_sys_includes,gcc,)
> +
> +$(OUTPUT)/test_progs-bpf_gcc: $(RUNNER_PREREQS) FORCE
> +	+$(Q)$(RUNNER_MAKE) RUNNER=test_progs FLAVOR=bpf_gcc TESTS_DIR=prog_tests \
> +		BPF_CC='$(BPF_GCC)' BPF_CC_MSG=GCC-BPF				\
> +		BPF_SYS_INCLUDES='$(GCC_SYS_INCLUDES)'				\
> +		BPF_CC_FLAGS='-DBPF_NO_PRESERVE_ACCESS_INDEX -Wno-attributes -O2'
>  endif

Did you test the bpf_gcc flavor?
I have a recipe to build the toolchain somewhere, if you need it.

>
> -# Define test_maps test runner.
> -TRUNNER_TESTS_DIR := map_tests
> -TRUNNER_BPF_PROGS_DIR := progs
> -TRUNNER_EXTRA_SOURCES := test_maps.c
> -TRUNNER_LIB_SOURCES :=
> -TRUNNER_EXTRA_FILES :=
> -TRUNNER_BPF_BUILD_RULE := $$(error no BPF objects should be built)
> -TRUNNER_BPF_CFLAGS :=
> -$(eval $(call DEFINE_TEST_RUNNER,test_maps))
> -
> -# Define test_verifier test runner.
> -# It is much simpler than test_maps/test_progs and sufficiently different from
> -# them (e.g., test.h is using completely pattern), that it's worth just
> -# explicitly defining all the rules explicitly.
> +# test_maps compiles map_tests/*.c against the default flavor's skeletons
> +$(OUTPUT)/test_maps: $(RUNNER_PREREQS) map_tests/tests.h default-skels FORCE
> +	+$(Q)$(RUNNER_MAKE) RUNNER=test_maps FLAVOR= TESTS_DIR=map_tests
> +
> +# Default-flavor BPF objects and skeletons consumed by targets in this
> +# Makefile (and by lib.mk's install rule) are produced by the runner
> +# sub-make above; the empty recipe plus the order-only prerequisite
> +# makes them available here without duplicating the runner's rules.
> +DEFAULT_BPF_OBJS := $(patsubst progs/%.c,$(OUTPUT)/%.bpf.o,$(wildcard progs/*.c))
> +TEST_GEN_FILES += $(DEFAULT_BPF_OBJS)

--- 8< --------------------------------------------------------------------------

> +BENCH_SKELS := $(addprefix $(OUTPUT)/,					\
> +	       test_overhead.skel.h trigger_bench.skel.h		\
> +	       ringbuf_bench.skel.h perfbuf_bench.skel.h		\
> +	       bloom_filter_bench.skel.h bpf_loop_bench.skel.h		\
> +	       strncmp_bench.skel.h bpf_hashmap_full_update_bench.skel.h\
> +	       local_storage_bench.skel.h				\
> +	       local_storage_rcu_tasks_trace_bench.skel.h		\
> +	       bench_local_storage_create.skel.h			\
> +	       bpf_hashmap_lookup.skel.h htab_mem_bench.skel.h		\
> +	       crypto_bench.skel.h bench_sockmap_prog.skel.h		\
> +	       lpm_trie_bench.skel.h lpm_trie_map.skel.h		\
> +	       bpf_nop_bench.skel.h xdp_lb_bench.skel.h)
> +TOP_SKELS := $(addprefix $(OUTPUT)/,xsk_xdp_progs.skel.h		\
> +	     xdp_hw_metadata.skel.h xdp_features.skel.h			\
> +	     test_core_extern.skel.h) $(BENCH_SKELS)
> +
> +# Empty-recipe delegation: "default-skels" (re)builds the file via the
> +# runner sub-make, after which make re-stats the target, so dependents
> +# see fresh timestamps within the same invocation. Dependents still
> +# rebuild on mtime only - the phony prerequisite does not cascade.
> +$(DEFAULT_BPF_OBJS) $(TOP_SKELS): default-skels ;

-------------------------------------------------------------------------- >8 ---

Note, the above two lists can be replaced with the following two rules:

  $(OUTPUT)/%.skel.h: default-skels ;
  $(DEFAULT_BPF_OBJS): default-skels ;

> +
> +# Standalone test binaries
> +
> +# test_verifier is much simpler than test_maps/test_progs and
> +# sufficiently different from them (e.g., its tests.h uses a completely
> +# different pattern), that it's worth just defining its rules explicitly.
>  verifier/tests.h: verifier/*.c
>  	$(Q)( cd verifier/; \
>  		  echo '/* Generated header, do not edit */'; \

...

[-- Attachment #2: common-objects.diff --]
[-- Type: text/x-patch, Size: 10684 bytes --]

From 25addc8be0d5548652a9a93504a1245157faa845 Mon Sep 17 00:00:00 2001
From: Eduard Zingerman <eddyz87@gmail.com>
Date: Wed, 5 Aug 2026 23:35:14 -0700
Subject: [PATCH] selftests/bpf: build the runner userspace objects in the main
 Makefile

Squash into "selftests/bpf: build each test runner instance in its own
sub-make".

Instead of maintaining an invariant list of source files to pre-build
in the main makefile and having the rules to build same objects in the
Makefile.runner, build these objects explicitly in the main makefile
and drop the rules from Makefile.runner. Let each runner instance link
them as plain prerequisites. The lists live in Makefile.buildvars.

Gone from Makefile.runner: the invariant note, EXTRA_SOURCES,
LIB_SOURCES, EXTRA_OBJS, LIB_OBJS and both compile rules.
EXTRA_HDRS shrinks to the generated headers and is renamed
accordingly. The flavored instances no longer build their own copies
of shared prerequesties.

With no rule left for those objects, a missing one would match make's
built-in %.o rule and be rebuilt with default flags, so disable the
built-in rules (The `MAKEFLAGS += -r` thingy).
---
 tools/testing/selftests/bpf/Makefile          | 39 ++++++-------
 .../testing/selftests/bpf/Makefile.buildvars  | 17 ++++++
 tools/testing/selftests/bpf/Makefile.runner   | 55 +++++--------------
 3 files changed, 46 insertions(+), 65 deletions(-)

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index af3709d51f67..dc14a89ed55b 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -245,32 +245,25 @@ $(OUTPUT)/test_sock_fields: $(CGROUP_HELPERS) $(TESTING_HELPERS)
 $(OUTPUT)/test_tag: $(TESTING_HELPERS)
 $(OUTPUT)/test_lirc_mode2_user: $(TESTING_HELPERS)
 $(OUTPUT)/flow_dissector_load: $(TESTING_HELPERS)
-$(OUTPUT)/test_maps: $(TESTING_HELPERS)
 $(OUTPUT)/test_verifier: $(TESTING_HELPERS) $(CAP_HELPERS) $(UNPRIV_HELPERS)
-$(OUTPUT)/xsk.o: $(BPFOBJ)
-
-# All helper objects a runner instance links, pre-built here so runner
-# sub-makes sharing $(OUTPUT) never compile them concurrently.
-HELPER_OBJS := $(TESTING_HELPERS) $(CGROUP_HELPERS) $(UNPRIV_HELPERS)	\
-	       $(TRACE_HELPERS) $(JSON_WRITER) $(CAP_HELPERS)		\
-	       $(NETWORK_HELPERS) $(OUTPUT)/usdt_1.o $(OUTPUT)/usdt_2.o	\
-	       $(OUTPUT)/xsk.o
 
+# The userspace objects the runner instances link (RUNNER_OBJS, see
+# Makefile.buildvars) are built here, once, so that no runner sub-make
+# ever writes a file this Makefile also builds.
+#
 # $(BPFTOOL) is a prerequisite because its sub-make is what installs
 # libbpf's internal headers (bpf/hashmap.h, bpf/libbpf_internal.h) into
-# $(INCLUDE_DIR); without it, helpers including those headers race the
-# install and can silently pick up the source-tree copies instead.
-#
-# Invariant: this list must be a superset of every prerequisite the
-# runner's EXTRA_OBJS rule attaches to these same objects (EXTRA_HDRS,
-# both tests.h flavors, $(BPFOBJ)). It guarantees the helpers built
-# here are never older than a runner-side prerequisite, so the
-# unflavored test_progs and test_maps sub-makes, which share $(OUTPUT),
-# treat them as up to date instead of both recompiling the same object
-# file concurrently.
-$(HELPER_OBJS): flow_dissector_load.h ip_check_defrag_frags.h		\
-		$(VERIFY_SIG_HDR) $(LIBARENA_SKEL) $(LIBARENA_ASAN_SKEL)\
-		prog_tests/tests.h map_tests/tests.h $(BPFOBJ) $(BPFTOOL)
+# $(INCLUDE_DIR); without it, trace_helpers.c races the install and can
+# silently pick up the source-tree copies instead.
+$(RUNNER_OBJS): $(VERIFY_SIG_HDR) prog_tests/tests.h map_tests/tests.h	\
+		$(BPFOBJ) $(BPFTOOL)
+
+# Some utility functions use LLVM libraries
+$(OUTPUT)/jit_disasm_helpers.o: CFLAGS += $(LLVM_CFLAGS)
+
+$(OUTPUT)/find_bit.o: $(TOOLSDIR)/lib/find_bit.c
+	$(call msg,CC,,$@)
+	$(Q)$(CC) $(CFLAGS) -c $< -o $@
 
 $(OUTPUT)/flow_dissector_load: flow_dissector_load.h
 
@@ -446,7 +439,7 @@ RUNNER_PREREQS := $(INCLUDE_DIR)/vmlinux.h $(BPFOBJ) $(BPFTOOL)		\
 		  $(VERIFY_SIG_HDR) $(PRIVATE_KEY) $(VERIFICATION_CERT)	\
 		  $(LIBARENA_SKEL) $(LIBARENA_ASAN_SKEL)		\
 		  prog_tests/tests.h map_tests/tests.h			\
-		  $(HELPER_OBJS)					\
+		  $(RUNNER_OBJS)					\
 		  $(OUTPUT)/urandom_read $(OUTPUT)/liburandom_read.so	\
 		  $(OUTPUT)/xdp_synproxy $(OUTPUT)/sign-file		\
 		  $(OUTPUT)/uprobe_multi $(TEST_KMOD_TARGETS)
diff --git a/tools/testing/selftests/bpf/Makefile.buildvars b/tools/testing/selftests/bpf/Makefile.buildvars
index 044e0d73b09b..bb95cff65324 100644
--- a/tools/testing/selftests/bpf/Makefile.buildvars
+++ b/tools/testing/selftests/bpf/Makefile.buildvars
@@ -169,3 +169,20 @@ ifneq ($(CLANG_HAS_ARENA_ASAN),)
 LIBARENA_ASAN_SKEL := libarena/libarena_asan.skel.h
 CFLAGS += -DHAS_BPF_ARENA_ASAN
 endif
+
+RUNNER_OBJS-test_progs := $(addprefix $(OUTPUT)/,			\
+	test_progs.o cgroup_helpers.o trace_helpers.o			\
+	network_helpers.o testing_helpers.o btf_helpers.o		\
+	cap_helpers.o unpriv_helpers.o sysctl_helpers.o			\
+	netlink_helpers.o jit_disasm_helpers.o io_helpers.o		\
+	test_loader.o xsk.o disasm.o disasm_helpers.o			\
+	json_writer.o bpftool_helpers.o usdt_1.o usdt_2.o)
+RUNNER_OBJS-test_maps := $(addprefix $(OUTPUT)/,			\
+	test_maps.o testing_helpers.o)
+
+# find_bit.c is the only runner source outside this directory,
+# so it needs a rule of its own
+RUNNER_LIB_OBJS-test_progs := $(OUTPUT)/find_bit.o
+
+RUNNER_OBJS := $(sort $(RUNNER_OBJS-test_progs) $(RUNNER_OBJS-test_maps)\
+		      $(RUNNER_LIB_OBJS-test_progs))
diff --git a/tools/testing/selftests/bpf/Makefile.runner b/tools/testing/selftests/bpf/Makefile.runner
index 91e8a2df468f..ed6262dc13e3 100644
--- a/tools/testing/selftests/bpf/Makefile.runner
+++ b/tools/testing/selftests/bpf/Makefile.runner
@@ -7,9 +7,9 @@
 # so everything here is written in plain make - no $$-escaping, no eval,
 # no per-flavor guards. This file is always invoked by the main Makefile,
 # never directly: all shared prerequisites (libbpf, bpftool, vmlinux.h,
-# veristat, helper objects, signing key, generated tests.h, extra
-# binaries) are built by the main Makefile *before* this one runs and are
-# referenced below as plain files.
+# veristat, helper objects, signing key, generated
+# tests.h, extra binaries) are built by the main Makefile *before* this
+# one runs and are referenced below as plain files.
 #
 # Parameters (all passed on the sub-make command line):
 #   OUTPUT      absolute path of the selftests output directory
@@ -63,6 +63,11 @@ all: $(OUTPUT)/$(BINARY)
 # Delete partially updated (corrupted) files on error
 .DELETE_ON_ERROR:
 
+# No built-in rules: every file built here has an explicit rule, and the
+# objects that come from the main Makefile have to be an error when
+# missing rather than a silent rebuild by the built-in %.o recipes.
+MAKEFLAGS += -r
+
 # Permissive skip-on-failure of individual tests applies to test_progs and
 # its flavors only; test_maps uses strong cross-object references and keeps
 # strict semantics even when BPF_STRICT_BUILD=0.
@@ -77,15 +82,7 @@ $(RDIR):
 # ---------------------------------------------------------------------
 
 ifeq ($(RUNNER),test_progs)
-EXTRA_SOURCES := test_progs.c cgroup_helpers.c trace_helpers.c		\
-		 network_helpers.c testing_helpers.c btf_helpers.c	\
-		 cap_helpers.c unpriv_helpers.c sysctl_helpers.c	\
-		 netlink_helpers.c jit_disasm_helpers.c io_helpers.c	\
-		 test_loader.c xsk.c disasm.c disasm_helpers.c		\
-		 json_writer.c bpftool_helpers.c usdt_1.c usdt_2.c
-LIB_SOURCES := find_bit.c
-EXTRA_HDRS := flow_dissector_load.h ip_check_defrag_frags.h		\
-	      $(VERIFY_SIG_HDR) $(LIBARENA_SKEL) $(LIBARENA_ASAN_SKEL)
+GENERATED_HDRS := $(LIBARENA_SKEL) $(LIBARENA_ASAN_SKEL)
 EXTRA_FILES := $(OUTPUT)/urandom_read $(OUTPUT)/liburandom_read.so	\
 	       $(OUTPUT)/xdp_synproxy $(OUTPUT)/sign-file		\
 	       $(OUTPUT)/uprobe_multi					\
@@ -95,25 +92,9 @@ EXTRA_FILES := $(OUTPUT)/urandom_read $(OUTPUT)/liburandom_read.so	\
 	       $(wildcard progs/*.bpf.o)
 endif
 
-ifeq ($(RUNNER),test_maps)
-EXTRA_SOURCES := test_maps.c testing_helpers.c
-endif
-
-# Note on the unflavored runners, which share $(OUTPUT) with the main
-# Makefile: helper objects the main Makefile also uses (and lists in the
-# runner prerequisites) are already built and fresh when a runner starts,
-# so the rules below find them up to date and never write them. This
-# holds because the main Makefile's helper-object rule depends on a
-# superset of the prerequisites the EXTRA_OBJS rule uses here - keep
-# the two lists in sync (see the invariant comment there).
-
-TESTS_HDR := $(TESTS_DIR)/tests.h
-
 TEST_SRCS  := $(notdir $(wildcard $(TESTS_DIR)/*.c))
 TEST_OBJS  := $(patsubst %.c,$(RDIR)/%.test.o,$(TEST_SRCS))
 TEST_DEPS  := $(TEST_OBJS:.o=.d)
-EXTRA_OBJS := $(patsubst %.c,$(RDIR)/%.o,$(filter %.c,$(EXTRA_SOURCES)))
-LIB_OBJS   := $(patsubst %.c,$(RDIR)/%.o,$(LIB_SOURCES))
 
 # ---------------------------------------------------------------------
 # BPF objects and skeletons
@@ -270,22 +251,11 @@ $(TEST_OBJS): $(RDIR)/%.test.o: $(TESTS_DIR)/%.c | $(RDIR)/%.test.d
 		$(RESOLVE_BTFIDS) --patch_btfids $@.BTF_ids $@;		\
 		fi)
 
-$(TEST_DEPS): $(RDIR)/%.test.d: $(TESTS_DIR)/%.c $(EXTRA_HDRS) $(BPFOBJ) \
+$(TEST_DEPS): $(RDIR)/%.test.d: $(TESTS_DIR)/%.c $(GENERATED_HDRS) $(BPFOBJ) \
 	      | $(RDIR) $(ALL_SKELS)
 
 include $(wildcard $(TEST_DEPS))
 
-# Some utility functions use LLVM libraries
-$(RDIR)/jit_disasm_helpers.o: CFLAGS += $(LLVM_CFLAGS)
-
-$(EXTRA_OBJS): $(RDIR)/%.o: %.c $(EXTRA_HDRS) $(TESTS_HDR) $(BPFOBJ) | $(RDIR)
-	$(call msg,EXT-OBJ,$(BINARY),$@)
-	$(Q)$(CC) $(CFLAGS) -c $< -o $@
-
-$(LIB_OBJS): $(RDIR)/%.o: $(TOOLSDIR)/lib/%.c | $(RDIR)
-	$(call msg,LIB-OBJ,$(BINARY),$@)
-	$(Q)$(CC) $(CFLAGS) -c $< -o $@
-
 # Non-flavored in-srctree builds receive special treatment, in particular
 # we do not need to copy extra resources (see e.g. test_btf_dump_case()).
 .PHONY: extras
@@ -303,10 +273,11 @@ endif
 # relinks the runner - while the full set stays order-only to drive the
 # build attempts, and the wildcard in the recipe picks up the survivors
 # at link time.
-# Prerequisite order is also link order (test objects, extra objects,
+# Prerequisite order is also link order (test objects, runner objects,
 # libbpf, lib objects).
 $(OUTPUT)/$(BINARY): $(if $(PERMISSIVE_TESTS),$(wildcard $(TEST_OBJS)),$(TEST_OBJS)) \
-		     $(EXTRA_OBJS) $(BPFOBJ) $(LIB_OBJS)		\
+		     $(RUNNER_OBJS-$(RUNNER)) $(BPFOBJ)			\
+		     $(RUNNER_LIB_OBJS-$(RUNNER))			\
 		     $(TRUNNER_BPFTOOL) $(OUTPUT)/veristat		\
 		     | extras $(BPF_OBJS)				\
 		     $(if $(PERMISSIVE_TESTS),$(TEST_OBJS))
-- 
2.53.0-Meta


  reply	other threads:[~2026-08-06  8:02 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-04 17:01 [RFC PATCH bpf-next v5 0/8] selftests/bpf: restructure the Makefile as a layered build Mykola Lysenko
2026-08-04 17:01 ` [RFC PATCH bpf-next v5 1/8] selftests/bpf: keep headers off the generic link command line Mykola Lysenko
2026-08-05 21:21   ` Eduard Zingerman
2026-08-04 17:01 ` [RFC PATCH bpf-next v5 2/8] selftests/bpf: drop stale and no-op lines Mykola Lysenko
2026-08-05 21:28   ` Eduard Zingerman
2026-08-06  4:43     ` Mykola Lysenko
2026-08-04 17:01 ` [RFC PATCH bpf-next v5 3/8] selftests/bpf: factor the permissive-mode skip suffix into a helper Mykola Lysenko
2026-08-04 17:21   ` sashiko-bot
2026-08-05  0:13     ` Mykola Lysenko
2026-08-05 21:33   ` Eduard Zingerman
2026-08-04 17:01 ` [RFC PATCH bpf-next v5 4/8] selftests/bpf: generate the signing key and certificate once Mykola Lysenko
2026-08-05 22:03   ` Eduard Zingerman
2026-08-04 17:01 ` [RFC PATCH bpf-next v5 5/8] selftests/bpf: generate verifier/tests.h in a regular recipe Mykola Lysenko
2026-08-05 22:11   ` Eduard Zingerman
2026-08-04 17:01 ` [RFC PATCH bpf-next v5 6/8] selftests/bpf: extract BPF skeleton generation into a helper script Mykola Lysenko
2026-08-04 17:59   ` sashiko-bot
2026-08-05  1:40     ` Mykola Lysenko
2026-08-05 22:39   ` Eduard Zingerman
2026-08-04 17:01 ` [RFC PATCH bpf-next v5 7/8] selftests/bpf: move shared build definitions into Makefile.buildvars Mykola Lysenko
2026-08-05 23:34   ` Eduard Zingerman
2026-08-06  4:51     ` Mykola Lysenko
2026-08-04 17:01 ` [RFC PATCH bpf-next v5 8/8] selftests/bpf: build each test runner instance in its own sub-make Mykola Lysenko
2026-08-06  8:02   ` Eduard Zingerman [this message]
2026-08-06 18:30     ` Eduard Zingerman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8da8aa48afa6ef52c22f976793af75b334b189a1.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=jolsa@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=nickolay.lysenko@gmail.com \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.