selftests: lib.mk: define LINK.c, COMPILE.S and LINK.S when make has none
PATCH 1/1 selftests: lib.mk: define LINK.c, COMPILE.S and LINK.S when make has none
The kernel build runs make with -rR, which removes make's built-in rules and variables. tools/testing/selftests/Makefile copes by clearing MAKEFLAGS for its sub-makes, and lib.mk defines LINK.c, COMPILE.S and LINK.S again, but only when building_out_of_srctree is set. A selftest directory built directly by a make that inherited -R gets neither, so LINK.c is empty and the generic rule tries to execute the source file:
make[4]: acct_syscall.c: No such file or directory
Define them whenever make does not provide them, as make itself defines them, so that they are the same with and without -R. The definitions lib.mk used for O= builds until now differed from make's only in using TARGET_ARCH instead of TARGET_MACH for assembly, which no selftest sets.
--- tools/testing/selftests/lib.mk | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
tools/testing/selftests/lib.mk +5 -8
@@ -207,14 +207,11 @@ CFLAGS += -I${top_srcdir}/tools/testing/selftests CFLAGS += $(USERCFLAGS) LDFLAGS += $(USERLDFLAGS) -# When make O= with kselftest target from main level -# the following aren't defined. -# -ifdef building_out_of_srctree -LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) -COMPILE.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -LINK.S = $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) -endif +# Make's built-in variables are not defined when run with -R, which kbuild +# passes down when a test is built from the main level. +LINK.c ?= $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) +COMPILE.S ?= $(CC) $(ASFLAGS) $(CPPFLAGS) $(TARGET_MACH) -c +LINK.S ?= $(CC) $(ASFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_MACH) # Selftest makefiles can override those targets by setting # OVERRIDE_TARGETS = 1.
Signature · 1 line
2.53.0
Quoted 8 lines · Sasha Levin
The kernel build runs make with -rR, which removes make's built-in rules and variables.
tools/testing/selftests/Makefilecopes by clearing MAKEFLAGS for its sub-makes, and lib.mk definesLINK.c,COMPILE.SandLINK.Sagain, but only whenbuilding_out_of_srctreeis set. A selftest directory built directly by a make that inherited -R gets neither, soLINK.cis empty and the generic rule tries to execute the source file:make[4]:
acct_syscall.c: No such file or directory
Hi Shuah,
Ping on this one. It still applies to v7.4-rc1.
The tools_build series [1] depends on it: without it, 70 of the 74 selftests the series builds fail this way. Could you pick it up for 7.5, or ack it so it can go through kbuild with the next version of the series?
[1] https://lore.kernel.org/r/[email protected]
Signature · 2 lines
Thanks, Sasha