From 3204a7fb98a3bccd0004ea0f2769fbeadc2c2dba Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 28 Feb 2021 15:10:26 +0900 Subject: [PATCH 01/42] 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 ++++---- scripts/Makefile.asm-generic | 4 ++-- scripts/Makefile.build | 8 ++++---- scripts/Makefile.clean | 2 +- scripts/Makefile.dtbinst | 2 +- scripts/Makefile.headersinst | 2 +- scripts/Makefile.modinst | 2 +- scripts/Makefile.modpost | 4 ++-- scripts/Makefile.modsign | 2 +- 9 files changed, 17 insertions(+), 17 deletions(-) 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 diff --git a/scripts/Makefile.asm-generic b/scripts/Makefile.asm-generic index 82ad63dcd62b..1d501c57f9ef 100644 --- a/scripts/Makefile.asm-generic +++ b/scripts/Makefile.asm-generic @@ -14,10 +14,10 @@ src := $(subst /generated,,$(obj)) # $(generic)/Kbuild lists mandatory-y. Exclude um since it is a special case. ifneq ($(SRCARCH),um) -include $(generic)/Kbuild +include $(srctree)/$(generic)/Kbuild endif -include scripts/Kbuild.include +include $(srctree)/scripts/Kbuild.include redundant := $(filter $(mandatory-y) $(generated-y), $(generic-y)) redundant += $(foreach f, $(generic-y), $(if $(wildcard $(srctree)/$(src)/$(f)),$(f))) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 1b6094a13034..750d6d5225af 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -35,27 +35,27 @@ subdir-ccflags-y := # Read auto.conf if it exists, otherwise ignore -include include/config/auto.conf -include scripts/Kbuild.include +include $(srctree)/scripts/Kbuild.include # The filename Kbuild has precedence over Makefile kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile) include $(kbuild-file) -include scripts/Makefile.lib +include $(srctree)/scripts/Makefile.lib # Do not include hostprogs rules unless needed. # $(sort ...) is used here to remove duplicated words and excessive spaces. hostprogs := $(sort $(hostprogs)) ifneq ($(hostprogs),) -include scripts/Makefile.host +include $(srctree)/scripts/Makefile.host endif # Do not include userprogs rules unless needed. # $(sort ...) is used here to remove duplicated words and excessive spaces. userprogs := $(sort $(userprogs)) ifneq ($(userprogs),) -include scripts/Makefile.userprogs +include $(srctree)/scripts/Makefile.userprogs endif ifndef obj diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean index 22a8172bce1f..fd6175322470 100644 --- a/scripts/Makefile.clean +++ b/scripts/Makefile.clean @@ -8,7 +8,7 @@ src := $(obj) PHONY := __clean __clean: -include scripts/Kbuild.include +include $(srctree)/scripts/Kbuild.include # The filename Kbuild has precedence over Makefile kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) diff --git a/scripts/Makefile.dtbinst b/scripts/Makefile.dtbinst index ba01f5ba2517..190d781e84f4 100644 --- a/scripts/Makefile.dtbinst +++ b/scripts/Makefile.dtbinst @@ -14,7 +14,7 @@ PHONY := __dtbs_install __dtbs_install: include include/config/auto.conf -include scripts/Kbuild.include +include $(srctree)/scripts/Kbuild.include include $(src)/Makefile dtbs := $(addprefix $(dst)/, $(dtb-y) $(if $(CONFIG_OF_ALL_DTBS),$(dtb-))) diff --git a/scripts/Makefile.headersinst b/scripts/Makefile.headersinst index 708fbd08a2c5..029d85bb0b23 100644 --- a/scripts/Makefile.headersinst +++ b/scripts/Makefile.headersinst @@ -12,7 +12,7 @@ PHONY := __headers __headers: -include scripts/Kbuild.include +include $(srctree)/scripts/Kbuild.include src := $(srctree)/$(obj) gen := $(objtree)/$(subst include/,include/generated/,$(obj)) diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst index 5a4579e76485..ad1981233d0b 100644 --- a/scripts/Makefile.modinst +++ b/scripts/Makefile.modinst @@ -6,7 +6,7 @@ PHONY := __modinst __modinst: -include scripts/Kbuild.include +include $(srctree)/scripts/Kbuild.include modules := $(sort $(shell cat $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/)modules.order)) diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index 066beffca09a..df57e259fac3 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -41,10 +41,10 @@ PHONY := __modpost __modpost: include include/config/auto.conf -include scripts/Kbuild.include +include $(srctree)/scripts/Kbuild.include # for ld_flags -include scripts/Makefile.lib +include $(srctree)/scripts/Makefile.lib MODPOST = scripts/mod/modpost \ $(if $(CONFIG_MODVERSIONS),-m) \ diff --git a/scripts/Makefile.modsign b/scripts/Makefile.modsign index d7325cefe709..ddf9b5ca77d7 100644 --- a/scripts/Makefile.modsign +++ b/scripts/Makefile.modsign @@ -6,7 +6,7 @@ PHONY := __modsign __modsign: -include scripts/Kbuild.include +include $(srctree)/scripts/Kbuild.include modules := $(sort $(shell cat modules.order)) From 57fd251c789647552d32d2fc51bedd4f90d70f9f Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 28 Feb 2021 15:10:27 +0900 Subject: [PATCH 02/42] 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 ++ scripts/Kbuild.include | 80 --------------------------------------- scripts/Makefile.build | 1 + scripts/Makefile.compiler | 75 ++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 80 deletions(-) create mode 100644 scripts/Makefile.compiler 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 diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 509e0856d653..82dd1b65b7a8 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -67,86 +67,6 @@ define filechk fi endef -###### -# gcc support functions -# See documentation in Documentation/kbuild/makefiles.rst - -# cc-cross-prefix -# Usage: CROSS_COMPILE := $(call cc-cross-prefix, m68k-linux-gnu- m68k-linux-) -# Return first where a gcc is found in PATH. -# If no gcc found in PATH with listed prefixes return nothing -# -# Note: '2>/dev/null' is here to force Make to invoke a shell. Otherwise, it -# would try to directly execute the shell builtin 'command'. This workaround -# should be kept for a long time since this issue was fixed only after the -# GNU Make 4.2.1 release. -cc-cross-prefix = $(firstword $(foreach c, $(1), \ - $(if $(shell command -v -- $(c)gcc 2>/dev/null), $(c)))) - -# output directory for tests below -TMPOUT = $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_$$$$ - -# try-run -# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise) -# Exit code chooses option. "$$TMP" serves as a temporary file and is -# automatically cleaned up. -try-run = $(shell set -e; \ - TMP=$(TMPOUT)/tmp; \ - TMPO=$(TMPOUT)/tmp.o; \ - mkdir -p $(TMPOUT); \ - trap "rm -rf $(TMPOUT)" EXIT; \ - if ($(1)) >/dev/null 2>&1; \ - then echo "$(2)"; \ - else echo "$(3)"; \ - fi) - -# as-option -# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,) - -as-option = $(call try-run,\ - $(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2)) - -# as-instr -# Usage: cflags-y += $(call as-instr,instr,option1,option2) - -as-instr = $(call try-run,\ - printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3)) - -# __cc-option -# Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586) -__cc-option = $(call try-run,\ - $(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4)) - -# cc-option -# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586) - -cc-option = $(call __cc-option, $(CC),\ - $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS),$(1),$(2)) - -# cc-option-yn -# Usage: flag := $(call cc-option-yn,-march=winchip-c6) -cc-option-yn = $(call try-run,\ - $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n) - -# cc-disable-warning -# Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable) -cc-disable-warning = $(call try-run,\ - $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1))) - -# cc-ifversion -# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1) -cc-ifversion = $(shell [ $(CONFIG_GCC_VERSION)0 $(1) $(2)000 ] && echo $(3) || echo $(4)) - -# ld-option -# Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y) -ld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3)) - -# ld-ifversion -# Usage: $(call ld-ifversion, -ge, 22252, y) -ld-ifversion = $(shell [ $(CONFIG_LD_VERSION)0 $(1) $(2)0 ] && echo $(3) || echo $(4)) - -###### - ### # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj= # Usage: diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 750d6d5225af..d74d3383666e 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -36,6 +36,7 @@ subdir-ccflags-y := -include include/config/auto.conf include $(srctree)/scripts/Kbuild.include +include $(srctree)/scripts/Makefile.compiler # The filename Kbuild has precedence over Makefile kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) diff --git a/scripts/Makefile.compiler b/scripts/Makefile.compiler new file mode 100644 index 000000000000..3f2f3665216f --- /dev/null +++ b/scripts/Makefile.compiler @@ -0,0 +1,75 @@ +# SPDX-License-Identifier: GPL-2.0-only + +# cc-cross-prefix +# Usage: CROSS_COMPILE := $(call cc-cross-prefix, m68k-linux-gnu- m68k-linux-) +# Return first where a gcc is found in PATH. +# If no gcc found in PATH with listed prefixes return nothing +# +# Note: '2>/dev/null' is here to force Make to invoke a shell. Otherwise, it +# would try to directly execute the shell builtin 'command'. This workaround +# should be kept for a long time since this issue was fixed only after the +# GNU Make 4.2.1 release. +cc-cross-prefix = $(firstword $(foreach c, $(1), \ + $(if $(shell command -v -- $(c)gcc 2>/dev/null), $(c)))) + +# output directory for tests below +TMPOUT = $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_$$$$ + +# try-run +# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise) +# Exit code chooses option. "$$TMP" serves as a temporary file and is +# automatically cleaned up. +try-run = $(shell set -e; \ + TMP=$(TMPOUT)/tmp; \ + TMPO=$(TMPOUT)/tmp.o; \ + mkdir -p $(TMPOUT); \ + trap "rm -rf $(TMPOUT)" EXIT; \ + if ($(1)) >/dev/null 2>&1; \ + then echo "$(2)"; \ + else echo "$(3)"; \ + fi) + +# as-option +# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,) + +as-option = $(call try-run,\ + $(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2)) + +# as-instr +# Usage: cflags-y += $(call as-instr,instr,option1,option2) + +as-instr = $(call try-run,\ + printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3)) + +# __cc-option +# Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586) +__cc-option = $(call try-run,\ + $(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4)) + +# cc-option +# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586) + +cc-option = $(call __cc-option, $(CC),\ + $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS),$(1),$(2)) + +# cc-option-yn +# Usage: flag := $(call cc-option-yn,-march=winchip-c6) +cc-option-yn = $(call try-run,\ + $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n) + +# cc-disable-warning +# Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable) +cc-disable-warning = $(call try-run,\ + $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1))) + +# cc-ifversion +# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1) +cc-ifversion = $(shell [ $(CONFIG_GCC_VERSION)0 $(1) $(2)000 ] && echo $(3) || echo $(4)) + +# ld-option +# Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y) +ld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3)) + +# ld-ifversion +# Usage: $(call ld-ifversion, -ge, 22252, y) +ld-ifversion = $(shell [ $(CONFIG_LD_VERSION)0 $(1) $(2)0 ] && echo $(3) || echo $(4)) From 805b2e1d427aab4bb27fa7c51ebb9db7547551b1 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 28 Feb 2021 15:10:28 +0900 Subject: [PATCH 03/42] 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(+) 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 # =========================================================================== From 609bbb4de4f85b7ef45d81a88e6b7dfe3bf5ccea Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 2 Mar 2021 23:26:14 +0900 Subject: [PATCH 04/42] 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(-) 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 From 5cc1247204616528b427e276c97c5bc4c9612347 Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Fri, 5 Mar 2021 10:27:07 +0100 Subject: [PATCH 05/42] kbuild: add CONFIG_VMLINUX_MAP expert option It can be quite useful to have ld emit a link map file, in order to debug or verify that special sections end up where they are supposed to, and to see what LD_DEAD_CODE_DATA_ELIMINATION manages to get rid of. The only reason I'm not just adding this unconditionally is that the .map file can be rather large (several MB), and that's a waste of space when one isn't interested in these things. Also make it depend on CONFIG_EXPERT. Signed-off-by: Rasmus Villemoes Signed-off-by: Masahiro Yamada --- .gitignore | 1 + Documentation/dontdiff | 1 + lib/Kconfig.debug | 10 ++++++++++ scripts/link-vmlinux.sh | 8 ++++++++ 4 files changed, 20 insertions(+) diff --git a/.gitignore b/.gitignore index 3af66272d6f1..3adea59847ce 100644 --- a/.gitignore +++ b/.gitignore @@ -59,6 +59,7 @@ modules.order /linux /vmlinux /vmlinux.32 +/vmlinux.map /vmlinux.symvers /vmlinux-gdb.py /vmlinuz diff --git a/Documentation/dontdiff b/Documentation/dontdiff index e361fc95ca29..ac42ad8d430d 100644 --- a/Documentation/dontdiff +++ b/Documentation/dontdiff @@ -252,6 +252,7 @@ vmlinux-* vmlinux.aout vmlinux.bin.all vmlinux.lds +vmlinux.map vmlinux.symvers vmlinuz voffset.h diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 2779c29d9981..b479ae609a31 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -449,6 +449,16 @@ config VMLINUX_VALIDATION depends on STACK_VALIDATION && DEBUG_ENTRY && !PARAVIRT default y +config VMLINUX_MAP + bool "Generate vmlinux.map file when linking" + depends on EXPERT + help + Selecting this option will pass "-Map=vmlinux.map" to ld + when linking vmlinux. That file can be useful for verifying + and debugging magic section games, and for seeing which + pieces of code get eliminated with + CONFIG_LD_DEAD_CODE_DATA_ELIMINATION. + config DEBUG_FORCE_WEAK_PER_CPU bool "Force weak per-cpu definitions" depends on DEBUG_KERNEL diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 3b261b0f74f0..855fd4e6f03e 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -155,6 +155,7 @@ vmlinux_link() local output=${1} local objects local strip_debug + local map_option info LD ${output} @@ -166,6 +167,10 @@ vmlinux_link() strip_debug=-Wl,--strip-debug fi + if [ -n "${CONFIG_VMLINUX_MAP}" ]; then + map_option="-Map=${output}.map" + fi + if [ "${SRCARCH}" != "um" ]; then if [ -n "${CONFIG_LTO_CLANG}" ]; then # Use vmlinux.o instead of performing the slow LTO @@ -187,6 +192,7 @@ vmlinux_link() ${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux} \ ${strip_debug#-Wl,} \ -o ${output} \ + ${map_option} \ -T ${lds} ${objects} else objects="-Wl,--whole-archive \ @@ -200,6 +206,7 @@ vmlinux_link() ${CC} ${CFLAGS_vmlinux} \ ${strip_debug} \ -o ${output} \ + ${map_option:+-Wl,${map_option}} \ -Wl,-T,${lds} \ ${objects} \ -lutil -lrt -lpthread @@ -303,6 +310,7 @@ cleanup() rm -f .tmp_vmlinux* rm -f System.map rm -f vmlinux + rm -f vmlinux.map rm -f vmlinux.o } From 0b956e204132ce3fe4221a062638bf83a30e6200 Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Fri, 5 Mar 2021 11:02:12 +0100 Subject: [PATCH 06/42] 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 +- scripts/link-vmlinux.sh | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) 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 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 855fd4e6f03e..e9516bdfcc6f 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -312,6 +312,7 @@ cleanup() rm -f vmlinux rm -f vmlinux.map rm -f vmlinux.o + rm -f .vmlinux.d } on_exit() @@ -449,3 +450,6 @@ if [ -n "${CONFIG_KALLSYMS}" ]; then exit 1 fi fi + +# For fixdep +echo "vmlinux: $0" > .vmlinux.d From a6601e01cd54838fc01e3c355476f67e7c887a67 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 6 Mar 2021 15:11:20 +0900 Subject: [PATCH 07/42] kbuild: rename multi-used-* to multi-obj-* I think multi-obj-* is clearer, and more consistent with real-obj-*. Rename as follows: multi-used-y -> multi-obj-y multi-used-m -> multi-obj-m multi-used -> multi-obj-ym Signed-off-by: Masahiro Yamada --- scripts/Makefile.build | 6 +++--- scripts/Makefile.lib | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index d74d3383666e..e47c054d3db2 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -445,11 +445,11 @@ quiet_cmd_link_multi-m = LD [M] $@ cmd_link_multi-m = $(LD) $(ld_flags) -r -o $@ $(filter %.o,$^) endif -$(multi-used-m): FORCE +$(multi-obj-m): FORCE $(call if_changed,link_multi-m) -$(call multi_depend, $(multi-used-m), .o, -objs -y -m) +$(call multi_depend, $(multi-obj-m), .o, -objs -y -m) -targets += $(multi-used-m) +targets += $(multi-obj-m) targets := $(filter-out $(PHONY), $(targets)) # Add intermediate targets: diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 8cd67b1b6d15..bc611c11e28a 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -48,9 +48,9 @@ endif suffix-search = $(foreach s,$(2),$($(1:.o=$s))) # If $(foo-objs), $(foo-y), $(foo-m), or $(foo-) exists, foo.o is a composite object multi-search = $(sort $(foreach m,$(1), $(if $(strip $(call suffix-search,$(m),$(2) -)), $(m)))) -multi-used-y := $(call multi-search,$(obj-y),-objs -y) -multi-used-m := $(call multi-search,$(obj-m),-objs -y -m) -multi-used := $(multi-used-y) $(multi-used-m) +multi-obj-y := $(call multi-search,$(obj-y),-objs -y) +multi-obj-m := $(call multi-search,$(obj-m),-objs -y -m) +multi-obj-ym := $(multi-obj-y) $(multi-obj-m) # Replace multi-part objects by their individual parts, # including built-in.a from subdirectories @@ -92,12 +92,12 @@ obj-m := $(addprefix $(obj)/,$(obj-m)) lib-y := $(addprefix $(obj)/,$(lib-y)) real-obj-y := $(addprefix $(obj)/,$(real-obj-y)) real-obj-m := $(addprefix $(obj)/,$(real-obj-m)) -multi-used-m := $(addprefix $(obj)/,$(multi-used-m)) +multi-obj-m := $(addprefix $(obj)/, $(multi-obj-m)) subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) # Finds the multi-part object the current object will be linked into. # If the object belongs to two or more multi-part objects, list them all. -modname-multi = $(sort $(foreach m,$(multi-used),\ +modname-multi = $(sort $(foreach m,$(multi-obj-ym),\ $(if $(filter $*.o, $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$(m:.o=)))) __modname = $(if $(modname-multi),$(modname-multi),$(basetarget)) From a34e6d1e4a49035203819425694349caa004992a Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sat, 6 Mar 2021 15:11:21 +0900 Subject: [PATCH 08/42] kbuild: move $(strip ) to suffix-search definition Move $(strip ...) to the callee from the callers of suffix-search. It shortens the code slightly. Adding a space after a comma will not be a matter. I also dropped parentheses from single character variables. Signed-off-by: Masahiro Yamada --- scripts/Makefile.lib | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index bc611c11e28a..a4fbaf8880b9 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -45,16 +45,16 @@ obj-y := $(filter-out %/, $(obj-y)) endif # Expand $(foo-objs) $(foo-y) by calling $(call suffix-search,foo.o,-objs -y) -suffix-search = $(foreach s,$(2),$($(1:.o=$s))) +suffix-search = $(strip $(foreach s, $2, $($(1:.o=$s)))) # If $(foo-objs), $(foo-y), $(foo-m), or $(foo-) exists, foo.o is a composite object -multi-search = $(sort $(foreach m,$(1), $(if $(strip $(call suffix-search,$(m),$(2) -)), $(m)))) +multi-search = $(sort $(foreach m, $1, $(if $(call suffix-search, $m, $2 -), $m))) multi-obj-y := $(call multi-search,$(obj-y),-objs -y) multi-obj-m := $(call multi-search,$(obj-m),-objs -y -m) multi-obj-ym := $(multi-obj-y) $(multi-obj-m) # Replace multi-part objects by their individual parts, # including built-in.a from subdirectories -real-search = $(foreach m,$(1), $(if $(strip $(call suffix-search,$(m),$(2) -)),$(call suffix-search,$(m),$(2)),$(m))) +real-search = $(foreach m, $1, $(if $(call suffix-search, $m, $2 -), $(call suffix-search, $m, $2), $m)) real-obj-y := $(call real-search, $(obj-y),-objs -y) real-obj-m := $(call real-search, $(obj-m),-objs -y -m) From c91d4e47e10ee4d3163838b1b727fe1d0664115b Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Tue, 9 Mar 2021 13:59:14 -0700 Subject: [PATCH 09/42] 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(-) 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 From eec08090bcc113643522d4272dc0b945045aba74 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Tue, 9 Mar 2021 13:59:15 -0700 Subject: [PATCH 10/42] 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(-) 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) From 879a3209009fbbeb013a1d81952abcbe13918a13 Mon Sep 17 00:00:00 2001 From: Bhaskar Chowdhury Date: Sun, 14 Mar 2021 10:00:44 +0530 Subject: [PATCH 11/42] docs: kbuild: Fix a typo in the file Kconfig.recursion-issue-02 s/sematics/semantics/ Signed-off-by: Bhaskar Chowdhury Acked-by: Randy Dunlap Signed-off-by: Masahiro Yamada --- Documentation/kbuild/Kconfig.recursion-issue-02 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/kbuild/Kconfig.recursion-issue-02 b/Documentation/kbuild/Kconfig.recursion-issue-02 index df245fd7670d..0034eb494d11 100644 --- a/Documentation/kbuild/Kconfig.recursion-issue-02 +++ b/Documentation/kbuild/Kconfig.recursion-issue-02 @@ -6,7 +6,7 @@ # make KBUILD_KCONFIG=Documentation/kbuild/Kconfig.recursion-issue-02 allnoconfig # # The recursive limitations with Kconfig has some non intuitive implications on -# kconfig sematics which are documented here. One known practical implication +# kconfig semantics which are documented here. One known practical implication # of the recursive limitation is that drivers cannot negate features from other # drivers if they share a common core requirement and use disjoint semantics to # annotate those requirements, ie, some drivers use "depends on" while others From 6e0839fda3f8598b164a7f23f3eec039e2db5fbc Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Sun, 14 Mar 2021 15:15:50 +0900 Subject: [PATCH 12/42] 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 --- Documentation/devicetree/bindings/Makefile | 2 +- Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/Makefile b/Documentation/devicetree/bindings/Makefile index 780e5618ec0a..ac446c62fbc3 100644 --- a/Documentation/devicetree/bindings/Makefile +++ b/Documentation/devicetree/bindings/Makefile @@ -48,7 +48,7 @@ define rule_chkdt $(call cmd,mk_schema) endef -DT_DOCS = $(shell $(find_cmd) | sed -e 's|^$(srctree)/||') +DT_DOCS = $(patsubst $(srctree)/%,%,$(shell $(find_cmd))) override DTC_FLAGS := \ -Wno-avoid_unnecessary_addr_size \ 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),) From e24b3ffcf4216d819b52618b6f17ba7410d1d845 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 16 Mar 2021 01:12:55 +0900 Subject: [PATCH 13/42] kbuild: collect minimum tool versions into scripts/min-tool-version.sh The kernel build uses various tools, many of which are provided by the same software suite, for example, LLVM and Binutils. When you raise the minimum version of Clang/LLVM, you need to update clang_min_version in scripts/cc-version.sh and also lld_min_version in scripts/ld-version.sh. Kbuild can handle CC=clang and LD=ld.lld independently, but it does not make much sense to maintain their versions separately. Let's create a central place of minimum tool versions so you do not need to touch multiple files. scripts/min-tool-version.sh prints the minimum version of the given tool. Signed-off-by: Masahiro Yamada Reviewed-by: Nathan Chancellor Acked-by: Miguel Ojeda Tested-by: Sedat Dilek --- scripts/cc-version.sh | 20 +++++-------------- scripts/ld-version.sh | 11 ++++------- scripts/min-tool-version.sh | 39 +++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 22 deletions(-) create mode 100755 scripts/min-tool-version.sh diff --git a/scripts/cc-version.sh b/scripts/cc-version.sh index 3f2ee885b116..f1952c522466 100755 --- a/scripts/cc-version.sh +++ b/scripts/cc-version.sh @@ -6,18 +6,6 @@ set -e -# When you raise the minimum compiler version, please update -# Documentation/process/changes.rst as well. -gcc_min_version=4.9.0 -clang_min_version=10.0.1 -icc_min_version=16.0.3 # temporary - -# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63293 -# https://lore.kernel.org/r/20210107111841.GN1551@shell.armlinux.org.uk -if [ "$SRCARCH" = arm64 ]; then - gcc_min_version=5.1.0 -fi - # Print the compiler name and some version components. get_compiler_info() { @@ -48,18 +36,20 @@ set -- $(get_compiler_info "$@") name=$1 +min_tool_version=$(dirname $0)/min-tool-version.sh + case "$name" in GCC) version=$2.$3.$4 - min_version=$gcc_min_version + min_version=$($min_tool_version gcc) ;; Clang) version=$2.$3.$4 - min_version=$clang_min_version + min_version=$($min_tool_version llvm) ;; ICC) version=$(($2 / 100)).$(($2 % 100)).$3 - min_version=$icc_min_version + min_version=$($min_tool_version icc) ;; *) echo "$orig_args: unknown compiler" >&2 diff --git a/scripts/ld-version.sh b/scripts/ld-version.sh index 1bf3aadde9de..a78b804b680c 100755 --- a/scripts/ld-version.sh +++ b/scripts/ld-version.sh @@ -6,11 +6,6 @@ set -e -# When you raise the minimum linker version, please update -# Documentation/process/changes.rst as well. -bfd_min_version=2.23.0 -lld_min_version=10.0.1 - # Convert the version string x.y.z to a canonical 5 or 6-digit form. get_canonical_version() { @@ -35,10 +30,12 @@ set -- $(LC_ALL=C "$@" --version) IFS=' ' set -- $1 +min_tool_version=$(dirname $0)/min-tool-version.sh + if [ "$1" = GNU -a "$2" = ld ]; then shift $(($# - 1)) version=$1 - min_version=$bfd_min_version + min_version=$($min_tool_version binutils) name=BFD disp_name="GNU ld" elif [ "$1" = GNU -a "$2" = gold ]; then @@ -51,7 +48,7 @@ else if [ "$1" = LLD ]; then version=$2 - min_version=$lld_min_version + min_version=$($min_tool_version llvm) name=LLD disp_name=LLD else diff --git a/scripts/min-tool-version.sh b/scripts/min-tool-version.sh new file mode 100755 index 000000000000..d22cf91212b0 --- /dev/null +++ b/scripts/min-tool-version.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-only +# +# Print the minimum supported version of the given tool. +# When you raise the minimum version, please update +# Documentation/process/changes.rst as well. + +set -e + +if [ $# != 1 ]; then + echo "Usage: $0 toolname" >&2 + exit 1 +fi + +case "$1" in +binutils) + echo 2.23.0 + ;; +gcc) + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63293 + # https://lore.kernel.org/r/20210107111841.GN1551@shell.armlinux.org.uk + if [ "$SRCARCH" = arm64 ]; then + echo 5.1.0 + else + echo 4.9.0 + fi + ;; +icc) + # temporary + echo 16.0.3 + ;; +llvm) + echo 10.0.1 + ;; +*) + echo "$1: unknown tool" >&2 + exit 1 + ;; +esac From ba64beb17493a4bfec563100c86a462a15926f24 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 16 Mar 2021 01:12:56 +0900 Subject: [PATCH 14/42] 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 +- arch/Kconfig | 3 +- init/Kconfig | 12 ++++++ scripts/Kconfig.include | 6 +++ scripts/as-version.sh | 82 +++++++++++++++++++++++++++++++++++++++++ scripts/dummy-tools/gcc | 6 +++ 6 files changed, 110 insertions(+), 3 deletions(-) create mode 100755 scripts/as-version.sh 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)) diff --git a/arch/Kconfig b/arch/Kconfig index ecfd3520b676..555b4f09a9b2 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -631,8 +631,7 @@ config ARCH_SUPPORTS_LTO_CLANG_THIN config HAS_LTO_CLANG def_bool y # Clang >= 11: https://github.com/ClangBuiltLinux/linux/issues/510 - depends on CC_IS_CLANG && CLANG_VERSION >= 110000 && LD_IS_LLD - depends on $(success,test $(LLVM_IAS) -eq 1) + depends on CC_IS_CLANG && CLANG_VERSION >= 110000 && LD_IS_LLD && AS_IS_LLVM depends on $(success,$(NM) --help | head -n 1 | grep -qi llvm) depends on $(success,$(AR) --help | head -n 1 | grep -qi llvm) depends on ARCH_SUPPORTS_LTO_CLANG diff --git a/init/Kconfig b/init/Kconfig index 5f5c776ef192..019c1874e609 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -41,6 +41,18 @@ config CLANG_VERSION default $(cc-version) if CC_IS_CLANG default 0 +config AS_IS_GNU + def_bool $(success,test "$(as-name)" = GNU) + +config AS_IS_LLVM + def_bool $(success,test "$(as-name)" = LLVM) + +config AS_VERSION + int + # Use clang version if this is the integrated assembler + default CLANG_VERSION if AS_IS_LLVM + default $(as-version) + config LD_IS_BFD def_bool $(success,test "$(ld-name)" = BFD) diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include index 58fdb5308725..0496efd6e117 100644 --- a/scripts/Kconfig.include +++ b/scripts/Kconfig.include @@ -45,6 +45,12 @@ $(error-if,$(success,test -z "$(cc-info)"),Sorry$(comma) this compiler is not su cc-name := $(shell,set -- $(cc-info) && echo $1) cc-version := $(shell,set -- $(cc-info) && echo $2) +# Get the assembler name, version, and error out if it is not supported. +as-info := $(shell,$(srctree)/scripts/as-version.sh $(CC) $(CLANG_FLAGS)) +$(error-if,$(success,test -z "$(as-info)"),Sorry$(comma) this assembler is not supported.) +as-name := $(shell,set -- $(as-info) && echo $1) +as-version := $(shell,set -- $(as-info) && echo $2) + # Get the linker name, version, and error out if it is not supported. ld-info := $(shell,$(srctree)/scripts/ld-version.sh $(LD)) $(error-if,$(success,test -z "$(ld-info)"),Sorry$(comma) this linker is not supported.) diff --git a/scripts/as-version.sh b/scripts/as-version.sh new file mode 100755 index 000000000000..8b9410e329df --- /dev/null +++ b/scripts/as-version.sh @@ -0,0 +1,82 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-only +# +# Print the assembler name and its version in a 5 or 6-digit form. +# Also, perform the minimum version check. +# (If it is the integrated assembler, return 0 as the version, and +# skip the version check.) + +set -e + +# Convert the version string x.y.z to a canonical 5 or 6-digit form. +get_canonical_version() +{ + IFS=. + set -- $1 + + # If the 2nd or 3rd field is missing, fill it with a zero. + # + # The 4th field, if present, is ignored. + # This occurs in development snapshots as in 2.35.1.20201116 + echo $((10000 * $1 + 100 * ${2:-0} + ${3:-0})) +} + +# Clang fails to handle -Wa,--version unless -no-integrated-as is given. +# We check -(f)integrated-as, expecting it is explicitly passed in for the +# integrated assembler case. +check_integrated_as() +{ + while [ $# -gt 0 ]; do + if [ "$1" = -integrated-as -o "$1" = -fintegrated-as ]; then + # For the intergrated assembler, we do not check the + # version here. It is the same as the clang version, and + # it has been already checked by scripts/cc-version.sh. + echo LLVM 0 + exit 0 + fi + shift + done +} + +check_integrated_as "$@" + +orig_args="$@" + +# Get the first line of the --version output. +IFS=' +' +set -- $(LC_ALL=C "$@" -Wa,--version -c -x assembler /dev/null -o /dev/null 2>/dev/null) + +# Split the line on spaces. +IFS=' ' +set -- $1 + +min_tool_version=$(dirname $0)/min-tool-version.sh + +if [ "$1" = GNU -a "$2" = assembler ]; then + shift $(($# - 1)) + version=$1 + min_version=$($min_tool_version binutils) + name=GNU +else + echo "$orig_args: unknown assembler invoked" >&2 + exit 1 +fi + +# Some distributions append a package release number, as in 2.34-4.fc32 +# Trim the hyphen and any characters that follow. +version=${version%-*} + +cversion=$(get_canonical_version $version) +min_cversion=$(get_canonical_version $min_version) + +if [ "$cversion" -lt "$min_cversion" ]; then + echo >&2 "***" + echo >&2 "*** Assembler is too old." + echo >&2 "*** Your $name assembler version: $version" + echo >&2 "*** Minimum $name assembler version: $min_version" + echo >&2 "***" + exit 1 +fi + +echo $name $cversion diff --git a/scripts/dummy-tools/gcc b/scripts/dummy-tools/gcc index 39e65fee59bd..f6d543725f1e 100755 --- a/scripts/dummy-tools/gcc +++ b/scripts/dummy-tools/gcc @@ -67,6 +67,12 @@ if arg_contain -E "$@"; then fi fi +# To set CONFIG_AS_IS_GNU +if arg_contain -Wa,--version "$@"; then + echo "GNU assembler (scripts/dummy-tools) 2.50" + exit 0 +fi + if arg_contain -S "$@"; then # For scripts/gcc-x86-*-has-stack-protector.sh if arg_contain -fstack-protector "$@"; then From 2e98815794fb51250da4528f67fc2f699d5e3c37 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 16 Mar 2021 01:12:57 +0900 Subject: [PATCH 15/42] kbuild: dwarf: use AS_VERSION instead of test_dwarf5_support.sh The test code in scripts/test_dwarf5_support.sh is somewhat difficult to understand, but after all, we want to check binutils >= 2.35.2 From the former discussion, the requirement for generating DWARF v5 from C code is as follows: - gcc + gnu as -> requires gcc 5.0+ (but 7.0+ for full support) - clang + gnu as -> requires binutils 2.35.2+ - clang + integrated as -> OK Signed-off-by: Masahiro Yamada Reviewed-by: Nathan Chancellor Reviewed-by: Nick Desaulniers --- lib/Kconfig.debug | 3 +-- scripts/test_dwarf5_support.sh | 8 -------- 2 files changed, 1 insertion(+), 10 deletions(-) delete mode 100755 scripts/test_dwarf5_support.sh diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index b479ae609a31..c85d5f7a1aeb 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -284,8 +284,7 @@ config DEBUG_INFO_DWARF4 config DEBUG_INFO_DWARF5 bool "Generate DWARF Version 5 debuginfo" - depends on GCC_VERSION >= 50000 || CC_IS_CLANG - depends on CC_IS_GCC || $(success,$(srctree)/scripts/test_dwarf5_support.sh $(CC) $(CLANG_FLAGS)) + depends on GCC_VERSION >= 50000 || (CC_IS_CLANG && (AS_IS_LLVM || (AS_IS_GNU && AS_VERSION >= 23502))) depends on !DEBUG_INFO_BTF help Generate DWARF v5 debug info. Requires binutils 2.35.2, gcc 5.0+ (gcc diff --git a/scripts/test_dwarf5_support.sh b/scripts/test_dwarf5_support.sh deleted file mode 100755 index c46e2456b47a..000000000000 --- a/scripts/test_dwarf5_support.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0 - -# Test that the assembler doesn't need -Wa,-gdwarf-5 when presented with DWARF -# v5 input, such as `.file 0` and `md5 0x00`. Should be fixed in GNU binutils -# 2.35.2. https://sourceware.org/bugzilla/show_bug.cgi?id=25611 -echo '.file 0 "filename" md5 0x7a0b65214090b6693bd1dc24dd248245' | \ - $* -gdwarf-5 -Wno-unused-command-line-argument -c -x assembler -o /dev/null - From 987fdfec24102a151c032c467e51c7f0d6d18af9 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 24 Mar 2021 16:11:28 +0900 Subject: [PATCH 16/42] arm64: move --fix-cortex-a53-843419 linker test to Kconfig Since commit 805b2e1d427a ("kbuild: include Makefile.compiler only when compiler is needed"), "make ARCH=arm64 (modules_)install" shows a false positive warning. Move the ld-option test to Kconfig, so that the result can be stored in the .config file, avoiding multiple-time evaluations in the build and installation time. Reported-by: Nathan Chancellor Signed-off-by: Masahiro Yamada Acked-by: Will Deacon Tested-by: Nathan Chancellor Reviewed-by: Nathan Chancellor --- arch/arm64/Kconfig | 3 +++ arch/arm64/Makefile | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 5656e7aacd69..4a33428de8ac 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -521,6 +521,9 @@ config ARM64_ERRATUM_843419 If unsure, say Y. +config ARM64_LD_HAS_FIX_ERRATUM_843419 + def_bool $(ld-option,--fix-cortex-a53-843419) + config ARM64_ERRATUM_1024718 bool "Cortex-A55: 1024718: Update of DBM/AP bits without break before make might result in incorrect update" default y diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 5b84aec31ed3..7ef44478560d 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -21,7 +21,7 @@ LDFLAGS_vmlinux += -shared -Bsymbolic -z notext \ endif ifeq ($(CONFIG_ARM64_ERRATUM_843419),y) - ifeq ($(call ld-option, --fix-cortex-a53-843419),) + ifneq ($(CONFIG_ARM64_LD_HAS_FIX_ERRATUM_843419),y) $(warning ld does not support --fix-cortex-a53-843419; kernel may be susceptible to erratum) else LDFLAGS_vmlinux += --fix-cortex-a53-843419 From 69bc8d386aebbd91a6bb44b6d33f77c8dfa9ed8c Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 26 Mar 2021 03:54:09 +0900 Subject: [PATCH 17/42] 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 --- .gitignore | 1 + Documentation/dontdiff | 1 + Makefile | 2 +- scripts/Makefile.modpost | 15 ++++++++++++++- scripts/mod/modpost.c | 15 +-------------- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 3adea59847ce..df8d3146a43f 100644 --- a/.gitignore +++ b/.gitignore @@ -57,6 +57,7 @@ modules.order /tags /TAGS /linux +/modules-only.symvers /vmlinux /vmlinux.32 /vmlinux.map diff --git a/Documentation/dontdiff b/Documentation/dontdiff index ac42ad8d430d..910b30a2a7d9 100644 --- a/Documentation/dontdiff +++ b/Documentation/dontdiff @@ -178,6 +178,7 @@ mktables mktree mkutf8data modpost +modules-only.symvers modules.builtin modules.builtin.modinfo modules.nsdeps 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 diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index df57e259fac3..3f5b09a09aef 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -68,7 +68,20 @@ else ifeq ($(KBUILD_EXTMOD),) input-symdump := vmlinux.symvers -output-symdump := Module.symvers +output-symdump := modules-only.symvers + +quiet_cmd_cat = GEN $@ + cmd_cat = cat $(real-prereqs) > $@ + +ifneq ($(wildcard vmlinux.symvers),) + +__modpost: Module.symvers +Module.symvers: vmlinux.symvers modules-only.symvers FORCE + $(call if_changed,cat) + +targets += Module.symvers + +endif else diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 24725e50c7b4..10c3fba26f03 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -2423,19 +2423,6 @@ fail: fatal("parse error in symbol dump file\n"); } -/* For normal builds always dump all symbols. - * For external modules only dump symbols - * that are not read from kernel Module.symvers. - **/ -static int dump_sym(struct symbol *sym) -{ - if (!external_module) - return 1; - if (sym->module->from_dump) - return 0; - return 1; -} - static void write_dump(const char *fname) { struct buffer buf = { }; @@ -2446,7 +2433,7 @@ static void write_dump(const char *fname) for (n = 0; n < SYMBOL_HASH_SIZE ; n++) { symbol = symbolhash[n]; while (symbol) { - if (dump_sym(symbol)) { + if (!symbol->module->from_dump) { namespace = symbol->namespace; buf_printf(&buf, "0x%08x\t%s\t%s\t%s\t%s\n", symbol->crc, symbol->name, From 5ab70ff4286f74732c082b65366bad39146d2b10 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 26 Mar 2021 03:54:10 +0900 Subject: [PATCH 18/42] kbuild: do not set -w for vmlinux.o modpost The -w option is meaningless for the first pass of modpost (vmlinux.o). We know there are unresolved symbols in vmlinux.o, hence we skip check_exports() and other checks when mod->is_vmlinux is set. See the following part in the for-loop. if (mod->is_vmlinux || mod->from_dump) continue; Signed-off-by: Masahiro Yamada --- scripts/Makefile.modpost | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index 3f5b09a09aef..b3e08fb1fd56 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -32,8 +32,6 @@ # Step 4 is solely used to allow module versioning in external modules, # where the CRC of each module is retrieved from the Module.symvers file. -# KBUILD_MODPOST_WARN can be set to avoid error out in case of undefined -# symbols in the final module linking stage # KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules. # This is solely useful to speed up test compiles @@ -50,7 +48,6 @@ MODPOST = scripts/mod/modpost \ $(if $(CONFIG_MODVERSIONS),-m) \ $(if $(CONFIG_MODULE_SRCVERSION_ALL),-a) \ $(if $(CONFIG_SECTION_MISMATCH_WARN_ONLY),,-E) \ - $(if $(KBUILD_MODPOST_WARN),-w) \ -o $@ ifdef MODPOST_VMLINUX @@ -136,6 +133,11 @@ endif modules := $(sort $(shell cat $(MODORDER))) +# KBUILD_MODPOST_WARN can be set to avoid error out in case of undefined symbols +ifneq ($(KBUILD_MODPOST_WARN),) +MODPOST += -w +endif + # Read out modules.order to pass in modpost. # Otherwise, allmodconfig would fail with "Argument list too long". quiet_cmd_modpost = MODPOST $@ From 4475dff55c54d855ef0179a055b3ce20a9c1ab3e Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 26 Mar 2021 03:54:11 +0900 Subject: [PATCH 19/42] kbuild: fix false-positive modpost warning when all symbols are trimmed Nathan reports that the mips defconfig emits the following warning: WARNING: modpost: Symbol info of vmlinux is missing. Unresolved symbol check will be entirely skipped. This false-positive happens when CONFIG_TRIM_UNUSED_KSYMS is enabled, but no CONFIG option is set to 'm'. Commit a0590473c5e6 ("nfs: fix PNFS_FLEXFILE_LAYOUT Kconfig default") turned the last 'm' into 'y' for the mips defconfig, and uncovered this issue. In this case, the module feature itself is enabled, but we have no module to build. As a result, CONFIG_TRIM_UNUSED_KSYMS drops all the instances of EXPORT_SYMBOL. Then, modpost wrongly assumes vmlinux is missing because vmlinux.symvers is empty. (As another false-positive case, you can create a module that does not use any symbol of vmlinux). The current behavior is to entirely suppress the unresolved symbol warnings when vmlinux is missing just because there are too many. I found the origin of this code in the historical git tree. [1] If this is a matter of noisiness, I think modpost can display the first 10 warnings, and the number of suppressed warnings at the end. You will get a bit noisier logs when you run 'make modules' without vmlinux, but such warnings are better to show because you never know the resulting modules are actually loadable or not. This commit changes the following: - If any of input *.symver files is missing, pass -w option to let the module build keep going with warnings instead of errors. - If there are too many (10+) unresolved symbol warnings, show only the first 10, and also the number of suppressed warnings. [1]: https://git.kernel.org/pub/scm/linux/kernel/git/history/history.git/commit/?id=1cc0e0529569bf6a94f6d49770aa6d4b599d2c46 Reported-by: Nathan Chancellor Signed-off-by: Masahiro Yamada --- scripts/Makefile.modpost | 7 +++++-- scripts/mod/modpost.c | 25 ++++++++++++------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index b3e08fb1fd56..c383ba33d837 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -98,9 +98,11 @@ output-symdump := $(KBUILD_EXTMOD)/Module.symvers endif +existing-input-symdump := $(wildcard $(input-symdump)) + # modpost options for modules (both in-kernel and external) MODPOST += \ - $(addprefix -i ,$(wildcard $(input-symdump))) \ + $(addprefix -i ,$(existing-input-symdump)) \ $(if $(KBUILD_NSDEPS),-d $(MODULES_NSDEPS)) \ $(if $(CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS)$(KBUILD_NSDEPS),-N) @@ -114,6 +116,7 @@ VPATH := $(input-symdump): @echo >&2 'WARNING: Symbol version dump "$@" is missing.' @echo >&2 ' Modules may not have dependencies or modversions.' + @echo >&2 ' You may get many unresolved symbol warnings.' ifdef CONFIG_LTO_CLANG # With CONFIG_LTO_CLANG, .o files might be LLVM bitcode, so we need to run @@ -134,7 +137,7 @@ endif modules := $(sort $(shell cat $(MODORDER))) # KBUILD_MODPOST_WARN can be set to avoid error out in case of undefined symbols -ifneq ($(KBUILD_MODPOST_WARN),) +ifneq ($(KBUILD_MODPOST_WARN)$(filter-out $(existing-input-symdump), $(input-symdump)),) MODPOST += -w endif diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 10c3fba26f03..7c6bec78fa34 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -23,8 +23,6 @@ /* Are we using CONFIG_MODVERSIONS? */ static int modversions = 0; -/* Warn about undefined symbols? (do so if we have vmlinux) */ -static int have_vmlinux = 0; /* Is CONFIG_MODULE_SRCVERSION_ALL set? */ static int all_versions = 0; /* If we are modposting external module set to 1 */ @@ -41,6 +39,13 @@ static int allow_missing_ns_imports; static bool error_occurred; +/* + * Cut off the warnings when there are too many. This typically occurs when + * vmlinux is missing. ('make modules' without building vmlinux.) + */ +#define MAX_UNRESOLVED_REPORTS 10 +static unsigned int nr_unresolved; + enum export { export_plain, export_gpl, @@ -177,9 +182,6 @@ static struct module *new_module(const char *modname) mod->next = modules; modules = mod; - if (mod->is_vmlinux) - have_vmlinux = 1; - return mod; } @@ -2141,7 +2143,7 @@ static void check_exports(struct module *mod) const char *basename; exp = find_symbol(s->name); if (!exp || exp->module == mod) { - if (have_vmlinux && !s->weak) + if (!s->weak && nr_unresolved++ < MAX_UNRESOLVED_REPORTS) modpost_log(warn_unresolved ? LOG_WARN : LOG_ERROR, "\"%s\" [%s.ko] undefined!\n", s->name, mod->name); @@ -2545,13 +2547,6 @@ int main(int argc, char **argv) if (files_source) read_symbols_from_files(files_source); - /* - * When there's no vmlinux, don't print warnings about - * unresolved symbols (since there'll be too many ;) - */ - if (!have_vmlinux) - warn("Symbol info of vmlinux is missing. Unresolved symbol check will be entirely skipped.\n"); - for (mod = modules; mod; mod = mod->next) { char fname[PATH_MAX]; @@ -2595,6 +2590,10 @@ int main(int argc, char **argv) } } + if (nr_unresolved > MAX_UNRESOLVED_REPORTS) + warn("suppressed %u unresolved symbol warnings because there were too many)\n", + nr_unresolved - MAX_UNRESOLVED_REPORTS); + free(buf.p); return error_occurred ? 1 : 0; From f3945833e436d79d9a97e776c4986af8c9cbb483 Mon Sep 17 00:00:00 2001 From: Bhaskar Chowdhury Date: Fri, 26 Mar 2021 11:22:19 +0530 Subject: [PATCH 20/42] scripts: modpost.c: Fix a few typos s/agorithm/algorithm/ s/criterias/criteria/ s/targetting/targeting/ ....two different places. Signed-off-by: Bhaskar Chowdhury Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 7c6bec78fa34..20aab6960559 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -204,7 +204,7 @@ struct symbol { static struct symbol *symbolhash[SYMBOL_HASH_SIZE]; -/* This is based on the hash agorithm from gdbm, via tdb */ +/* This is based on the hash algorithm from gdbm, via tdb */ static inline unsigned int tdb_hash(const char *name) { unsigned value; /* Used to compute the hash value. */ @@ -987,7 +987,7 @@ enum mismatch { }; /** - * Describe how to match sections on different criterias: + * Describe how to match sections on different criteria: * * @fromsec: Array of sections to be matched. * @@ -995,12 +995,12 @@ enum mismatch { * this array is forbidden (black-list). Can be empty. * * @good_tosec: Relocations applied to a section in @fromsec must be - * targetting sections in this array (white-list). Can be empty. + * targeting sections in this array (white-list). Can be empty. * * @mismatch: Type of mismatch. * * @symbol_white_list: Do not match a relocation to a symbol in this list - * even if it is targetting a section in @bad_to_sec. + * even if it is targeting a section in @bad_to_sec. * * @handler: Specific handler to call when a match is found. If NULL, * default_mismatch_handler() will be called. From 4b97ec0e9cfd5995f41b9726c88566a31f4625cc Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 31 Mar 2021 22:38:02 +0900 Subject: [PATCH 21/42] 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(-) 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 From 3e3005df73b535cb849cf4ec8075d6aa3c460f68 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 31 Mar 2021 22:38:03 +0900 Subject: [PATCH 22/42] 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(-) 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))) From 3ac42b2112532a71125eea6bb07361deeca9aaa1 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 31 Mar 2021 22:38:04 +0900 Subject: [PATCH 23/42] 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(-) 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) From 1a998be620a10000c1e1240026e4bd6bc3378c96 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 31 Mar 2021 22:38:05 +0900 Subject: [PATCH 24/42] 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 +++++----- scripts/modules-check.sh | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) 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) diff --git a/scripts/modules-check.sh b/scripts/modules-check.sh index 43de226071ae..e06327722263 100755 --- a/scripts/modules-check.sh +++ b/scripts/modules-check.sh @@ -13,10 +13,10 @@ exit_code=0 # Check uniqueness of module names check_same_name_modules() { - for m in $(sed 's:.*/::' $1 | sort | uniq -d) + for m in $(sed 's:.*/::' "$1" | sort | uniq -d) do echo "error: the following would cause module name conflict:" >&2 - sed -n "/\/$m/s:^: :p" modules.order >&2 + sed -n "/\/$m/s:^: :p" "$1" >&2 exit_code=1 done } From 7f69180b8e905fe13559573b89245f6256b99434 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 31 Mar 2021 22:38:06 +0900 Subject: [PATCH 25/42] 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(-) 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: From ccae4cfa7bfbec323abc399228e0ada7c377b16b Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 31 Mar 2021 22:38:07 +0900 Subject: [PATCH 26/42] 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 +- scripts/Makefile.modinst | 36 ++++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 17 deletions(-) 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 diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst index ad1981233d0b..8e9debb781d1 100644 --- a/scripts/Makefile.modinst +++ b/scripts/Makefile.modinst @@ -8,28 +8,32 @@ __modinst: include $(srctree)/scripts/Kbuild.include -modules := $(sort $(shell cat $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/)modules.order)) +modules := $(sort $(shell cat $(MODORDER))) + +ifeq ($(KBUILD_EXTMOD),) +dst := $(MODLIB)/kernel +else +INSTALL_MOD_DIR ?= extra +dst := $(MODLIB)/$(INSTALL_MOD_DIR) +endif + +modules := $(patsubst $(extmod_prefix)%, $(dst)/%, $(modules)) -PHONY += $(modules) __modinst: $(modules) @: # Don't stop modules_install if we can't sign external modules. -quiet_cmd_modules_install = INSTALL $@ - cmd_modules_install = \ - mkdir -p $(2) ; \ - cp $@ $(2) ; \ - $(mod_strip_cmd) $(2)/$(notdir $@) ; \ - $(mod_sign_cmd) $(2)/$(notdir $@) $(patsubst %,|| true,$(KBUILD_EXTMOD)) ; \ - $(mod_compress_cmd) $(2)/$(notdir $@) +quiet_cmd_install = INSTALL $@ + cmd_install = \ + mkdir -p $(dir $@); cp $< $@; \ + $(mod_strip_cmd) $@; \ + $(mod_sign_cmd) $@ $(patsubst %,|| true,$(KBUILD_EXTMOD)) ; \ + $(mod_compress_cmd) $@ -# Modules built outside the kernel source tree go into extra by default -INSTALL_MOD_DIR ?= extra -ext-mod-dir = $(INSTALL_MOD_DIR)$(subst $(patsubst %/,%,$(KBUILD_EXTMOD)),,$(@D)) +$(modules): $(dst)/%: $(extmod_prefix)% FORCE + $(call cmd,install) -modinst_dir = $(if $(KBUILD_EXTMOD),$(ext-mod-dir),kernel/$(@D)) - -$(modules): - $(call cmd,modules_install,$(MODLIB)/$(modinst_dir)) +PHONY += FORCE +FORCE: .PHONY: $(PHONY) From 65ce9c38326e2588fcd1a3a4817c14b4660f430b Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 31 Mar 2021 22:38:08 +0900 Subject: [PATCH 27/42] 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 ----------------- scripts/Makefile.modinst | 78 +++++++++++++++++++++++++++++++++++----- 2 files changed, 69 insertions(+), 41 deletions(-) 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)) diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst index 8e9debb781d1..84696ef99df7 100644 --- a/scripts/Makefile.modinst +++ b/scripts/Makefile.modinst @@ -6,6 +6,7 @@ PHONY := __modinst __modinst: +include include/config/auto.conf include $(srctree)/scripts/Kbuild.include modules := $(sort $(shell cat $(MODORDER))) @@ -17,21 +18,80 @@ INSTALL_MOD_DIR ?= extra dst := $(MODLIB)/$(INSTALL_MOD_DIR) endif -modules := $(patsubst $(extmod_prefix)%, $(dst)/%, $(modules)) +suffix-y := +suffix-$(CONFIG_MODULE_COMPRESS_GZIP) := .gz +suffix-$(CONFIG_MODULE_COMPRESS_XZ) := .xz + +modules := $(patsubst $(extmod_prefix)%, $(dst)/%$(suffix-y), $(modules)) __modinst: $(modules) @: -# Don't stop modules_install if we can't sign external modules. -quiet_cmd_install = INSTALL $@ - cmd_install = \ - mkdir -p $(dir $@); cp $< $@; \ - $(mod_strip_cmd) $@; \ - $(mod_sign_cmd) $@ $(patsubst %,|| true,$(KBUILD_EXTMOD)) ; \ - $(mod_compress_cmd) $@ +quiet_cmd_none = + cmd_none = : -$(modules): $(dst)/%: $(extmod_prefix)% FORCE +# +# Installation +# +quiet_cmd_install = INSTALL $@ + cmd_install = mkdir -p $(dir $@); cp $< $@ + +# Strip +# +# 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) +strip-option := --strip-debug +else +strip-option := $(INSTALL_MOD_STRIP) +endif + +quiet_cmd_strip = STRIP $@ + cmd_strip = $(STRIP) $(strip-option) $@ + +else + +quiet_cmd_strip = + cmd_strip = : + +endif + +# +# Signing +# Don't stop modules_install even if we can't sign external modules. +# +ifeq ($(CONFIG_MODULE_SIG_ALL),y) +quiet_cmd_sign = SIGN $@ +$(eval $(call config_filename,MODULE_SIG_KEY)) + cmd_sign = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) $(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY) certs/signing_key.x509 $@ \ + $(if $(KBUILD_EXTMOD),|| true) +else +quiet_cmd_sign := + cmd_sign := : +endif + +$(dst)/%.ko: $(extmod_prefix)%.ko FORCE $(call cmd,install) + $(call cmd,strip) + $(call cmd,sign) + +# +# Compression +# +quiet_cmd_gzip = GZIP $@ + cmd_gzip = $(KGZIP) -n -f $< +quiet_cmd_xz = XZ $@ + cmd_xz = $(XZ) --lzma2=dict=2MiB -f $< + +$(dst)/%.ko.gz: $(dst)/%.ko FORCE + $(call cmd,gzip) + +$(dst)/%.ko.xz: $(dst)/%.ko FORCE + $(call cmd,xz) PHONY += FORCE FORCE: From 961ab4a3cd66c285951cf4c8ec10bc8d9a4b0232 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 31 Mar 2021 22:38:09 +0900 Subject: [PATCH 28/42] 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 ++++++++++++++++++++---------------- scripts/Makefile.modinst | 9 +++++++++ scripts/Makefile.modsign | 29 ----------------------------- 3 files changed, 29 insertions(+), 45 deletions(-) delete mode 100644 scripts/Makefile.modsign 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 ### diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst index 84696ef99df7..191408f7a91a 100644 --- a/scripts/Makefile.modinst +++ b/scripts/Makefile.modinst @@ -74,11 +74,20 @@ quiet_cmd_sign := cmd_sign := : endif +ifeq ($(modules_sign_only),) + $(dst)/%.ko: $(extmod_prefix)%.ko FORCE $(call cmd,install) $(call cmd,strip) $(call cmd,sign) +else + +$(dst)/%.ko: FORCE + $(call cmd,sign) + +endif + # # Compression # diff --git a/scripts/Makefile.modsign b/scripts/Makefile.modsign deleted file mode 100644 index ddf9b5ca77d7..000000000000 --- a/scripts/Makefile.modsign +++ /dev/null @@ -1,29 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# ========================================================================== -# Signing modules -# ========================================================================== - -PHONY := __modsign -__modsign: - -include $(srctree)/scripts/Kbuild.include - -modules := $(sort $(shell cat modules.order)) - -PHONY += $(modules) -__modsign: $(modules) - @: - -quiet_cmd_sign_ko = SIGN [M] $(2)/$(notdir $@) - cmd_sign_ko = $(mod_sign_cmd) $(2)/$(notdir $@) - -# Modules built outside the kernel source tree go into extra by default -INSTALL_MOD_DIR ?= extra -ext-mod-dir = $(INSTALL_MOD_DIR)$(subst $(patsubst %/,%,$(KBUILD_EXTMOD)),,$(@D)) - -modinst_dir = $(if $(KBUILD_EXTMOD),$(ext-mod-dir),kernel/$(@D)) - -$(modules): - $(call cmd,sign_ko,$(MODLIB)/$(modinst_dir)) - -.PHONY: $(PHONY) From d4bbe942098b0c9b487d424a3c545c9ed56462d7 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 31 Mar 2021 22:38:10 +0900 Subject: [PATCH 29/42] kbuild: remove CONFIG_MODULE_COMPRESS CONFIG_MODULE_COMPRESS is only used to activate the choice for module compression algorithm. It will be simpler to make the choice always visible, and add CONFIG_MODULE_COMPRESS_NONE in the choice. This is more consistent with the "Kernel compression mode" and "Built-in initramfs compression mode" choices. CONFIG_KERNEL_UNCOMPRESSED and CONFIG_INITRAMFS_COMPRESSION_NONE are available to choose no compression. Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers --- init/Kconfig | 57 +++++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/init/Kconfig b/init/Kconfig index 019c1874e609..510f6fcd9b7f 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -2225,40 +2225,47 @@ config MODULE_SIG_HASH default "sha384" if MODULE_SIG_SHA384 default "sha512" if MODULE_SIG_SHA512 -config MODULE_COMPRESS - bool "Compress modules on installation" - help - - Compresses kernel modules when 'make modules_install' is run; gzip or - xz depending on "Compression algorithm" below. - - module-init-tools MAY support gzip, and kmod MAY support gzip and xz. - - Out-of-tree kernel modules installed using Kbuild will also be - compressed upon installation. - - Note: for modules inside an initrd or initramfs, it's more efficient - to compress the whole initrd or initramfs instead. - - Note: This is fully compatible with signed modules. - - If in doubt, say N. - choice - prompt "Compression algorithm" - depends on MODULE_COMPRESS - default MODULE_COMPRESS_GZIP + prompt "Module compression mode" help - This determines which sort of compression will be used during - 'make modules_install'. + This option allows you to choose the algorithm which will be used to + compress modules when 'make modules_install' is run. (or, you can + choose to not compress modules at all.) - GZIP (default) and XZ are supported. + External modules will also be compressed in the same way during the + installation. + + For modules inside an initrd or initramfs, it's more efficient to + compress the whole initrd or initramfs instead. + + This is fully compatible with signed modules. + + Please note that the tool used to load modules needs to support the + corresponding algorithm. module-init-tools MAY support gzip, and kmod + MAY support gzip and xz. + + Your build system needs to provide the appropriate compression tool + to compress the modules. + + If in doubt, select 'None'. + +config MODULE_COMPRESS_NONE + bool "None" + help + Do not compress modules. The installed modules are suffixed + with .ko. config MODULE_COMPRESS_GZIP bool "GZIP" + help + Compress modules with GZIP. The installed modules are suffixed + with .ko.gz. config MODULE_COMPRESS_XZ bool "XZ" + help + Compress modules with XZ. The installed modules are suffixed + with .ko.xz. endchoice From c3d7ef377eb2564b165b1e8fdb4646952c90ac17 Mon Sep 17 00:00:00 2001 From: Piotr Gorski Date: Wed, 7 Apr 2021 18:09:27 +0200 Subject: [PATCH 30/42] kbuild: add support for zstd compressed modules kmod 28 supports modules compressed in zstd format so let's add this possibility to kernel. Signed-off-by: Piotr Gorski Reviewed-by: Oleksandr Natalenko Signed-off-by: Masahiro Yamada --- init/Kconfig | 8 +++++++- scripts/Makefile.modinst | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/init/Kconfig b/init/Kconfig index 510f6fcd9b7f..b5744d32c4df 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -2242,7 +2242,7 @@ choice Please note that the tool used to load modules needs to support the corresponding algorithm. module-init-tools MAY support gzip, and kmod - MAY support gzip and xz. + MAY support gzip, xz and zstd. Your build system needs to provide the appropriate compression tool to compress the modules. @@ -2267,6 +2267,12 @@ config MODULE_COMPRESS_XZ Compress modules with XZ. The installed modules are suffixed with .ko.xz. +config MODULE_COMPRESS_ZSTD + bool "ZSTD" + help + Compress modules with ZSTD. The installed modules are suffixed + with .ko.zst. + endchoice config MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst index 191408f7a91a..ff9b09e4cfca 100644 --- a/scripts/Makefile.modinst +++ b/scripts/Makefile.modinst @@ -21,6 +21,7 @@ endif suffix-y := suffix-$(CONFIG_MODULE_COMPRESS_GZIP) := .gz suffix-$(CONFIG_MODULE_COMPRESS_XZ) := .xz +suffix-$(CONFIG_MODULE_COMPRESS_ZSTD) := .zst modules := $(patsubst $(extmod_prefix)%, $(dst)/%$(suffix-y), $(modules)) @@ -95,6 +96,8 @@ quiet_cmd_gzip = GZIP $@ cmd_gzip = $(KGZIP) -n -f $< quiet_cmd_xz = XZ $@ cmd_xz = $(XZ) --lzma2=dict=2MiB -f $< +quiet_cmd_zstd = ZSTD $@ + cmd_zstd = $(ZSTD) -T0 --rm -f -q $< $(dst)/%.ko.gz: $(dst)/%.ko FORCE $(call cmd,gzip) @@ -102,6 +105,9 @@ $(dst)/%.ko.gz: $(dst)/%.ko FORCE $(dst)/%.ko.xz: $(dst)/%.ko FORCE $(call cmd,xz) +$(dst)/%.ko.zst: $(dst)/%.ko FORCE + $(call cmd,zstd) + PHONY += FORCE FORCE: From d8fc9b667d483614974d80f59405f0db4dfc72e2 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 4 Jan 2021 17:32:21 +0900 Subject: [PATCH 31/42] sysctl: use min() helper for namecmp() Make it slightly readable by using min(). Signed-off-by: Masahiro Yamada Acked-by: Kees Cook --- fs/proc/proc_sysctl.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 984e42f8cb11..d25e8264099a 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -94,14 +94,9 @@ static void sysctl_print_dir(struct ctl_dir *dir) static int namecmp(const char *name1, int len1, const char *name2, int len2) { - int minlen; int cmp; - minlen = len1; - if (minlen > len2) - minlen = len2; - - cmp = memcmp(name1, name2, minlen); + cmp = memcmp(name1, name2, min(len1, len2)); if (cmp == 0) cmp = len1 - len2; return cmp; From b186f2c3d877de82c7960bdac5145e69dcfe110d Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 1 Mar 2021 23:18:25 +0900 Subject: [PATCH 32/42] alpha: syscalls: switch to generic syscalltbl.sh Many architectures duplicate similar shell scripts. This commit converts alpha to use scripts/syscalltbl.sh. Signed-off-by: Masahiro Yamada --- arch/alpha/kernel/syscalls/Makefile | 7 ++---- arch/alpha/kernel/syscalls/syscalltbl.sh | 32 ------------------------ arch/alpha/kernel/systbls.S | 3 +-- 3 files changed, 3 insertions(+), 39 deletions(-) delete mode 100644 arch/alpha/kernel/syscalls/syscalltbl.sh diff --git a/arch/alpha/kernel/syscalls/Makefile b/arch/alpha/kernel/syscalls/Makefile index 285aaba832d9..ad2492cb5568 100644 --- a/arch/alpha/kernel/syscalls/Makefile +++ b/arch/alpha/kernel/syscalls/Makefile @@ -7,7 +7,7 @@ _dummy := $(shell [ -d '$(uapi)' ] || mkdir -p '$(uapi)') \ syscall := $(src)/syscall.tbl syshdr := $(srctree)/$(src)/syscallhdr.sh -systbl := $(srctree)/$(src)/syscalltbl.sh +systbl := $(srctree)/scripts/syscalltbl.sh quiet_cmd_syshdr = SYSHDR $@ cmd_syshdr = $(CONFIG_SHELL) '$(syshdr)' '$<' '$@' \ @@ -16,10 +16,7 @@ quiet_cmd_syshdr = SYSHDR $@ '$(syshdr_offset_$(basetarget))' quiet_cmd_systbl = SYSTBL $@ - cmd_systbl = $(CONFIG_SHELL) '$(systbl)' '$<' '$@' \ - '$(systbl_abis_$(basetarget))' \ - '$(systbl_abi_$(basetarget))' \ - '$(systbl_offset_$(basetarget))' + cmd_systbl = $(CONFIG_SHELL) $(systbl) $< $@ $(uapi)/unistd_32.h: $(syscall) $(syshdr) FORCE $(call if_changed,syshdr) diff --git a/arch/alpha/kernel/syscalls/syscalltbl.sh b/arch/alpha/kernel/syscalls/syscalltbl.sh deleted file mode 100644 index 85d78d9309ad..000000000000 --- a/arch/alpha/kernel/syscalls/syscalltbl.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0 - -in="$1" -out="$2" -my_abis=`echo "($3)" | tr ',' '|'` -my_abi="$4" -offset="$5" - -emit() { - t_nxt="$1" - t_nr="$2" - t_entry="$3" - - while [ $t_nxt -lt $t_nr ]; do - printf "__SYSCALL(%s, sys_ni_syscall, )\n" "${t_nxt}" - t_nxt=$((t_nxt+1)) - done - printf "__SYSCALL(%s, %s, )\n" "${t_nxt}" "${t_entry}" -} - -grep -E "^[0-9A-Fa-fXx]+[[:space:]]+${my_abis}" "$in" | sort -n | ( - nxt=0 - if [ -z "$offset" ]; then - offset=0 - fi - - while read nr abi name entry ; do - emit $((nxt+offset)) $((nr+offset)) $entry - nxt=$((nr+1)) - done -) > "$out" diff --git a/arch/alpha/kernel/systbls.S b/arch/alpha/kernel/systbls.S index 9704f22ed5e3..68f3e4f329eb 100644 --- a/arch/alpha/kernel/systbls.S +++ b/arch/alpha/kernel/systbls.S @@ -7,10 +7,9 @@ #include -#define __SYSCALL(nr, entry, nargs) .quad entry +#define __SYSCALL(nr, entry) .quad entry .data .align 3 .globl sys_call_table sys_call_table: #include -#undef __SYSCALL From 14b36dcfd640a69ed657a0c3085f7c3853d83569 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 1 Mar 2021 23:18:26 +0900 Subject: [PATCH 33/42] alpha: syscalls: switch to generic syscallhdr.sh Many architectures duplicate similar shell scripts. This commit converts alpha to use scripts/syscallhdr.sh. Signed-off-by: Masahiro Yamada --- arch/alpha/kernel/syscalls/Makefile | 7 ++--- arch/alpha/kernel/syscalls/syscallhdr.sh | 36 ------------------------ 2 files changed, 2 insertions(+), 41 deletions(-) delete mode 100644 arch/alpha/kernel/syscalls/syscallhdr.sh diff --git a/arch/alpha/kernel/syscalls/Makefile b/arch/alpha/kernel/syscalls/Makefile index ad2492cb5568..6713c65a25e1 100644 --- a/arch/alpha/kernel/syscalls/Makefile +++ b/arch/alpha/kernel/syscalls/Makefile @@ -6,14 +6,11 @@ _dummy := $(shell [ -d '$(uapi)' ] || mkdir -p '$(uapi)') \ $(shell [ -d '$(kapi)' ] || mkdir -p '$(kapi)') syscall := $(src)/syscall.tbl -syshdr := $(srctree)/$(src)/syscallhdr.sh +syshdr := $(srctree)/scripts/syscallhdr.sh systbl := $(srctree)/scripts/syscalltbl.sh quiet_cmd_syshdr = SYSHDR $@ - cmd_syshdr = $(CONFIG_SHELL) '$(syshdr)' '$<' '$@' \ - '$(syshdr_abis_$(basetarget))' \ - '$(syshdr_pfx_$(basetarget))' \ - '$(syshdr_offset_$(basetarget))' + cmd_syshdr = $(CONFIG_SHELL) $(syshdr) --emit-nr $< $@ quiet_cmd_systbl = SYSTBL $@ cmd_systbl = $(CONFIG_SHELL) $(systbl) $< $@ diff --git a/arch/alpha/kernel/syscalls/syscallhdr.sh b/arch/alpha/kernel/syscalls/syscallhdr.sh deleted file mode 100644 index 1780e861492a..000000000000 --- a/arch/alpha/kernel/syscalls/syscallhdr.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0 - -in="$1" -out="$2" -my_abis=`echo "($3)" | tr ',' '|'` -prefix="$4" -offset="$5" - -fileguard=_UAPI_ASM_ALPHA_`basename "$out" | sed \ - -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \ - -e 's/[^A-Z0-9_]/_/g' -e 's/__/_/g'` -grep -E "^[0-9A-Fa-fXx]+[[:space:]]+${my_abis}" "$in" | sort -n | ( - printf "#ifndef %s\n" "${fileguard}" - printf "#define %s\n" "${fileguard}" - printf "\n" - - nxt=0 - while read nr abi name entry ; do - if [ -z "$offset" ]; then - printf "#define __NR_%s%s\t%s\n" \ - "${prefix}" "${name}" "${nr}" - else - printf "#define __NR_%s%s\t(%s + %s)\n" \ - "${prefix}" "${name}" "${offset}" "${nr}" - fi - nxt=$((nr+1)) - done - - printf "\n" - printf "#ifdef __KERNEL__\n" - printf "#define __NR_syscalls\t%s\n" "${nxt}" - printf "#endif\n" - printf "\n" - printf "#endif /* %s */\n" "${fileguard}" -) > "$out" From a92359aa6de8871b1502b17c1ea71b93f5eb606b Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 1 Mar 2021 23:19:36 +0900 Subject: [PATCH 34/42] ia64: syscalls: switch to generic syscalltbl.sh Many architectures duplicate similar shell scripts. This commit converts ia64 to use scripts/syscalltbl.sh. Signed-off-by: Masahiro Yamada --- arch/ia64/kernel/entry.S | 3 +-- arch/ia64/kernel/syscalls/Makefile | 8 ++----- arch/ia64/kernel/syscalls/syscalltbl.sh | 32 ------------------------- 3 files changed, 3 insertions(+), 40 deletions(-) delete mode 100644 arch/ia64/kernel/syscalls/syscalltbl.sh diff --git a/arch/ia64/kernel/entry.S b/arch/ia64/kernel/entry.S index e98e3dafffd8..5eba3fb2e311 100644 --- a/arch/ia64/kernel/entry.S +++ b/arch/ia64/kernel/entry.S @@ -1420,10 +1420,9 @@ END(ftrace_stub) #endif /* CONFIG_FUNCTION_TRACER */ -#define __SYSCALL(nr, entry, nargs) data8 entry +#define __SYSCALL(nr, entry) data8 entry .rodata .align 8 .globl sys_call_table sys_call_table: #include -#undef __SYSCALL diff --git a/arch/ia64/kernel/syscalls/Makefile b/arch/ia64/kernel/syscalls/Makefile index bf4bda0f63eb..2d2e420749b0 100644 --- a/arch/ia64/kernel/syscalls/Makefile +++ b/arch/ia64/kernel/syscalls/Makefile @@ -7,7 +7,7 @@ _dummy := $(shell [ -d '$(uapi)' ] || mkdir -p '$(uapi)') \ syscall := $(src)/syscall.tbl syshdr := $(srctree)/$(src)/syscallhdr.sh -systbl := $(srctree)/$(src)/syscalltbl.sh +systbl := $(srctree)/scripts/syscalltbl.sh quiet_cmd_syshdr = SYSHDR $@ cmd_syshdr = $(CONFIG_SHELL) '$(syshdr)' '$<' '$@' \ @@ -16,16 +16,12 @@ quiet_cmd_syshdr = SYSHDR $@ '$(syshdr_offset_$(basetarget))' quiet_cmd_systbl = SYSTBL $@ - cmd_systbl = $(CONFIG_SHELL) '$(systbl)' '$<' '$@' \ - '$(systbl_abis_$(basetarget))' \ - '$(systbl_abi_$(basetarget))' \ - '$(systbl_offset_$(basetarget))' + cmd_systbl = $(CONFIG_SHELL) $(systbl) $< $@ syshdr_offset_unistd_64 := __NR_Linux $(uapi)/unistd_64.h: $(syscall) $(syshdr) FORCE $(call if_changed,syshdr) -systbl_offset_syscall_table := 1024 $(kapi)/syscall_table.h: $(syscall) $(systbl) FORCE $(call if_changed,systbl) diff --git a/arch/ia64/kernel/syscalls/syscalltbl.sh b/arch/ia64/kernel/syscalls/syscalltbl.sh deleted file mode 100644 index 85d78d9309ad..000000000000 --- a/arch/ia64/kernel/syscalls/syscalltbl.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0 - -in="$1" -out="$2" -my_abis=`echo "($3)" | tr ',' '|'` -my_abi="$4" -offset="$5" - -emit() { - t_nxt="$1" - t_nr="$2" - t_entry="$3" - - while [ $t_nxt -lt $t_nr ]; do - printf "__SYSCALL(%s, sys_ni_syscall, )\n" "${t_nxt}" - t_nxt=$((t_nxt+1)) - done - printf "__SYSCALL(%s, %s, )\n" "${t_nxt}" "${t_entry}" -} - -grep -E "^[0-9A-Fa-fXx]+[[:space:]]+${my_abis}" "$in" | sort -n | ( - nxt=0 - if [ -z "$offset" ]; then - offset=0 - fi - - while read nr abi name entry ; do - emit $((nxt+offset)) $((nr+offset)) $entry - nxt=$((nr+1)) - done -) > "$out" From 6e74bc4c84546ddbf67ed0f4d45284c9bb153846 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Mon, 1 Mar 2021 23:19:37 +0900 Subject: [PATCH 35/42] ia64: syscalls: switch to generic syscallhdr.sh Many architectures duplicate similar shell scripts. This commit converts ia64 to use scripts/syscallhdr.sh. Signed-off-by: Masahiro Yamada --- arch/ia64/kernel/syscalls/Makefile | 8 ++---- arch/ia64/kernel/syscalls/syscallhdr.sh | 36 ------------------------- 2 files changed, 2 insertions(+), 42 deletions(-) delete mode 100644 arch/ia64/kernel/syscalls/syscallhdr.sh diff --git a/arch/ia64/kernel/syscalls/Makefile b/arch/ia64/kernel/syscalls/Makefile index 2d2e420749b0..14f40ecf8b65 100644 --- a/arch/ia64/kernel/syscalls/Makefile +++ b/arch/ia64/kernel/syscalls/Makefile @@ -6,19 +6,15 @@ _dummy := $(shell [ -d '$(uapi)' ] || mkdir -p '$(uapi)') \ $(shell [ -d '$(kapi)' ] || mkdir -p '$(kapi)') syscall := $(src)/syscall.tbl -syshdr := $(srctree)/$(src)/syscallhdr.sh +syshdr := $(srctree)/scripts/syscallhdr.sh systbl := $(srctree)/scripts/syscalltbl.sh quiet_cmd_syshdr = SYSHDR $@ - cmd_syshdr = $(CONFIG_SHELL) '$(syshdr)' '$<' '$@' \ - '$(syshdr_abis_$(basetarget))' \ - '$(syshdr_pfx_$(basetarget))' \ - '$(syshdr_offset_$(basetarget))' + cmd_syshdr = $(CONFIG_SHELL) $(syshdr) --emit-nr --offset __NR_Linux $< $@ quiet_cmd_systbl = SYSTBL $@ cmd_systbl = $(CONFIG_SHELL) $(systbl) $< $@ -syshdr_offset_unistd_64 := __NR_Linux $(uapi)/unistd_64.h: $(syscall) $(syshdr) FORCE $(call if_changed,syshdr) diff --git a/arch/ia64/kernel/syscalls/syscallhdr.sh b/arch/ia64/kernel/syscalls/syscallhdr.sh deleted file mode 100644 index f407b6e53283..000000000000 --- a/arch/ia64/kernel/syscalls/syscallhdr.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0 - -in="$1" -out="$2" -my_abis=`echo "($3)" | tr ',' '|'` -prefix="$4" -offset="$5" - -fileguard=_UAPI_ASM_IA64_`basename "$out" | sed \ - -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \ - -e 's/[^A-Z0-9_]/_/g' -e 's/__/_/g'` -grep -E "^[0-9A-Fa-fXx]+[[:space:]]+${my_abis}" "$in" | sort -n | ( - printf "#ifndef %s\n" "${fileguard}" - printf "#define %s\n" "${fileguard}" - printf "\n" - - nxt=0 - while read nr abi name entry ; do - if [ -z "$offset" ]; then - printf "#define __NR_%s%s\t%s\n" \ - "${prefix}" "${name}" "${nr}" - else - printf "#define __NR_%s%s\t(%s + %s)\n" \ - "${prefix}" "${name}" "${offset}" "${nr}" - fi - nxt=$((nr+1)) - done - - printf "\n" - printf "#ifdef __KERNEL__\n" - printf "#define __NR_syscalls\t%s\n" "${nxt}" - printf "#endif\n" - printf "\n" - printf "#endif /* %s */\n" "${fileguard}" -) > "$out" From 1fdd7433a98a2f5511f49ad3f3b82bdd6f77265c Mon Sep 17 00:00:00 2001 From: Yonghong Song Date: Thu, 1 Apr 2021 16:27:23 -0700 Subject: [PATCH 36/42] kbuild: add an elfnote for whether vmlinux is built with lto Currently, clang LTO built vmlinux won't work with pahole. LTO introduced cross-cu dwarf tag references and broke current pahole model which handles one cu as a time. The solution is to merge all cu's as one pahole cu as in [1]. We would like to do this merging only if cross-cu dwarf references happens. The LTO build mode is a pretty good indication for that. In earlier version of this patch ([2]), clang flag -grecord-gcc-switches is proposed to add to compilation flags so pahole could detect "-flto" and then merging cu's. This will increate the binary size of 1% without LTO though. Arnaldo suggested to use a note to indicate the vmlinux is built with LTO. Such a cheap way to get whether the vmlinux is built with LTO or not helps pahole but is also useful for tracing as LTO may inline/delete/demote global functions, promote static functions, etc. So this patch added an elfnote with a new type LINUX_ELFNOTE_LTO_INFO. The owner of the note is "Linux". With gcc 8.4.1 and clang trunk, without LTO, I got $ readelf -n vmlinux Displaying notes found in: .notes Owner Data size Description ... Linux 0x00000004 func description data: 00 00 00 00 ... With "readelf -x ".notes" vmlinux", I can verify the above "func" with type code 0x101. With clang thin-LTO, I got the same as above except the following: description data: 01 00 00 00 which indicates the vmlinux is built with LTO. [1] https://lore.kernel.org/bpf/20210325065316.3121287-1-yhs@fb.com/ [2] https://lore.kernel.org/bpf/20210331001623.2778934-1-yhs@fb.com/ Suggested-by: Arnaldo Carvalho de Melo Signed-off-by: Yonghong Song Reviewed-by: Nick Desaulniers Tested-by: Sedat Dilek # LLVM/Clang v12.0.0-rc4 (x86-64) Tested-by: Arnaldo Carvalho de Melo Signed-off-by: Masahiro Yamada --- include/linux/elfnote-lto.h | 14 ++++++++++++++ init/version.c | 2 ++ scripts/mod/modpost.c | 2 ++ 3 files changed, 18 insertions(+) create mode 100644 include/linux/elfnote-lto.h diff --git a/include/linux/elfnote-lto.h b/include/linux/elfnote-lto.h new file mode 100644 index 000000000000..d4635a3ecc4f --- /dev/null +++ b/include/linux/elfnote-lto.h @@ -0,0 +1,14 @@ +#ifndef __ELFNOTE_LTO_H +#define __ELFNOTE_LTO_H + +#include + +#define LINUX_ELFNOTE_LTO_INFO 0x101 + +#ifdef CONFIG_LTO +#define BUILD_LTO_INFO ELFNOTE32("Linux", LINUX_ELFNOTE_LTO_INFO, 1) +#else +#define BUILD_LTO_INFO ELFNOTE32("Linux", LINUX_ELFNOTE_LTO_INFO, 0) +#endif + +#endif /* __ELFNOTE_LTO_H */ diff --git a/init/version.c b/init/version.c index 92afc782b043..1a356f5493e8 100644 --- a/init/version.c +++ b/init/version.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -45,3 +46,4 @@ const char linux_proc_banner[] = " (" LINUX_COMPILER ") %s\n"; BUILD_SALT; +BUILD_LTO_INFO; diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 20aab6960559..3e623ccc020b 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -2193,10 +2193,12 @@ static void add_header(struct buffer *b, struct module *mod) */ buf_printf(b, "#define INCLUDE_VERMAGIC\n"); buf_printf(b, "#include \n"); + buf_printf(b, "#include \n"); buf_printf(b, "#include \n"); buf_printf(b, "#include \n"); buf_printf(b, "\n"); buf_printf(b, "BUILD_SALT;\n"); + buf_printf(b, "BUILD_LTO_INFO;\n"); buf_printf(b, "\n"); buf_printf(b, "MODULE_INFO(vermagic, VERMAGIC_STRING);\n"); buf_printf(b, "MODULE_INFO(name, KBUILD_MODNAME);\n"); From 35f93a09e9683bf962f9164c0db5beeb65ad2c64 Mon Sep 17 00:00:00 2001 From: Michal Suchanek Date: Thu, 8 Apr 2021 23:31:40 +0200 Subject: [PATCH 37/42] MAINTAINERS: add pattern for dummy-tools scripts/get_maintainer.pl does not find a maintainer for new files otherwise. Signed-off-by: Michal Suchanek Signed-off-by: Masahiro Yamada --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index aa84121c5611..256a2c0fd2c0 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9691,6 +9691,7 @@ F: scripts/*vmlinux* F: scripts/Kbuild* F: scripts/Makefile* F: scripts/basic/ +F: scripts/dummy-tools/ F: scripts/mk* F: scripts/mod/ F: scripts/package/ From e3456056f1d935491ee9148dbae98c6b95f58910 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 15 Apr 2021 16:26:59 +0900 Subject: [PATCH 38/42] kbuild: remove TMPO from try-run TMPO is only used by arch/x86/Makefile. Change arch/x86/Makefile to use $$TMPO.o and remove TMPO from scripts/Makefile.compiler. Signed-off-by: Masahiro Yamada --- arch/x86/Makefile | 4 ++-- scripts/Makefile.compiler | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 2d6d5a28c3bf..c55da2833fe8 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -129,8 +129,8 @@ ifdef CONFIG_X86_X32 x32_ld_ok := $(call try-run,\ /bin/echo -e '1: .quad 1b' | \ $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" - && \ - $(OBJCOPY) -O elf32-x86-64 "$$TMP" "$$TMPO" && \ - $(LD) -m elf32_x86_64 "$$TMPO" -o "$$TMP",y,n) + $(OBJCOPY) -O elf32-x86-64 "$$TMP" "$$TMP.o" && \ + $(LD) -m elf32_x86_64 "$$TMP.o" -o "$$TMP",y,n) ifeq ($(x32_ld_ok),y) CONFIG_X86_X32_ABI := y KBUILD_AFLAGS += -DCONFIG_X86_X32_ABI diff --git a/scripts/Makefile.compiler b/scripts/Makefile.compiler index 3f2f3665216f..86ecd2ac874c 100644 --- a/scripts/Makefile.compiler +++ b/scripts/Makefile.compiler @@ -21,7 +21,6 @@ TMPOUT = $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_$$$$ # automatically cleaned up. try-run = $(shell set -e; \ TMP=$(TMPOUT)/tmp; \ - TMPO=$(TMPOUT)/tmp.o; \ mkdir -p $(TMPOUT); \ trap "rm -rf $(TMPOUT)" EXIT; \ if ($(1)) >/dev/null 2>&1; \ From 0e0345b77ac4605d5447b252d220e4a2ee118da7 Mon Sep 17 00:00:00 2001 From: Alexey Dobriyan Date: Thu, 15 Apr 2021 20:36:07 +0300 Subject: [PATCH 39/42] kbuild: redo fake deps at include/config/*.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make include/config/foo/bar.h fake deps files generation simpler. * delete .h suffix those aren't header files, shorten filenames, * delete tolower() Linux filesystems can deal with both upper and lowercase filenames very well, * put everything in 1 directory Presumably 'mkdir -p' split is from dark times when filesystems handled huge directories badly, disks were round adding to seek times. x86_64 allmodconfig lists 12364 files in include/config. ../obj/include/config/ ├── 104_QUAD_8 ├── 60XX_WDT ├── 64BIT ... ├── ZSWAP_DEFAULT_ON ├── ZSWAP_ZPOOL_DEFAULT └── ZSWAP_ZPOOL_DEFAULT_ZBUD 0 directories, 12364 files Signed-off-by: Alexey Dobriyan Signed-off-by: Masahiro Yamada --- include/linux/compiler-version.h | 2 +- init/Kconfig | 2 +- kernel/gen_kheaders.sh | 2 +- scripts/Makefile.build | 4 +-- scripts/basic/fixdep.c | 43 +++++--------------------------- scripts/kconfig/confdata.c | 15 ++++------- 6 files changed, 16 insertions(+), 52 deletions(-) diff --git a/include/linux/compiler-version.h b/include/linux/compiler-version.h index 2b2972c77c62..573fa85b6c0c 100644 --- a/include/linux/compiler-version.h +++ b/include/linux/compiler-version.h @@ -9,6 +9,6 @@ * This header exists to force full rebuild when the compiler is upgraded. * * When fixdep scans this, it will find this string "CONFIG_CC_VERSION_TEXT" - * and add dependency on include/config/cc/version/text.h, which is touched + * and add dependency on include/config/CC_VERSION_TEXT, which is touched * by Kconfig when the version string from the compiler changes. */ diff --git a/init/Kconfig b/init/Kconfig index b5744d32c4df..c2339da03468 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -21,7 +21,7 @@ config CC_VERSION_TEXT - Ensure full rebuild when the compiler is updated include/linux/compiler-version.h contains this option in the comment - line so fixdep adds include/config/cc/version/text.h into the + line so fixdep adds include/config/CC_VERSION_TEXT into the auto-generated dependency. When the compiler is updated, syncconfig will touch it and then every file will be rebuilt. diff --git a/kernel/gen_kheaders.sh b/kernel/gen_kheaders.sh index c1510f0ab3ea..34a1dc2abc7d 100755 --- a/kernel/gen_kheaders.sh +++ b/kernel/gen_kheaders.sh @@ -36,7 +36,7 @@ all_dirs="$all_dirs $dir_list" # # When Kconfig regenerates include/generated/autoconf.h, its timestamp is # updated, but the contents might be still the same. When any CONFIG option is -# changed, Kconfig touches the corresponding timestamp file include/config/*.h. +# changed, Kconfig touches the corresponding timestamp file include/config/*. # Hence, the md5sum detects the configuration change anyway. We do not need to # check include/generated/autoconf.h explicitly. # diff --git a/scripts/Makefile.build b/scripts/Makefile.build index e47c054d3db2..5e39b0517186 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -239,8 +239,8 @@ endif # CONFIG_STACK_VALIDATION # Rebuild all objects when objtool changes, or is enabled/disabled. objtool_dep = $(objtool_obj) \ - $(wildcard include/config/orc/unwinder.h \ - include/config/stack/validation.h) + $(wildcard include/config/ORC_UNWINDER \ + include/config/STACK_VALIDATION) ifdef CONFIG_TRIM_UNUSED_KSYMS cmd_gen_ksymdeps = \ diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index d98540552941..44e887cff49b 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -34,7 +34,7 @@ * the config symbols are rebuilt. * * So if the user changes his CONFIG_HIS_DRIVER option, only the objects - * which depend on "include/config/his/driver.h" will be rebuilt, + * which depend on "include/config/HIS_DRIVER" will be rebuilt, * so most likely only his driver ;-) * * The idea above dates, by the way, back to Michael E Chastain, AFAIK. @@ -74,7 +74,7 @@ * * and then basically copies the ..d file to stdout, in the * process filtering out the dependency on autoconf.h and adding - * dependencies on include/config/my/option.h for every + * dependencies on include/config/MY_OPTION for every * CONFIG_MY_OPTION encountered in any of the prerequisites. * * We don't even try to really parse the header files, but @@ -107,8 +107,8 @@ static void usage(void) /* * In the intended usage of this program, the stdout is redirected to .*.cmd - * files. The return value of printf() and putchar() must be checked to catch - * any error, e.g. "No space left on device". + * files. The return value of printf() must be checked to catch any error, + * e.g. "No space left on device". */ static void xprintf(const char *format, ...) { @@ -124,38 +124,6 @@ static void xprintf(const char *format, ...) va_end(ap); } -static void xputchar(int c) -{ - int ret; - - ret = putchar(c); - if (ret == EOF) { - perror("fixdep"); - exit(1); - } -} - -/* - * Print out a dependency path from a symbol name - */ -static void print_dep(const char *m, int slen, const char *dir) -{ - int c, prev_c = '/', i; - - xprintf(" $(wildcard %s/", dir); - for (i = 0; i < slen; i++) { - c = m[i]; - if (c == '_') - c = '/'; - else - c = tolower(c); - if (c != '/' || prev_c != '/') - xputchar(c); - prev_c = c; - } - xprintf(".h) \\\n"); -} - struct item { struct item *next; unsigned int len; @@ -220,7 +188,8 @@ static void use_config(const char *m, int slen) return; define_config(m, slen, hash); - print_dep(m, slen, "include/config"); + /* Print out a dependency path from a symbol name. */ + xprintf(" $(wildcard include/config/%.*s) \\\n", slen, m); } /* test if s ends in sub */ diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 2568dbe16ed6..c7b7e1c62a9c 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -130,19 +130,14 @@ static size_t depfile_prefix_len; static int conf_touch_dep(const char *name) { int fd, ret; - const char *s; - char *d, c; + char *d; - /* check overflow: prefix + name + ".h" + '\0' must fit in buffer. */ - if (depfile_prefix_len + strlen(name) + 3 > sizeof(depfile_path)) + /* check overflow: prefix + name + '\0' must fit in buffer. */ + if (depfile_prefix_len + strlen(name) + 1 > sizeof(depfile_path)) return -1; d = depfile_path + depfile_prefix_len; - s = name; - - while ((c = *s++)) - *d++ = (c == '_') ? '/' : tolower(c); - strcpy(d, ".h"); + strcpy(d, name); /* Assume directory path already exists. */ fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644); @@ -465,7 +460,7 @@ load: * Reading from include/config/auto.conf * If CONFIG_FOO previously existed in * auto.conf but it is missing now, - * include/config/foo.h must be touched. + * include/config/FOO must be touched. */ conf_touch_dep(line + strlen(CONFIG_)); else From b61442df748f06e98085fb604093a6215ce730eb Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 16 Apr 2021 22:00:51 +0900 Subject: [PATCH 40/42] tools: do not include scripts/Kbuild.include Since commit 57fd251c7896 ("kbuild: split cc-option and friends to scripts/Makefile.compiler"), some kselftests fail to build. The tools/ directory opted out Kbuild, and went in a different direction. People copied scripts and Makefiles to the tools/ directory to create their own build system. tools/build/Build.include mimics scripts/Kbuild.include, but some tool Makefiles include the Kbuild one to import a feature that is missing in tools/build/Build.include: - Commit ec04aa3ae87b ("tools/thermal: tmon: use "-fstack-protector" only if supported") included scripts/Kbuild.include from tools/thermal/tmon/Makefile to import the cc-option macro. - Commit c2390f16fc5b ("selftests: kvm: fix for compilers that do not support -no-pie") included scripts/Kbuild.include from tools/testing/selftests/kvm/Makefile to import the try-run macro. - Commit 9cae4ace80ef ("selftests/bpf: do not ignore clang failures") included scripts/Kbuild.include from tools/testing/selftests/bpf/Makefile to import the .DELETE_ON_ERROR target. - Commit 0695f8bca93e ("selftests/powerpc: Handle Makefile for unrecognized option") included scripts/Kbuild.include from tools/testing/selftests/powerpc/pmu/ebb/Makefile to import the try-run macro. Copy what they need into tools/build/Build.include, and make them include it instead of scripts/Kbuild.include. Link: https://lore.kernel.org/lkml/86dadf33-70f7-a5ac-cb8c-64966d2f45a1@linux.ibm.com/ Fixes: 57fd251c7896 ("kbuild: split cc-option and friends to scripts/Makefile.compiler") Reported-by: Janosch Frank Reported-by: Christian Borntraeger Signed-off-by: Masahiro Yamada Tested-by: Christian Borntraeger Acked-by: Yonghong Song --- tools/build/Build.include | 24 +++++++++++++++++++ tools/testing/selftests/bpf/Makefile | 2 +- tools/testing/selftests/kvm/Makefile | 2 +- .../selftests/powerpc/pmu/ebb/Makefile | 2 +- tools/thermal/tmon/Makefile | 2 +- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/tools/build/Build.include b/tools/build/Build.include index 585486e40995..2cf3b1bde86e 100644 --- a/tools/build/Build.include +++ b/tools/build/Build.include @@ -100,3 +100,27 @@ cxx_flags = -Wp,-MD,$(depfile) -Wp,-MT,$@ $(CXXFLAGS) -D"BUILD_STR(s)=\#s" $(CXX ## HOSTCC C flags host_c_flags = -Wp,-MD,$(depfile) -Wp,-MT,$@ $(KBUILD_HOSTCFLAGS) -D"BUILD_STR(s)=\#s" $(HOSTCFLAGS_$(basetarget).o) $(HOSTCFLAGS_$(obj)) + +# output directory for tests below +TMPOUT = .tmp_$$$$ + +# try-run +# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise) +# Exit code chooses option. "$$TMP" serves as a temporary file and is +# automatically cleaned up. +try-run = $(shell set -e; \ + TMP=$(TMPOUT)/tmp; \ + mkdir -p $(TMPOUT); \ + trap "rm -rf $(TMPOUT)" EXIT; \ + if ($(1)) >/dev/null 2>&1; \ + then echo "$(2)"; \ + else echo "$(3)"; \ + fi) + +# cc-option +# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586) +cc-option = $(call try-run, \ + $(CC) -Werror $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2)) + +# delete partially updated (i.e. corrupted) files on error +.DELETE_ON_ERROR: diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index 044bfdcf5b74..17a5cdf48d37 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -include ../../../../scripts/Kbuild.include +include ../../../build/Build.include include ../../../scripts/Makefile.arch include ../../../scripts/Makefile.include diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile index a6d61f451f88..5ef141f265bd 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -include ../../../../scripts/Kbuild.include +include ../../../build/Build.include all: diff --git a/tools/testing/selftests/powerpc/pmu/ebb/Makefile b/tools/testing/selftests/powerpc/pmu/ebb/Makefile index af3df79d8163..c5ecb4634094 100644 --- a/tools/testing/selftests/powerpc/pmu/ebb/Makefile +++ b/tools/testing/selftests/powerpc/pmu/ebb/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -include ../../../../../../scripts/Kbuild.include +include ../../../../../build/Build.include noarg: $(MAKE) -C ../../ diff --git a/tools/thermal/tmon/Makefile b/tools/thermal/tmon/Makefile index 59e417ec3e13..9db867df7679 100644 --- a/tools/thermal/tmon/Makefile +++ b/tools/thermal/tmon/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 # We need this for the "cc-option" macro. -include ../../../scripts/Kbuild.include +include ../../build/Build.include VERSION = 1.0 From 82526ef43399a7556b860538041802042b3872c1 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 20 Apr 2021 02:05:05 +0900 Subject: [PATCH 41/42] kbuild: deb-pkg: change the source package name to linux-upstream Change the source package name from 'linux-$(KERNELRELEASE)' to 'linux-upstream'. Initially, I tried to use 'linux' to be aligned with the Debian kernel package, but Ben suggested 'linux-upstream' so that it is clearly distinguished from distribution packages. [1] The filenames will be changed as follows: [Before] linux-5.12.0-rc3+_5.12.0-rc3+-1.dsc linux-5.12.0-rc3+_5.12.0-rc3+.orig.tar.gz linux-5.12.0-rc3+_5.12.0-rc3+-1.diff.gz [After] linux-upstream_5.12.0-rc3+-1.dsc linux-upstream_5.12.0-rc3+.orig.tar.gz linux-upstream_5.12.0-rc3+-1.diff.gz Commit 3716001bcb7f ("deb-pkg: add source package") introduced KDEB_SOURCENAME. If you are unhappy with the default name, you can override it via KDEB_SOURCENAME. [1]: https://lore.kernel.org/linux-kbuild/06ffa2a690d57f867b4bc1b42f0026917b1dd3cd.camel@decadent.org.uk/T/#m2c4afa0eca5ced5e57795b002f2dbcb05d7a4a44 Suggested-by: Ben Hutchings Signed-off-by: Masahiro Yamada --- scripts/Makefile.package | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Makefile.package b/scripts/Makefile.package index f952fb64789d..b74c65284fb2 100644 --- a/scripts/Makefile.package +++ b/scripts/Makefile.package @@ -25,7 +25,7 @@ include $(srctree)/scripts/Kbuild.include # Remove hyphens since they have special meaning in RPM filenames KERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE)) -KDEB_SOURCENAME ?= linux-$(KERNELRELEASE) +KDEB_SOURCENAME ?= linux-upstream KBUILD_PKG_ROOTCMD ?="fakeroot -u" export KDEB_SOURCENAME # Include only those top-level files that are needed by make, plus the GPL copy From f634ca650f724347892068489c7920631a3aac6a Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Thu, 22 Apr 2021 13:19:14 -0700 Subject: [PATCH 42/42] 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(-) 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)