kbuild: remove ARCH_POSTLINK from module builds
PATCH v2 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.
---
(no changes since v1)
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 v2 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 executed 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
---
Changes in v2:
- Fix a typo in commit description
- Update MAINTAINERS
MAINTAINERS | 2 +- Makefile | 4 +--- scripts/Makefile.btf | 19 +++++++++++++++++++ scripts/pahole-flags.sh | 30 ------------------------------ 4 files changed, 21 insertions(+), 34 deletions(-) create mode 100644 scripts/Makefile.btf delete mode 100755 scripts/pahole-flags.sh
MAINTAINERS +1 -1
@@ -3742,7 +3742,7 @@ F: net/sched/act_bpf.c F: net/sched/cls_bpf.c F: samples/bpf/ F: scripts/bpf_doc.py -F: scripts/pahole-flags.sh +F: scripts/Makefile.btf F: scripts/pahole-version.sh F: tools/bpf/ F: tools/lib/bpf/
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: [bpf-next PATCH v2 2/4] kbuild: avoid too many execution of scripts/pahole-flags.sh
Quoted 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 executed 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 8 lines
[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]>
nice!
thanks,
jirka
Quoted 120 lines
---
Changes in v2:
- Fix a typo in commit description
- UpdateMAINTAINERSMAINTAINERS | 2 +- Makefile | 4 +--- scripts/Makefile.btf | 19 +++++++++++++++++++ scripts/pahole-flags.sh | 30 ------------------------------ 4 files changed, 21 insertions(+), 34 deletions(-) create mode 100644 scripts/Makefile.btf delete mode 100755 scripts/pahole-flags.shMAINTAINERS +1
-1@@ -3742,7 +3742,7 @@ F: net/sched/act_bpf.c F: net/sched/cls_bpf.c F: samples/bpf/ F: scripts/bpf_doc.py -F: scripts/pahole-flags.sh +F: scripts/Makefile.btf F: scripts/pahole-version.sh F: tools/bpf/ F: tools/lib/bpf/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.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: [bpf-next PATCH v2 2/4] kbuild: avoid too many execution of scripts/pahole-flags.sh
In reply to Masahiro YamadaQuoted 44 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 executed 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]>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]>---
[...]
Makefile KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=) · line 1002
Quoted 4 lines
Makefile +1
-0@@ -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
Would've used a tab, for legibility sake.
Makefile KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=) · line 1005
Quoted 4 lines
Makefile +0
-0include-$(CONFIG_KASAN) += scripts/Makefile.kasan include-$(CONFIG_KCSAN) += scripts/Makefile.kcsan include-$(CONFIG_KMSAN) += scripts/Makefile.kmsan
PATCH v2 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.
---
(no changes since v1)
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: [bpf-next PATCH v2 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]>Reviewed-by Nicolas Schier <[email protected]>
lgtm
jirka
Quoted 57 lines
---
(no changes since v1)
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)) endifSignature · 1 line
2.40.1
PATCH v2 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.
---
Changes in v2:
- Fix if_changed_except to if_changed
scripts/Makefile.modfinal | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-)
scripts/Makefile.modfinal +6 -19
@@ -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 + +$(call if_changed,ld_ko_o) targets += $(modules:%.o=%.ko) $(modules:%.o=%.mod.o)
Signature · 1 line
2.40.1
Re: [bpf-next PATCH v2 4/4] kbuild: refactor module BTF rule
Quoted 10 lines · On Thu, Oct 19, 2023 at 12:19:50AM +0900 Masahiro Yamada wrote:
newer_prereqs_exceptandif_changed_exceptare ugly hacks of the newer-prereqs andif_changedinscripts/Kbuild.include.Remove.
Signed-off-by Masahiro Yamada <[email protected]>---
Changes in v2:
- Fixif_changed_excepttoif_changed
thanks
Quoted 50 lines
scripts/Makefile.modfinal | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-)scripts/Makefile.modfinal +6
-19@@ -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 + +$(call if_changed,ld_ko_o) targets += $(modules:%.o=%.ko) $(modules:%.o=%.mod.o)Signature · 1 line
2.40.1
Signature · 3 lines
epost|xmpp: [email protected] irc://oftc.net/nsc ↳ gpg: 18ed 52db e34f 860e e9fb c82b 7d97 0932 55a0 ce7f -- frykten for herren er opphav til kunnskap --
Re: [bpf-next PATCH v2 4/4] kbuild: refactor module BTF rule
In reply to Masahiro YamadaQuoted 29 lines · Masahiro Yamada
newer_prereqs_exceptandif_changed_exceptare ugly hacks of the newer-prereqs andif_changedinscripts/Kbuild.include.Remove.
Signed-off-by Masahiro Yamada <[email protected]>---
Changes in v2:
- Fixif_changed_excepttoif_changedscripts/Makefile.modfinal | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-)scripts/Makefile.modfinal +3
-0@@ -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
scripts/Makefile.modfinal quiet_cmd_ld_ko_o = LD [M] $@ · line 46
Quoted 8 lines
scripts/Makefile.modfinal +2
-2@@ -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] $@
nit not sure it's intentional but we no longer display 'BTF [M] ...ko' lines, I don't mind not displaying that, but we should mention that in changelog
jirka
Quoted 26 lines
scripts/Makefile.modfinal +1
-17- 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 + +$(call if_changed,ld_ko_o) targets += $(modules:%.o=%.ko) $(modules:%.o=%.mod.o)Signature · 1 line
2.40.1
Re: [bpf-next PATCH v2 4/4] kbuild: refactor module BTF rule
Quoted 38 lines · Jiri Olsa
Quoted 36 lines · Masahiro Yamada
newer_prereqs_exceptandif_changed_exceptare ugly hacks of the newer-prereqs andif_changedinscripts/Kbuild.include.Remove.
Signed-off-by Masahiro Yamada <[email protected]>---
Changes in v2:
- Fixif_changed_excepttoif_changedscripts/Makefile.modfinal | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-)scripts/Makefile.modfinal +5
-1@@ -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)
Quoted 5 lines
scripts/Makefile.modfinal quiet_cmd_ld_ko_o = LD [M] $@ · line 46
Quoted 1 line
scripts/Makefile.modfinal +0
-1-quiet_cmd_btf_ko = BTF [M] $@nit not sure it's intentional but we no longer display 'BTF [M] ...ko' lines, I don't mind not displaying that, but we should mention that in changelog
Thanks for spotting this! I think those messages are useful and important to keep. Masahiro, is it possible to preserve them?
Quoted 29 lines
jirka
Quoted 26 lines
scripts/Makefile.modfinal +1
-18- 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 + +$(call if_changed,ld_ko_o) targets += $(modules:%.o=%.ko) $(modules:%.o=%.mod.o) --2.40.1
Re: [bpf-next PATCH v2 4/4] kbuild: refactor module BTF rule
Quoted 40 lines · Andrii Nakryiko
Quoted 38 lines · Jiri Olsa
Quoted 36 lines · Masahiro Yamada
newer_prereqs_exceptandif_changed_exceptare ugly hacks of the newer-prereqs andif_changedinscripts/Kbuild.include.Remove.
Signed-off-by Masahiro Yamada <[email protected]>---
Changes in v2:
- Fixif_changed_excepttoif_changedscripts/Makefile.modfinal | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-)scripts/Makefile.modfinal +5
-1@@ -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)
Quoted 8 lines
Quoted 5 lines
scripts/Makefile.modfinal quiet_cmd_ld_ko_o = LD [M] $@ · line 46
Quoted 1 line
scripts/Makefile.modfinal +0
-1-quiet_cmd_btf_ko = BTF [M] $@nit not sure it's intentional but we no longer display 'BTF [M] ...ko' lines, I don't mind not displaying that, but we should mention that in changelog
Thanks for spotting this! I think those messages are useful and important to keep. Masahiro, is it possible to preserve them?
No, I do not think so.
Your code is wrong.
To clarify this is a fix,
I will replace the commit as follows:
------------------->8----------------------
kbuild: detect btf command change for modules
Currently, the command change in cmd_btf_ko does not cause to rebuild the modules because it is not passed to if_changed.
Pass everything to if_change so that the btf command is also recorded in the .*.cmd files. This removes the hacky newer_prereqs_except and if_changed_except macros too. ------------------->8----------------------
--
Best Regards
Masahiro Yamada
Re: [bpf-next PATCH v2 4/4] kbuild: refactor module BTF rule
Quoted 49 lines · Masahiro Yamada
Quoted 46 lines · Andrii Nakryiko
Quoted 43 lines · Jiri Olsa
Quoted 29 lines · Masahiro Yamada
newer_prereqs_exceptandif_changed_exceptare ugly hacks of the newer-prereqs andif_changedinscripts/Kbuild.include.Remove.
Signed-off-by Masahiro Yamada <[email protected]>---
Changes in v2:
- Fixif_changed_excepttoif_changedscripts/Makefile.modfinal | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-)scripts/Makefile.modfinal +3
-0@@ -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) endifscripts/Makefile.modfinal quiet_cmd_ld_ko_o = LD [M] $@ · line 46
Quoted 8 lines
scripts/Makefile.modfinal +2
-2@@ -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] $@nit not sure it's intentional but we no longer display 'BTF [M] ...ko' lines, I don't mind not displaying that, but we should mention that in changelog
Quoted 7 lines
Quoted 2 lines
Thanks for spotting this! I think those messages are useful and important to keep. Masahiro, is it possible to preserve them?
No, I do not think so.
That's too bad, I think it's a useful one.
Quoted 2 lines
Your code is wrong.
Could be, but note the comment you are removing:
# Re-generate module BTFs if either module's .ko or vmlinux changed
BTF has to be re-generated not just when module .ko is regenerated, but also when the vmlinux image itself changes.
I don't see where this is done with your changes. Can you please point it out explicitly?
Quoted 25 lines
To clarify this is a fix,
I will replace the commit as follows:------------------->8----------------------
kbuild: detect btf command change for modulesCurrently, the command change in
cmd_btf_kodoes not cause to rebuild the modules because it is not passed toif_changed.Pass everything to
if_changeso that the btf command is also recorded in the .*.cmd files. This removes the hackynewer_prereqs_exceptandif_changed_exceptmacros too. ------------------->8------------------------
Best RegardsMasahiro Yamada
Re: [bpf-next PATCH v2 4/4] kbuild: refactor module BTF rule
Quoted 56 lines · Andrii Nakryiko
Quoted 54 lines · Masahiro Yamada
Quoted 48 lines · Andrii Nakryiko
Quoted 38 lines · Jiri Olsa
Quoted 36 lines · Masahiro Yamada
newer_prereqs_exceptandif_changed_exceptare ugly hacks of the newer-prereqs andif_changedinscripts/Kbuild.include.Remove.
Signed-off-by Masahiro Yamada <[email protected]>---
Changes in v2:
- Fixif_changed_excepttoif_changedscripts/Makefile.modfinal | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-)scripts/Makefile.modfinal +5
-1@@ -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)Quoted 5 lines
scripts/Makefile.modfinal quiet_cmd_ld_ko_o = LD [M] $@ · line 46
Quoted 1 line
scripts/Makefile.modfinal +0
-1-quiet_cmd_btf_ko = BTF [M] $@nit not sure it's intentional but we no longer display 'BTF [M] ...ko' lines, I don't mind not displaying that, but we should mention that in changelog
Thanks for spotting this! I think those messages are useful and important to keep. Masahiro, is it possible to preserve them?
Quoted 4 lines
Quoted 2 lines
No, I do not think so.
That's too bad, I think it's a useful one.
I prioritize that the code is correct.
Quoted 6 lines
Quoted 3 lines
Your code is wrong.
Could be, but note the comment you are removing:
Quoted 7 lines
# Re-generate module BTFs if either module's .ko or vmlinux changed
BTF has to be re-generated not just when module .ko is regenerated, but also when the vmlinux image itself changes.
I don't see where this is done with your changes. Can you please point it out explicitly?
That is too obvious; %.ko depends on $(vmlinux).
%.ko: %.o %.mod.o scripts/module.lds $(vmlinux) FORCE
Signature · 2 lines
Best Regards Masahiro Yamada
Re: [bpf-next PATCH v2 4/4] kbuild: refactor module BTF rule
Quoted 59 lines · Masahiro Yamada
Quoted 56 lines · Andrii Nakryiko
Quoted 54 lines · Masahiro Yamada
Quoted 48 lines · Andrii Nakryiko
Quoted 38 lines · Jiri Olsa
Quoted 36 lines · Masahiro Yamada
newer_prereqs_exceptandif_changed_exceptare ugly hacks of the newer-prereqs andif_changedinscripts/Kbuild.include.Remove.
Signed-off-by Masahiro Yamada <[email protected]>---
Changes in v2:
- Fixif_changed_excepttoif_changedscripts/Makefile.modfinal | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-)scripts/Makefile.modfinal +5
-1@@ -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)Quoted 5 lines
scripts/Makefile.modfinal quiet_cmd_ld_ko_o = LD [M] $@ · line 46
Quoted 1 line
scripts/Makefile.modfinal +0
-1-quiet_cmd_btf_ko = BTF [M] $@nit not sure it's intentional but we no longer display 'BTF [M] ...ko' lines, I don't mind not displaying that, but we should mention that in changelog
Thanks for spotting this! I think those messages are useful and important to keep. Masahiro, is it possible to preserve them?
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
No, I do not think so.
That's too bad, I think it's a useful one.
I prioritize that the code is correct.
Could you please also prioritize not regressing informativeness of a build log? With your changes it's not clear now if BTF was generated or not for a kernel module, while previously it was obvious and was easy to spot if for some reason BTF was not generated. I'd like to preserve this
property, thank you.
E.g, can we still have BTF generation as a separate command and do a separate $(call if_changed,btf_ko)? Or something along those lines. Would that work?
Quoted 13 lines
Quoted 13 lines
Quoted 5 lines
Your code is wrong.
Could be, but note the comment you are removing:
# Re-generate module BTFs if either module's .ko or vmlinux changed
BTF has to be re-generated not just when module .ko is regenerated, but also when the vmlinux image itself changes.
Quoted 6 lines
Quoted 2 lines
I don't see where this is done with your changes. Can you please point it out explicitly?
That is too obvious; %.ko depends on $(vmlinux).
Thank you for your gracious answer. We used to not rebuild module's .ko's when vmlinux didn't change (but we did regen BTFs), and that's why I was confused. Now we forcefully recompile modules, which is a change in behavior which would be nice to call out in the commit message.
Quoted 11 lines
%.ko: %.o %.mod.o
scripts/module.lds$(vmlinux) FORCE--
Best Regards
Masahiro Yamada
Re: [bpf-next PATCH v2 4/4] kbuild: refactor module BTF rule
Quoted 78 lines · Andrii Nakryiko
Quoted 59 lines · Masahiro Yamada
Quoted 56 lines · Andrii Nakryiko
Quoted 54 lines · Masahiro Yamada
Quoted 48 lines · Andrii Nakryiko
Quoted 38 lines · Jiri Olsa
Quoted 36 lines · Masahiro Yamada
newer_prereqs_exceptandif_changed_exceptare ugly hacks of the newer-prereqs andif_changedinscripts/Kbuild.include.Remove.
Signed-off-by Masahiro Yamada <[email protected]>---
Changes in v2:
- Fixif_changed_excepttoif_changedscripts/Makefile.modfinal | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-)scripts/Makefile.modfinal +5
-1@@ -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)Quoted 5 lines
scripts/Makefile.modfinal quiet_cmd_ld_ko_o = LD [M] $@ · line 46
Quoted 1 line
scripts/Makefile.modfinal +0
-1-quiet_cmd_btf_ko = BTF [M] $@nit not sure it's intentional but we no longer display 'BTF [M] ...ko' lines, I don't mind not displaying that, but we should mention that in changelog
Thanks for spotting this! I think those messages are useful and important to keep. Masahiro, is it possible to preserve them?
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
No, I do not think so.
That's too bad, I think it's a useful one.
I prioritize that the code is correct.
Could you please also prioritize not regressing informativeness of a build log? With your changes it's not clear now if BTF was generated or not for a kernel module, while previously it was obvious and was easy to spot if for some reason BTF was not generated. I'd like to preserve this
property, thank you.
Quoted 3 lines
E.g, can we still have BTF generation as a separate command and do a separate $(call if_changed,btf_ko)? Or something along those lines. Would that work?
If we have an intermediate file (say, *.no-btf.ko), it would make sense to have separate
$(call if_changed,ld_ko_o) and $(call if_changed,btf_ko).
LD RESOLVE_BTFIDS
*.mod.o ------> *.no-btf.ko ------------> *.ko
When vmlinux is changed, only the second step would be re-run, but that would require extra file copy.
Is this what you want to see?
Quoted 39 lines
Quoted 14 lines
Quoted 14 lines
Quoted 6 lines
Your code is wrong.
Could be, but note the comment you are removing:
# Re-generate module BTFs if either module's .ko or vmlinux changed
BTF has to be re-generated not just when module .ko is regenerated, but also when the vmlinux image itself changes.
Quoted 6 lines
Quoted 2 lines
I don't see where this is done with your changes. Can you please point it out explicitly?
That is too obvious; %.ko depends on $(vmlinux).
Thank you for your gracious answer. We used to not rebuild module's .ko's when vmlinux didn't change (but we did regen BTFs), and that's why I was confused. Now we forcefully recompile modules, which is a change in behavior which would be nice to call out in the commit message.
Quoted 11 lines
%.ko: %.o %.mod.o
scripts/module.lds$(vmlinux) FORCE--
Best Regards
Masahiro Yamada
Signature · 2 lines
Best Regards Masahiro Yamada
Re: [bpf-next PATCH v2 4/4] kbuild: refactor module BTF rule
Quoted 81 lines · Masahiro Yamada
Quoted 78 lines · Andrii Nakryiko
Quoted 59 lines · Masahiro Yamada
Quoted 56 lines · Andrii Nakryiko
Quoted 54 lines · Masahiro Yamada
Quoted 48 lines · Andrii Nakryiko
Quoted 38 lines · Jiri Olsa
Quoted 36 lines · Masahiro Yamada
newer_prereqs_exceptandif_changed_exceptare ugly hacks of the newer-prereqs andif_changedinscripts/Kbuild.include.Remove.
Signed-off-by Masahiro Yamada <[email protected]>---
Changes in v2:
- Fixif_changed_excepttoif_changedscripts/Makefile.modfinal | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-)scripts/Makefile.modfinal +5
-1@@ -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)Quoted 5 lines
scripts/Makefile.modfinal quiet_cmd_ld_ko_o = LD [M] $@ · line 46
Quoted 1 line
scripts/Makefile.modfinal +0
-1-quiet_cmd_btf_ko = BTF [M] $@nit not sure it's intentional but we no longer display 'BTF [M] ...ko' lines, I don't mind not displaying that, but we should mention that in changelog
Thanks for spotting this! I think those messages are useful and important to keep. Masahiro, is it possible to preserve them?
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
No, I do not think so.
That's too bad, I think it's a useful one.
I prioritize that the code is correct.
Could you please also prioritize not regressing informativeness of a build log? With your changes it's not clear now if BTF was generated or not for a kernel module, while previously it was obvious and was easy to spot if for some reason BTF was not generated. I'd like to preserve this
property, thank you.
Quoted 7 lines
Quoted 3 lines
E.g, can we still have BTF generation as a separate command and do a separate $(call if_changed,btf_ko)? Or something along those lines. Would that work?
If we have an intermediate file (say, *.no-btf.ko), it would make sense to have separate
$(call if_changed,ld_ko_o) and $(call if_changed,btf_ko).
Currently we don't generate intermediate files, but we do rewrite original .ko file as a post-processing step.
And that rewriting step might not happen depending on Kconfig and toolchain (e.g., too old pahole makes it impossible to generate kernel module BTF). And that's why having a separate BTF [M] message in the build log is important.
Quoted 8 lines
LD
RESOLVE_BTFIDS
*.mod.o ------> *.no-btf.ko ------------> *.koWhen vmlinux is changed, only the second step would be re-run, but that would require extra file copy.
Today we rewrite .ko with a new .ko ELF file which gains a new ELF section (.BTF), so we already pay this price when BTF is enabled (if that's your concern).
Quoted 2 lines
Is this what you want to see?
I don't have strong preferences for exact implementation, but what you propose will work, I think. What I'd like to avoid is unnecessarily relinking .ko files if all we need to do is regenerate BTF.
Quoted 50 lines
Quoted 24 lines
Quoted 24 lines
Quoted 21 lines
Quoted 11 lines
Your code is wrong.
Could be, but note the comment you are removing:
# Re-generate module BTFs if either module's .ko or vmlinux changed
BTF has to be re-generated not just when module .ko is regenerated, but also when the vmlinux image itself changes.
I don't see where this is done with your changes. Can you please point it out explicitly?
Quoted 20 lines
Quoted 1 line
That is too obvious; %.ko depends on $(vmlinux).
Thank you for your gracious answer. We used to not rebuild module's .ko's when vmlinux didn't change (but we did regen BTFs), and that's why I was confused. Now we forcefully recompile modules, which is a change in behavior which would be nice to call out in the commit message.
Quoted 11 lines
%.ko: %.o %.mod.o
scripts/module.lds$(vmlinux) FORCE--
Best Regards
Masahiro Yamada--
Best Regards
Masahiro Yamada
Re: [bpf-next PATCH v2 4/4] kbuild: refactor module BTF rule
Quoted 113 lines · Andrii Nakryiko
Quoted 81 lines · Masahiro Yamada
Quoted 78 lines · Andrii Nakryiko
Quoted 59 lines · Masahiro Yamada
Quoted 56 lines · Andrii Nakryiko
Quoted 54 lines · Masahiro Yamada
Quoted 48 lines · Andrii Nakryiko
Quoted 38 lines · Jiri Olsa
Quoted 36 lines · Masahiro Yamada
newer_prereqs_exceptandif_changed_exceptare ugly hacks of the newer-prereqs andif_changedinscripts/Kbuild.include.Remove.
Signed-off-by Masahiro Yamada <[email protected]>---
Changes in v2:
- Fixif_changed_excepttoif_changedscripts/Makefile.modfinal | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-)scripts/Makefile.modfinal +5
-1@@ -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)Quoted 5 lines
scripts/Makefile.modfinal quiet_cmd_ld_ko_o = LD [M] $@ · line 46
Quoted 1 line
scripts/Makefile.modfinal +0
-1-quiet_cmd_btf_ko = BTF [M] $@nit not sure it's intentional but we no longer display 'BTF [M] ...ko' lines, I don't mind not displaying that, but we should mention that in changelog
Thanks for spotting this! I think those messages are useful and important to keep. Masahiro, is it possible to preserve them?
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
No, I do not think so.
That's too bad, I think it's a useful one.
I prioritize that the code is correct.
Could you please also prioritize not regressing informativeness of a build log? With your changes it's not clear now if BTF was generated or not for a kernel module, while previously it was obvious and was easy to spot if for some reason BTF was not generated. I'd like to preserve this
property, thank you.Quoted 7 lines
Quoted 3 lines
E.g, can we still have BTF generation as a separate command and do a separate $(call if_changed,btf_ko)? Or something along those lines. Would that work?
If we have an intermediate file (say, *.no-btf.ko), it would make sense to have separate
$(call if_changed,ld_ko_o) and $(call if_changed,btf_ko).Currently we don't generate intermediate files, but we do rewrite original .ko file as a post-processing step.
And that rewriting step might not happen depending on
Kconfigand toolchain (e.g., too old pahole makes it impossible to generate kernel module BTF). And that's why having a separate BTF [M] message in the build log is important.Quoted 8 lines
LD
RESOLVE_BTFIDS
*.mod.o ------> *.no-btf.ko ------------> *.koWhen vmlinux is changed, only the second step would be re-run, but that would require extra file copy.
Today we rewrite .ko with a new .ko ELF file which gains a new ELF section (.BTF), so we already pay this price when BTF is enabled (if that's your concern).
Quoted 1 line
Quoted 5 lines
Quoted 1 line
Is this what you want to see?
I don't have strong preferences for exact implementation, but what you propose will work, I think. What I'd like to avoid is unnecessarily relinking .ko files if all we need to do is regenerate BTF.
Is there any way to make pahole/resolve_btfids
take separate input and output files
instead of in-place modification?
Otherwise, explicit "cp *.no-btf.ko *.ko" would be needed.
--
Best Regards
Masahiro Yamada
Re: [bpf-next PATCH v2 4/4] kbuild: refactor module BTF rule
Quoted 124 lines · Masahiro Yamada
Quoted 113 lines · Andrii Nakryiko
Quoted 81 lines · Masahiro Yamada
Quoted 78 lines · Andrii Nakryiko
Quoted 59 lines · Masahiro Yamada
Quoted 56 lines · Andrii Nakryiko
Quoted 54 lines · Masahiro Yamada
Quoted 48 lines · Andrii Nakryiko
Quoted 38 lines · Jiri Olsa
Quoted 36 lines · Masahiro Yamada
newer_prereqs_exceptandif_changed_exceptare ugly hacks of the newer-prereqs andif_changedinscripts/Kbuild.include.Remove.
Signed-off-by Masahiro Yamada <[email protected]>---
Changes in v2:
- Fixif_changed_excepttoif_changedscripts/Makefile.modfinal | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-)scripts/Makefile.modfinal +5
-1@@ -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)Quoted 5 lines
scripts/Makefile.modfinal quiet_cmd_ld_ko_o = LD [M] $@ · line 46
Quoted 1 line
scripts/Makefile.modfinal +0
-1-quiet_cmd_btf_ko = BTF [M] $@nit not sure it's intentional but we no longer display 'BTF [M] ...ko' lines, I don't mind not displaying that, but we should mention that in changelog
Thanks for spotting this! I think those messages are useful and important to keep. Masahiro, is it possible to preserve them?
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
No, I do not think so.
That's too bad, I think it's a useful one.
I prioritize that the code is correct.
Could you please also prioritize not regressing informativeness of a build log? With your changes it's not clear now if BTF was generated or not for a kernel module, while previously it was obvious and was easy to spot if for some reason BTF was not generated. I'd like to preserve this
property, thank you.Quoted 7 lines
Quoted 3 lines
E.g, can we still have BTF generation as a separate command and do a separate $(call if_changed,btf_ko)? Or something along those lines. Would that work?
If we have an intermediate file (say, *.no-btf.ko), it would make sense to have separate
$(call if_changed,ld_ko_o) and $(call if_changed,btf_ko).Currently we don't generate intermediate files, but we do rewrite original .ko file as a post-processing step.
And that rewriting step might not happen depending on
Kconfigand toolchain (e.g., too old pahole makes it impossible to generate kernel module BTF). And that's why having a separate BTF [M] message in the build log is important.Quoted 8 lines
LD
RESOLVE_BTFIDS
*.mod.o ------> *.no-btf.ko ------------> *.koWhen vmlinux is changed, only the second step would be re-run, but that would require extra file copy.
Today we rewrite .ko with a new .ko ELF file which gains a new ELF section (.BTF), so we already pay this price when BTF is enabled (if that's your concern).
Quoted 1 line
Quoted 5 lines
Quoted 1 line
Is this what you want to see?
I don't have strong preferences for exact implementation, but what you propose will work, I think. What I'd like to avoid is unnecessarily relinking .ko files if all we need to do is regenerate BTF.
Quoted 3 lines
Is there any way to make pahole/resolve_btfids
take separate input and output files
instead of in-place modification?
for pahole I think it'd be possible to get object file with .BTF section and just link it with other module objects (it's done like that for vmlinux) but I'm not sure which module linking stage this could happen
for resolve_btfids it's not possible at the moment, it just updates the .BTF_ids section in the object file
I'm working on changing resolve_btfids to actually generate separate object with .BTF_ids section, which is then link-ed with the final object, but will take more time.. especially because I'm not sure where to place this logic in module linking ;-)
jirka
Re: [bpf-next PATCH v2 4/4] kbuild: refactor module BTF rule
Quoted 134 lines · Jiri Olsa
Quoted 124 lines · Masahiro Yamada
Quoted 113 lines · Andrii Nakryiko
Quoted 81 lines · Masahiro Yamada
Quoted 78 lines · Andrii Nakryiko
Quoted 59 lines · Masahiro Yamada
Quoted 56 lines · Andrii Nakryiko
Quoted 54 lines · Masahiro Yamada
Quoted 48 lines · Andrii Nakryiko
Quoted 38 lines · Jiri Olsa
Quoted 36 lines · Masahiro Yamada
newer_prereqs_exceptandif_changed_exceptare ugly hacks of the newer-prereqs andif_changedinscripts/Kbuild.include.Remove.
Signed-off-by Masahiro Yamada <[email protected]>---
Changes in v2:
- Fixif_changed_excepttoif_changedscripts/Makefile.modfinal | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-)scripts/Makefile.modfinal +5
-1@@ -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)Quoted 5 lines
scripts/Makefile.modfinal quiet_cmd_ld_ko_o = LD [M] $@ · line 46
Quoted 1 line
scripts/Makefile.modfinal +0
-1-quiet_cmd_btf_ko = BTF [M] $@nit not sure it's intentional but we no longer display 'BTF [M] ...ko' lines, I don't mind not displaying that, but we should mention that in changelog
Thanks for spotting this! I think those messages are useful and important to keep. Masahiro, is it possible to preserve them?
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
No, I do not think so.
That's too bad, I think it's a useful one.
I prioritize that the code is correct.
Could you please also prioritize not regressing informativeness of a build log? With your changes it's not clear now if BTF was generated or not for a kernel module, while previously it was obvious and was easy to spot if for some reason BTF was not generated. I'd like to preserve this
property, thank you.Quoted 7 lines
Quoted 3 lines
E.g, can we still have BTF generation as a separate command and do a separate $(call if_changed,btf_ko)? Or something along those lines. Would that work?
If we have an intermediate file (say, *.no-btf.ko), it would make sense to have separate
$(call if_changed,ld_ko_o) and $(call if_changed,btf_ko).Currently we don't generate intermediate files, but we do rewrite original .ko file as a post-processing step.
And that rewriting step might not happen depending on
Kconfigand toolchain (e.g., too old pahole makes it impossible to generate kernel module BTF). And that's why having a separate BTF [M] message in the build log is important.Quoted 8 lines
LD
RESOLVE_BTFIDS
*.mod.o ------> *.no-btf.ko ------------> *.koWhen vmlinux is changed, only the second step would be re-run, but that would require extra file copy.
Today we rewrite .ko with a new .ko ELF file which gains a new ELF section (.BTF), so we already pay this price when BTF is enabled (if that's your concern).
Quoted 1 line
Quoted 5 lines
Quoted 1 line
Is this what you want to see?
I don't have strong preferences for exact implementation, but what you propose will work, I think. What I'd like to avoid is unnecessarily relinking .ko files if all we need to do is regenerate BTF.
Quoted 3 lines
Is there any way to make pahole/resolve_btfids
take separate input and output files
instead of in-place modification?for pahole I think it'd be possible to get object file with .BTF section and just link it with other module objects (it's done like that for vmlinux) but I'm not sure which module linking stage this could happen
Quoted 7 lines
for
resolve_btfidsit's not possible at the moment, it just updates the .BTF_ids section in the object fileI'm working on changing
resolve_btfidsto actually generate separate object with .BTF_ids section, which is then link-ed with the final object, but will take more time.. especially because I'm not sure where to place this logic in module linking ;-)
pahole also supports mode of generating BTF into a separate file without modifying the original one. The option is called --btf_encode_detached. It was added in v1.22 (currently the minimal version is v1.16), though, so depending on whether we are willing to bump the minimum pahole version, we might use that. That will allow us to also simplify and clean up link-vmlinux.sh a bit, I think.
But I don't know if it's worth the trouble right now.
Quoted 2 lines
jirka