2023-10-17 10:38:32

by Masahiro Yamada

[permalink] [raw]
Subject: [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.

Signed-off-by: Masahiro Yamada <[email protected]>
---

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(-)

diff --git a/arch/mips/Makefile.postlink b/arch/mips/Makefile.postlink
index 34e3bd71f3b0..6cfdc149d3bc 100644
--- a/arch/mips/Makefile.postlink
+++ b/arch/mips/Makefile.postlink
@@ -31,9 +31,6 @@ ifeq ($(CONFIG_RELOCATABLE),y)
$(call if_changed,relocs)
endif

-%.ko: FORCE
- @true
-
clean:
@true

diff --git a/arch/powerpc/Makefile.postlink b/arch/powerpc/Makefile.postlink
index 1f860b3c9bec..ae5a4256b03d 100644
--- a/arch/powerpc/Makefile.postlink
+++ b/arch/powerpc/Makefile.postlink
@@ -35,9 +35,6 @@ ifdef CONFIG_RELOCATABLE
$(call if_changed,relocs_check)
endif

-%.ko: FORCE
- @true
-
clean:
rm -f .tmp_symbols.txt

diff --git a/arch/riscv/Makefile.postlink b/arch/riscv/Makefile.postlink
index a46fc578b30b..829b9abc91f6 100644
--- a/arch/riscv/Makefile.postlink
+++ b/arch/riscv/Makefile.postlink
@@ -36,9 +36,6 @@ ifdef CONFIG_RELOCATABLE
$(call if_changed,relocs_strip)
endif

-%.ko: FORCE
- @true
-
clean:
@true

diff --git a/arch/x86/Makefile.postlink b/arch/x86/Makefile.postlink
index 936093d29160..fef2e977cc7d 100644
--- a/arch/x86/Makefile.postlink
+++ b/arch/x86/Makefile.postlink
@@ -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

diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal
index b3a6aa8fbe8c..8568d256d6fb 100644
--- a/scripts/Makefile.modfinal
+++ b/scripts/Makefile.modfinal
@@ -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 = \
--
2.40.1


2023-10-17 10:38:32

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 3/4] kbuild: skip module BTF with one-time check for vmlinux

When 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.

Signed-off-by: Masahiro Yamada <[email protected]>
---

scripts/Makefile.modfinal | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal
index 8568d256d6fb..9fd7a26e4fe9 100644
--- a/scripts/Makefile.modfinal
+++ b/scripts/Makefile.modfinal
@@ -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

--
2.40.1

2023-10-17 10:38:33

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 4/4] kbuild: refactor module BTF rule

newer_prereqs_except and if_changed_except are ugly hacks of the
newer_prereqs and if_changed in scripts/Kbuild.include.

Remove.

Signed-off-by: Masahiro Yamada <[email protected]>
---

scripts/Makefile.modfinal | 23 +++++------------------
1 file changed, 5 insertions(+), 18 deletions(-)

diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal
index 9fd7a26e4fe9..6ab10dba05c7 100644
--- a/scripts/Makefile.modfinal
+++ b/scripts/Makefile.modfinal
@@ -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)

--
2.40.1

2023-10-17 12:14:25

by Nicolas Schier

[permalink] [raw]
Subject: Re: [PATCH 1/4] kbuild: remove ARCH_POSTLINK from module builds

On Tue, Oct 17, 2023 at 07:37:39PM +0900, Masahiro Yamada wrote:
> The '%.ko' rule in arch/*/Makefile.postlink does nothing but call the
> 'true' command.
>
> Remove the meaningless code.
>
> Signed-off-by: Masahiro Yamada <[email protected]>
> ---
>
> 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(-)

Reviewed-by: Nicolas Schier <[email protected]>

2023-10-17 12:37:31

by Nicolas Schier

[permalink] [raw]
Subject: Re: [PATCH 3/4] kbuild: skip module BTF with one-time check for vmlinux

On Tue, Oct 17, 2023 at 07:37:41PM +0900, Masahiro Yamada wrote:
> When 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.
>
> Signed-off-by: Masahiro Yamada <[email protected]>
> ---

Reviewed-by: Nicolas Schier <[email protected]>

2023-10-17 12:59:02

by Nicolas Schier

[permalink] [raw]
Subject: Re: [PATCH 4/4] kbuild: refactor module BTF rule

On Tue, Oct 17, 2023 at 07:37:42PM +0900, Masahiro Yamada wrote:
> newer_prereqs_except and if_changed_except are ugly hacks of the
> newer_prereqs and if_changed in scripts/Kbuild.include.

newer-prereqs

>
> Remove.
>
> Signed-off-by: Masahiro Yamada <[email protected]>
> ---
>
> scripts/Makefile.modfinal | 23 +++++------------------
> 1 file changed, 5 insertions(+), 18 deletions(-)
>
> diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal
> index 9fd7a26e4fe9..6ab10dba05c7 100644
> --- a/scripts/Makefile.modfinal
> +++ b/scripts/Makefile.modfinal
> @@ -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.

> + 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)

This should probably be:

+$(call if_changed,ld_ko_o)


> -ifdef vmlinux
> - +$(if $(newer-prereqs),$(call cmd,btf_ko))
> -endif
>
> targets += $(modules:%.o=%.ko) $(modules:%.o=%.mod.o)
>
> --
> 2.40.1
>

2023-10-18 15:17:02

by Masahiro Yamada

[permalink] [raw]
Subject: Re: [PATCH 4/4] kbuild: refactor module BTF rule

On Tue, Oct 17, 2023 at 9:58 PM Nicolas Schier <[email protected]> wrote:
>
> On Tue, Oct 17, 2023 at 07:37:42PM +0900, Masahiro Yamada wrote:
> > newer_prereqs_except and if_changed_except are ugly hacks of the
> > newer_prereqs and if_changed in scripts/Kbuild.include.
>
> newer-prereqs

Yes.


>
> >
> > Remove.
> >
> > Signed-off-by: Masahiro Yamada <[email protected]>
> > ---
> >
> > scripts/Makefile.modfinal | 23 +++++------------------
> > 1 file changed, 5 insertions(+), 18 deletions(-)
> >
> > diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal
> > index 9fd7a26e4fe9..6ab10dba05c7 100644
> > --- a/scripts/Makefile.modfinal
> > +++ b/scripts/Makefile.modfinal
> > @@ -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.


A semicolon is needed as a command separator, but
the trailing semicolon after the last command.

I usually prepend a semicolon to conditional commands.


>
> > + 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)
>
> This should probably be:
>
> +$(call if_changed,ld_ko_o)


Right. Thanks for catching it.


>
> > -ifdef vmlinux
> > - +$(if $(newer-prereqs),$(call cmd,btf_ko))
> > -endif
> >
> > targets += $(modules:%.o=%.ko) $(modules:%.o=%.mod.o)
> >
> > --
> > 2.40.1
> >



--
Best Regards
Masahiro Yamada