From 3204a7fb98a3bccd0004ea0f2769fbeadc2c2dba Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 28 Feb 2021 15:10:26 +0900 Subject: kbuild: prefix $(srctree)/ to some included Makefiles VPATH is used in Kbuild to make pattern rules search for prerequisites in both $(objtree) and $(srctree). Some of *.c, *.S files are not real sources, but generated by tools such as flex, bison, perl. In contrast, I doubt the benefit of --include-dir=$(abs_srctree) because it is always clear which Makefiles are real sources, and which are not. So, my hope is to add $(srctree)/ prefix to all check-in Makefiles, then remove --include-dir=$(abs_srctree) flag in the future. I am touching only some Kbuild core parts for now. Treewide fixes will be needed to achieve this goal. Signed-off-by: Masahiro Yamada --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index a28bb374663d..93e6e2d28d89 100644 --- a/Makefile +++ b/Makefile @@ -339,14 +339,14 @@ __build_one_by_one: else # !mixed-build -include scripts/Kbuild.include +include $(srctree)/scripts/Kbuild.include # Read KERNELRELEASE from include/config/kernel.release (if it exists) KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null) KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION) export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION -include scripts/subarch.include +include $(srctree)/scripts/subarch.include # Cross compiling and selecting different set of gcc/bin-utils # --------------------------------------------------------------------------- @@ -592,7 +592,7 @@ ifdef config-build # Read arch specific Makefile to set KBUILD_DEFCONFIG as needed. # KBUILD_DEFCONFIG may point out an alternative default configuration # used for 'make defconfig' -include arch/$(SRCARCH)/Makefile +include $(srctree)/arch/$(SRCARCH)/Makefile export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT config: outputmakefile scripts_basic FORCE @@ -679,7 +679,7 @@ RETPOLINE_VDSO_CFLAGS := $(call cc-option,$(RETPOLINE_VDSO_CFLAGS_GCC),$(call cc export RETPOLINE_CFLAGS export RETPOLINE_VDSO_CFLAGS -include arch/$(SRCARCH)/Makefile +include $(srctree)/arch/$(SRCARCH)/Makefile ifdef need-config ifdef may-sync-config -- cgit From 57fd251c789647552d32d2fc51bedd4f90d70f9f Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 28 Feb 2021 15:10:27 +0900 Subject: kbuild: split cc-option and friends to scripts/Makefile.compiler scripts/Kbuild.include is included everywhere, but macros such as cc-option are needed by build targets only. For example, when 'make clean' traverses the tree, it does not need to evaluate $(call cc-option,). Split cc-option, ld-option, etc. to scripts/Makefile.compiler, which is only included from the top Makefile and scripts/Makefile.build. Signed-off-by: Masahiro Yamada --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 93e6e2d28d89..80bae8a1341f 100644 --- a/Makefile +++ b/Makefile @@ -584,6 +584,10 @@ KBUILD_AFLAGS += $(CLANG_FLAGS) export CLANG_FLAGS endif +# Include this also for config targets because some architectures need +# cc-cross-prefix to determine CROSS_COMPILE. +include $(srctree)/scripts/Makefile.compiler + ifdef config-build # =========================================================================== # *config targets only - make sure prerequisites are updated, and descend -- cgit From 805b2e1d427aab4bb27fa7c51ebb9db7547551b1 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 28 Feb 2021 15:10:28 +0900 Subject: kbuild: include Makefile.compiler only when compiler is needed Since commit f2f02ebd8f38 ("kbuild: improve cc-option to clean up all temporary files"), running 'make kernelversion' in a read-only source tree emits a bunch of warnings: mkdir: cannot create directory '.tmp_12345': Permission denied No-build targets such as kernelversion, clean, help, etc. do not need to evaluate $(call cc-option,) or friends. Skip Makefile.compiler so $(call cc-option,) becomes no-op. This not only fixes the warnings, but also runs non-build targets much faster. Basically, all installation targets should also be non-build targets. Unfortunately, vdso_install requires the compiler because it builds vdso before installation. This is a problem that must be fixed by a separate patch. Reported-by: Israel Tsadok Signed-off-by: Masahiro Yamada --- Makefile | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 80bae8a1341f..d79823428cd7 100644 --- a/Makefile +++ b/Makefile @@ -264,6 +264,10 @@ no-dot-config-targets := $(clean-targets) \ $(version_h) headers headers_% archheaders archscripts \ %asm-generic kernelversion %src-pkg dt_binding_check \ outputmakefile +# Installation targets should not require compiler. Unfortunately, vdso_install +# is an exception where build artifacts may be updated. This must be fixed. +no-compiler-targets := $(no-dot-config-targets) install dtbs_install \ + headers_install modules_install kernelrelease image_name no-sync-config-targets := $(no-dot-config-targets) %install kernelrelease \ image_name single-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.s %.symtypes %/ @@ -271,6 +275,7 @@ single-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.s %.symtypes %/ config-build := mixed-build := need-config := 1 +need-compiler := 1 may-sync-config := 1 single-build := @@ -280,6 +285,12 @@ ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),) endif endif +ifneq ($(filter $(no-compiler-targets), $(MAKECMDGOALS)),) + ifeq ($(filter-out $(no-compiler-targets), $(MAKECMDGOALS)),) + need-compiler := + endif +endif + ifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),) ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),) may-sync-config := @@ -586,7 +597,9 @@ endif # Include this also for config targets because some architectures need # cc-cross-prefix to determine CROSS_COMPILE. +ifdef need-compiler include $(srctree)/scripts/Makefile.compiler +endif ifdef config-build # =========================================================================== -- cgit From 609bbb4de4f85b7ef45d81a88e6b7dfe3bf5ccea Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 2 Mar 2021 23:26:14 +0900 Subject: kbuild: show warning if 'make headers_check' is used Since commit 7ecaf069da52 ("kbuild: move headers_check rule to usr/include/Makefile"), 'make headers_check' is no-op. This stub target is remaining here in case some scripts still invoke it. In order to prompt people to remove stale code, show a noisy warning message if used. The stub will be really removed after the Linux 5.15 release. Signed-off-by: Masahiro Yamada --- Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index d79823428cd7..80c82155ebb6 100644 --- a/Makefile +++ b/Makefile @@ -1358,7 +1358,11 @@ headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts # Deprecated. It is no-op now. PHONY += headers_check headers_check: - @: + @echo >&2 "=================== WARNING ===================" + @echo >&2 "Since Linux 5.5, 'make headers_check' is no-op," + @echo >&2 "and will be removed after Linux 5.15 release." + @echo >&2 "Please remove headers_check from your scripts." + @echo >&2 "===============================================" ifdef CONFIG_HEADERS_INSTALL prepare: headers -- cgit From 0b956e204132ce3fe4221a062638bf83a30e6200 Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Fri, 5 Mar 2021 11:02:12 +0100 Subject: kbuild: apply fixdep logic to link-vmlinux.sh The patch adding CONFIG_VMLINUX_MAP revealed a small defect in the build system: link-vmlinux.sh takes decisions based on CONFIG_* options, but changing one of those does not always lead to vmlinux being linked again. For most of the CONFIG_* knobs referenced previously, this has probably been hidden by those knobs also affecting some object file, hence indirectly also vmlinux. But CONFIG_VMLINUX_MAP is only handled inside link-vmlinux.sh, and changing CONFIG_VMLINUX_MAP=n to CONFIG_VMLINUX_MAP=y does not cause the build system to re-link (and hence have vmlinux.map emitted). Since that map file is mostly a debugging aid, this is merely a nuisance which is easily worked around by just deleting vmlinux and building again. But one could imagine other (possibly future) CONFIG options that actually do affect the vmlinux binary but which are not captured through some object file dependency. To fix this, make link-vmlinux.sh emit a .vmlinux.d file in the same format as the dependency files generated by gcc, and apply the fixdep logic to that. I've tested that this correctly works with both in-tree and out-of-tree builds. Signed-off-by: Rasmus Villemoes Signed-off-by: Masahiro Yamada --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 80c82155ebb6..03e3ee982f14 100644 --- a/Makefile +++ b/Makefile @@ -1213,7 +1213,7 @@ cmd_link-vmlinux = \ $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) vmlinux: scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps) FORCE - +$(call if_changed,link-vmlinux) + +$(call if_changed_dep,link-vmlinux) targets := vmlinux -- cgit From c91d4e47e10ee4d3163838b1b727fe1d0664115b Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Tue, 9 Mar 2021 13:59:14 -0700 Subject: Makefile: Remove '--gcc-toolchain' flag This flag was originally added to allow clang to find the GNU cross tools in commit 785f11aa595b ("kbuild: Add better clang cross build support"). This flag was not enough to find the tools at times so '--prefix' was added to the list in commit ef8c4ed9db80 ("kbuild: allow to use GCC toolchain not in Clang search path") and improved upon in commit ca9b31f6bb9c ("Makefile: Fix GCC_TOOLCHAIN_DIR prefix for Clang cross compilation"). Now that '--prefix' specifies a full path and prefix, '--gcc-toolchain' serves no purpose because the kernel builds with '-nostdinc' and '-nostdlib'. This has been verified with self compiled LLVM 10.0.1 and LLVM 13.0.0 as well as a distribution version of LLVM 11.1.0 without binutils in the LLVM toolchain locations. Link: https://reviews.llvm.org/D97902 Signed-off-by: Nathan Chancellor Reviewed-by: Fangrui Song Reviewed-by: Nick Desaulniers Tested-by: Nick Desaulniers Tested-by: Sedat Dilek Signed-off-by: Masahiro Yamada --- Makefile | 4 ---- 1 file changed, 4 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 03e3ee982f14..40bfd059b5ef 100644 --- a/Makefile +++ b/Makefile @@ -581,10 +581,6 @@ ifneq ($(CROSS_COMPILE),) CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%)) GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit)) CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE)) -GCC_TOOLCHAIN := $(realpath $(GCC_TOOLCHAIN_DIR)/..) -endif -ifneq ($(GCC_TOOLCHAIN),) -CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN) endif ifneq ($(LLVM_IAS),1) CLANG_FLAGS += -no-integrated-as -- cgit From eec08090bcc113643522d4272dc0b945045aba74 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Tue, 9 Mar 2021 13:59:15 -0700 Subject: Makefile: Only specify '--prefix=' when building with clang + GNU as When building with LLVM_IAS=1, there is no point to specifying '--prefix=' because that flag is only used to find GNU cross tools, which will not be used indirectly when using the integrated assembler. All of the tools are invoked directly from PATH or a full path specified via the command line, which does not depend on the value of '--prefix='. Sharing commands to reproduce issues becomes a little bit easier without a '--prefix=' value because that '--prefix=' value is specific to a user's machine due to it being an absolute path. Some further notes from Fangrui Song: clang can spawn GNU as (if -f?no-integrated-as is specified) and GNU objcopy (-f?no-integrated-as and -gsplit-dwarf and -g[123]). objcopy is only used for GNU as assembled object files. With integrated assembler, the object file streamer creates .o and .dwo simultaneously. With GNU as, two objcopy commands are needed to extract .debug*.dwo to .dwo files && another command to remove .debug*.dwo sections. A small consequence of this change (to keep things simple) is that '--prefix=' will always be specified now, even with a native build, when it was not before. This should not be an issue due to the way that the Makefile searches for the prefix (based on elfedit's location). This ends up improving the experience for host builds because PATH is better respected and matches GCC's behavior more closely. See the below thread for more details: https://lore.kernel.org/r/20210205213651.GA16907@Ryzen-5-4500U.localdomain/ Signed-off-by: Nathan Chancellor Signed-off-by: Masahiro Yamada --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 40bfd059b5ef..5cb44595418c 100644 --- a/Makefile +++ b/Makefile @@ -579,11 +579,11 @@ CC_VERSION_TEXT = $(shell $(CC) --version 2>/dev/null | head -n 1 | sed 's/\#//g ifneq ($(findstring clang,$(CC_VERSION_TEXT)),) ifneq ($(CROSS_COMPILE),) CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%)) -GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit)) -CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE)) endif ifneq ($(LLVM_IAS),1) CLANG_FLAGS += -no-integrated-as +GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit)) +CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE)) endif CLANG_FLAGS += -Werror=unknown-warning-option KBUILD_CFLAGS += $(CLANG_FLAGS) -- cgit From 6e0839fda3f8598b164a7f23f3eec039e2db5fbc Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 14 Mar 2021 15:15:50 +0900 Subject: kbuild: replace sed with $(subst ) or $(patsubst ) For simple text replacement, it is better to use a built-in function instead of sed if possible. You can save one process forking. I do not mean to replace all sed invocations because GNU Make itself does not support regular expression (unless you use guile). I just replaced simple ones. Signed-off-by: Masahiro Yamada --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 5cb44595418c..cc5b7e39fde4 100644 --- a/Makefile +++ b/Makefile @@ -574,7 +574,7 @@ endif # Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile. # CC_VERSION_TEXT is referenced from Kconfig (so it needs export), # and from include/config/auto.conf.cmd to detect the compiler upgrade. -CC_VERSION_TEXT = $(shell $(CC) --version 2>/dev/null | head -n 1 | sed 's/\#//g') +CC_VERSION_TEXT = $(subst $(pound),,$(shell $(CC) --version 2>/dev/null | head -n 1)) ifneq ($(findstring clang,$(CC_VERSION_TEXT)),) ifneq ($(CROSS_COMPILE),) -- cgit From ba64beb17493a4bfec563100c86a462a15926f24 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 16 Mar 2021 01:12:56 +0900 Subject: kbuild: check the minimum assembler version in Kconfig Documentation/process/changes.rst defines the minimum assembler version (binutils version), but we have never checked it in the build time. Kbuild never invokes 'as' directly because all assembly files in the kernel tree are *.S, hence must be preprocessed. I do not expect raw assembly source files (*.s) would be added to the kernel tree. Therefore, we always use $(CC) as the assembler driver, and commit aa824e0c962b ("kbuild: remove AS variable") removed 'AS'. However, we are still interested in the version of the assembler acting behind. As usual, the --version option prints the version string. $ as --version | head -n 1 GNU assembler (GNU Binutils for Ubuntu) 2.35.1 But, we do not have $(AS). So, we can add the -Wa prefix so that $(CC) passes --version down to the backing assembler. $ gcc -Wa,--version | head -n 1 gcc: fatal error: no input files compilation terminated. OK, we need to input something to satisfy gcc. $ gcc -Wa,--version -c -x assembler /dev/null -o /dev/null | head -n 1 GNU assembler (GNU Binutils for Ubuntu) 2.35.1 The combination of Clang and GNU assembler works in the same way: $ clang -no-integrated-as -Wa,--version -c -x assembler /dev/null -o /dev/null | head -n 1 GNU assembler (GNU Binutils for Ubuntu) 2.35.1 Clang with the integrated assembler fails like this: $ clang -integrated-as -Wa,--version -c -x assembler /dev/null -o /dev/null | head -n 1 clang: error: unsupported argument '--version' to option 'Wa,' For the last case, checking the error message is fragile. If the proposal for -Wa,--version support [1] is accepted, this may not be even an error in the future. One easy way is to check if -integrated-as is present in the passed arguments. We did not pass -integrated-as to CLANG_FLAGS before, but we can make it explicit. Nathan pointed out -integrated-as is the default for all of the architectures/targets that the kernel cares about, but it goes along with "explicit is better than implicit" policy. [2] With all this in my mind, I implemented scripts/as-version.sh to check the assembler version in Kconfig time. $ scripts/as-version.sh gcc GNU 23501 $ scripts/as-version.sh clang -no-integrated-as GNU 23501 $ scripts/as-version.sh clang -integrated-as LLVM 0 [1]: https://github.com/ClangBuiltLinux/linux/issues/1320 [2]: https://lore.kernel.org/linux-kbuild/20210307044253.v3h47ucq6ng25iay@archlinux-ax161/ Signed-off-by: Masahiro Yamada Reviewed-by: Nathan Chancellor --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index cc5b7e39fde4..2b161f5a5a66 100644 --- a/Makefile +++ b/Makefile @@ -580,7 +580,9 @@ ifneq ($(findstring clang,$(CC_VERSION_TEXT)),) ifneq ($(CROSS_COMPILE),) CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%)) endif -ifneq ($(LLVM_IAS),1) +ifeq ($(LLVM_IAS),1) +CLANG_FLAGS += -integrated-as +else CLANG_FLAGS += -no-integrated-as GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit)) CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE)) -- cgit From 69bc8d386aebbd91a6bb44b6d33f77c8dfa9ed8c Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 26 Mar 2021 03:54:09 +0900 Subject: kbuild: generate Module.symvers only when vmlinux exists The external module build shows the following warning if Module.symvers is missing in the kernel tree. WARNING: Symbol version dump "Module.symvers" is missing. Modules may not have dependencies or modversions. I think this is an important heads-up because the resulting modules may not work as expected. This happens when you did not build the entire kernel tree, for example, you might have prepared the minimal setups for external modules by 'make defconfig && make modules_preapre'. A problem is that 'make modules' creates Module.symvers even without vmlinux. In this case, that warning is suppressed since Module.symvers already exists in spite of its incomplete content. The incomplete (i.e. invalid) Module.symvers should not be created. This commit changes the second pass of modpost to dump symbols into modules-only.symvers. The final Module.symvers is created by concatenating vmlinux.symvers and modules-only.symvers if both exist. Module.symvers is supposed to collect symbols from both vmlinux and modules. It might be a bit confusing, and I am not quite sure if it is an official interface, but presumably it is difficult to rename it because some tools (e.g. kmod) parse it. Signed-off-by: Masahiro Yamada --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 2b161f5a5a66..ed8bd815e8a3 100644 --- a/Makefile +++ b/Makefile @@ -1532,7 +1532,7 @@ endif # CONFIG_MODULES # make distclean Remove editor backup files, patch leftover files and the like # Directories & files removed with 'make clean' -CLEAN_FILES += include/ksym vmlinux.symvers \ +CLEAN_FILES += include/ksym vmlinux.symvers modules-only.symvers \ modules.builtin modules.builtin.modinfo modules.nsdeps \ compile_commands.json .thinlto-cache -- cgit From 4b97ec0e9cfd5995f41b9726c88566a31f4625cc Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 31 Mar 2021 22:38:02 +0900 Subject: kbuild: remove unneeded mkdir for external modules_install scripts/Makefile.modinst creates directories as needed. Signed-off-by: Masahiro Yamada --- Makefile | 2 -- 1 file changed, 2 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index ed8bd815e8a3..0e06db5ed9d8 100644 --- a/Makefile +++ b/Makefile @@ -1779,10 +1779,8 @@ $(MODORDER): descend PHONY += modules_install modules_install: _emodinst_ _emodinst_post -install-dir := $(if $(INSTALL_MOD_DIR),$(INSTALL_MOD_DIR),extra) PHONY += _emodinst_ _emodinst_: - $(Q)mkdir -p $(MODLIB)/$(install-dir) $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst PHONY += _emodinst_post -- cgit From 3e3005df73b535cb849cf4ec8075d6aa3c460f68 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 31 Mar 2021 22:38:03 +0900 Subject: kbuild: unify modules(_install) for in-tree and external modules If you attempt to build or install modules ('make modules(_install)' with CONFIG_MODULES disabled, you will get a clear error message, but nothing for external module builds. Factor out the modules and modules_install rules into the common part, so you will get the same error message when you try to build external modules with CONFIG_MODULES=n. Signed-off-by: Masahiro Yamada --- Makefile | 85 +++++++++++++++++++++++++++------------------------------------- 1 file changed, 36 insertions(+), 49 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 0e06db5ed9d8..99a2bd51c02d 100644 --- a/Makefile +++ b/Makefile @@ -1458,7 +1458,6 @@ endif PHONY += modules modules: $(if $(KBUILD_BUILTIN),vmlinux) modules_check modules_prepare - $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost PHONY += modules_check modules_check: modules.order @@ -1476,12 +1475,9 @@ PHONY += modules_prepare modules_prepare: prepare $(Q)$(MAKE) $(build)=scripts scripts/module.lds -# Target to install modules -PHONY += modules_install -modules_install: _modinst_ _modinst_post - -PHONY += _modinst_ -_modinst_: +modules_install: __modinst_pre +PHONY += __modinst_pre +__modinst_pre: @rm -rf $(MODLIB)/kernel @rm -f $(MODLIB)/source @mkdir -p $(MODLIB)/kernel @@ -1493,14 +1489,6 @@ _modinst_: @sed 's:^:kernel/:' modules.order > $(MODLIB)/modules.order @cp -f modules.builtin $(MODLIB)/ @cp -f $(objtree)/modules.builtin.modinfo $(MODLIB)/ - $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst - -# This depmod is only for convenience to give the initial -# boot a modules.dep even before / is mounted read-write. However the -# boot script depmod is the master version. -PHONY += _modinst_post -_modinst_post: _modinst_ - $(call cmd,depmod) ifeq ($(CONFIG_MODULE_SIG), y) PHONY += modules_sign @@ -1508,20 +1496,6 @@ modules_sign: $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modsign endif -else # CONFIG_MODULES - -# Modules not configured -# --------------------------------------------------------------------------- - -PHONY += modules modules_install -modules modules_install: - @echo >&2 - @echo >&2 "The present kernel configuration has modules disabled." - @echo >&2 "Type 'make config' and enable loadable module support." - @echo >&2 "Then build a kernel with module support enabled." - @echo >&2 - @exit 1 - endif # CONFIG_MODULES ### @@ -1769,24 +1743,9 @@ KBUILD_BUILTIN := KBUILD_MODULES := 1 build-dirs := $(KBUILD_EXTMOD) -PHONY += modules -modules: $(MODORDER) - $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost - $(MODORDER): descend @: -PHONY += modules_install -modules_install: _emodinst_ _emodinst_post - -PHONY += _emodinst_ -_emodinst_: - $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst - -PHONY += _emodinst_post -_emodinst_post: _emodinst_ - $(call cmd,depmod) - compile_commands.json: $(extmod-prefix)compile_commands.json PHONY += compile_commands.json @@ -1809,6 +1768,39 @@ PHONY += prepare modules_prepare endif # KBUILD_EXTMOD +# --------------------------------------------------------------------------- +# Modules + +PHONY += modules modules_install + +ifdef CONFIG_MODULES + +modules: $(MODORDER) + $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost + +quiet_cmd_depmod = DEPMOD $(KERNELRELEASE) + cmd_depmod = $(CONFIG_SHELL) $(srctree)/scripts/depmod.sh $(DEPMOD) \ + $(KERNELRELEASE) + +modules_install: + $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst + $(call cmd,depmod) + +else # CONFIG_MODULES + +# Modules not configured +# --------------------------------------------------------------------------- + +modules modules_install: + @echo >&2 '***' + @echo >&2 '*** The present kernel configuration has modules disabled.' + @echo >&2 '*** To use the module feature, please run "make menuconfig" etc.' + @echo >&2 '*** to enable CONFIG_MODULES.' + @echo >&2 '***' + @exit 1 + +endif # CONFIG_MODULES + # Single targets # --------------------------------------------------------------------------- # To build individual files in subdirectories, you can do like this: @@ -1997,11 +1989,6 @@ tools/%: FORCE quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files))) cmd_rmfiles = rm -rf $(rm-files) -# Run depmod only if we have System.map and depmod is executable -quiet_cmd_depmod = DEPMOD $(KERNELRELEASE) - cmd_depmod = $(CONFIG_SHELL) $(srctree)/scripts/depmod.sh $(DEPMOD) \ - $(KERNELRELEASE) - # read saved command lines for existing targets existing-targets := $(wildcard $(sort $(targets))) -- cgit From 3ac42b2112532a71125eea6bb07361deeca9aaa1 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 31 Mar 2021 22:38:04 +0900 Subject: kbuild: show the target directory for depmod log It is clearer to show the directory which depmod will work on. Signed-off-by: Masahiro Yamada --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 99a2bd51c02d..a6f73335757d 100644 --- a/Makefile +++ b/Makefile @@ -1778,7 +1778,7 @@ ifdef CONFIG_MODULES modules: $(MODORDER) $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost -quiet_cmd_depmod = DEPMOD $(KERNELRELEASE) +quiet_cmd_depmod = DEPMOD $(MODLIB) cmd_depmod = $(CONFIG_SHELL) $(srctree)/scripts/depmod.sh $(DEPMOD) \ $(KERNELRELEASE) -- cgit From 1a998be620a10000c1e1240026e4bd6bc3378c96 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 31 Mar 2021 22:38:05 +0900 Subject: kbuild: check module name conflict for external modules as well If there are multiple modules with the same name in the same external module tree, there is ambiguity about which one will be loaded, and very likely something odd is happening. Signed-off-by: Masahiro Yamada --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index a6f73335757d..b5ff4753eba8 100644 --- a/Makefile +++ b/Makefile @@ -1459,10 +1459,6 @@ endif PHONY += modules modules: $(if $(KBUILD_BUILTIN),vmlinux) modules_check modules_prepare -PHONY += modules_check -modules_check: modules.order - $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $< - cmd_modules_order = $(AWK) '!x[$$0]++' $(real-prereqs) > $@ modules.order: $(subdir-modorder) FORCE @@ -1775,9 +1771,13 @@ PHONY += modules modules_install ifdef CONFIG_MODULES -modules: $(MODORDER) +modules: modules_check $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost +PHONY += modules_check +modules_check: $(MODORDER) + $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $< + quiet_cmd_depmod = DEPMOD $(MODLIB) cmd_depmod = $(CONFIG_SHELL) $(srctree)/scripts/depmod.sh $(DEPMOD) \ $(KERNELRELEASE) -- cgit From 7f69180b8e905fe13559573b89245f6256b99434 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 31 Mar 2021 22:38:06 +0900 Subject: kbuild: rename extmod-prefix to extmod_prefix This seems to be useful in sub-make as well. As a preparation of exporting it, rename extmod-prefix to extmod_prefix because exported variables cannot contain hyphens. Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers --- Makefile | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index b5ff4753eba8..e3c2bd1b6f42 100644 --- a/Makefile +++ b/Makefile @@ -919,7 +919,7 @@ endif ifdef CONFIG_LTO_CLANG ifdef CONFIG_LTO_CLANG_THIN CC_FLAGS_LTO := -flto=thin -fsplit-lto-unit -KBUILD_LDFLAGS += --thinlto-cache-dir=$(extmod-prefix).thinlto-cache +KBUILD_LDFLAGS += --thinlto-cache-dir=$(extmod_prefix).thinlto-cache else CC_FLAGS_LTO := -flto endif @@ -1141,9 +1141,9 @@ endif # CONFIG_BPF PHONY += prepare0 -extmod-prefix = $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/) -export MODORDER := $(extmod-prefix)modules.order -export MODULES_NSDEPS := $(extmod-prefix)modules.nsdeps +extmod_prefix = $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/) +export MODORDER := $(extmod_prefix)modules.order +export MODULES_NSDEPS := $(extmod_prefix)modules.nsdeps ifeq ($(KBUILD_EXTMOD),) core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/ @@ -1742,7 +1742,7 @@ build-dirs := $(KBUILD_EXTMOD) $(MODORDER): descend @: -compile_commands.json: $(extmod-prefix)compile_commands.json +compile_commands.json: $(extmod_prefix)compile_commands.json PHONY += compile_commands.json clean-dirs := $(KBUILD_EXTMOD) @@ -1832,12 +1832,12 @@ endif PHONY += single_modpost single_modpost: $(single-no-ko) modules_prepare - $(Q){ $(foreach m, $(single-ko), echo $(extmod-prefix)$m;) } > $(MODORDER) + $(Q){ $(foreach m, $(single-ko), echo $(extmod_prefix)$m;) } > $(MODORDER) $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost KBUILD_MODULES := 1 -export KBUILD_SINGLE_TARGETS := $(addprefix $(extmod-prefix), $(single-no-ko)) +export KBUILD_SINGLE_TARGETS := $(addprefix $(extmod_prefix), $(single-no-ko)) # trim unrelated directories build-dirs := $(foreach d, $(build-dirs), \ @@ -1906,12 +1906,12 @@ nsdeps: modules quiet_cmd_gen_compile_commands = GEN $@ cmd_gen_compile_commands = $(PYTHON3) $< -a $(AR) -o $@ $(filter-out $<, $(real-prereqs)) -$(extmod-prefix)compile_commands.json: scripts/clang-tools/gen_compile_commands.py \ +$(extmod_prefix)compile_commands.json: scripts/clang-tools/gen_compile_commands.py \ $(if $(KBUILD_EXTMOD),,$(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS)) \ $(if $(CONFIG_MODULES), $(MODORDER)) FORCE $(call if_changed,gen_compile_commands) -targets += $(extmod-prefix)compile_commands.json +targets += $(extmod_prefix)compile_commands.json PHONY += clang-tidy clang-analyzer @@ -1919,7 +1919,7 @@ ifdef CONFIG_CC_IS_CLANG quiet_cmd_clang_tools = CHECK $< cmd_clang_tools = $(PYTHON3) $(srctree)/scripts/clang-tools/run-clang-tools.py $@ $< -clang-tidy clang-analyzer: $(extmod-prefix)compile_commands.json +clang-tidy clang-analyzer: $(extmod_prefix)compile_commands.json $(call cmd,clang_tools) else clang-tidy clang-analyzer: -- cgit From ccae4cfa7bfbec323abc399228e0ada7c377b16b Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 31 Mar 2021 22:38:07 +0900 Subject: kbuild: refactor scripts/Makefile.modinst scripts/Makefile.modinst is ugly and weird in multiple ways; it specifies real files $(modules) as phony, makes directory manipulation needlessly too complicated. Clean up the Makefile code, and show the full path of installed modules in the log. Signed-off-by: Masahiro Yamada --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index e3c2bd1b6f42..88e5c15e1186 100644 --- a/Makefile +++ b/Makefile @@ -1141,7 +1141,7 @@ endif # CONFIG_BPF PHONY += prepare0 -extmod_prefix = $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/) +export extmod_prefix = $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/) export MODORDER := $(extmod_prefix)modules.order export MODULES_NSDEPS := $(extmod_prefix)modules.nsdeps -- cgit From 65ce9c38326e2588fcd1a3a4817c14b4660f430b Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 31 Mar 2021 22:38:08 +0900 Subject: kbuild: move module strip/compression code into scripts/Makefile.modinst Both mod_strip_cmd and mod_compress_cmd are only used in scripts/Makefile.modinst, hence there is no good reason to define them in the top Makefile. Move the relevant code to scripts/Makefile.modinst. Also, show separate log messages for each of install, strip, sign, and compress. Signed-off-by: Masahiro Yamada --- Makefile | 32 -------------------------------- 1 file changed, 32 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 88e5c15e1186..f96ae09d111b 100644 --- a/Makefile +++ b/Makefile @@ -1063,38 +1063,6 @@ export INSTALL_DTBS_PATH ?= $(INSTALL_PATH)/dtbs/$(KERNELRELEASE) MODLIB = $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE) export MODLIB -# -# INSTALL_MOD_STRIP, if defined, will cause modules to be -# stripped after they are installed. If INSTALL_MOD_STRIP is '1', then -# the default option --strip-debug will be used. Otherwise, -# INSTALL_MOD_STRIP value will be used as the options to the strip command. - -ifdef INSTALL_MOD_STRIP -ifeq ($(INSTALL_MOD_STRIP),1) -mod_strip_cmd = $(STRIP) --strip-debug -else -mod_strip_cmd = $(STRIP) $(INSTALL_MOD_STRIP) -endif # INSTALL_MOD_STRIP=1 -else -mod_strip_cmd = true -endif # INSTALL_MOD_STRIP -export mod_strip_cmd - -# CONFIG_MODULE_COMPRESS, if defined, will cause module to be compressed -# after they are installed in agreement with CONFIG_MODULE_COMPRESS_GZIP -# or CONFIG_MODULE_COMPRESS_XZ. - -mod_compress_cmd = true -ifdef CONFIG_MODULE_COMPRESS - ifdef CONFIG_MODULE_COMPRESS_GZIP - mod_compress_cmd = $(KGZIP) -n -f - endif # CONFIG_MODULE_COMPRESS_GZIP - ifdef CONFIG_MODULE_COMPRESS_XZ - mod_compress_cmd = $(XZ) --lzma2=dict=2MiB -f - endif # CONFIG_MODULE_COMPRESS_XZ -endif # CONFIG_MODULE_COMPRESS -export mod_compress_cmd - ifdef CONFIG_MODULE_SIG_ALL $(eval $(call config_filename,MODULE_SIG_KEY)) -- cgit From 961ab4a3cd66c285951cf4c8ec10bc8d9a4b0232 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 31 Mar 2021 22:38:09 +0900 Subject: kbuild: merge scripts/Makefile.modsign to scripts/Makefile.modinst scripts/Makefile.modsign is a subset of scripts/Makefile.modinst, and duplicates the code. Let's merge them. By the way, you do not need to run 'make modules_sign' explicitly because modules are signed as a part of 'make modules_install' when CONFIG_MODULE_SIG_ALL=y. If CONFIG_MODULE_SIG_ALL=n, mod_sign_cmd is set to 'true', so 'make modules_sign' is not functional. In my understanding, the reason of still keeping this is to handle corner cases like commit 64178cb62c32 ("builddeb: fix stripped module signatures if CONFIG_DEBUG_INFO and CONFIG_MODULE_SIG_ALL are set"). Signed-off-by: Masahiro Yamada --- Makefile | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index f96ae09d111b..b14483742a67 100644 --- a/Makefile +++ b/Makefile @@ -1063,15 +1063,6 @@ export INSTALL_DTBS_PATH ?= $(INSTALL_PATH)/dtbs/$(KERNELRELEASE) MODLIB = $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE) export MODLIB -ifdef CONFIG_MODULE_SIG_ALL -$(eval $(call config_filename,MODULE_SIG_KEY)) - -mod_sign_cmd = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) $(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY) certs/signing_key.x509 -else -mod_sign_cmd = true -endif -export mod_sign_cmd - HOST_LIBELF_LIBS = $(shell pkg-config libelf --libs 2>/dev/null || echo -lelf) has_libelf = $(call try-run,\ @@ -1439,7 +1430,26 @@ PHONY += modules_prepare modules_prepare: prepare $(Q)$(MAKE) $(build)=scripts scripts/module.lds -modules_install: __modinst_pre +export modules_sign_only := + +ifeq ($(CONFIG_MODULE_SIG),y) +PHONY += modules_sign +modules_sign: modules_install + @: + +# modules_sign is a subset of modules_install. +# 'make modules_install modules_sign' is equivalent to 'make modules_install'. +ifeq ($(filter modules_install,$(MAKECMDGOALS)),) +modules_sign_only := y +endif +endif + +modinst_pre := +ifneq ($(filter modules_install,$(MAKECMDGOALS)),) +modinst_pre := __modinst_pre +endif + +modules_install: $(modinst_pre) PHONY += __modinst_pre __modinst_pre: @rm -rf $(MODLIB)/kernel @@ -1454,12 +1464,6 @@ __modinst_pre: @cp -f modules.builtin $(MODLIB)/ @cp -f $(objtree)/modules.builtin.modinfo $(MODLIB)/ -ifeq ($(CONFIG_MODULE_SIG), y) -PHONY += modules_sign -modules_sign: - $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modsign -endif - endif # CONFIG_MODULES ### -- cgit From f634ca650f724347892068489c7920631a3aac6a Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Thu, 22 Apr 2021 13:19:14 -0700 Subject: kbuild: Add $(KBUILD_HOSTLDFLAGS) to 'has_libelf' test Normally, invocations of $(HOSTCC) include $(KBUILD_HOSTLDFLAGS), which in turn includes $(HOSTLDFLAGS), which allows users to pass in their own flags when linking. However, the 'has_libelf' test does not, meaning that if a user requests a specific linker via HOSTLDFLAGS=-fuse-ld=..., it is not respected and the build might error. For example, if a user building with clang wants to use all of the LLVM tools without any GNU tools, they might remove all of the GNU tools from their system or PATH then build with $ make HOSTLDFLAGS=-fuse-ld=lld LLVM=1 LLVM_IAS=1 which says use all of the LLVM tools, the integrated assembler, and ld.lld for linking host executables. Without this change, the build will error because $(HOSTCC) uses its default linker, rather than the one requested via -fuse-ld=..., which is GNU ld in clang's case in a default configuration. error: Cannot generate ORC metadata for CONFIG_UNWINDER_ORC=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel make[1]: *** [Makefile:1260: prepare-objtool] Error 1 Add $(KBUILD_HOSTLDFLAGS) to the 'has_libelf' test so that the linker choice is respected. Link: https://github.com/ClangBuiltLinux/linux/issues/479 Signed-off-by: Nathan Chancellor Signed-off-by: Masahiro Yamada --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index b14483742a67..a0319d0a6a86 100644 --- a/Makefile +++ b/Makefile @@ -1066,7 +1066,7 @@ export MODLIB HOST_LIBELF_LIBS = $(shell pkg-config libelf --libs 2>/dev/null || echo -lelf) has_libelf = $(call try-run,\ - echo "int main() {}" | $(HOSTCC) -xc -o /dev/null $(HOST_LIBELF_LIBS) -,1,0) + echo "int main() {}" | $(HOSTCC) $(KBUILD_HOSTLDFLAGS) -xc -o /dev/null $(HOST_LIBELF_LIBS) -,1,0) ifdef CONFIG_STACK_VALIDATION ifeq ($(has_libelf),1) -- cgit