diff mbox series

[6/7] kbuild: make *.mod not depend on *.o

Message ID 20220406153023.500847-7-masahiroy@kernel.org (mailing list archive)
State New, archived
Headers show
Series kbuild: more misc cleanups | expand

Commit Message

Masahiro Yamada April 6, 2022, 3:30 p.m. UTC
The dependency

    $(obj)/%.mod: $(obj)/%$(mod-prelink-ext).o

... exists because *.mod files previously contained undefined symbols,
which are computed from *.o files when CONFIG_TRIM_UNUSED_KSYMS=y.

Now that the undefined symbols are put into separate *.usyms files,
there is no reason to make *.mod depend on *.o files.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 Makefile               | 3 ++-
 scripts/Makefile.build | 5 ++---
 2 files changed, 4 insertions(+), 4 deletions(-)

Comments

Nick Desaulniers April 7, 2022, 5:59 p.m. UTC | #1
On Wed, Apr 6, 2022 at 8:31 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> The dependency
>
>     $(obj)/%.mod: $(obj)/%$(mod-prelink-ext).o
>
> ... exists because *.mod files previously contained undefined symbols,
> which are computed from *.o files when CONFIG_TRIM_UNUSED_KSYMS=y.
>
> Now that the undefined symbols are put into separate *.usyms files,
> there is no reason to make *.mod depend on *.o files.
>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
>
>  Makefile               | 3 ++-
>  scripts/Makefile.build | 5 ++---
>  2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index 82ee893909e9..e915aacd02b0 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1792,7 +1792,8 @@ ifdef single-build
>
>  # .ko is special because modpost is needed
>  single-ko := $(sort $(filter %.ko, $(MAKECMDGOALS)))
> -single-no-ko := $(sort $(patsubst %.ko,%.mod, $(MAKECMDGOALS)))
> +single-no-ko := $(filter-out $(single-ko), $(MAKECMDGOALS)) \
> +               $(foreach x, o mod, $(patsubst %.ko, %.$x, $(single-ko)))

I'm on board with this patch, and the overall goal with the series. My
brain is having a hard time parsing `o mod` though. Can you walk me
through that? Are those targets for .o and .mod files, respectively?

>
>  $(single-ko): single_modpost
>         @:
> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> index f7a30f378e20..3da731cf6978 100644
> --- a/scripts/Makefile.build
> +++ b/scripts/Makefile.build
> @@ -85,7 +85,7 @@ ifdef need-builtin
>  targets-for-builtin += $(obj)/built-in.a
>  endif
>
> -targets-for-modules := $(foreach x, mod $(if $(CONFIG_TRIM_UNUSED_KSYMS), usyms), \
> +targets-for-modules := $(foreach x, o mod $(if $(CONFIG_TRIM_UNUSED_KSYMS), usyms), \
>                                 $(patsubst %.o, %.$x, $(filter %.o, $(obj-m))))
>
>  ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),)
> @@ -306,7 +306,7 @@ endif
>  cmd_mod = echo $(addprefix $(obj)/, $(call real-search, $*.o, .o, -objs -y -m)) | \
>         $(AWK) -v RS='( |\n)' '!x[$$0]++' > $@
>
> -$(obj)/%.mod: $(obj)/%$(mod-prelink-ext).o FORCE
> +$(obj)/%.mod: FORCE
>         $(call if_changed,mod)
>
>  # List module undefined symbols
> @@ -469,7 +469,6 @@ $(multi-obj-m): FORCE
>         $(call if_changed,link_multi-m)
>  $(call multi_depend, $(multi-obj-m), .o, -objs -y -m)
>
> -targets += $(multi-obj-m)
>  targets := $(filter-out $(PHONY), $(targets))
>
>  # Add intermediate targets:
> --
> 2.32.0
>
David Laight April 7, 2022, 9:39 p.m. UTC | #2
From: Nick Desaulniers
> Sent: 07 April 2022 18:59
> 
> On Wed, Apr 6, 2022 at 8:31 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
> >
> > The dependency
> >
> >     $(obj)/%.mod: $(obj)/%$(mod-prelink-ext).o
> >
> > ... exists because *.mod files previously contained undefined symbols,
> > which are computed from *.o files when CONFIG_TRIM_UNUSED_KSYMS=y.
> >
> > Now that the undefined symbols are put into separate *.usyms files,
> > there is no reason to make *.mod depend on *.o files.
> >
> > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> > ---
> >
> >  Makefile               | 3 ++-
> >  scripts/Makefile.build | 5 ++---
> >  2 files changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/Makefile b/Makefile
> > index 82ee893909e9..e915aacd02b0 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -1792,7 +1792,8 @@ ifdef single-build
> >
> >  # .ko is special because modpost is needed
> >  single-ko := $(sort $(filter %.ko, $(MAKECMDGOALS)))
> > -single-no-ko := $(sort $(patsubst %.ko,%.mod, $(MAKECMDGOALS)))
> > +single-no-ko := $(filter-out $(single-ko), $(MAKECMDGOALS)) \
> > +               $(foreach x, o mod, $(patsubst %.ko, %.$x, $(single-ko)))
> 
> I'm on board with this patch, and the overall goal with the series. My
> brain is having a hard time parsing `o mod` though. Can you walk me
> through that? Are those targets for .o and .mod files, respectively?

I think I'd do:
single-no-ko := $(filter-out $(single-ko), $(MAKECMDGOALS))
single-no-ko += $(patsubst %.ko, %.o, $(single-ko))
single-no-ko += $(patsubst %.ko, %.mod, $(single-ko))

Although you can use the simpler SYSV make suffix substitution syntax:
single-no-ko += $(single-ko:.ko=.o) $(single-ko:.ko=.mod)

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Masahiro Yamada April 8, 2022, 12:37 a.m. UTC | #3
On Fri, Apr 8, 2022 at 6:39 AM David Laight <David.Laight@aculab.com> wrote:
>
> From: Nick Desaulniers
> > Sent: 07 April 2022 18:59
> >
> > On Wed, Apr 6, 2022 at 8:31 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
> > >
> > > The dependency
> > >
> > >     $(obj)/%.mod: $(obj)/%$(mod-prelink-ext).o
> > >
> > > ... exists because *.mod files previously contained undefined symbols,
> > > which are computed from *.o files when CONFIG_TRIM_UNUSED_KSYMS=y.
> > >
> > > Now that the undefined symbols are put into separate *.usyms files,
> > > there is no reason to make *.mod depend on *.o files.
> > >
> > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> > > ---
> > >
> > >  Makefile               | 3 ++-
> > >  scripts/Makefile.build | 5 ++---
> > >  2 files changed, 4 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/Makefile b/Makefile
> > > index 82ee893909e9..e915aacd02b0 100644
> > > --- a/Makefile
> > > +++ b/Makefile
> > > @@ -1792,7 +1792,8 @@ ifdef single-build
> > >
> > >  # .ko is special because modpost is needed
> > >  single-ko := $(sort $(filter %.ko, $(MAKECMDGOALS)))
> > > -single-no-ko := $(sort $(patsubst %.ko,%.mod, $(MAKECMDGOALS)))
> > > +single-no-ko := $(filter-out $(single-ko), $(MAKECMDGOALS)) \
> > > +               $(foreach x, o mod, $(patsubst %.ko, %.$x, $(single-ko)))
> >
> > I'm on board with this patch, and the overall goal with the series. My
> > brain is having a hard time parsing `o mod` though. Can you walk me
> > through that? Are those targets for .o and .mod files, respectively?


Yes.

Kbuild can build a module individually.

    make  foo/bar/baz.ko

(but modpost check does not work well)

To do this, Kbuild needs to descend to
the directory and generate
foo/bar/baz.o  and  foo/bar/baz.mod.

Previously, foo/bar/baz.o was generated as a
prerequisite of foo/bar/baz.mod, but now we
need to request Kbuild to generate both of them.





> I think I'd do:
> single-no-ko := $(filter-out $(single-ko), $(MAKECMDGOALS))
> single-no-ko += $(patsubst %.ko, %.o, $(single-ko))
> single-no-ko += $(patsubst %.ko, %.mod, $(single-ko))
>
> Although you can use the simpler SYSV make suffix substitution syntax:
> single-no-ko += $(single-ko:.ko=.o) $(single-ko:.ko=.mod)


Right.   I tend to use $(patsubst ), but
in some places, shorter SYSV syntax is used.
I admit inconsistency.





>
>         David
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
Masahiro Yamada April 8, 2022, 2:37 a.m. UTC | #4
On Fri, Apr 8, 2022 at 9:37 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> On Fri, Apr 8, 2022 at 6:39 AM David Laight <David.Laight@aculab.com> wrote:
> >
> > From: Nick Desaulniers
> > > Sent: 07 April 2022 18:59
> > >
> > > On Wed, Apr 6, 2022 at 8:31 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
> > > >
> > > > The dependency
> > > >
> > > >     $(obj)/%.mod: $(obj)/%$(mod-prelink-ext).o
> > > >
> > > > ... exists because *.mod files previously contained undefined symbols,
> > > > which are computed from *.o files when CONFIG_TRIM_UNUSED_KSYMS=y.
> > > >
> > > > Now that the undefined symbols are put into separate *.usyms files,
> > > > there is no reason to make *.mod depend on *.o files.
> > > >
> > > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> > > > ---
> > > >
> > > >  Makefile               | 3 ++-
> > > >  scripts/Makefile.build | 5 ++---
> > > >  2 files changed, 4 insertions(+), 4 deletions(-)
> > > >
> > > > diff --git a/Makefile b/Makefile
> > > > index 82ee893909e9..e915aacd02b0 100644
> > > > --- a/Makefile
> > > > +++ b/Makefile
> > > > @@ -1792,7 +1792,8 @@ ifdef single-build
> > > >
> > > >  # .ko is special because modpost is needed
> > > >  single-ko := $(sort $(filter %.ko, $(MAKECMDGOALS)))
> > > > -single-no-ko := $(sort $(patsubst %.ko,%.mod, $(MAKECMDGOALS)))
> > > > +single-no-ko := $(filter-out $(single-ko), $(MAKECMDGOALS)) \
> > > > +               $(foreach x, o mod, $(patsubst %.ko, %.$x, $(single-ko)))
> > >
> > > I'm on board with this patch, and the overall goal with the series. My
> > > brain is having a hard time parsing `o mod` though. Can you walk me
> > > through that? Are those targets for .o and .mod files, respectively?
>
>
> Yes.
>
> Kbuild can build a module individually.
>
>     make  foo/bar/baz.ko
>
> (but modpost check does not work well)
>
> To do this, Kbuild needs to descend to
> the directory and generate
> foo/bar/baz.o  and  foo/bar/baz.mod.
>
> Previously, foo/bar/baz.o was generated as a
> prerequisite of foo/bar/baz.mod, but now we
> need to request Kbuild to generate both of them.
>


BTW, this feature is broken for CONFIG_LTO_CLANG=y
because the ELF object is not foo/bar/baz.o
but foo/bar/baz.prelink.o
(which was renamed from foo/bar/baz.lto.o).

I will not fix it, though.
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 82ee893909e9..e915aacd02b0 100644
--- a/Makefile
+++ b/Makefile
@@ -1792,7 +1792,8 @@  ifdef single-build
 
 # .ko is special because modpost is needed
 single-ko := $(sort $(filter %.ko, $(MAKECMDGOALS)))
-single-no-ko := $(sort $(patsubst %.ko,%.mod, $(MAKECMDGOALS)))
+single-no-ko := $(filter-out $(single-ko), $(MAKECMDGOALS)) \
+		$(foreach x, o mod, $(patsubst %.ko, %.$x, $(single-ko)))
 
 $(single-ko): single_modpost
 	@:
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index f7a30f378e20..3da731cf6978 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -85,7 +85,7 @@  ifdef need-builtin
 targets-for-builtin += $(obj)/built-in.a
 endif
 
-targets-for-modules := $(foreach x, mod $(if $(CONFIG_TRIM_UNUSED_KSYMS), usyms), \
+targets-for-modules := $(foreach x, o mod $(if $(CONFIG_TRIM_UNUSED_KSYMS), usyms), \
 				$(patsubst %.o, %.$x, $(filter %.o, $(obj-m))))
 
 ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),)
@@ -306,7 +306,7 @@  endif
 cmd_mod = echo $(addprefix $(obj)/, $(call real-search, $*.o, .o, -objs -y -m)) | \
 	$(AWK) -v RS='( |\n)' '!x[$$0]++' > $@
 
-$(obj)/%.mod: $(obj)/%$(mod-prelink-ext).o FORCE
+$(obj)/%.mod: FORCE
 	$(call if_changed,mod)
 
 # List module undefined symbols
@@ -469,7 +469,6 @@  $(multi-obj-m): FORCE
 	$(call if_changed,link_multi-m)
 $(call multi_depend, $(multi-obj-m), .o, -objs -y -m)
 
-targets += $(multi-obj-m)
 targets := $(filter-out $(PHONY), $(targets))
 
 # Add intermediate targets: