mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-04-18 10:23:08 +02:00
03a072e0fb
[ Upstream commitfdb12c8a24] The difference between 'make clean' and 'make mrproper' is documented in 'make help' as: clean - Remove most generated files but keep the config and enough build support to build external modules mrproper - Remove all generated files + config + various backup files After commit68b4fe32d7("kbuild: Add objtool to top-level clean target"), running 'make clean' then attempting to build an external module with the resulting build directory fails with $ make ARCH=x86_64 O=build clean $ make -C build M=... MO=... ... /bin/sh: line 1: .../build/tools/objtool/objtool: No such file or directory as 'make clean' removes the objtool binary. Split the objtool clean target into mrproper and clean like Kbuild does and remove all generated artifacts with 'make clean' except for the objtool binary, which is removed with 'make mrproper'. To avoid a small race when running the objtool clean target through both objtool_mrproper and objtool_clean when running 'make mrproper', modify objtool's clean up find command to avoid using find's '-delete' command by piping the files into 'xargs rm -f' like the rest of Kbuild does. Cc: stable@vger.kernel.org Fixes:68b4fe32d7("kbuild: Add objtool to top-level clean target") Reported-by: Michal Suchanek <msuchanek@suse.de> Closes: https://lore.kernel.org/20260225112633.6123-1-msuchanek@suse.de/ Reported-by: Rainer Fiebig <jrf@mailbox.org> Closes: https://lore.kernel.org/62d12399-76e5-3d40-126a-7490b4795b17@mailbox.org/ Acked-by: Josh Poimboeuf <jpoimboe@kernel.org> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Nicolas Schier <nsc@kernel.org> Tested-by: Nicolas Schier <nsc@kernel.org> Link: https://patch.msgid.link/20260227-avoid-objtool-binary-removal-clean-v1-1-122f3e55eae9@kernel.org Signed-off-by: Nathan Chancellor <nathan@kernel.org> [ Context ] Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
103 lines
2.8 KiB
Makefile
103 lines
2.8 KiB
Makefile
# SPDX-License-Identifier: GPL-2.0
|
|
include ../scripts/Makefile.include
|
|
include ../scripts/Makefile.arch
|
|
|
|
ifeq ($(srctree),)
|
|
srctree := $(patsubst %/,%,$(dir $(CURDIR)))
|
|
srctree := $(patsubst %/,%,$(dir $(srctree)))
|
|
endif
|
|
|
|
RM ?= rm -f
|
|
|
|
LIBSUBCMD_DIR = $(srctree)/tools/lib/subcmd/
|
|
ifneq ($(OUTPUT),)
|
|
LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd
|
|
else
|
|
LIBSUBCMD_OUTPUT = $(CURDIR)/libsubcmd
|
|
endif
|
|
LIBSUBCMD = $(LIBSUBCMD_OUTPUT)/libsubcmd.a
|
|
|
|
OBJTOOL := $(OUTPUT)objtool
|
|
OBJTOOL_IN := $(OBJTOOL)-in.o
|
|
|
|
LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null)
|
|
LIBELF_LIBS := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf)
|
|
|
|
all: $(OBJTOOL)
|
|
|
|
INCLUDES := -I$(srctree)/tools/include \
|
|
-I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \
|
|
-I$(srctree)/tools/arch/$(SRCARCH)/include \
|
|
-I$(srctree)/tools/objtool/include \
|
|
-I$(srctree)/tools/objtool/arch/$(SRCARCH)/include \
|
|
-I$(LIBSUBCMD_OUTPUT)/include
|
|
# Note, EXTRA_WARNINGS here was determined for CC and not HOSTCC, it
|
|
# is passed here to match a legacy behavior.
|
|
WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs
|
|
OBJTOOL_CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS)
|
|
OBJTOOL_LDFLAGS := $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
|
|
|
|
# Allow old libelf to be used:
|
|
elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(HOSTCC) $(OBJTOOL_CFLAGS) -x c -E - | grep elf_getshdr)
|
|
OBJTOOL_CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
|
|
|
|
# Always want host compilation.
|
|
HOST_OVERRIDES := CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)"
|
|
|
|
AWK = awk
|
|
MKDIR = mkdir
|
|
|
|
ifeq ($(V),1)
|
|
Q =
|
|
else
|
|
Q = @
|
|
endif
|
|
|
|
BUILD_ORC := n
|
|
|
|
ifeq ($(SRCARCH),x86)
|
|
BUILD_ORC := y
|
|
endif
|
|
|
|
ifeq ($(SRCARCH),loongarch)
|
|
BUILD_ORC := y
|
|
endif
|
|
|
|
export BUILD_ORC
|
|
export srctree OUTPUT CFLAGS SRCARCH AWK
|
|
include $(srctree)/tools/build/Makefile.include
|
|
|
|
$(OBJTOOL_IN): fixdep $(LIBSUBCMD) FORCE
|
|
$(Q)$(CONFIG_SHELL) ./sync-check.sh
|
|
$(Q)$(MAKE) $(build)=objtool $(HOST_OVERRIDES) CFLAGS="$(OBJTOOL_CFLAGS)" \
|
|
LDFLAGS="$(OBJTOOL_LDFLAGS)"
|
|
|
|
|
|
$(OBJTOOL): $(LIBSUBCMD) $(OBJTOOL_IN)
|
|
$(QUIET_LINK)$(HOSTCC) $(OBJTOOL_IN) $(OBJTOOL_LDFLAGS) -o $@
|
|
|
|
|
|
$(LIBSUBCMD_OUTPUT):
|
|
$(Q)$(MKDIR) -p $@
|
|
|
|
$(LIBSUBCMD): fixdep $(LIBSUBCMD_OUTPUT) FORCE
|
|
$(Q)$(MAKE) -C $(LIBSUBCMD_DIR) O=$(LIBSUBCMD_OUTPUT) \
|
|
DESTDIR=$(LIBSUBCMD_OUTPUT) prefix= subdir= \
|
|
$(HOST_OVERRIDES) EXTRA_CFLAGS="$(OBJTOOL_CFLAGS)" \
|
|
$@ install_headers
|
|
|
|
$(LIBSUBCMD)-clean:
|
|
$(call QUIET_CLEAN, libsubcmd)
|
|
$(Q)$(RM) -r -- $(LIBSUBCMD_OUTPUT)
|
|
|
|
clean: $(LIBSUBCMD)-clean
|
|
$(Q)find $(OUTPUT) \( -name '*.o' -o -name '\.*.cmd' -o -name '\.*.d' \) -type f -print | xargs $(RM)
|
|
$(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep
|
|
|
|
mrproper: clean
|
|
$(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
|
|
|
|
FORCE:
|
|
|
|
.PHONY: clean mrproper FORCE
|