Skip to content

Commit 72d0918

Browse files
committed
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 <[email protected]> Reviewed-by: Alan Maguire <[email protected]> Tested-by: Alan Maguire <[email protected]> Reviewed-by: Nicolas Schier <[email protected]> Tested-by: Miguel Ojeda <[email protected]> Acked-by: Miguel Ojeda <[email protected]> Acked-by: Jiri Olsa <[email protected]> Reviewed-by: Martin Rodriguez Reboredo <[email protected]>
1 parent 7f6d8f7 commit 72d0918

File tree

4 files changed

+21
-34
lines changed

4 files changed

+21
-34
lines changed

MAINTAINERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3742,7 +3742,7 @@ F: net/sched/act_bpf.c
37423742
F: net/sched/cls_bpf.c
37433743
F: samples/bpf/
37443744
F: scripts/bpf_doc.py
3745-
F: scripts/pahole-flags.sh
3745+
F: scripts/Makefile.btf
37463746
F: scripts/pahole-version.sh
37473747
F: tools/bpf/
37483748
F: tools/lib/bpf/

Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,6 @@ LZ4 = lz4c
513513
XZ = xz
514514
ZSTD = zstd
515515

516-
PAHOLE_FLAGS = $(shell PAHOLE=$(PAHOLE) $(srctree)/scripts/pahole-flags.sh)
517-
518516
CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
519517
-Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF)
520518
NOSTDINC_FLAGS :=
@@ -605,7 +603,6 @@ export KBUILD_RUSTFLAGS RUSTFLAGS_KERNEL RUSTFLAGS_MODULE
605603
export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
606604
export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_RUSTFLAGS_MODULE KBUILD_LDFLAGS_MODULE
607605
export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL KBUILD_RUSTFLAGS_KERNEL
608-
export PAHOLE_FLAGS
609606

610607
# Files to ignore in find ... statements
611608

@@ -1002,6 +999,7 @@ KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
1002999
# include additional Makefiles when needed
10031000
include-y := scripts/Makefile.extrawarn
10041001
include-$(CONFIG_DEBUG_INFO) += scripts/Makefile.debug
1002+
include-$(CONFIG_DEBUG_INFO_BTF)+= scripts/Makefile.btf
10051003
include-$(CONFIG_KASAN) += scripts/Makefile.kasan
10061004
include-$(CONFIG_KCSAN) += scripts/Makefile.kcsan
10071005
include-$(CONFIG_KMSAN) += scripts/Makefile.kmsan

scripts/Makefile.btf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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)

scripts/pahole-flags.sh

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)