kbuild: remove ARCH_POSTLINK from module builds
PATCH 1/4 kbuild: remove ARCH_POSTLINK from module builds
The '%.ko' rule in arch/*/Makefile.postlink does nothing but call the 'true' command.
Remove the meaningless code.
---
arch/mips/Makefile.postlink | 3 --- arch/powerpc/Makefile.postlink | 3 --- arch/riscv/Makefile.postlink | 3 --- arch/x86/Makefile.postlink | 3 --- scripts/Makefile.modfinal | 5 +---- 5 files changed, 1 insertion(+), 16 deletions(-)
arch/mips/Makefile.postlink +0 -3
@@ -31,9 +31,6 @@ ifeq ($(CONFIG_RELOCATABLE),y) $(call if_changed,relocs) endif -%.ko: FORCE - @true - clean: @true
arch/powerpc/Makefile.postlink +0 -3
@@ -35,9 +35,6 @@ ifdef CONFIG_RELOCATABLE $(call if_changed,relocs_check) endif -%.ko: FORCE - @true - clean: rm -f .tmp_symbols.txt
arch/riscv/Makefile.postlink +0 -3
@@ -36,9 +36,6 @@ ifdef CONFIG_RELOCATABLE $(call if_changed,relocs_strip) endif -%.ko: FORCE - @true - clean: @true
arch/x86/Makefile.postlink +0 -3
@@ -34,9 +34,6 @@ ifeq ($(CONFIG_X86_NEED_RELOCS),y) $(call cmd,strip_relocs) endif -%.ko: FORCE - @true - clean: @rm -f $(OUT_RELOCS)/vmlinux.relocs
scripts/Makefile.modfinal +1 -4
@@ -28,14 +28,11 @@ quiet_cmd_cc_o_c = CC [M] $@ %.mod.o: %.mod.c FORCE $(call if_changed_dep,cc_o_c) -ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) - quiet_cmd_ld_ko_o = LD [M] $@ cmd_ld_ko_o += \ $(LD) -r $(KBUILD_LDFLAGS) \ $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ - -T scripts/module.lds -o $@ $(filter %.o, $^); \ - $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) + -T scripts/module.lds -o $@ $(filter %.o, $^) quiet_cmd_btf_ko = BTF [M] $@ cmd_btf_ko = \
Signature · 1 line
2.40.1
PATCH 2/4 kbuild: avoid too many execution of scripts/pahole-flags.sh
scripts/pahole-flags.sh is executed so many times.
You can check how many times it is invoked during the build, as follows:
$ cat <<EOF >> scripts/pahole-flags.sh
Quoted 2 lines
echo "
scripts/pahole-flags.shwas executed" >&2
EOF
$ make -s
scripts/pahole-flags.sh was executed
scripts/pahole-flags.sh was executed
scripts/pahole-flags.sh was executed
scripts/pahole-flags.sh was executed
scripts/pahole-flags.sh was executed
[ lots of repeated lines suppressed... ]This scripts is exectuted more than 20 times during the kernel build because PAHOLE_FLAGS is a recursively expanded variable and exported to sub-processes.
With the GNU Make >= 4.4, it is executed more than 60 times because exported variables are also passed to other $(shell ) invocations. Without careful coding, it is known to cause an exponential fork explosion. [1]
The use of $(shell ) in an exported recursive variable is likely wrong because $(shell ) is always evaluated due to the 'export' keyword, and the evaluation can occur multiple times by the nature of recursive variables.
Convert the shell script to a Makefile, which is included only when CONFIG_DEBUG_INFO_BTF=y.
[1]: https://savannah.gnu.org/bugs/index.php?64746
---
Makefile | 4 +--- scripts/Makefile.btf | 19 +++++++++++++++++++ scripts/pahole-flags.sh | 30 ------------------------------ 3 files changed, 20 insertions(+), 33 deletions(-) create mode 100644 scripts/Makefile.btf delete mode 100755 scripts/pahole-flags.sh
Makefile +1 -3
@@ -513,8 +513,6 @@ LZ4 = lz4c XZ = xz ZSTD = zstd -PAHOLE_FLAGS = $(shell PAHOLE=$(PAHOLE) $(srctree)/scripts/pahole-flags.sh) - CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \ -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF) NOSTDINC_FLAGS :=
@@ -605,7 +603,6 @@ export KBUILD_RUSTFLAGS RUSTFLAGS_KERNEL RUSTFLAGS_MODULE export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_RUSTFLAGS_MODULE KBUILD_LDFLAGS_MODULE export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL KBUILD_RUSTFLAGS_KERNEL -export PAHOLE_FLAGS # Files to ignore in find ... statements
@@ -1002,6 +999,7 @@ KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=) # include additional Makefiles when needed include-y := scripts/Makefile.extrawarn include-$(CONFIG_DEBUG_INFO) += scripts/Makefile.debug +include-$(CONFIG_DEBUG_INFO_BTF)+= scripts/Makefile.btf include-$(CONFIG_KASAN) += scripts/Makefile.kasan include-$(CONFIG_KCSAN) += scripts/Makefile.kcsan include-$(CONFIG_KMSAN) += scripts/Makefile.kmsan
scripts/Makefile.btf new file +19 -0
@@ -0,0 +1,19 @@ +# SPDX-License-Identifier: GPL-2.0 + +pahole-ver := $(CONFIG_PAHOLE_VERSION) +pahole-flags-y := + +# pahole 1.18 through 1.21 can't handle zero-sized per-CPU vars +ifeq ($(call test-le, $(pahole-ver), 121),y) +pahole-flags-$(call test-ge, $(pahole-ver), 118) += --skip_encoding_btf_vars +endif + +pahole-flags-$(call test-ge, $(pahole-ver), 121) += --btf_gen_floats + +pahole-flags-$(call test-ge, $(pahole-ver), 122) += -j + +pahole-flags-$(CONFIG_PAHOLE_HAS_LANG_EXCLUDE) += --lang_exclude=rust + +pahole-flags-$(call test-ge, $(pahole-ver), 125) += --skip_encoding_btf_inconsistent_proto --btf_gen_optimized + +export PAHOLE_FLAGS := $(pahole-flags-y)
scripts/pahole-flags.sh deleted +0 -30
@@ -1,30 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0 - -extra_paholeopt= - -if ! [ -x "$(command -v ${PAHOLE})" ]; then - exit 0 -fi - -pahole_ver=$($(dirname $0)/pahole-version.sh ${PAHOLE}) - -if [ "${pahole_ver}" -ge "118" ] && [ "${pahole_ver}" -le "121" ]; then - # pahole 1.18 through 1.21 can't handle zero-sized per-CPU vars - extra_paholeopt="${extra_paholeopt} --skip_encoding_btf_vars" -fi -if [ "${pahole_ver}" -ge "121" ]; then - extra_paholeopt="${extra_paholeopt} --btf_gen_floats" -fi -if [ "${pahole_ver}" -ge "122" ]; then - extra_paholeopt="${extra_paholeopt} -j" -fi -if [ "${pahole_ver}" -ge "124" ]; then - # see PAHOLE_HAS_LANG_EXCLUDE - extra_paholeopt="${extra_paholeopt} --lang_exclude=rust" -fi -if [ "${pahole_ver}" -ge "125" ]; then - extra_paholeopt="${extra_paholeopt} --skip_encoding_btf_inconsistent_proto --btf_gen_optimized" -fi - -echo ${extra_paholeopt}
Signature · 1 line
2.40.1
Re: [PATCH 2/4] kbuild: avoid too many execution of scripts/pahole-flags.sh
Quoted 16 lines · Masahiro Yamada
scripts/pahole-flags.shis executed so many times.You can check how many times it is invoked during the build, as follows:
$ cat <<EOF >> scripts/pahole-flags.shQuoted 2 lines
echo "
scripts/pahole-flags.shwas executed" >&2
EOF$ make -s scripts/pahole-flags.sh was executed scripts/pahole-flags.sh was executed scripts/pahole-flags.sh was executed scripts/pahole-flags.sh was executed scripts/pahole-flags.sh was executed [ lots of repeated lines suppressed... ]
Quoted 8 lines
This scripts is exectuted more than 20 times during the kernel build because
PAHOLE_FLAGSis a recursively expanded variable and exported to sub-processes.With the GNU Make >= 4.4, it is executed more than 60 times because exported variables are also passed to other $(shell ) invocations. Without careful coding, it is known to cause an exponential fork explosion. [1]
nice :-\
Quoted 8 lines
The use of $(shell ) in an exported recursive variable is likely wrong because $(shell ) is always evaluated due to the 'export' keyword, and the evaluation can occur multiple times by the nature of recursive variables.
Convert the shell script to a
Makefile, which is included only whenCONFIG_DEBUG_INFO_BTF=y.
looks good.. could you please resend this patch with bpf-next in subject so CI tests would trigger for it?
thanks,
jirka
Quoted 106 lines
[1]: https://savannah.gnu.org/bugs/index.php?64746
Signed-off-by Masahiro Yamada <[email protected]>---
Makefile | 4 +--- scripts/Makefile.btf | 19 +++++++++++++++++++ scripts/pahole-flags.sh | 30 ------------------------------ 3 files changed, 20 insertions(+), 33 deletions(-) create mode 100644 scripts/Makefile.btf delete mode 100755 scripts/pahole-flags.shMakefile +1
-3@@ -513,8 +513,6 @@ LZ4 = lz4c XZ = xz ZSTD = zstd -PAHOLE_FLAGS = $(shell PAHOLE=$(PAHOLE) $(srctree)/scripts/pahole-flags.sh) - CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \ -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF) NOSTDINC_FLAGS :=@@ -605,7 +603,6 @@ export KBUILD_RUSTFLAGS RUSTFLAGS_KERNEL RUSTFLAGS_MODULE export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_RUSTFLAGS_MODULE KBUILD_LDFLAGS_MODULE export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL KBUILD_RUSTFLAGS_KERNEL -export PAHOLE_FLAGS # Files to ignore in find ... statements@@ -1002,6 +999,7 @@ KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=) # include additional Makefiles when needed include-y := scripts/Makefile.extrawarn include-$(CONFIG_DEBUG_INFO) += scripts/Makefile.debug +include-$(CONFIG_DEBUG_INFO_BTF)+= scripts/Makefile.btf include-$(CONFIG_KASAN) += scripts/Makefile.kasan include-$(CONFIG_KCSAN) += scripts/Makefile.kcsan include-$(CONFIG_KMSAN) += scripts/Makefile.kmsanscripts/Makefile.btf new file +19
-0@@ -0,0 +1,19 @@ +# SPDX-License-Identifier: GPL-2.0 + +pahole-ver := $(CONFIG_PAHOLE_VERSION) +pahole-flags-y := + +# pahole 1.18 through 1.21 can't handle zero-sized per-CPU vars +ifeq ($(call test-le, $(pahole-ver), 121),y) +pahole-flags-$(call test-ge, $(pahole-ver), 118) += --skip_encoding_btf_vars +endif + +pahole-flags-$(call test-ge, $(pahole-ver), 121) += --btf_gen_floats + +pahole-flags-$(call test-ge, $(pahole-ver), 122) += -j + +pahole-flags-$(CONFIG_PAHOLE_HAS_LANG_EXCLUDE) += --lang_exclude=rust + +pahole-flags-$(call test-ge, $(pahole-ver), 125) += --skip_encoding_btf_inconsistent_proto --btf_gen_optimized + +export PAHOLE_FLAGS := $(pahole-flags-y)scripts/pahole-flags.sh deleted +0
-30@@ -1,30 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0 - -extra_paholeopt= - -if ! [ -x "$(command -v ${PAHOLE})" ]; then - exit 0 -fi - -pahole_ver=$($(dirname $0)/pahole-version.sh ${PAHOLE}) - -if [ "${pahole_ver}" -ge "118" ] && [ "${pahole_ver}" -le "121" ]; then - # pahole 1.18 through 1.21 can't handle zero-sized per-CPU vars - extra_paholeopt="${extra_paholeopt} --skip_encoding_btf_vars" -fi -if [ "${pahole_ver}" -ge "121" ]; then - extra_paholeopt="${extra_paholeopt} --btf_gen_floats" -fi -if [ "${pahole_ver}" -ge "122" ]; then - extra_paholeopt="${extra_paholeopt} -j" -fi -if [ "${pahole_ver}" -ge "124" ]; then - # see PAHOLE_HAS_LANG_EXCLUDE - extra_paholeopt="${extra_paholeopt} --lang_exclude=rust" -fi -if [ "${pahole_ver}" -ge "125" ]; then - extra_paholeopt="${extra_paholeopt} --skip_encoding_btf_inconsistent_proto --btf_gen_optimized" -fi - -echo ${extra_paholeopt}Signature · 1 line
2.40.1
Re: [PATCH 2/4] kbuild: avoid too many execution of scripts/pahole-flags.sh
In reply to Masahiro YamadaQuoted 30 lines · Masahiro Yamada
scripts/pahole-flags.shis executed so many times.You can check how many times it is invoked during the build, as follows:
$ cat <<EOF >> scripts/pahole-flags.shQuoted 2 lines
echo "
scripts/pahole-flags.shwas executed" >&2
EOF$ make -s scripts/pahole-flags.sh was executed scripts/pahole-flags.sh was executed scripts/pahole-flags.sh was executed scripts/pahole-flags.sh was executed scripts/pahole-flags.sh was executed [ lots of repeated lines suppressed... ]This scripts is exectuted more than 20 times during the kernel build because
PAHOLE_FLAGSis a recursively expanded variable and exported to sub-processes.With the GNU Make >= 4.4, it is executed more than 60 times because exported variables are also passed to other $(shell ) invocations. Without careful coding, it is known to cause an exponential fork explosion. [1]
The use of $(shell ) in an exported recursive variable is likely wrong because $(shell ) is always evaluated due to the 'export' keyword, and the evaluation can occur multiple times by the nature of recursive variables.
Quoted 6 lines
Convert the shell script to a
Makefile, which is included only whenCONFIG_DEBUG_INFO_BTF=y.[1]: https://savannah.gnu.org/bugs/index.php?64746
Signed-off-by Masahiro Yamada <[email protected]>
Looks like a neat change to me. I tested with CONFIG_DEBUG_INFO_BTF=y builds for full kernel build and 'make M=modpath' module-only builds, and both work well with correct pahole flags. Feel free to add either/both of
Quoted 99 lines
---
Makefile | 4 +--- scripts/Makefile.btf | 19 +++++++++++++++++++ scripts/pahole-flags.sh | 30 ------------------------------ 3 files changed, 20 insertions(+), 33 deletions(-) create mode 100644 scripts/Makefile.btf delete mode 100755 scripts/pahole-flags.shMakefile +1
-3@@ -513,8 +513,6 @@ LZ4 = lz4c XZ = xz ZSTD = zstd -PAHOLE_FLAGS = $(shell PAHOLE=$(PAHOLE) $(srctree)/scripts/pahole-flags.sh) - CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \ -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF) NOSTDINC_FLAGS :=@@ -605,7 +603,6 @@ export KBUILD_RUSTFLAGS RUSTFLAGS_KERNEL RUSTFLAGS_MODULE export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_RUSTFLAGS_MODULE KBUILD_LDFLAGS_MODULE export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL KBUILD_RUSTFLAGS_KERNEL -export PAHOLE_FLAGS # Files to ignore in find ... statements@@ -1002,6 +999,7 @@ KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=) # include additional Makefiles when needed include-y := scripts/Makefile.extrawarn include-$(CONFIG_DEBUG_INFO) += scripts/Makefile.debug +include-$(CONFIG_DEBUG_INFO_BTF)+= scripts/Makefile.btf include-$(CONFIG_KASAN) += scripts/Makefile.kasan include-$(CONFIG_KCSAN) += scripts/Makefile.kcsan include-$(CONFIG_KMSAN) += scripts/Makefile.kmsanscripts/Makefile.btf new file +19
-0@@ -0,0 +1,19 @@ +# SPDX-License-Identifier: GPL-2.0 + +pahole-ver := $(CONFIG_PAHOLE_VERSION) +pahole-flags-y := + +# pahole 1.18 through 1.21 can't handle zero-sized per-CPU vars +ifeq ($(call test-le, $(pahole-ver), 121),y) +pahole-flags-$(call test-ge, $(pahole-ver), 118) += --skip_encoding_btf_vars +endif + +pahole-flags-$(call test-ge, $(pahole-ver), 121) += --btf_gen_floats + +pahole-flags-$(call test-ge, $(pahole-ver), 122) += -j + +pahole-flags-$(CONFIG_PAHOLE_HAS_LANG_EXCLUDE) += --lang_exclude=rust + +pahole-flags-$(call test-ge, $(pahole-ver), 125) += --skip_encoding_btf_inconsistent_proto --btf_gen_optimized + +export PAHOLE_FLAGS := $(pahole-flags-y)scripts/pahole-flags.sh deleted +0
-30@@ -1,30 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0 - -extra_paholeopt= - -if ! [ -x "$(command -v ${PAHOLE})" ]; then - exit 0 -fi - -pahole_ver=$($(dirname $0)/pahole-version.sh ${PAHOLE}) - -if [ "${pahole_ver}" -ge "118" ] && [ "${pahole_ver}" -le "121" ]; then - # pahole 1.18 through 1.21 can't handle zero-sized per-CPU vars - extra_paholeopt="${extra_paholeopt} --skip_encoding_btf_vars" -fi -if [ "${pahole_ver}" -ge "121" ]; then - extra_paholeopt="${extra_paholeopt} --btf_gen_floats" -fi -if [ "${pahole_ver}" -ge "122" ]; then - extra_paholeopt="${extra_paholeopt} -j" -fi -if [ "${pahole_ver}" -ge "124" ]; then - # see PAHOLE_HAS_LANG_EXCLUDE - extra_paholeopt="${extra_paholeopt} --lang_exclude=rust" -fi -if [ "${pahole_ver}" -ge "125" ]; then - extra_paholeopt="${extra_paholeopt} --skip_encoding_btf_inconsistent_proto --btf_gen_optimized" -fi - -echo ${extra_paholeopt}
Re: [PATCH 2/4] kbuild: avoid too many execution of scripts/pahole-flags.sh
In reply to Masahiro YamadaQuoted 1 line
Subject: kbuild: avoid too many execution of
scripts/pahole-flags.sh
executions?
Quoted 16 lines · Masahiro Yamada
scripts/pahole-flags.shis executed so many times.You can check how many times it is invoked during the build, as follows:
$ cat <<EOF >> scripts/pahole-flags.shQuoted 2 lines
echo "
scripts/pahole-flags.shwas executed" >&2
EOF$ make -s scripts/pahole-flags.sh was executed scripts/pahole-flags.sh was executed scripts/pahole-flags.sh was executed scripts/pahole-flags.sh was executed scripts/pahole-flags.sh was executed [ lots of repeated lines suppressed... ]
Quoted 1 line
This scripts is exectuted more than 20 times during the kernel build
executed
Quoted 13 lines
because
PAHOLE_FLAGSis a recursively expanded variable and exported to sub-processes.With the GNU Make >= 4.4, it is executed more than 60 times because exported variables are also passed to other $(shell ) invocations. Without careful coding, it is known to cause an exponential fork explosion. [1]
The use of $(shell ) in an exported recursive variable is likely wrong because $(shell ) is always evaluated due to the 'export' keyword, and the evaluation can occur multiple times by the nature of recursive variables.
Quoted 7 lines
Convert the shell script to a
Makefile, which is included only whenCONFIG_DEBUG_INFO_BTF=y.[1]: https://savannah.gnu.org/bugs/index.php?64746
Signed-off-by Masahiro Yamada <[email protected]>---
Thanks, looks good to me!
Re: [PATCH 2/4] kbuild: avoid too many execution of scripts/pahole-flags.sh
In reply to Masahiro YamadaQuoted 7 lines · Masahiro Yamada
Convert the shell script to a
Makefile, which is included only whenCONFIG_DEBUG_INFO_BTF=y.[1]: https://savannah.gnu.org/bugs/index.php?64746
Signed-off-by Masahiro Yamada <[email protected]>
The field in MAINTAINERS should be removed:
F: scripts/pahole-flags.sh
But other than that, it looks good to me! I tried it for a given config and it does call pahole with the same flags.
Cheers,
Miguel
Re: [PATCH 2/4] kbuild: avoid too many execution of scripts/pahole-flags.sh
Quoted 6 lines · Miguel Ojeda
Quoted 4 lines · Masahiro Yamada
Convert the shell script to a
Makefile, which is included only whenCONFIG_DEBUG_INFO_BTF=y.
Quoted 7 lines
Quoted 3 lines
[1]: https://savannah.gnu.org/bugs/index.php?64746
Signed-off-by Masahiro Yamada <[email protected]>The field in
MAINTAINERSshould be removed:F:
scripts/pahole-flags.sh
I will replace it with
F: scripts/Makefile.btf
Thanks.
Quoted 9 lines
But other than that, it looks good to me! I tried it for a given config and it does call
paholewith the same flags.Tested-by Miguel Ojeda <[email protected]>Acked-by Miguel Ojeda <[email protected]>Cheers,
Miguel
Signature · 2 lines
Best Regards Masahiro Yamada
Re: [PATCH 2/4] kbuild: avoid too many execution of scripts/pahole-flags.sh
In reply to Masahiro YamadaQuoted 51 lines · Masahiro Yamada
scripts/pahole-flags.shis executed so many times.You can check how many times it is invoked during the build, as follows:
$ cat <<EOF >> scripts/pahole-flags.shQuoted 2 lines
echo "
scripts/pahole-flags.shwas executed" >&2
EOF$ make -s scripts/pahole-flags.sh was executed scripts/pahole-flags.sh was executed scripts/pahole-flags.sh was executed scripts/pahole-flags.sh was executed scripts/pahole-flags.sh was executed [ lots of repeated lines suppressed... ]This scripts is exectuted more than 20 times during the kernel build because
PAHOLE_FLAGSis a recursively expanded variable and exported to sub-processes.With the GNU Make >= 4.4, it is executed more than 60 times because exported variables are also passed to other $(shell ) invocations. Without careful coding, it is known to cause an exponential fork explosion. [1]
The use of $(shell ) in an exported recursive variable is likely wrong because $(shell ) is always evaluated due to the 'export' keyword, and the evaluation can occur multiple times by the nature of recursive variables.
Convert the shell script to a
Makefile, which is included only whenCONFIG_DEBUG_INFO_BTF=y.[1]: https://savannah.gnu.org/bugs/index.php?64746
Signed-off-by Masahiro Yamada <[email protected]>---
Makefile | 4 +--- scripts/Makefile.btf | 19 +++++++++++++++++++ scripts/pahole-flags.sh | 30 ------------------------------ 3 files changed, 20 insertions(+), 33 deletions(-) create mode 100644 scripts/Makefile.btf delete mode 100755 scripts/pahole-flags.shMakefile +0
-0
Makefile LZ4 = lz4c · line 516
Quoted 4 lines
Makefile +0
-1@@ -513,8 +513,6 @@ LZ4 = lz4c XZ = xz ZSTD = zstd -PAHOLE_FLAGS = $(shell PAHOLE=$(PAHOLE) $(srctree)/scripts/pahole-flags.sh)
What if we just used := here? Wouldn't it avoid unnecessary multiple executions?
I don't make Makefile.btf approach, just curious why := doesn't work, if it doesn't.
Quoted 84 lines
Makefile +1
-2- CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \ -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF) NOSTDINC_FLAGS :=@@ -605,7 +603,6 @@ export KBUILD_RUSTFLAGS RUSTFLAGS_KERNEL RUSTFLAGS_MODULE export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_RUSTFLAGS_MODULE KBUILD_LDFLAGS_MODULE export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL KBUILD_RUSTFLAGS_KERNEL -export PAHOLE_FLAGS # Files to ignore in find ... statements@@ -1002,6 +999,7 @@ KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=) # include additional Makefiles when needed include-y := scripts/Makefile.extrawarn include-$(CONFIG_DEBUG_INFO) += scripts/Makefile.debug +include-$(CONFIG_DEBUG_INFO_BTF)+= scripts/Makefile.btf include-$(CONFIG_KASAN) += scripts/Makefile.kasan include-$(CONFIG_KCSAN) += scripts/Makefile.kcsan include-$(CONFIG_KMSAN) += scripts/Makefile.kmsanscripts/Makefile.btf new file +19
-0@@ -0,0 +1,19 @@ +# SPDX-License-Identifier: GPL-2.0 + +pahole-ver := $(CONFIG_PAHOLE_VERSION) +pahole-flags-y := + +# pahole 1.18 through 1.21 can't handle zero-sized per-CPU vars +ifeq ($(call test-le, $(pahole-ver), 121),y) +pahole-flags-$(call test-ge, $(pahole-ver), 118) += --skip_encoding_btf_vars +endif + +pahole-flags-$(call test-ge, $(pahole-ver), 121) += --btf_gen_floats + +pahole-flags-$(call test-ge, $(pahole-ver), 122) += -j + +pahole-flags-$(CONFIG_PAHOLE_HAS_LANG_EXCLUDE) += --lang_exclude=rust + +pahole-flags-$(call test-ge, $(pahole-ver), 125) += --skip_encoding_btf_inconsistent_proto --btf_gen_optimized + +export PAHOLE_FLAGS := $(pahole-flags-y)scripts/pahole-flags.sh deleted +0
-31@@ -1,30 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0 - -extra_paholeopt= - -if ! [ -x "$(command -v ${PAHOLE})" ]; then - exit 0 -fi - -pahole_ver=$($(dirname $0)/pahole-version.sh ${PAHOLE}) - -if [ "${pahole_ver}" -ge "118" ] && [ "${pahole_ver}" -le "121" ]; then - # pahole 1.18 through 1.21 can't handle zero-sized per-CPU vars - extra_paholeopt="${extra_paholeopt} --skip_encoding_btf_vars" -fi -if [ "${pahole_ver}" -ge "121" ]; then - extra_paholeopt="${extra_paholeopt} --btf_gen_floats" -fi -if [ "${pahole_ver}" -ge "122" ]; then - extra_paholeopt="${extra_paholeopt} -j" -fi -if [ "${pahole_ver}" -ge "124" ]; then - # see PAHOLE_HAS_LANG_EXCLUDE - extra_paholeopt="${extra_paholeopt} --lang_exclude=rust" -fi -if [ "${pahole_ver}" -ge "125" ]; then - extra_paholeopt="${extra_paholeopt} --skip_encoding_btf_inconsistent_proto --btf_gen_optimized" -fi - -echo ${extra_paholeopt} --2.40.1
Re: [PATCH 2/4] kbuild: avoid too many execution of scripts/pahole-flags.sh
Quoted 56 lines · Andrii Nakryiko
Quoted 54 lines · Masahiro Yamada
scripts/pahole-flags.shis executed so many times.You can check how many times it is invoked during the build, as follows:
$ cat <<EOF >> scripts/pahole-flags.shQuoted 2 lines
echo "
scripts/pahole-flags.shwas executed" >&2
EOF$ make -s scripts/pahole-flags.sh was executed scripts/pahole-flags.sh was executed scripts/pahole-flags.sh was executed scripts/pahole-flags.sh was executed scripts/pahole-flags.sh was executed [ lots of repeated lines suppressed... ]This scripts is exectuted more than 20 times during the kernel build because
PAHOLE_FLAGSis a recursively expanded variable and exported to sub-processes.With the GNU Make >= 4.4, it is executed more than 60 times because exported variables are also passed to other $(shell ) invocations. Without careful coding, it is known to cause an exponential fork explosion. [1]
The use of $(shell ) in an exported recursive variable is likely wrong because $(shell ) is always evaluated due to the 'export' keyword, and the evaluation can occur multiple times by the nature of recursive variables.
Convert the shell script to a
Makefile, which is included only whenCONFIG_DEBUG_INFO_BTF=y.[1]: https://savannah.gnu.org/bugs/index.php?64746
Signed-off-by Masahiro Yamada <[email protected]>---
Makefile | 4 +--- scripts/Makefile.btf | 19 +++++++++++++++++++ scripts/pahole-flags.sh | 30 ------------------------------ 3 files changed, 20 insertions(+), 33 deletions(-) create mode 100644 scripts/Makefile.btf delete mode 100755 scripts/pahole-flags.shMakefile +0
-0@@ -513,8 +513,6 @@ LZ4 = lz4c XZ = xz ZSTD = zstd
Quoted 3 lines
Makefile LZ4 = lz4c · line 516
Quoted 1 line
Makefile +0
-1-PAHOLE_FLAGS = $(shell PAHOLE=$(PAHOLE) $(srctree)/scripts/pahole-flags.sh)What if we just used := here? Wouldn't it avoid unnecessary multiple executions?
Yeah, := is less silly than =.
But, I do not like to run the script for non-build targets such as 'make clean', 'make help', etc.
Also, when building with CONFIG_DEBUG_INFO_BTF=n, the shell is forked to compute PAHOLE_FLAGS, which we know are unnecessary.
--
Best Regards
Masahiro Yamada
Re: [PATCH 2/4] kbuild: avoid too many execution of scripts/pahole-flags.sh
In reply to Masahiro YamadaQuoted 33 lines · Masahiro Yamada
scripts/pahole-flags.shis executed so many times.You can check how many times it is invoked during the build, as follows:
$ cat <<EOF >> scripts/pahole-flags.shQuoted 2 lines
echo "
scripts/pahole-flags.shwas executed" >&2
EOF$ make -s scripts/pahole-flags.sh was executed scripts/pahole-flags.sh was executed scripts/pahole-flags.sh was executed scripts/pahole-flags.sh was executed scripts/pahole-flags.sh was executed [ lots of repeated lines suppressed... ]This scripts is exectuted more than 20 times during the kernel build because
PAHOLE_FLAGSis a recursively expanded variable and exported to sub-processes.With the GNU Make >= 4.4, it is executed more than 60 times because exported variables are also passed to other $(shell ) invocations. Without careful coding, it is known to cause an exponential fork explosion. [1]
The use of $(shell ) in an exported recursive variable is likely wrong because $(shell ) is always evaluated due to the 'export' keyword, and the evaluation can occur multiple times by the nature of recursive variables.
Convert the shell script to a
Makefile, which is included only whenCONFIG_DEBUG_INFO_BTF=y.
Quoted 6 lines
[1]: https://savannah.gnu.org/bugs/index.php?64746
Signed-off-by Masahiro Yamada <[email protected]>---
[...]
+include-$(CONFIG_DEBUG_INFO_BTF)+=scripts/Makefile.btf
Would have used a tab.
Quoted 1 line
[...]
PATCH 3/4 kbuild: skip module BTF with one-time check for vmlinux
In reply to Masahiro YamadaWhen CONFIG_DEBUG_INFO_BTF_MODULES is enabled, vmlinux presence is checked in every module build, resulting in repetitive warning messages if vmlinux is missing.
Check vmlinux and print a warning just once.
---
scripts/Makefile.modfinal | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
scripts/Makefile.modfinal +12 -7
@@ -14,6 +14,15 @@ include $(srctree)/scripts/Makefile.lib # find all modules listed in modules.order modules := $(call read-file, $(MODORDER)) +vmlinux := + +ifdef CONFIG_DEBUG_INFO_BTF_MODULES +ifneq ($(wildcard vmlinux),) +vmlinux := vmlinux +else +$(warning Skipping BTF generation due to unavailability of vmlinux) +endif +endif __modfinal: $(modules:%.o=%.ko) @:
@@ -36,12 +45,8 @@ quiet_cmd_ld_ko_o = LD [M] $@ quiet_cmd_btf_ko = BTF [M] $@ cmd_btf_ko = \ - if [ ! -f vmlinux ]; then \ - printf "Skipping BTF generation for %s due to unavailability of vmlinux\n" $@ 1>&2; \ - else \ LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) --btf_base vmlinux $@; \ - $(RESOLVE_BTFIDS) -b vmlinux $@; \ - fi; + $(RESOLVE_BTFIDS) -b vmlinux $@ # Same as newer-prereqs, but allows to exclude specified extra dependencies newer_prereqs_except = $(filter-out $(PHONY) $(1),$?)
@@ -52,9 +57,9 @@ if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check), \ printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) # Re-generate module BTFs if either module's .ko or vmlinux changed -%.ko: %.o %.mod.o scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),vmlinux) FORCE +%.ko: %.o %.mod.o scripts/module.lds $(vmlinux) FORCE +$(call if_changed_except,ld_ko_o,vmlinux) -ifdef CONFIG_DEBUG_INFO_BTF_MODULES +ifdef vmlinux +$(if $(newer-prereqs),$(call cmd,btf_ko)) endif
Signature · 1 line
2.40.1
Re: [PATCH 3/4] kbuild: skip module BTF with one-time check for vmlinux
Quoted 8 lines · Masahiro Yamada
When
CONFIG_DEBUG_INFO_BTF_MODULESis enabled, vmlinux presence is checked in every module build, resulting in repetitive warning messages if vmlinux is missing.Check vmlinux and print a warning just once.
Signed-off-by Masahiro Yamada <[email protected]>---
PATCH 4/4 kbuild: refactor module BTF rule
In reply to Masahiro Yamadanewer_prereqs_except and if_changed_except are ugly hacks of the newer_prereqs and if_changed in scripts/Kbuild.include.
Remove.
---
scripts/Makefile.modfinal | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-)
scripts/Makefile.modfinal +5 -18
@@ -19,6 +19,9 @@ vmlinux := ifdef CONFIG_DEBUG_INFO_BTF_MODULES ifneq ($(wildcard vmlinux),) vmlinux := vmlinux +cmd_btf = ; \ + LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) --btf_base vmlinux $@; \ + $(RESOLVE_BTFIDS) -b vmlinux $@ else $(warning Skipping BTF generation due to unavailability of vmlinux) endif
@@ -41,27 +44,11 @@ quiet_cmd_ld_ko_o = LD [M] $@ cmd_ld_ko_o += \ $(LD) -r $(KBUILD_LDFLAGS) \ $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ - -T scripts/module.lds -o $@ $(filter %.o, $^) + -T scripts/module.lds -o $@ $(filter %.o, $^) \ + $(cmd_btf) -quiet_cmd_btf_ko = BTF [M] $@ - cmd_btf_ko = \ - LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) --btf_base vmlinux $@; \ - $(RESOLVE_BTFIDS) -b vmlinux $@ - -# Same as newer-prereqs, but allows to exclude specified extra dependencies -newer_prereqs_except = $(filter-out $(PHONY) $(1),$?) - -# Same as if_changed, but allows to exclude specified extra dependencies -if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check), \ - $(cmd); \ - printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) - -# Re-generate module BTFs if either module's .ko or vmlinux changed %.ko: %.o %.mod.o scripts/module.lds $(vmlinux) FORCE +$(call if_changed_except,ld_ko_o,vmlinux) -ifdef vmlinux - +$(if $(newer-prereqs),$(call cmd,btf_ko)) -endif targets += $(modules:%.o=%.ko) $(modules:%.o=%.mod.o)
Signature · 1 line
2.40.1
Re: [PATCH 4/4] kbuild: refactor module BTF rule
Quoted 2 lines · Masahiro Yamada
newer_prereqs_exceptandif_changed_exceptare ugly hacks of thenewer_prereqsandif_changedinscripts/Kbuild.include.
newer-prereqs
Quoted 14 lines
Remove.
Signed-off-by Masahiro Yamada <[email protected]>---
scripts/Makefile.modfinal | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-)scripts/Makefile.modfinal +0
-0
scripts/Makefile.modfinal vmlinux := · line 22
Quoted 4 lines
scripts/Makefile.modfinal +1
-0@@ -19,6 +19,9 @@ vmlinux := ifdef CONFIG_DEBUG_INFO_BTF_MODULES ifneq ($(wildcard vmlinux),) vmlinux := vmlinux +cmd_btf = ; \
while reading, I stumpled over this semicolon, but probably it's a good reminder that cmd_btf is only a cmd extension.
Quoted 19 lines
scripts/Makefile.modfinal +4
-7+ LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) --btf_base vmlinux $@; \ + $(RESOLVE_BTFIDS) -b vmlinux $@ else $(warning Skipping BTF generation due to unavailability of vmlinux) endif@@ -41,27 +44,11 @@ quiet_cmd_ld_ko_o = LD [M] $@ cmd_ld_ko_o += \ $(LD) -r $(KBUILD_LDFLAGS) \ $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ - -T scripts/module.lds -o $@ $(filter %.o, $^) + -T scripts/module.lds -o $@ $(filter %.o, $^) \ + $(cmd_btf) -quiet_cmd_btf_ko = BTF [M] $@ - cmd_btf_ko = \ - LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) --btf_base vmlinux $@; \ - $(RESOLVE_BTFIDS) -b vmlinux $@ - -# Same as newer-prereqs, but allows to exclude specified extra dependencies
scripts/Makefile.modfinal quiet_cmd_ld_ko_o = LD [M] $@ · line 51
Quoted 10 lines
scripts/Makefile.modfinal +0
-8-newer_prereqs_except = $(filter-out $(PHONY) $(1),$?) - -# Same as if_changed, but allows to exclude specified extra dependencies -if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check), \ - $(cmd); \ - printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) - -# Re-generate module BTFs if either module's .ko or vmlinux changed %.ko: %.o %.mod.o scripts/module.lds $(vmlinux) FORCE +$(call if_changed_except,ld_ko_o,vmlinux)
This should probably be:
+$(call if_changed,ld_ko_o)
Quoted 9 lines
scripts/Makefile.modfinal +0
-3-ifdef vmlinux - +$(if $(newer-prereqs),$(call cmd,btf_ko)) -endif targets += $(modules:%.o=%.ko) $(modules:%.o=%.mod.o)Signature · 1 line
2.40.1
Re: [PATCH 4/4] kbuild: refactor module BTF rule
Quoted 6 lines · Nicolas Schier
Quoted 2 lines · Masahiro Yamada
newer_prereqs_exceptandif_changed_exceptare ugly hacks of thenewer_prereqsandif_changedinscripts/Kbuild.include.newer-prereqs
Yes.
Quoted 10 lines
Quoted 10 lines
Remove.
Signed-off-by Masahiro Yamada <[email protected]>---
scripts/Makefile.modfinal | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-)
Quoted 12 lines
scripts/Makefile.modfinal vmlinux := · line 22
Quoted 9 lines
scripts/Makefile.modfinal +1
-0@@ -19,6 +19,9 @@ vmlinux := ifdef CONFIG_DEBUG_INFO_BTF_MODULES ifneq ($(wildcard vmlinux),) vmlinux := vmlinux +cmd_btf = ; \while reading, I stumpled over this semicolon, but probably it's a good reminder that
cmd_btfis only a cmd extension.
A semicolon is needed as a command separator, but
the trailing semicolon after the last command.
I usually prepend a semicolon to conditional commands.
Quoted 33 lines
Quoted 20 lines
scripts/Makefile.modfinal +4
-7+ LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) --btf_base vmlinux $@; \ + $(RESOLVE_BTFIDS) -b vmlinux $@ else $(warning Skipping BTF generation due to unavailability of vmlinux) endif@@ -41,27 +44,11 @@ quiet_cmd_ld_ko_o = LD [M] $@ cmd_ld_ko_o += \ $(LD) -r $(KBUILD_LDFLAGS) \ $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ - -T scripts/module.lds -o $@ $(filter %.o, $^) + -T scripts/module.lds -o $@ $(filter %.o, $^) \ + $(cmd_btf) -quiet_cmd_btf_ko = BTF [M] $@ - cmd_btf_ko = \ - LLVM_OBJCOPY="$(OBJCOPY)" $(PAHOLE) -J $(PAHOLE_FLAGS) --btf_base vmlinux $@; \ - $(RESOLVE_BTFIDS) -b vmlinux $@ - -# Same as newer-prereqs, but allows to exclude specified extra dependenciesscripts/Makefile.modfinal quiet_cmd_ld_ko_o = LD [M] $@ · line 51
Quoted 10 lines
scripts/Makefile.modfinal +0
-8-newer_prereqs_except = $(filter-out $(PHONY) $(1),$?) - -# Same as if_changed, but allows to exclude specified extra dependencies -if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check), \ - $(cmd); \ - printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) - -# Re-generate module BTFs if either module's .ko or vmlinux changed %.ko: %.o %.mod.o scripts/module.lds $(vmlinux) FORCE +$(call if_changed_except,ld_ko_o,vmlinux)This should probably be:
Quoted 1 line
+$(call if_changed,ld_ko_o)
Right. Thanks for catching it.
Quoted 10 lines
Quoted 10 lines
scripts/Makefile.modfinal +0
-4-ifdef vmlinux - +$(if $(newer-prereqs),$(call cmd,btf_ko)) -endif targets += $(modules:%.o=%.ko) $(modules:%.o=%.mod.o) --2.40.1
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 6 lines · Masahiro Yamada
The '%.ko' rule in
arch/*/Makefile.postlinkdoes nothing but call the 'true' command.Remove the meaningless code.
Signed-off-by Masahiro Yamada <[email protected]>
Quoted 8 lines
---
arch/mips/Makefile.postlink | 3 --- arch/powerpc/Makefile.postlink | 3 --- arch/riscv/Makefile.postlink | 3 --- arch/x86/Makefile.postlink | 3 --- scripts/Makefile.modfinal | 5 +---- 5 files changed, 1 insertion(+), 16 deletions(-)
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
This patch was applied to riscv/linux.git (fixes) by Masahiro Yamada <[email protected]>:
Hello:
This patch was applied to riscv/linux.git (fixes)
by Masahiro Yamada <[email protected]>:
Quoted 8 lines · On Tue, 17 Oct 2023 19:37:39 +0900 you wrote:
The '%.ko' rule in
arch/*/Makefile.postlinkdoes nothing but call the 'true' command.Remove the meaningless code.
Signed-off-by Masahiro Yamada <[email protected]>[...]
Here is the summary with links:
- [1/4] kbuild: remove ARCH_POSTLINK from module builds
https://git.kernel.org/riscv/c/7f6d8f7e43fb
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html