From 6784e53c14ff99d53c219c835ab73c272e8a10e2 Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Tue, 2 Sep 2025 10:51:10 +1000 Subject: [PATCH 1/2] lkl: fix hijack and zpoline parallel builds This is a follow up change for commit 3c97822a40cb1 ("lkl: add tests build barrier") tracked via https://github.com/lkl/linux/issues/558. The hijack and zpoline libraries also share object files, so need extra logic to avoid parallel build failures. Add a new intermediate libhijack-priv-in.o prerequisite for the hijack libraries, avoiding the .WAIT target which breaks make libraries_install on older (e.g. 4.2.1) versions of make. The existing liblkl$(SOSUF) target is currently unmatched, so fix it and use it as a linker target which omits libhijack-priv-in.o. Signed-off-by: David Disseldorp --- tools/lkl/Makefile | 9 +++++---- tools/lkl/Targets | 1 + tools/lkl/lib/hijack/Build | 13 +++++-------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/tools/lkl/Makefile b/tools/lkl/Makefile index 9ca22b7605e3ad..1946fac364be66 100644 --- a/tools/lkl/Makefile +++ b/tools/lkl/Makefile @@ -87,13 +87,15 @@ $(OUTPUT)lib/lkl.o: bin/stat $(DOT_CONFIG) $(MAKE) -C ../.. ARCH=lkl $(KOPT) $(MAKE) -C ../.. ARCH=lkl $(KOPT) install INSTALL_PATH=$(OUTPUT) -# rules to link libs +# rules to link hijack libs $(OUTPUT)%$(SOSUF): LDFLAGS += -shared -$(OUTPUT)%$(SOSUF): $(OUTPUT)%-in.o $(OUTPUT)liblkl.a +$(OUTPUT)%$(SOSUF): $(priv-libs-y:%=$(OUTPUT)%-in.o) $(OUTPUT)%-in.o $(OUTPUT)liblkl.a $(QUIET_LINK)$(CC) $(LDFLAGS) $(LDFLAGS_$*-y) -o $@ $^ $(LDLIBS) $(LDLIBS_$*-y) # liblkl is special -$(OUTPUT)liblkl$(SOSUF): $(OUTPUT)%-in.o $(OUTPUT)lib/lkl.o +$(OUTPUT)lib/liblkl$(SOSUF): $(OUTPUT)lib/liblkl-in.o $(OUTPUT)lib/lkl.o + $(QUIET_LINK)$(CC) $(LDFLAGS) $(LDFLAGS_$*-y) -o $@ $^ $(LDLIBS) $(LDLIBS_$*-y) + $(OUTPUT)liblkl.a: $(OUTPUT)lib/liblkl-in.o $(OUTPUT)lib/lkl.o $(QUIET_AR)$(AR) -rc $@ $^ @@ -105,7 +107,6 @@ $(OUTPUT)%$(EXESUF): $(OUTPUT)%-in.o $(OUTPUT)liblkl.a $(OUTPUT)%-in.o: $(OUTPUT)lib/lkl.o FORCE $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(patsubst %/,%,$(dir $*)) obj=$(notdir $*) - $(OUTPUT)cpfromfs$(EXESUF): cptofs$(EXESUF) $(Q)if ! [ -e $@ ]; then ln -s $< $@; fi diff --git a/tools/lkl/Targets b/tools/lkl/Targets index 3d30bd8be3c840..7974d57b4ac88a 100644 --- a/tools/lkl/Targets +++ b/tools/lkl/Targets @@ -1,6 +1,7 @@ libs-y += lib/liblkl ifneq ($(LKL_HOST_CONFIG_BSD),y) +priv-libs-$(LKL_HOST_CONFIG_POSIX) += lib/hijack/libhijack-priv libs-$(LKL_HOST_CONFIG_POSIX) += lib/hijack/liblkl-hijack libs-$(LKL_HOST_CONFIG_POSIX) += lib/hijack/liblkl-zpoline endif diff --git a/tools/lkl/lib/hijack/Build b/tools/lkl/lib/hijack/Build index b42239e47d8e78..64f61db29882c0 100644 --- a/tools/lkl/lib/hijack/Build +++ b/tools/lkl/lib/hijack/Build @@ -1,14 +1,11 @@ +libhijack-priv-y += hijack.o +libhijack-priv-y += init.o +libhijack-priv-y += xlate.o +libhijack-priv-y += dbg_handler.o + liblkl-hijack-y += preload.o -liblkl-hijack-y += hijack.o -liblkl-hijack-y += init.o -liblkl-hijack-y += xlate.o -liblkl-hijack-y += dbg_handler.o liblkl-zpoline-y += zpoline.o -liblkl-zpoline-y += hijack.o -liblkl-zpoline-y += init.o -liblkl-zpoline-y += xlate.o -liblkl-zpoline-y += dbg_handler.o # -std=gnu23/c23 fails due to HOST_CALL (*host_##name)() CFLAGS_hijack.o += -std=gnu11 From 6d360d164e5d57ec0539b20c372fc7184959eef5 Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Wed, 3 Sep 2025 16:37:29 +1000 Subject: [PATCH 2/2] lkl: link tests against common private library This effectively reverts commit 3c97822a40cb1 ("lkl: add tests build barrier"), replacing the tests .WAIT barrier with a common-object prerequisite to keep parallel builds working. Prerequisites are preferable to explicit .WAIT barriers, as they better allow for build concurrency and also avoid install target breakage described in the previous commit. One minor drawback is that some of the test binaries don't use any cla.o symbols, but get linked nevertheless. E.g. Before: text data bss dec hex filename 7878818 4851995 885880 13616693 cfc635 tools/lkl/tests/boot After: text data bss dec hex filename 7880494 4852094 885856 13618444 cfcd0c tools/lkl/tests/boot I don't see it as a problem, but if it is then we could split up the prerequisites. Signed-off-by: David Disseldorp --- tools/lkl/Makefile | 18 +++++++----------- tools/lkl/Targets | 7 +++---- tools/lkl/tests/Build | 13 +++++++------ 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/tools/lkl/Makefile b/tools/lkl/Makefile index 1946fac364be66..2929944d77b3bf 100644 --- a/tools/lkl/Makefile +++ b/tools/lkl/Makefile @@ -52,15 +52,9 @@ export CFLAGS += -I$(OUTPUT)/include -Iinclude -Wall -g -O2 -Wextra \ include Targets -# Expand targets to output location and suffix but preserve special -# targets (e.g. .WAIT) -# $1 - targets -# $2 - suffix -expand-targets = $(foreach t,$(1),$(if $(filter .%,$(t)),$(t),$(OUTPUT)$(t)$(2))) - -TARGETS := $(call expand-targets,$(progs-y),$(EXESUF)) -TARGETS += $(call expand-targets,$(tests-y),$(EXESUF)) -TARGETS += $(call expand-targets,$(libs-y),$(SOSUF)) +TARGETS := $(progs-y:%=$(OUTPUT)%$(EXESUF)) +TARGETS := $(tests-y:%=$(OUTPUT)%$(EXESUF)) +TARGETS += $(libs-y:%=$(OUTPUT)%$(SOSUF)) all: $(TARGETS) # this workaround is for FreeBSD @@ -103,6 +97,9 @@ $(OUTPUT)liblkl.a: $(OUTPUT)lib/liblkl-in.o $(OUTPUT)lib/lkl.o $(OUTPUT)%$(EXESUF): $(OUTPUT)%-in.o $(OUTPUT)liblkl.a $(QUIET_LINK)$(CC) $(LDFLAGS) $(LDFLAGS_$*-y) -o $@ $^ $(LDLIBS) $(LDLIBS_$*-y) +# tests use a common private lib +$(tests-y:%=$(OUTPUT)%$(EXESUF)): $(tests-priv-y:%=$(OUTPUT)%-in.o) + # rule to build objects $(OUTPUT)%-in.o: $(OUTPUT)lib/lkl.o FORCE $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(patsubst %/,%,$(dir $*)) obj=$(notdir $*) @@ -182,7 +179,7 @@ libraries_install: $(libs-y:%=$(OUTPUT)%$(SOSUF)) $(OUTPUT)liblkl.a install -d $(DESTDIR)$(LIBDIR) ; \ install -m 644 $^ $(DESTDIR)$(LIBDIR) -programs_install: $(call expand-targets,$(progs-y),$(EXESUF)) +programs_install: $(progs-y:%=$(OUTPUT)%$(EXESUF)) $(call QUIET_INSTALL, programs) \ install -d $(DESTDIR)$(BINDIR) ; \ install -m 755 $^ $(DESTDIR)$(BINDIR) @@ -198,4 +195,3 @@ FORCE: ; .PHONY: headers_install libraries_install programs_install install .NOTPARALLEL : lib/lkl.o .SECONDARY: -.WAIT: diff --git a/tools/lkl/Targets b/tools/lkl/Targets index 7974d57b4ac88a..741462c8dd21f1 100644 --- a/tools/lkl/Targets +++ b/tools/lkl/Targets @@ -27,11 +27,10 @@ LDLIBS_cptofs-y := -larchive LDLIBS_cptofs-$(LKL_HOST_CONFIG_NEEDS_LARGP) += -largp # tools/build/Makefile.build does not support parallel builds when -# objects are shared between build objects so keep the test that uses -# the most common object first and insert a build barrier to avoid -# rebuilding common objects +# objects are shared between build objects so use tests-common-in.o +# as a tests build prerequisite which gets linked into each binary. +tests-priv-y := tests/tests-common tests-y := tests/disk -tests-y += .WAIT tests-y += tests/boot tests-y += tests/disk-vfio-pci tests-y += tests/net-test diff --git a/tools/lkl/tests/Build b/tools/lkl/tests/Build index b156f780ae402e..8e8245c3af4633 100644 --- a/tools/lkl/tests/Build +++ b/tools/lkl/tests/Build @@ -1,6 +1,7 @@ -boot-y += boot.o test.o -disk-y += disk.o cla.o test.o -disk-vfio-pci-y += disk-vfio-pci.o cla.o test.o -net-test-y += net-test.o cla.o test.o -config-y += config.o test.o -test-dlmopen-y += test-dlmopen.o test.o +tests-common-y += cla.o test.o +boot-y += boot.o +disk-y += disk.o +disk-vfio-pci-y += disk-vfio-pci.o +net-test-y += net-test.o +config-y += config.o +test-dlmopen-y += test-dlmopen.o