mirror of
https://github.com/torvalds/linux.git
synced 2026-09-14 16:10:02 +02:00
Commit2d69b891e6("kbuild: Support generated asm-headers in subdirectories") switched the stale-wrapper sweep in scripts/Makefile.asm-headers from $(wildcard $(obj)/*.h) to a find(1) invocation, so that generated headers in subdirectories are considered. The two do not match the same set of files. Make's $(wildcard) uses glob semantics, where a leading '.' has to be matched explicitly, whereas find's -name uses fnmatch() without FNM_PERIOD, so '*.h' matches dotfiles as well. filechk writes its output to $(dir $@).tmp_$(notdir $@) before renaming it into place, so such a scratch file, if it happens to exist in $(obj) when the sub-make is parsed, is now picked up in old-headers. It appears in neither generic-y, generated-y nor syscall-y, is therefore classified as unwanted, and cmd_remove deletes it. On x86 this races with archprepare, which lists both asm-generic and arch/x86/include/generated/asm/cpufeaturemasks.h as prerequisites. Under -j they run concurrently against the same directory, and the build fails intermittently: mv: cannot stat 'arch/x86/include/generated/asm/.tmp_cpufeaturemasks.h': No such file or directory make[1]: *** [arch/x86/Makefile:269: arch/x86/include/generated/asm/cpufeaturemasks.h] Error 1 The same commit also converted the generic wrapper rule to filechk, so those wrappers now create .tmp_*.h in $(obj) too and can race among themselves. Restore the previous behaviour by excluding dotfiles from the sweep. Subdirectories, which is what the find(1) conversion was for, keep being descended into. While at it, quote the -name argument: it is currently expanded by the shell against the build directory before find sees it. Fixes:2d69b891e6("kbuild: Support generated asm-headers in subdirectories") Signed-off-by: Vlad Poenaru <vlad.wing@gmail.com> Reviewed-by: Nathan Chancellor <nathan@kernel.org> Reviewed-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Reviewed-by: Nicolas Schier <n.schier@fritz.com> Link: https://patch.msgid.link/20260902161347.4163577-1-vlad.wing@gmail.com Signed-off-by: Nicolas Schier <nsc@kernel.org>
106 lines
3.4 KiB
Makefile
106 lines
3.4 KiB
Makefile
# SPDX-License-Identifier: GPL-2.0
|
|
# include/asm-generic contains a lot of files that are used
|
|
# verbatim by several architectures.
|
|
#
|
|
# This Makefile generates arch/$(SRCARCH)/include/generated/(uapi/)/asm
|
|
# headers from multiple sources:
|
|
# - a small wrapper to include the corresponding asm-generic/*.h
|
|
# is generated for each file listed as generic-y
|
|
# - uapi/asm/unistd_*.h files listed as syscalls-y are generated from
|
|
# syscall.tbl with the __NR_* macros
|
|
# - Corresponding asm/syscall_table_*.h are generated from the same input
|
|
|
|
PHONY := all
|
|
all:
|
|
|
|
src := $(srctree)/$(subst /generated,,$(obj))
|
|
|
|
syscall_abis_32 += common,32
|
|
syscall_abis_64 += common,64
|
|
syscalltbl := $(srctree)/scripts/syscall.tbl
|
|
syshdr-args := --emit-nr
|
|
|
|
# let architectures override $(syscall_abis_%) and $(syscalltbl)
|
|
-include $(srctree)/arch/$(SRCARCH)/kernel/Makefile.syscalls
|
|
include $(srctree)/scripts/Kbuild.include
|
|
-include $(kbuild-file)
|
|
|
|
syshdr := $(srctree)/scripts/syscallhdr.sh
|
|
systbl := $(srctree)/scripts/syscalltbl.sh
|
|
|
|
# $(generic)/Kbuild lists mandatory-y. Exclude um since it is a special case.
|
|
ifneq ($(SRCARCH),um)
|
|
include $(srctree)/$(generic)/Kbuild
|
|
endif
|
|
|
|
redundant := $(filter $(mandatory-y) $(generated-y), $(generic-y))
|
|
redundant += $(foreach f, $(generic-y), $(if $(wildcard $(src)/$(f)),$(f)))
|
|
redundant := $(sort $(redundant))
|
|
$(if $(redundant),\
|
|
$(warning redundant generic-y found in $(src)/Kbuild: $(redundant)))
|
|
|
|
# If arch does not implement mandatory headers, fallback to asm-generic ones.
|
|
mandatory-y := $(filter-out $(generated-y), $(mandatory-y))
|
|
generic-y += $(foreach f, $(mandatory-y), $(if $(wildcard $(src)/$(f)),,$(f)))
|
|
|
|
generic-y := $(addprefix $(obj)/, $(generic-y))
|
|
syscall-y := $(addprefix $(obj)/, $(syscall-y))
|
|
generated-y := $(addprefix $(obj)/, $(generated-y))
|
|
|
|
# Remove stale wrappers when the corresponding files are removed from generic-y
|
|
old-headers := $(shell test -d $(obj) && find $(obj) -name '*.h' ! -name '.*')
|
|
unwanted := $(filter-out $(generic-y) $(generated-y) $(syscall-y),$(old-headers))
|
|
|
|
filechk_wrap = echo "\#include <asm-generic/$*.h>"
|
|
|
|
quiet_cmd_remove = REMOVE $(unwanted)
|
|
cmd_remove = rm -f $(unwanted); find $(obj) -type d -empty -delete
|
|
|
|
quiet_cmd_syshdr = SYSHDR $@
|
|
cmd_syshdr = $(CONFIG_SHELL) $(syshdr) \
|
|
$(if $(syshdr-args-$*),$(syshdr-args-$*),$(syshdr-args)) \
|
|
$(if $(syscall_compat),--prefix "compat$*_") \
|
|
--abis $(subst $(space),$(comma),$(strip $(syscall_abis_$*))) \
|
|
$< $@
|
|
|
|
quiet_cmd_systbl = SYSTBL $@
|
|
cmd_systbl = $(CONFIG_SHELL) $(systbl) \
|
|
$(if $(systbl-args-$*),$(systbl-args-$*),$(systbl-args)) \
|
|
--abis $(subst $(space),$(comma),$(strip $(syscall_abis_$*))) \
|
|
$< $@
|
|
|
|
all: $(generic-y) $(syscall-y)
|
|
$(if $(unwanted),$(call cmd,remove))
|
|
@:
|
|
|
|
$(obj)/%.h: $(srctree)/$(generic)/%.h FORCE
|
|
$(call filechk,wrap)
|
|
|
|
$(obj)/unistd_%.h: $(syscalltbl) $(syshdr) FORCE
|
|
$(call if_changed,syshdr)
|
|
|
|
$(obj)/unistd_compat_%.h: syscall_compat:=1
|
|
$(obj)/unistd_compat_%.h: $(syscalltbl) $(syshdr) FORCE
|
|
$(call if_changed,syshdr)
|
|
|
|
$(obj)/syscall_table_%.h: $(syscalltbl) $(systbl) FORCE
|
|
$(call if_changed,systbl)
|
|
|
|
targets := $(syscall-y)
|
|
|
|
# Create output directory. Skip it if at least one old header exists
|
|
# since we know the output directory already exists.
|
|
ifeq ($(old-headers),)
|
|
$(shell mkdir -p $(obj))
|
|
endif
|
|
|
|
PHONY += FORCE
|
|
|
|
FORCE:
|
|
|
|
existing-targets := $(wildcard $(sort $(targets)))
|
|
|
|
-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
|
|
|
|
.PHONY: $(PHONY)
|