kbuild: serialize scripts after scripts_unifdef
Subsystems (2)
PATCH 1/1 kbuild: serialize scripts after scripts_unifdef
When CONFIG_HEADERS_INSTALL is enabled, the prepare target depends on both prepare0 -> archprepare -> scripts and headers -> scripts_unifdef with no ordering between scripts and scripts_unifdef. Both targets invoke $(MAKE) $(build)=scripts concurrently:
scripts: $(MAKE) $(build)=scripts scripts_unifdef: $(MAKE) $(build)=scripts scripts/unifdef
Because scripts/Makefile lists unifdef in hostprogs, scripts/Makefile.host adds scripts/unifdef to targets, causing scripts/Makefile.build to include scripts/.unifdef.cmd as soon as scripts/unifdef exists. If scripts reads scripts/.unifdef.cmd while scripts_unifdef is still writing it via fixdep, make aborts with:
scripts/.unifdef.cmd:1: *** missing separator. Stop. make[2]: *** [Makefile:1400: scripts] Error 2
Make scripts depend on scripts_unifdef under CONFIG_HEADERS_INSTALL so scripts_unifdef finishes before scripts enters scripts/. Keeping the dependency under CONFIG_HEADERS_INSTALL avoids building scripts/unifdef when it is not needed and preserves "make headers" without a .config.
Bug triage, instrumented reproduction, and patch drafting were assisted by Gemini.
--- Makefile | 1 + 1 file changed, 1 insertion(+)
Makefile +1 -0
@@ -1518,6 +1518,7 @@ endif ifdef CONFIG_HEADERS_INSTALL prepare: headers +scripts: scripts_unifdef endif PHONY += scripts_gen_init_cpio
base-commit: 63fdb511c27afcebce797e3db580b3534ddfa639
Signature · 1 line
2.56.1.915.g69d5ec7298-goog
Quoted 25 lines · HONG Yifan
When
CONFIG_HEADERS_INSTALLis enabled, the prepare target depends on both prepare0 -> archprepare -> scripts and headers ->scripts_unifdefwith no ordering between scripts andscripts_unifdef. Both targets invoke $(MAKE) $(build)=scripts concurrently:scripts: $(MAKE) $(build)=scripts scripts_unifdef: $(MAKE) $(build)=scripts scripts/unifdefBecause
scripts/Makefilelists unifdef in hostprogs,scripts/Makefile.hostaddsscripts/unifdefto targets, causingscripts/Makefile.buildto includescripts/.unifdef.cmdas soon asscripts/unifdefexists. If scripts readsscripts/.unifdef.cmdwhilescripts_unifdefis still writing it via fixdep, make aborts with:
scripts/.unifdef.cmd:1: *** missing separator. Stop. make[2]: *** [Makefile:1400: scripts] Error 2Make scripts depend on
scripts_unifdefunderCONFIG_HEADERS_INSTALLsoscripts_unifdeffinishes before scripts entersscripts/. Keeping the dependency underCONFIG_HEADERS_INSTALLavoids buildingscripts/unifdefwhen it is not needed and preserves "make headers" without a .config.Bug triage, instrumented reproduction, and patch drafting were assisted by Gemini.
Quoted 7 lines
Fixes e949f4c2d6a3 ("kbuild: add CONFIG_HEADERS_INSTALL and loosen the dependency of samples")Signed-off-by HONG Yifan <[email protected]>--- Makefile | 1 + 1 file changed, 1 insertion(+)
Signature · 1 line
Nicolas
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] kbuild: scripts and recursive scripts_unifdef still race on ARCH=um --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] kbuild: scripts and recursive scripts_unifdef still race on ARCH=um
--
commit 4bf37da0ae8b1fb30389763a88c140890a30608d
Author: HONG Yifan <[email protected]>
kbuild: serialize scripts after scripts_unifdef
This commit adds scripts_unifdef as a prerequisite of scripts under CONFIG_HEADERS_INSTALL to serialize the two targets during parallel builds.
Makefile endif · line 1524
Quoted 12 lines
Makefile +1
-0@@ -1518,6 +1518,7 @@ endif ifdef CONFIG_HEADERS_INSTALL prepare: headers +scripts: scripts_unifdef endif PHONY += scripts_gen_init_cpio
[Severity: Medium]
Can scripts still race with scripts_unifdef on ARCH=um?
Adding scripts: scripts_unifdef orders scripts after the outer scripts_unifdef, but not after headers. On ARCH=um with CONFIG_HEADERS_INSTALL=y, arch/um/Makefile defines HEADER_ARCH, so headers spawns a recursive make headers that runs scripts_unifdef again:
scripts headers
$(MAKE) $(build)=scripts $(MAKE) ... SRCARCH=$(HEADER_ARCH) headers
scripts_unifdef
$(MAKE) $(build)=scripts scripts/unifdef cmd_and_fixdep writes -include scripts/.*.cmd
scripts/.*.cmd <-- missing separator
Both $(build)=scripts invocations include .cmd files for all existing hostprogs in scripts/ via scripts/Makefile.build, while cmd_and_fixdep writes them non-atomically via shell redirection. The recursive scripts_unifdef can read a partial .cmd file and fail with missing separator.
With CONFIG_WERROR=y (such as ARCH=um allmodconfig), the recursive headers sub-make skips auto.conf and drops -Werror and -Wl,--fatal-warnings, so recursive scripts_unifdef also recompiles scripts/unifdef and rewrites scripts/.unifdef.cmd concurrently with scripts.
Ordering scripts after headers under CONFIG_HEADERS_INSTALL would serialize both invocations.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 26 lines · On Fri, Dec 4, 2026 at 11:18 AM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] kbuild: scripts and recursivescripts_unifdefstill race on ARCH=um
--commit
4bf37da0ae8b1fb30389763a88c140890a30608d
Author: HONG Yifan <[email protected]>kbuild: serialize scripts after
scripts_unifdefThis commit adds
scripts_unifdefas a prerequisite of scripts underCONFIG_HEADERS_INSTALLto serialize the two targets during parallel builds.Quoted 11 lines
Makefile +1
-0@@ -1518,6 +1518,7 @@ endif ifdef CONFIG_HEADERS_INSTALL prepare: headers +scripts: scripts_unifdef endif
Quoted 4 lines
Makefile endif · line 1524
Quoted 1 line
Makefile +0
-0PHONY += scripts_gen_init_cpio[Severity: Medium]
Can scripts still race withscripts_unifdefon ARCH=um?
Short answer: yes.
Quoted 18 lines
Adding scripts:
scripts_unifdeforders scripts after the outerscripts_unifdef, but not after headers. On ARCH=um withCONFIG_HEADERS_INSTALL=y,arch/um/MakefiledefinesHEADER_ARCH, so headers spawns a recursive make headers that runsscripts_unifdefagain:scripts headers
$(MAKE) $(build)=scripts $(MAKE) ... SRCARCH=$(HEADER_ARCH) headersscripts_unifdef $(MAKE) $(build)=scripts scripts/unifdef
cmd_and_fixdepwrites -includescripts/.*.cmd
scripts/.*.cmd<-- missing separatorBoth $(build)=scripts invocations include .cmd files for all existing hostprogs in
scripts/viascripts/Makefile.build, whilecmd_and_fixdepwrites them non-atomically via shell redirection. The recursivescripts_unifdefcan read a partial .cmd file and fail with missing separator.
Quoted 7 lines
With
CONFIG_WERROR=y(such as ARCH=um allmodconfig), the recursive headers sub-make skips auto.conf and drops -Werror and -Wl,--fatal-warnings, so recursivescripts_unifdefalso recompilesscripts/unifdefand rewritesscripts/.unifdef.cmdconcurrently with scripts.Ordering scripts after headers under
CONFIG_HEADERS_INSTALLwould serialize both invocations.
Problems with ordering scripts: headers:
- It serializes scripts behind installing ~1,000 UAPI headers on all architectures when CONFIG_HEADERS_INSTALL=y.
- Running make scripts standalone with CONFIG_HEADERS_INSTALL=y would install UAPI headers.
- It leaves the redundant recursive make headers on ARCH=um (and the CONFIG_WERROR scripts/unifdef recompile) unfixed.
IMHO a cleaner fix for ARCH=um is to stop headers from recursing into top-level headers when HEADER_ARCH is set, and invoke $(hdr-inst) directly with SRCARCH=$(or $(HEADER_ARCH),$(SRCARCH)) (since arch/um/Makefile's archheaders already generates the HEADER_ARCH UAPI headers).
I will send that as an independent patch targeting commit 268d191abc57 ("kbuild: implement CONFIG_HEADERS_INSTALL for Usermode Linux"), and keep this patch standalone for e949f4c2d6a3 for non-UM architectures.
Quoted 3 lines
--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1