Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kbuild: avoid too many execution of scripts/pahole-flags.sh

scripts/pahole-flags.sh is executed so many times.

You can confirm it, as follows:

$ cat <<EOF >> scripts/pahole-flags.sh
> echo "scripts/pahole-flags.sh was 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... ]

This scripts is executed more than 20 times during the kernel build
because PAHOLE_FLAGS is a recursively expanded variable and exported
to sub-processes.

With 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

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
Tested-by: Alan Maguire <alan.maguire@oracle.com>
Reviewed-by: Nicolas Schier <n.schier@avm.de>
Tested-by: Miguel Ojeda <ojeda@kernel.org>
Acked-by: Miguel Ojeda <ojeda@kernel.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>

+21 -34
+1 -1
MAINTAINERS
··· 3742 3742 F: net/sched/cls_bpf.c 3743 3743 F: samples/bpf/ 3744 3744 F: scripts/bpf_doc.py 3745 - F: scripts/pahole-flags.sh 3745 + F: scripts/Makefile.btf 3746 3746 F: scripts/pahole-version.sh 3747 3747 F: tools/bpf/ 3748 3748 F: tools/lib/bpf/
+1 -3
Makefile
··· 513 513 XZ = xz 514 514 ZSTD = zstd 515 515 516 - PAHOLE_FLAGS = $(shell PAHOLE=$(PAHOLE) $(srctree)/scripts/pahole-flags.sh) 517 - 518 516 CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \ 519 517 -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF) 520 518 NOSTDINC_FLAGS := ··· 603 605 export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE 604 606 export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_RUSTFLAGS_MODULE KBUILD_LDFLAGS_MODULE 605 607 export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL KBUILD_RUSTFLAGS_KERNEL 606 - export PAHOLE_FLAGS 607 608 608 609 # Files to ignore in find ... statements 609 610 ··· 999 1002 # include additional Makefiles when needed 1000 1003 include-y := scripts/Makefile.extrawarn 1001 1004 include-$(CONFIG_DEBUG_INFO) += scripts/Makefile.debug 1005 + include-$(CONFIG_DEBUG_INFO_BTF)+= scripts/Makefile.btf 1002 1006 include-$(CONFIG_KASAN) += scripts/Makefile.kasan 1003 1007 include-$(CONFIG_KCSAN) += scripts/Makefile.kcsan 1004 1008 include-$(CONFIG_KMSAN) += scripts/Makefile.kmsan
+19
scripts/Makefile.btf
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + 3 + pahole-ver := $(CONFIG_PAHOLE_VERSION) 4 + pahole-flags-y := 5 + 6 + # pahole 1.18 through 1.21 can't handle zero-sized per-CPU vars 7 + ifeq ($(call test-le, $(pahole-ver), 121),y) 8 + pahole-flags-$(call test-ge, $(pahole-ver), 118) += --skip_encoding_btf_vars 9 + endif 10 + 11 + pahole-flags-$(call test-ge, $(pahole-ver), 121) += --btf_gen_floats 12 + 13 + pahole-flags-$(call test-ge, $(pahole-ver), 122) += -j 14 + 15 + pahole-flags-$(CONFIG_PAHOLE_HAS_LANG_EXCLUDE) += --lang_exclude=rust 16 + 17 + pahole-flags-$(call test-ge, $(pahole-ver), 125) += --skip_encoding_btf_inconsistent_proto --btf_gen_optimized 18 + 19 + export PAHOLE_FLAGS := $(pahole-flags-y)
-30
scripts/pahole-flags.sh
··· 1 - #!/bin/sh 2 - # SPDX-License-Identifier: GPL-2.0 3 - 4 - extra_paholeopt= 5 - 6 - if ! [ -x "$(command -v ${PAHOLE})" ]; then 7 - exit 0 8 - fi 9 - 10 - pahole_ver=$($(dirname $0)/pahole-version.sh ${PAHOLE}) 11 - 12 - if [ "${pahole_ver}" -ge "118" ] && [ "${pahole_ver}" -le "121" ]; then 13 - # pahole 1.18 through 1.21 can't handle zero-sized per-CPU vars 14 - extra_paholeopt="${extra_paholeopt} --skip_encoding_btf_vars" 15 - fi 16 - if [ "${pahole_ver}" -ge "121" ]; then 17 - extra_paholeopt="${extra_paholeopt} --btf_gen_floats" 18 - fi 19 - if [ "${pahole_ver}" -ge "122" ]; then 20 - extra_paholeopt="${extra_paholeopt} -j" 21 - fi 22 - if [ "${pahole_ver}" -ge "124" ]; then 23 - # see PAHOLE_HAS_LANG_EXCLUDE 24 - extra_paholeopt="${extra_paholeopt} --lang_exclude=rust" 25 - fi 26 - if [ "${pahole_ver}" -ge "125" ]; then 27 - extra_paholeopt="${extra_paholeopt} --skip_encoding_btf_inconsistent_proto --btf_gen_optimized" 28 - fi 29 - 30 - echo ${extra_paholeopt}