[PATCH] selftests/rseq: Fix circular dependencies in Makefile

Mahad Ibrahim <[email protected]>
Newsgroups org.kernel.vger.linux-kernel,org.kernel.vger.linux-kselftest
Message-ID <[email protected]>
TEST_GEN_PROGS_EXTENDED lists the binaries which are to be built but not
run. However it is also listed as prerequisite for every generated binary
to link against; all binaries only require librseq.so.

This results in the following warnings:

  make: Circular .../rseq/check_optimized <- .../rseq/check_optimized dependency dropped.

Such warnings are emitted 36 times in in-tree and out-of-tree builds.

Additionally, the generation of a single binary pulls in all of
TEST_GEN_PROGS_EXTENDED as they are listed as prerequisites for each
other. However since Make drops all the prerequisites which form a cycle,
the build succeeds, but results in unintended behavior. For example
building a single binary like check_optimized compiles 9 binaries while
only 2 are required.

Fix circular dependencies and unnecessary compilation of binaries in rseq
Makefile by isolating librseq.so and headers into a single variable which
is added as the prerequisite.

No warnings are emitted after the change, and building a single binary
only compiles that binary and librseq.so. Verified in-tree and with
OUTPUT= set to a separate directory.

Fixes: cb48828f06af ("selftests/rseq: Don't run tests with runner scripts outside of the scripts")
Signed-off-by: Mahad Ibrahim <[email protected]>
---
 tools/testing/selftests/rseq/Makefile | 28 ++++++++++++---------------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/tools/testing/selftests/rseq/Makefile b/tools/testing/selftests/rseq/Makefile
index aba6317f6cb8..9c369e59bb2d 100644
--- a/tools/testing/selftests/rseq/Makefile
+++ b/tools/testing/selftests/rseq/Makefile
@@ -37,41 +37,37 @@ TEST_FILES := settings
 
 include ../lib.mk
 
+RSEQ_DEPS := $(OUTPUT)/librseq.so rseq.h rseq-*.h
+
 $(OUTPUT)/librseq.so: rseq.c rseq.h rseq-*.h
 	$(CC) $(CFLAGS) -shared -fPIC $< $(LDLIBS) -o $@
 
-$(OUTPUT)/%: %.c $(TEST_GEN_PROGS_EXTENDED) rseq.h rseq-*.h
+$(OUTPUT)/%: %.c $(RSEQ_DEPS)
 	$(CC) $(CFLAGS) $< $(LDLIBS) -lrseq -o $@
 
-$(OUTPUT)/basic_percpu_ops_mm_cid_test: basic_percpu_ops_test.c $(TEST_GEN_PROGS_EXTENDED) rseq.h rseq-*.h
+$(OUTPUT)/basic_percpu_ops_mm_cid_test: basic_percpu_ops_test.c $(RSEQ_DEPS)
 	$(CC) $(CFLAGS) -DBUILDOPT_RSEQ_PERCPU_MM_CID $< $(LDLIBS) -lrseq -o $@
 
-$(OUTPUT)/param_test_benchmark: param_test.c $(TEST_GEN_PROGS_EXTENDED) \
-					rseq.h rseq-*.h
+$(OUTPUT)/param_test_benchmark: param_test.c $(RSEQ_DEPS)
 	$(CC) $(CFLAGS) -DBENCHMARK $< $(LDLIBS) -lrseq -o $@
 
-$(OUTPUT)/param_test_compare_twice: param_test.c $(TEST_GEN_PROGS_EXTENDED) \
-					rseq.h rseq-*.h
+$(OUTPUT)/param_test_compare_twice: param_test.c $(RSEQ_DEPS)
 	$(CC) $(CFLAGS) -DRSEQ_COMPARE_TWICE $< $(LDLIBS) -lrseq -o $@
 
-$(OUTPUT)/param_test_mm_cid: param_test.c $(TEST_GEN_PROGS_EXTENDED) \
-					rseq.h rseq-*.h
+$(OUTPUT)/param_test_mm_cid: param_test.c $(RSEQ_DEPS)
 	$(CC) $(CFLAGS) -DBUILDOPT_RSEQ_PERCPU_MM_CID $< $(LDLIBS) -lrseq -o $@
 
-$(OUTPUT)/param_test_mm_cid_benchmark: param_test.c $(TEST_GEN_PROGS_EXTENDED) \
-					rseq.h rseq-*.h
+$(OUTPUT)/param_test_mm_cid_benchmark: param_test.c $(RSEQ_DEPS)
 	$(CC) $(CFLAGS) -DBUILDOPT_RSEQ_PERCPU_MM_CID -DBENCHMARK $< $(LDLIBS) -lrseq -o $@
 
-$(OUTPUT)/param_test_mm_cid_compare_twice: param_test.c $(TEST_GEN_PROGS_EXTENDED) \
-					rseq.h rseq-*.h
+$(OUTPUT)/param_test_mm_cid_compare_twice: param_test.c $(RSEQ_DEPS)
 	$(CC) $(CFLAGS) -DBUILDOPT_RSEQ_PERCPU_MM_CID -DRSEQ_COMPARE_TWICE $< $(LDLIBS) -lrseq -o $@
 
-$(OUTPUT)/syscall_errors_test: syscall_errors_test.c $(TEST_GEN_PROGS_EXTENDED) \
-					rseq.h rseq-*.h
+$(OUTPUT)/syscall_errors_test: syscall_errors_test.c $(RSEQ_DEPS)
 	$(CC) $(CFLAGS) $< $(LDLIBS) -lrseq -o $@
 
-$(OUTPUT)/slice_test: slice_test.c $(TEST_GEN_PROGS_EXTENDED) rseq.h rseq-*.h
+$(OUTPUT)/slice_test: slice_test.c $(RSEQ_DEPS)
 	$(CC) $(CFLAGS) $< $(LDLIBS) -lrseq -o $@
 
-$(OUTPUT)/check_optimized: check_optimized.c $(TEST_GEN_PROGS_EXTENDED) rseq.h rseq-*.h
+$(OUTPUT)/check_optimized: check_optimized.c $(RSEQ_DEPS)
 	$(CC) $(CFLAGS) $< $(LDLIBS) -lrseq -o $@

base-commit: 0f23d56f17fdfc7db69d51f64c8b91bbab947aa9
-- 
2.54.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.