When individual test files are skipped due to compilation failures, their
.test.o files are absent. The linker step currently lists all expected
.test.o files as explicit prerequisites, so make considers any missing one
an error.

In permissive mode, declare the test objects that already exist on disk
(via parse-time $(wildcard ...)) as normal prerequisites of the binary so
that modifications to a test source still trigger a relink, and keep the
full TRUNNER_TEST_OBJS list as order-only prerequisites so that initial
fresh builds still produce them and missing objects do not abort the link.
The recipe filter is split per mode: in permissive mode it combines a
recipe-time $(wildcard ...) (which catches objects freshly produced via the
order-only path on a fresh build) with $(filter-out
$(TRUNNER_TEST_OBJS),$^) (which keeps the non-test inputs from $^ but drops
the parse-time wildcard duplicates). This avoids passing the same .test.o
twice to the linker while still presenting test objects before libbpf.a so
that GNU ld, which scans static archives left-to-right, pulls in archive
members referenced exclusively by test objects (e.g. ring_buffer__new from
ringbuf.c). In default (strict) mode the recipe remains the simple $(filter
%.a %.o,$^) since TRUNNER_TEST_OBJS is part of $^ exactly once.

Note: adding a brand-new test_*.c file in permissive mode requires removing
the binary (or a clean rebuild) before the new test is linked in, because
the parse-time $(wildcard ...) is evaluated when the Makefile is read and
will not yet see the new .test.o. This is acceptable since permissive mode
targets tolerant CI builds rather than incremental development.

Signed-off-by: Ricardo B. Marlière <[email protected]>
---
 tools/testing/selftests/bpf/Makefile | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/bpf/Makefile 
b/tools/testing/selftests/bpf/Makefile
index f0545ee6b32a..9a5177455f0a 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -767,14 +767,15 @@ endif
 # some X.test.o files have runtime dependencies on Y.bpf.o files
 $(OUTPUT)/$(TRUNNER_BINARY): | $(TRUNNER_BPF_OBJS)
 
-$(OUTPUT)/$(TRUNNER_BINARY): $(TRUNNER_TEST_OBJS)                      \
+$(OUTPUT)/$(TRUNNER_BINARY): $(if $(PERMISSIVE),$$(wildcard 
$(TRUNNER_TEST_OBJS)),$(TRUNNER_TEST_OBJS))        \
                             $(TRUNNER_EXTRA_OBJS) $$(BPFOBJ)           \
                             $(TRUNNER_LIB_OBJS)                        \
                             $(TRUNNER_BPFTOOL)                         \
                             $(OUTPUT)/veristat                         \
-                            | $(TRUNNER_BINARY)-extras
+                            | $(TRUNNER_BINARY)-extras                 \
+                            $(if $(PERMISSIVE),$(TRUNNER_TEST_OBJS))
        $$(call msg,BINARY,,$$@)
-       $(Q)$$(CC) $$(CFLAGS) $$(filter %.a %.o,$$^) $$(LDLIBS) $$(LLVM_LDLIBS) 
$$(LDFLAGS) $$(LLVM_LDFLAGS) -o $$@
+       $(Q)$$(CC) $$(CFLAGS) $(if $(PERMISSIVE),$$(filter %.a %.o,$$(wildcard 
$(TRUNNER_TEST_OBJS)) $$(filter-out $(TRUNNER_TEST_OBJS),$$^)),$$(filter %.a 
%.o,$$^)) $$(LDLIBS) $$(LLVM_LDLIBS) $$(LDFLAGS) $$(LLVM_LDFLAGS) -o $$@
        $(Q)ln -sf $(if $2,..,.)/tools/build/bpftool/$(USE_BOOTSTRAP)bpftool \
                   $(OUTPUT)/$(if $2,$2/)bpftool
 

-- 
2.54.0


Reply via email to