[RFC PATCH bpf-next v5 1/8] selftests/bpf: keep headers off the generic link command line
Mykola Lysenko <[email protected]> Tue, 4 Aug 2026 10:01:49 -0700
| Newsgroups | org.kernel.vger.bpf |
|---|---|
| Message-ID | <[email protected]> |
The generic '$(OUTPUT)/%:%.c' rule links with '$(LINK.c) $^', so every prerequisite of such a binary lands on the compiler driver's command line. That only works while none of them is a header: gcc tolerates a stray .h argument on a link line, but clang treats it as a request to precompile the header and fails with "cannot specify -o when generating multiple output files". Filter headers out of the recipe, with a comment: header prerequisites on these targets are useful for dependency tracking - the next patch declares one - and the constraint is easy to rediscover the hard way. Signed-off-by: Mykola Lysenko <[email protected]> --- tools/testing/selftests/bpf/Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index 55d394438..65c702613 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -258,9 +258,12 @@ $(OUTPUT)/%.o: %.c $(call msg,CC,,$@) $(Q)$(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@ +# Headers may appear among the prerequisites for dependency tracking; +# they must not reach the clang/gcc command line (clang treats a bare .h +# argument as a precompiled-header job and refuses -o). $(OUTPUT)/%:%.c $(call msg,BINARY,,$@) - $(Q)$(LINK.c) $^ $(LDLIBS) -o $@ + $(Q)$(LINK.c) $(filter-out %.h,$^) $(LDLIBS) -o $@ # LLVM's ld.lld doesn't support all the architectures, so use it only on x86 ifeq ($(SRCARCH),$(filter $(SRCARCH),x86 riscv)) -- 2.43.0