linux-kbuild.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kbuild: Ignore __this_module in gen_autoksyms.sh
@ 2022-06-16 19:57 Sami Tolvanen
  2022-06-16 22:19 ` Steve Muckle
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Sami Tolvanen @ 2022-06-16 19:57 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Nicolas Schier, Alexander Lobakin, Nick Desaulniers,
	Steve Muckle, linux-kbuild, linux-kernel, Sami Tolvanen

Module object files can contain an undefined reference to __this_module,
which isn't resolved until we link the final .ko. The kernel doesn't
export this symbol, so ignore it in gen_autoksyms.sh. This avoids an
unnecessary vmlinux rebuild with UNUSED_KSYMS_WHITELIST when we have a
symbol list that already contains all the module dependencies.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
---
 scripts/gen_autoksyms.sh | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/scripts/gen_autoksyms.sh b/scripts/gen_autoksyms.sh
index faacf7062122..653fadbad302 100755
--- a/scripts/gen_autoksyms.sh
+++ b/scripts/gen_autoksyms.sh
@@ -56,4 +56,7 @@ EOT
 # point addresses.
 sed -e 's/^\.//' |
 sort -u |
+# Ignore __this_module. It's not an exported symbol, and will be resolved
+# when the final .ko's are linked.
+grep -v '^__this_module$' |
 sed -e 's/\(.*\)/#define __KSYM_\1 1/' >> "$output_file"
-- 
2.36.1.476.g0c4daa206d-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] kbuild: Ignore __this_module in gen_autoksyms.sh
  2022-06-16 19:57 [PATCH] kbuild: Ignore __this_module in gen_autoksyms.sh Sami Tolvanen
@ 2022-06-16 22:19 ` Steve Muckle
  2022-06-17 17:28 ` Nick Desaulniers
  2022-06-18 22:59 ` Masahiro Yamada
  2 siblings, 0 replies; 7+ messages in thread
From: Steve Muckle @ 2022-06-16 22:19 UTC (permalink / raw)
  To: Sami Tolvanen
  Cc: Nicolas Schier, Alexander Lobakin, Nick Desaulniers,
	linux-kbuild, linux-kernel, Masahiro Yamada

On 6/16/22 12:57, Sami Tolvanen wrote:
> Module object files can contain an undefined reference to __this_module,
> which isn't resolved until we link the final .ko. The kernel doesn't
> export this symbol, so ignore it in gen_autoksyms.sh. This avoids an
> unnecessary vmlinux rebuild with UNUSED_KSYMS_WHITELIST when we have a
> symbol list that already contains all the module dependencies.
> 
> Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
> ---
>   scripts/gen_autoksyms.sh | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/scripts/gen_autoksyms.sh b/scripts/gen_autoksyms.sh
> index faacf7062122..653fadbad302 100755
> --- a/scripts/gen_autoksyms.sh
> +++ b/scripts/gen_autoksyms.sh
> @@ -56,4 +56,7 @@ EOT
>   # point addresses.
>   sed -e 's/^\.//' |
>   sort -u |
> +# Ignore __this_module. It's not an exported symbol, and will be resolved
> +# when the final .ko's are linked.
> +grep -v '^__this_module$' |
>   sed -e 's/\(.*\)/#define __KSYM_\1 1/' >> "$output_file"

Tested-by: Steve Muckle <smuckle@google.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] kbuild: Ignore __this_module in gen_autoksyms.sh
  2022-06-16 19:57 [PATCH] kbuild: Ignore __this_module in gen_autoksyms.sh Sami Tolvanen
  2022-06-16 22:19 ` Steve Muckle
@ 2022-06-17 17:28 ` Nick Desaulniers
  2022-06-17 18:14   ` Ramji Jiyani
  2022-06-18 22:59 ` Masahiro Yamada
  2 siblings, 1 reply; 7+ messages in thread
From: Nick Desaulniers @ 2022-06-17 17:28 UTC (permalink / raw)
  To: Sami Tolvanen, Ramji Jiyani
  Cc: Masahiro Yamada, Nicolas Schier, Alexander Lobakin, Steve Muckle,
	Linux Kbuild mailing list, LKML, Sedat Dilek

+ Sedat
Re: https://lore.kernel.org/linux-kbuild/CAKwvOdmb5xdF70TzNp=4STCpzkGh16FnuKE1KbdzDhHt=OuRFA@mail.gmail.com/
In case this helps.

+ Ramji
Ramji, it sounds like you helped test this downstream? If that's the
case, mind supplying your tested-by tag for the record? Thanks for
help verifying this change. Thanks too, Steve!

On Thu, Jun 16, 2022 at 12:58 PM Sami Tolvanen <samitolvanen@google.com> wrote:
>
> Module object files can contain an undefined reference to __this_module,
> which isn't resolved until we link the final .ko. The kernel doesn't
> export this symbol, so ignore it in gen_autoksyms.sh. This avoids an
> unnecessary vmlinux rebuild with UNUSED_KSYMS_WHITELIST when we have a
> symbol list that already contains all the module dependencies.

Worth mentioning that this also fixes a significant build time
regression made more painful by CONFIG_LTO_CLANG_FULL when using
CONFIG_UNUSED_KSYMS_WHITELIST.

Thanks for the patch!
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

>
> Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
> ---
>  scripts/gen_autoksyms.sh | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/scripts/gen_autoksyms.sh b/scripts/gen_autoksyms.sh
> index faacf7062122..653fadbad302 100755
> --- a/scripts/gen_autoksyms.sh
> +++ b/scripts/gen_autoksyms.sh
> @@ -56,4 +56,7 @@ EOT
>  # point addresses.
>  sed -e 's/^\.//' |
>  sort -u |
> +# Ignore __this_module. It's not an exported symbol, and will be resolved
> +# when the final .ko's are linked.
> +grep -v '^__this_module$' |
>  sed -e 's/\(.*\)/#define __KSYM_\1 1/' >> "$output_file"
> --
> 2.36.1.476.g0c4daa206d-goog
>


-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] kbuild: Ignore __this_module in gen_autoksyms.sh
  2022-06-17 17:28 ` Nick Desaulniers
@ 2022-06-17 18:14   ` Ramji Jiyani
  0 siblings, 0 replies; 7+ messages in thread
From: Ramji Jiyani @ 2022-06-17 18:14 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Sami Tolvanen, Masahiro Yamada, Nicolas Schier,
	Alexander Lobakin, Steve Muckle, Linux Kbuild mailing list, LKML,
	Sedat Dilek

On Fri, Jun 17, 2022 at 10:28 AM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> + Sedat
> Re: https://lore.kernel.org/linux-kbuild/CAKwvOdmb5xdF70TzNp=4STCpzkGh16FnuKE1KbdzDhHt=OuRFA@mail.gmail.com/
> In case this helps.
>
> + Ramji
> Ramji, it sounds like you helped test this downstream? If that's the
> case, mind supplying your tested-by tag for the record? Thanks for
> help verifying this change. Thanks too, Steve!
>
> On Thu, Jun 16, 2022 at 12:58 PM Sami Tolvanen <samitolvanen@google.com> wrote:
> >
> > Module object files can contain an undefined reference to __this_module,
> > which isn't resolved until we link the final .ko. The kernel doesn't
> > export this symbol, so ignore it in gen_autoksyms.sh. This avoids an
> > unnecessary vmlinux rebuild with UNUSED_KSYMS_WHITELIST when we have a
> > symbol list that already contains all the module dependencies.
>
> Worth mentioning that this also fixes a significant build time
> regression made more painful by CONFIG_LTO_CLANG_FULL when using
> CONFIG_UNUSED_KSYMS_WHITELIST.
>

Yes, I tested it and it resolves the build time regression with modules.

Tested-by: Ramji Jiyani <ramjiyani@google.com>

Thanks,
Ramji

> Thanks for the patch!
> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
>
> >
> > Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
> > ---
> >  scripts/gen_autoksyms.sh | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/scripts/gen_autoksyms.sh b/scripts/gen_autoksyms.sh
> > index faacf7062122..653fadbad302 100755
> > --- a/scripts/gen_autoksyms.sh
> > +++ b/scripts/gen_autoksyms.sh
> > @@ -56,4 +56,7 @@ EOT
> >  # point addresses.
> >  sed -e 's/^\.//' |
> >  sort -u |
> > +# Ignore __this_module. It's not an exported symbol, and will be resolved
> > +# when the final .ko's are linked.
> > +grep -v '^__this_module$' |
> >  sed -e 's/\(.*\)/#define __KSYM_\1 1/' >> "$output_file"
> > --
> > 2.36.1.476.g0c4daa206d-goog
> >
>
>
> --
> Thanks,
> ~Nick Desaulniers

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] kbuild: Ignore __this_module in gen_autoksyms.sh
  2022-06-16 19:57 [PATCH] kbuild: Ignore __this_module in gen_autoksyms.sh Sami Tolvanen
  2022-06-16 22:19 ` Steve Muckle
  2022-06-17 17:28 ` Nick Desaulniers
@ 2022-06-18 22:59 ` Masahiro Yamada
  2022-06-21 15:37   ` Sami Tolvanen
  2 siblings, 1 reply; 7+ messages in thread
From: Masahiro Yamada @ 2022-06-18 22:59 UTC (permalink / raw)
  To: Sami Tolvanen
  Cc: Nicolas Schier, Alexander Lobakin, Nick Desaulniers,
	Steve Muckle, Linux Kbuild mailing list,
	Linux Kernel Mailing List

On Fri, Jun 17, 2022 at 4:58 AM Sami Tolvanen <samitolvanen@google.com> wrote:
>
> Module object files can contain an undefined reference to __this_module,
> which isn't resolved until we link the final .ko. The kernel doesn't
> export this symbol, so ignore it in gen_autoksyms.sh.

OK, I understand these two sentences.

> This avoids an
> unnecessary vmlinux rebuild with UNUSED_KSYMS_WHITELIST when we have a
> symbol list that already contains all the module dependencies.
>

I do not understand how this can happen.


Can you provide me steps to reproduce it?







> Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
> ---
>  scripts/gen_autoksyms.sh | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/scripts/gen_autoksyms.sh b/scripts/gen_autoksyms.sh
> index faacf7062122..653fadbad302 100755
> --- a/scripts/gen_autoksyms.sh
> +++ b/scripts/gen_autoksyms.sh
> @@ -56,4 +56,7 @@ EOT
>  # point addresses.
>  sed -e 's/^\.//' |
>  sort -u |
> +# Ignore __this_module. It's not an exported symbol, and will be resolved
> +# when the final .ko's are linked.
> +grep -v '^__this_module$' |
>  sed -e 's/\(.*\)/#define __KSYM_\1 1/' >> "$output_file"
> --
> 2.36.1.476.g0c4daa206d-goog
>


-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] kbuild: Ignore __this_module in gen_autoksyms.sh
  2022-06-18 22:59 ` Masahiro Yamada
@ 2022-06-21 15:37   ` Sami Tolvanen
  2022-06-23 19:34     ` Masahiro Yamada
  0 siblings, 1 reply; 7+ messages in thread
From: Sami Tolvanen @ 2022-06-21 15:37 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Nicolas Schier, Alexander Lobakin, Nick Desaulniers,
	Steve Muckle, Linux Kbuild mailing list,
	Linux Kernel Mailing List

On Sat, Jun 18, 2022 at 4:01 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> On Fri, Jun 17, 2022 at 4:58 AM Sami Tolvanen <samitolvanen@google.com> wrote:
> >
> > Module object files can contain an undefined reference to __this_module,
> > which isn't resolved until we link the final .ko. The kernel doesn't
> > export this symbol, so ignore it in gen_autoksyms.sh.
>
> OK, I understand these two sentences.
>
> > This avoids an
> > unnecessary vmlinux rebuild with UNUSED_KSYMS_WHITELIST when we have a
> > symbol list that already contains all the module dependencies.
> >
>
> I do not understand how this can happen.
>
>
> Can you provide me steps to reproduce it?

This issue only happens when we have a whitelist that already contains
all the symbols we need to export. As autoksyms.h contains all the
necessary symbols in the initial vmlinux build, there should be no
need to link vmlinux again. However, as the code is looking at
undefined symbols in module .o files before __this_module is resolved,
adjust_autoksyms.sh thinks that __this_module is still missing and
triggers a rebuild, without actually changing anything.

I suspect this isn't a common situation, but it does happen when
building Android kernels, which specify a complete list of exported
symbols. Linking vmlinux.o takes a while with LTO and we would like to
avoid performing this step more than once.

Sami

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] kbuild: Ignore __this_module in gen_autoksyms.sh
  2022-06-21 15:37   ` Sami Tolvanen
@ 2022-06-23 19:34     ` Masahiro Yamada
  0 siblings, 0 replies; 7+ messages in thread
From: Masahiro Yamada @ 2022-06-23 19:34 UTC (permalink / raw)
  To: Sami Tolvanen
  Cc: Nicolas Schier, Alexander Lobakin, Nick Desaulniers,
	Steve Muckle, Linux Kbuild mailing list,
	Linux Kernel Mailing List

On Wed, Jun 22, 2022 at 12:37 AM Sami Tolvanen <samitolvanen@google.com> wrote:
>
> On Sat, Jun 18, 2022 at 4:01 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
> >
> > On Fri, Jun 17, 2022 at 4:58 AM Sami Tolvanen <samitolvanen@google.com> wrote:
> > >
> > > Module object files can contain an undefined reference to __this_module,
> > > which isn't resolved until we link the final .ko. The kernel doesn't
> > > export this symbol, so ignore it in gen_autoksyms.sh.
> >
> > OK, I understand these two sentences.
> >
> > > This avoids an
> > > unnecessary vmlinux rebuild with UNUSED_KSYMS_WHITELIST when we have a
> > > symbol list that already contains all the module dependencies.
> > >
> >
> > I do not understand how this can happen.
> >
> >
> > Can you provide me steps to reproduce it?
>
> This issue only happens when we have a whitelist that already contains
> all the symbols we need to export. As autoksyms.h contains all the
> necessary symbols in the initial vmlinux build, there should be no
> need to link vmlinux again. However, as the code is looking at
> undefined symbols in module .o files before __this_module is resolved,
> adjust_autoksyms.sh thinks that __this_module is still missing and
> triggers a rebuild, without actually changing anything.
>
> I suspect this isn't a common situation, but it does happen when
> building Android kernels, which specify a complete list of exported
> symbols. Linking vmlinux.o takes a while with LTO and we would like to
> avoid performing this step more than once.
>
> Sami

Thanks, confirmed.

But, this patch does not shoot the root cause.
The relink of vmlinux should not happen irrespective of
UNUSED_KSYMS_WHITELIST.


I thought I had fixed this issue long time before, but
actually didn't due to my mistake in
commit 3fdc7d3fe4c0 ("kbuild: link vmlinux only once for
CONFIG_TRIM_UNUSED_KSYMS").


I will pick up this patch anyway, but the re-link of vmlinux
should be addressed by the other patch.



-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-06-23 19:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-16 19:57 [PATCH] kbuild: Ignore __this_module in gen_autoksyms.sh Sami Tolvanen
2022-06-16 22:19 ` Steve Muckle
2022-06-17 17:28 ` Nick Desaulniers
2022-06-17 18:14   ` Ramji Jiyani
2022-06-18 22:59 ` Masahiro Yamada
2022-06-21 15:37   ` Sami Tolvanen
2022-06-23 19:34     ` Masahiro Yamada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).