mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 03:04:51 +01:00
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 commit 68b4fe32d7 ("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>
156 lines
4.8 KiB
Makefile
156 lines
4.8 KiB
Makefile
# SPDX-License-Identifier: GPL-2.0
|
|
include ../scripts/Makefile.include
|
|
include ../scripts/Makefile.arch
|
|
|
|
ifeq ($(SRCARCH),x86)
|
|
BUILD_ORC := y
|
|
ARCH_HAS_KLP := y
|
|
endif
|
|
|
|
ifeq ($(SRCARCH),loongarch)
|
|
BUILD_ORC := y
|
|
endif
|
|
|
|
ifeq ($(ARCH_HAS_KLP),y)
|
|
HAVE_XXHASH = $(shell printf "$(pound)include <xxhash.h>\nXXH3_state_t *state;int main() {}" | \
|
|
$(HOSTCC) -xc - -o /dev/null -lxxhash 2> /dev/null && echo y || echo n)
|
|
ifeq ($(HAVE_XXHASH),y)
|
|
BUILD_KLP := y
|
|
LIBXXHASH_CFLAGS := $(shell $(HOSTPKG_CONFIG) libxxhash --cflags 2>/dev/null) \
|
|
-DBUILD_KLP
|
|
LIBXXHASH_LIBS := $(shell $(HOSTPKG_CONFIG) libxxhash --libs 2>/dev/null || echo -lxxhash)
|
|
endif
|
|
endif
|
|
|
|
export BUILD_ORC BUILD_KLP
|
|
|
|
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)
|
|
|
|
WARNINGS := -Werror -Wall -Wextra -Wmissing-prototypes \
|
|
-Wmissing-declarations -Wwrite-strings \
|
|
-Wno-implicit-fallthrough -Wno-sign-compare \
|
|
-Wno-unused-parameter
|
|
|
|
INCLUDES := -I$(srctree)/tools/include \
|
|
-I$(srctree)/tools/include/uapi \
|
|
-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
|
|
|
|
OBJTOOL_CFLAGS := -std=gnu11 -fomit-frame-pointer -O2 -g $(WARNINGS) \
|
|
$(INCLUDES) $(LIBELF_FLAGS) $(LIBXXHASH_CFLAGS) $(HOSTCFLAGS)
|
|
|
|
OBJTOOL_LDFLAGS := $(LIBSUBCMD) $(LIBELF_LIBS) $(LIBXXHASH_LIBS) $(HOSTLDFLAGS)
|
|
|
|
# Allow old libelf to be used:
|
|
elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(HOSTCC) $(OBJTOOL_CFLAGS) -x c -E - 2>/dev/null | grep elf_getshdr)
|
|
OBJTOOL_CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
|
|
|
|
# Always want host compilation.
|
|
HOST_OVERRIDES := CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)"
|
|
|
|
#
|
|
# To support disassembly, objtool needs libopcodes which is provided
|
|
# with libbfd (binutils-dev or binutils-devel package).
|
|
#
|
|
# We check using HOSTCC directly rather than the shared feature framework
|
|
# because objtool is a host tool that links against host libraries.
|
|
#
|
|
# When using shared libraries, -lopcodes is sufficient as dependencies are
|
|
# resolved automatically. With static libraries, we must explicitly link
|
|
# against libopcodes' dependencies: libbfd, libiberty, and sometimes libz.
|
|
# Try each combination and use the first one that succeeds.
|
|
#
|
|
LIBOPCODES_LIBS := $(shell \
|
|
for libs in "-lopcodes" \
|
|
"-lopcodes -lbfd" \
|
|
"-lopcodes -lbfd -liberty" \
|
|
"-lopcodes -lbfd -liberty -lz"; do \
|
|
echo 'extern void disassemble_init_for_target(void *);' \
|
|
'int main(void) { disassemble_init_for_target(0); return 0; }' | \
|
|
$(HOSTCC) -xc - -o /dev/null $$libs 2>/dev/null && \
|
|
echo "$$libs" && break; \
|
|
done)
|
|
|
|
# Styled disassembler support requires binutils >= 2.39
|
|
HAVE_DISASM_STYLED := $(shell echo '$(pound)include <dis-asm.h>' | \
|
|
$(HOSTCC) -E -xc - 2>/dev/null | grep -q disassembler_style && echo y)
|
|
|
|
BUILD_DISAS := n
|
|
|
|
ifneq ($(LIBOPCODES_LIBS),)
|
|
BUILD_DISAS := y
|
|
OBJTOOL_CFLAGS += -DDISAS -DPACKAGE='"objtool"'
|
|
OBJTOOL_LDFLAGS += $(LIBOPCODES_LIBS)
|
|
ifeq ($(HAVE_DISASM_STYLED),y)
|
|
OBJTOOL_CFLAGS += -DDISASM_INIT_STYLED
|
|
endif
|
|
endif
|
|
|
|
export BUILD_DISAS
|
|
|
|
AWK = awk
|
|
MKDIR = mkdir
|
|
|
|
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/cpu-feature-names.c $(OUTPUT)fixdep
|
|
$(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep
|
|
$(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.objtool
|
|
$(Q)$(RM) -r -- $(OUTPUT)feature
|
|
|
|
mrproper: clean
|
|
$(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL)
|
|
|
|
FORCE:
|
|
|
|
.PHONY: clean mrproper FORCE
|