[PATCH] kbuild: avoid recursive make headers when HEADER_ARCH is set
From: HONG Yifan
Date: Fri Dec 04 2026 - 18:21:40 EST
When HEADER_ARCH is set (ARCH=um), the headers target spawns a recursive
$(MAKE) -f $(srctree)/Makefile HEADER_ARCH= SRCARCH=$(HEADER_ARCH) headers.
This re-runs $(version_h), scripts_unifdef, uapi-asm-generic, and
archheaders a second time.
Because headers is in no-dot-config-targets, the recursive sub-make skips
include/config/auto.conf and drops CONFIG_WERROR flags (-Werror and
-Wl,--fatal-warnings) from KBUILD_HOSTCFLAGS and KBUILD_HOSTLDFLAGS,
causing scripts/unifdef to be recompiled on every prepare build with
CONFIG_HEADERS_INSTALL=y and CONFIG_WERROR=y. During parallel builds, the
recursive $(build)=scripts scripts/unifdef also races with the scripts
target even when scripts depends on the outer scripts_unifdef.
arch/um/Makefile's archheaders target already invokes
ARCH=$(HEADER_ARCH) asm-generic archheaders, generating the required
arch/$(HEADER_ARCH)/include/generated/uapi/ headers. Invoke $(hdr-inst)
directly for include/uapi (passing SRCARCH for include/uapi/Kbuild) and
arch/$(or $(HEADER_ARCH),$(SRCARCH))/include/uapi instead of recursing
into top-level headers.
Investigation, verification, and patch drafting were assisted by Gemini.
Fixes: 268d191abc57 ("kbuild: implement CONFIG_HEADERS_INSTALL for Usermode Linux")
Cc: stable@xxxxxxxxxxxxxxx
Link: https://lore.kernel.org/r/CAABy=s2iGODbNUdjYFd3MHLsTWsoN3_L5=v4aTX_wW4C3n1_Rg@xxxxxxxxxxxxxx
Signed-off-by: HONG Yifan <elsk@xxxxxxxxxx>
---
Makefile | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/Makefile b/Makefile
index 5aac6f1b011e..d990a19e7839 100644
--- a/Makefile
+++ b/Makefile
@@ -1509,12 +1509,8 @@ hdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj
PHONY += headers
headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders
-ifdef HEADER_ARCH
- $(Q)$(MAKE) -f $(srctree)/Makefile HEADER_ARCH= SRCARCH=$(HEADER_ARCH) headers
-else
- $(Q)$(MAKE) $(hdr-inst)=include/uapi
- $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi
-endif
+ $(Q)$(MAKE) $(hdr-inst)=include/uapi SRCARCH=$(or $(HEADER_ARCH),$(SRCARCH))
+ $(Q)$(MAKE) $(hdr-inst)=arch/$(or $(HEADER_ARCH),$(SRCARCH))/include/uapi
ifdef CONFIG_HEADERS_INSTALL
prepare: headers
base-commit: 63fdb511c27afcebce797e3db580b3534ddfa639
--
2.56.1.915.g69d5ec7298-goog