From 24507871c3c6ae4f6b460b016da7ff434cd34149 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 9 Jan 2024 21:07:34 +0900 Subject: kbuild: create a list of all built DTB files It is useful to have a list of all *.dtb and *.dtbo files generated from the current build. With this commit, 'make dtbs' creates arch/*/boot/dts/dtbs-list, which lists the dtb(o) files created in the current build. It maintains the order of the dtb-y additions in Makefiles although the order is not important for DTBs. It is a (good) side effect through the reuse of the modules.order rule. Please note this list only includes the files directly added to dtb-y. For example, consider this case: foo-dtbs := foo_base.dtb foo_overlay.dtbo dtb-y := foo.dtb In this example, the list will include foo.dtb, but not foo_base.dtb or foo_overlay.dtbo. Signed-off-by: Masahiro Yamada --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 41fa8a2565f5..f5755b81591b 100644 --- a/Makefile +++ b/Makefile @@ -1393,7 +1393,7 @@ ifneq ($(dtstree),) PHONY += dtbs dtbs_prepare dtbs_install dtbs_check dtbs: dtbs_prepare - $(Q)$(MAKE) $(build)=$(dtstree) + $(Q)$(MAKE) $(build)=$(dtstree) need-dtbslist=1 # include/config/kernel.release is actually needed when installing DTBs because # INSTALL_DTBS_PATH contains $(KERNELRELEASE). However, we do not want to make @@ -1932,7 +1932,7 @@ clean: $(clean-dirs) -o -name '*.ko.*' \ -o -name '*.dtb' -o -name '*.dtbo' \ -o -name '*.dtb.S' -o -name '*.dtbo.S' \ - -o -name '*.dt.yaml' \ + -o -name '*.dt.yaml' -o -name 'dtbs-list' \ -o -name '*.dwo' -o -name '*.lst' \ -o -name '*.su' -o -name '*.mod' \ -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ -- cgit v1.2.3 From 8f66864cee447835889ec0d91d52ff39bf2deabc Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Tue, 9 Jan 2024 21:07:35 +0900 Subject: kbuild: simplify dtbs_install by reading the list of compiled DTBs Retrieve the list of *.dtb(o) files from arch/*/boot/dts/dtbs-list instead of traversing the directory tree again. Please note that 'make dtbs_install' installs *.dtb(o) files directly added to dtb-y because scripts/Makefile.dtbinst installs $(dtb-y) without expanding the -dtbs suffix. This commit preserves this behavior. Signed-off-by: Masahiro Yamada --- Makefile | 2 +- scripts/Kbuild.include | 6 ------ scripts/Makefile.dtbinst | 32 ++++++++++++++++++-------------- 3 files changed, 19 insertions(+), 21 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index f5755b81591b..bc54a6cc8dc5 100644 --- a/Makefile +++ b/Makefile @@ -1411,7 +1411,7 @@ endif dtbs_check: dtbs dtbs_install: - $(Q)$(MAKE) $(dtbinst)=$(dtstree) dst=$(INSTALL_DTBS_PATH) + $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.dtbinst obj=$(dtstree) ifdef CONFIG_OF_EARLY_FLATTREE all: dtbs diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 7778cc97a4e0..2f331879816b 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -113,12 +113,6 @@ endef # $(Q)$(MAKE) $(build)=dir build := -f $(srctree)/scripts/Makefile.build obj -### -# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.dtbinst obj= -# Usage: -# $(Q)$(MAKE) $(dtbinst)=dir -dtbinst := -f $(srctree)/scripts/Makefile.dtbinst obj - ### # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj= # Usage: diff --git a/scripts/Makefile.dtbinst b/scripts/Makefile.dtbinst index 4405d5b67578..67956f6496a5 100644 --- a/scripts/Makefile.dtbinst +++ b/scripts/Makefile.dtbinst @@ -8,32 +8,36 @@ # $INSTALL_PATH/dtbs/$KERNELRELEASE # ========================================================================== -src := $(obj) - PHONY := __dtbs_install __dtbs_install: include include/config/auto.conf include $(srctree)/scripts/Kbuild.include -include $(kbuild-file) - -dtbs := $(addprefix $(dst)/, $(dtb-y) $(if $(CONFIG_OF_ALL_DTBS),$(dtb-))) -subdirs := $(addprefix $(obj)/, $(subdir-y) $(subdir-m)) -__dtbs_install: $(dtbs) $(subdirs) - @: +dst := $(INSTALL_DTBS_PATH) quiet_cmd_dtb_install = INSTALL $@ cmd_dtb_install = install -D $< $@ -$(dst)/%.dtb: $(obj)/%.dtb +$(dst)/%: $(obj)/% $(call cmd,dtb_install) -$(dst)/%.dtbo: $(obj)/%.dtbo - $(call cmd,dtb_install) +dtbs := $(patsubst $(obj)/%,%,$(call read-file, $(obj)/dtbs-list)) + +ifdef CONFIG_ARCH_WANT_FLAT_DTB_INSTALL -PHONY += $(subdirs) -$(subdirs): - $(Q)$(MAKE) $(dtbinst)=$@ dst=$(if $(CONFIG_ARCH_WANT_FLAT_DTB_INSTALL),$(dst),$(patsubst $(obj)/%,$(dst)/%,$@)) +define gen_install_rules +$(dst)/%: $(obj)/$(1)% + $$(call cmd,dtb_install) +endef + +$(foreach d, $(sort $(dir $(dtbs))), $(eval $(call gen_install_rules,$(d)))) + +dtbs := $(notdir $(dtbs)) + +endif # CONFIG_ARCH_WANT_FLAT_DTB_INSTALL + +__dtbs_install: $(addprefix $(dst)/, $(dtbs)) + @: .PHONY: $(PHONY) -- cgit v1.2.3 From 5270316c9fec8cc99aa0e0a258509c5c7f789d12 Mon Sep 17 00:00:00 2001 From: Petr Pavlu Date: Thu, 22 Feb 2024 14:35:00 +0100 Subject: kbuild: Use -fmin-function-alignment when available GCC recently added option -fmin-function-alignment, which should appear in GCC 14. Unlike -falign-functions, this option causes all functions to be aligned at the specified value, including the cold ones. In particular, when an arm64 kernel is built with DYNAMIC_FTRACE_WITH_CALL_OPS=y, the 8-byte function alignment is required for correct functionality. This was done by -falign-functions=8 and having workarounds in the kernel to force the compiler to follow this alignment. The new -fmin-function-alignment option directly guarantees it. Detect availability of -fmin-function-alignment and use it instead of -falign-functions when present. Introduce CC_HAS_SANE_FUNCTION_ALIGNMENT and enable __cold to work as expected when it is set. Signed-off-by: Petr Pavlu Reviewed-by: Nathan Chancellor Acked-by: Mark Rutland Signed-off-by: Masahiro Yamada --- Makefile | 7 +++++++ arch/Kconfig | 12 ++++++++++++ include/linux/compiler_types.h | 10 +++++----- 3 files changed, 24 insertions(+), 5 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index bc54a6cc8dc5..d84c0fb215fd 100644 --- a/Makefile +++ b/Makefile @@ -974,8 +974,15 @@ export CC_FLAGS_CFI endif ifneq ($(CONFIG_FUNCTION_ALIGNMENT),0) +# Set the minimal function alignment. Use the newer GCC option +# -fmin-function-alignment if it is available, or fall back to -falign-funtions. +# See also CONFIG_CC_HAS_SANE_FUNCTION_ALIGNMENT. +ifdef CONFIG_CC_HAS_MIN_FUNCTION_ALIGNMENT +KBUILD_CFLAGS += -fmin-function-alignment=$(CONFIG_FUNCTION_ALIGNMENT) +else KBUILD_CFLAGS += -falign-functions=$(CONFIG_FUNCTION_ALIGNMENT) endif +endif # arch Makefile may override CC so keep this after arch Makefile is included NOSTDINC_FLAGS += -nostdinc diff --git a/arch/Kconfig b/arch/Kconfig index a5af0edd3eb8..bd6c6335efac 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -1507,4 +1507,16 @@ config FUNCTION_ALIGNMENT default 4 if FUNCTION_ALIGNMENT_4B default 0 +config CC_HAS_MIN_FUNCTION_ALIGNMENT + # Detect availability of the GCC option -fmin-function-alignment which + # guarantees minimal alignment for all functions, unlike + # -falign-functions which the compiler ignores for cold functions. + def_bool $(cc-option, -fmin-function-alignment=8) + +config CC_HAS_SANE_FUNCTION_ALIGNMENT + # Set if the guaranteed alignment with -fmin-function-alignment is + # available or extra care is required in the kernel. Clang provides + # strict alignment always, even with -falign-functions. + def_bool CC_HAS_MIN_FUNCTION_ALIGNMENT || CC_IS_CLANG + endmenu diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h index 0caf354cb94b..fb8888678687 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -99,17 +99,17 @@ static inline void __chk_io_ptr(const volatile void __iomem *ptr) { } * gcc: https://gcc.gnu.org/onlinedocs/gcc/Label-Attributes.html#index-cold-label-attribute * * When -falign-functions=N is in use, we must avoid the cold attribute as - * contemporary versions of GCC drop the alignment for cold functions. Worse, - * GCC can implicitly mark callees of cold functions as cold themselves, so - * it's not sufficient to add __function_aligned here as that will not ensure - * that callees are correctly aligned. + * GCC drops the alignment for cold functions. Worse, GCC can implicitly mark + * callees of cold functions as cold themselves, so it's not sufficient to add + * __function_aligned here as that will not ensure that callees are correctly + * aligned. * * See: * * https://lore.kernel.org/lkml/Y77%2FqVgvaJidFpYt@FVFF77S0Q05N * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88345#c9 */ -#if !defined(CONFIG_CC_IS_GCC) || (CONFIG_FUNCTION_ALIGNMENT == 0) +#if defined(CONFIG_CC_HAS_SANE_FUNCTION_ALIGNMENT) || (CONFIG_FUNCTION_ALIGNMENT == 0) #define __cold __attribute__((__cold__)) #else #define __cold -- cgit v1.2.3 From 50a339981780e233a5be88b9116a6dfd0e00231a Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Fri, 1 Mar 2024 20:21:07 +0900 Subject: kbuild: fix inconsistent indentation in top Makefile Commit 3b9ab248bc45 ("kbuild: use 4-space indentation when followed by conditionals") introduced inconsistent indentation because it deliberately touched only the conditional directives to minimize the change set. This commit reformats some blocks in the top Makefile so they are consistently indented with 4 spaces. Signed-off-by: Masahiro Yamada Reviewed-by: Nathan Chancellor --- Makefile | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index d84c0fb215fd..859b0f52949e 100644 --- a/Makefile +++ b/Makefile @@ -295,51 +295,51 @@ single-build := ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),) ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),) - need-config := + need-config := endif endif ifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),) ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),) - may-sync-config := + may-sync-config := endif endif need-compiler := $(may-sync-config) ifneq ($(KBUILD_EXTMOD),) - may-sync-config := + may-sync-config := endif ifeq ($(KBUILD_EXTMOD),) - ifneq ($(filter %config,$(MAKECMDGOALS)),) - config-build := 1 - ifneq ($(words $(MAKECMDGOALS)),1) - mixed-build := 1 - endif + ifneq ($(filter %config,$(MAKECMDGOALS)),) + config-build := 1 + ifneq ($(words $(MAKECMDGOALS)),1) + mixed-build := 1 endif + endif endif # We cannot build single targets and the others at the same time ifneq ($(filter $(single-targets), $(MAKECMDGOALS)),) - single-build := 1 + single-build := 1 ifneq ($(filter-out $(single-targets), $(MAKECMDGOALS)),) - mixed-build := 1 + mixed-build := 1 endif endif # For "make -j clean all", "make -j mrproper defconfig all", etc. ifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),) - ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),) - mixed-build := 1 - endif + ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),) + mixed-build := 1 + endif endif # install and modules_install need also be processed one by one ifneq ($(filter install,$(MAKECMDGOALS)),) - ifneq ($(filter modules_install,$(MAKECMDGOALS)),) - mixed-build := 1 - endif + ifneq ($(filter modules_install,$(MAKECMDGOALS)),) + mixed-build := 1 + endif endif ifdef mixed-build -- cgit v1.2.3 From e2bad142bb3de836c5fbb3dff704578f5a73d8e6 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 6 Mar 2024 19:42:22 +0900 Subject: kbuild: unexport abs_srctree and abs_objtree Commit 25b146c5b8ce ("kbuild: allow Kbuild to start from any directory") exported abs_srctree and abs_objtree to avoid recomputation after the sub-make. However, this approach turned out to be fragile. Commit 5fa94ceb793e ("kbuild: set correct abs_srctree and abs_objtree for package builds") moved them above "ifneq ($(sub_make_done),1)", eliminating the need for exporting them. These are only needed in the top Makefile. If an absolute path is required in sub-directories, you can use $(abspath ) or $(realpath ) as needed. Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Makefile | 4 ++-- rust/Makefile | 4 ++-- scripts/Makefile.package | 2 +- tools/lib/bpf/Makefile | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 859b0f52949e..104e62560eed 100644 --- a/Makefile +++ b/Makefile @@ -39,8 +39,8 @@ __all: # prepare rule. this-makefile := $(lastword $(MAKEFILE_LIST)) -export abs_srctree := $(realpath $(dir $(this-makefile))) -export abs_objtree := $(CURDIR) +abs_srctree := $(realpath $(dir $(this-makefile))) +abs_objtree := $(CURDIR) ifneq ($(sub_make_done),1) diff --git a/rust/Makefile b/rust/Makefile index 9d2a16cc91cb..ae691b71d9fc 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -100,7 +100,7 @@ rustdoc: rustdoc-core rustdoc-macros rustdoc-compiler_builtins \ -e 's:rust-logo-[0-9a-f]+\.svg:logo.svg:g' \ -e 's:favicon-[0-9a-f]+\.svg:logo.svg:g' \ -e 's:::g' \ - -e 's:::g' + -e 's:::g' $(Q)for f in $(rustdoc_output)/static.files/rustdoc-*.css; do \ echo ".logo-container > img { object-fit: contain; }" >> $$f; done @@ -413,7 +413,7 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L rust-analyzer: $(Q)$(srctree)/scripts/generate_rust_analyzer.py \ --cfgs='core=$(core-cfgs)' --cfgs='alloc=$(alloc-cfgs)' \ - $(abs_srctree) $(abs_objtree) \ + $(realpath $(srctree)) $(realpath $(objtree)) \ $(RUST_LIB_SRC) $(KBUILD_EXTMOD) > \ $(if $(KBUILD_EXTMOD),$(extmod_prefix),$(objtree))/rust-project.json diff --git a/scripts/Makefile.package b/scripts/Makefile.package index a81dfb1f5181..38653f3e8108 100644 --- a/scripts/Makefile.package +++ b/scripts/Makefile.package @@ -135,7 +135,7 @@ snap-pkg: mkdir $(objtree)/snap $(MAKE) clean sed "s@KERNELRELEASE@$(KERNELRELEASE)@; \ - s@SRCTREE@$(abs_srctree)@" \ + s@SRCTREE@$(realpath $(srctree))@" \ $(srctree)/scripts/package/snapcraft.template > \ $(objtree)/snap/snapcraft.yaml cd $(objtree)/snap && \ diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile index 4be7144e4803..2cf892774346 100644 --- a/tools/lib/bpf/Makefile +++ b/tools/lib/bpf/Makefile @@ -2,7 +2,7 @@ # Most of this file is copied from tools/lib/traceevent/Makefile RM ?= rm -srctree = $(abs_srctree) +srctree := $(realpath $(srctree)) VERSION_SCRIPT := libbpf.map LIBBPF_VERSION := $(shell \ -- cgit v1.2.3