diff mbox series

[2/8] selftests/bpf: build bench.o for any $(OUTPUT)

Message ID 20200522041310.233185-3-yauheni.kaliuta@redhat.com
State Changes Requested
Delegated to: BPF Maintainers
Headers show
Series selftests/bpf: installation and out of tree build fixes | expand

Commit Message

Yauheni Kaliuta May 22, 2020, 4:13 a.m. UTC
bench.o is produced by implicit rule only if it's built in the same
directory where bench.c is located. If OUTPUT points somewhere else,
build fails.

Make an explicit rule for it (factor out common part).
Add bench.c as a dependency to make it source for CC.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
---
 tools/testing/selftests/bpf/Makefile | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Comments

Andrii Nakryiko May 26, 2020, 10:13 p.m. UTC | #1
On Thu, May 21, 2020 at 9:14 PM Yauheni Kaliuta
<yauheni.kaliuta@redhat.com> wrote:
>
> bench.o is produced by implicit rule only if it's built in the same
> directory where bench.c is located. If OUTPUT points somewhere else,
> build fails.
>
> Make an explicit rule for it (factor out common part).
> Add bench.c as a dependency to make it source for CC.

If that's the case, then the similar problem would happen to
test_l4lb_noinline.o, test_xdp_noinline.o, and flow_dissector_load.o,
at least. Let's fix the implicit rule (or define our own, but generic
one), instead of ad-hoc fixing it for bench.o only.


>
> Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
> ---
>  tools/testing/selftests/bpf/Makefile | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index 09700db35c2d..f0b7d41ed6dd 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
> @@ -243,6 +243,11 @@ define GCC_BPF_BUILD_RULE
>         $(BPF_GCC) $3 $4 -O2 -c $1 -o $2
>  endef
>
> +define COMPILE_C_RULE
> +       $(call msg,CC,,$@)
> +       $(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@
> +endef
> +
>  SKEL_BLACKLIST := btf__% test_pinning_invalid.c test_sk_assign.c
>
>  # Set up extra TRUNNER_XXX "temporary" variables in the environment (relies on
> @@ -409,11 +414,11 @@ $(OUTPUT)/test_cpp: test_cpp.cpp $(OUTPUT)/test_core_extern.skel.h $(BPFOBJ)
>
>  # Benchmark runner
>  $(OUTPUT)/bench_%.o: benchs/bench_%.c bench.h
> -       $(call msg,CC,,$@)
> -       $(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@
> +       $(COMPILE_C_RULE)
>  $(OUTPUT)/bench_rename.o: $(OUTPUT)/test_overhead.skel.h
>  $(OUTPUT)/bench_trigger.o: $(OUTPUT)/trigger_bench.skel.h
> -$(OUTPUT)/bench.o: bench.h testing_helpers.h
> +$(OUTPUT)/bench.o: bench.c bench.h testing_helpers.h
> +       $(COMPILE_C_RULE)
>  $(OUTPUT)/bench: LDLIBS += -lm
>  $(OUTPUT)/bench: $(OUTPUT)/bench.o $(OUTPUT)/testing_helpers.o \
>                  $(OUTPUT)/bench_count.o \
> --
> 2.26.2
>
Yauheni Kaliuta May 27, 2020, 4:54 a.m. UTC | #2
Hi, Andrii!

>>>>> On Tue, 26 May 2020 15:13:36 -0700, Andrii Nakryiko  wrote:

 > On Thu, May 21, 2020 at 9:14 PM Yauheni Kaliuta
 > <yauheni.kaliuta@redhat.com> wrote:
 >> 
 >> bench.o is produced by implicit rule only if it's built in the same
 >> directory where bench.c is located. If OUTPUT points somewhere else,
 >> build fails.
 >> 
 >> Make an explicit rule for it (factor out common part).
 >> Add bench.c as a dependency to make it source for CC.

 > If that's the case, then the similar problem would happen to
 > test_l4lb_noinline.o, test_xdp_noinline.o, and
 > flow_dissector_load.o, at least. Let's fix the implicit rule
 > (or define our own, but generic one), instead of ad-hoc fixing
 > it for bench.o only.

I'll check why they did not cause problems.


 >> 
 >> Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
 >> ---
 >> tools/testing/selftests/bpf/Makefile | 11 ++++++++---
 >> 1 file changed, 8 insertions(+), 3 deletions(-)
 >> 
 >> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
 >> index 09700db35c2d..f0b7d41ed6dd 100644
 >> --- a/tools/testing/selftests/bpf/Makefile
 >> +++ b/tools/testing/selftests/bpf/Makefile
 >> @@ -243,6 +243,11 @@ define GCC_BPF_BUILD_RULE
 >> $(BPF_GCC) $3 $4 -O2 -c $1 -o $2
 >> endef
 >> 
 >> +define COMPILE_C_RULE
 >> +       $(call msg,CC,,$@)
 >> +       $(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@
 >> +endef
 >> +
 >> SKEL_BLACKLIST := btf__% test_pinning_invalid.c test_sk_assign.c
 >> 
 >> # Set up extra TRUNNER_XXX "temporary" variables in the environment (relies on
 >> @@ -409,11 +414,11 @@ $(OUTPUT)/test_cpp: test_cpp.cpp $(OUTPUT)/test_core_extern.skel.h $(BPFOBJ)
 >> 
 >> # Benchmark runner
 >> $(OUTPUT)/bench_%.o: benchs/bench_%.c bench.h
 >> -       $(call msg,CC,,$@)
 >> -       $(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@
 >> +       $(COMPILE_C_RULE)
 >> $(OUTPUT)/bench_rename.o: $(OUTPUT)/test_overhead.skel.h
 >> $(OUTPUT)/bench_trigger.o: $(OUTPUT)/trigger_bench.skel.h
 >> -$(OUTPUT)/bench.o: bench.h testing_helpers.h
 >> +$(OUTPUT)/bench.o: bench.c bench.h testing_helpers.h
 >> +       $(COMPILE_C_RULE)
 >> $(OUTPUT)/bench: LDLIBS += -lm
 >> $(OUTPUT)/bench: $(OUTPUT)/bench.o $(OUTPUT)/testing_helpers.o \
 >> $(OUTPUT)/bench_count.o \
 >> --
 >> 2.26.2
 >>
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 09700db35c2d..f0b7d41ed6dd 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -243,6 +243,11 @@  define GCC_BPF_BUILD_RULE
 	$(BPF_GCC) $3 $4 -O2 -c $1 -o $2
 endef
 
+define COMPILE_C_RULE
+	$(call msg,CC,,$@)
+	$(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@
+endef
+
 SKEL_BLACKLIST := btf__% test_pinning_invalid.c test_sk_assign.c
 
 # Set up extra TRUNNER_XXX "temporary" variables in the environment (relies on
@@ -409,11 +414,11 @@  $(OUTPUT)/test_cpp: test_cpp.cpp $(OUTPUT)/test_core_extern.skel.h $(BPFOBJ)
 
 # Benchmark runner
 $(OUTPUT)/bench_%.o: benchs/bench_%.c bench.h
-	$(call msg,CC,,$@)
-	$(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@
+	$(COMPILE_C_RULE)
 $(OUTPUT)/bench_rename.o: $(OUTPUT)/test_overhead.skel.h
 $(OUTPUT)/bench_trigger.o: $(OUTPUT)/trigger_bench.skel.h
-$(OUTPUT)/bench.o: bench.h testing_helpers.h
+$(OUTPUT)/bench.o: bench.c bench.h testing_helpers.h
+	$(COMPILE_C_RULE)
 $(OUTPUT)/bench: LDLIBS += -lm
 $(OUTPUT)/bench: $(OUTPUT)/bench.o $(OUTPUT)/testing_helpers.o \
 		 $(OUTPUT)/bench_count.o \