Re: [PATCH v2 3/4] kbuild: re-implement CONFIG_TRIM_UNUSED_KSYMS to make it work in one-pass

From: Nicolas Pitre
Date: Tue Mar 09 2021 - 12:36:50 EST


On Wed, 10 Mar 2021, Masahiro Yamada wrote:

> Commit a555bdd0c58c ("Kbuild: enable TRIM_UNUSED_KSYMS again, with some
> guarding") re-enabled this feature, but Linus is still unhappy about
> the build time.
>
> The reason of the slowness is the recursion - this basically works in
> two loops.
>
> In the first loop, Kbuild builds the entire tree based on the temporary
> autoksyms.h, which contains macro defines to control whether their
> corresponding EXPORT_SYMBOL() is enabled or not, and also gathers all
> symbols required by modules. After the tree traverse, Kbuild updates
> autoksyms.h and triggers the second loop to rebuild source files whose
> EXPORT_SYMBOL() needs flipping.
>
> This commit re-implements CONFIG_TRIM_UNUSED_KSYMS to make it work in
> one pass. In the new design, unneeded EXPORT_SYMBOL() instances are
> trimmed by the linker instead of the preprocessor.
>
> After the tree traverse, a linker script snippet <generated/keep-ksyms.h>
> is generated. It feeds the list of necessary sections to vmlinus.lds.S
> and modules.lds.S. The other sections fall into /DISCARD/.
>
> Signed-off-by: Masahiro Yamada <masahiroy@xxxxxxxxxx>

I'm not sure I do understand every detail here, especially since it is
so far away from the version that I originally contributed. But the
concept looks good.

I still think that there is no way around a recursive approach to get
the maximum effect with LTO, but given that true LTO still isn't applied
to mainline after all those years, the recursive approach brings
nothing. Maybe that could be revisited if true LTO ever makes it into
mainline, and the desire to reduce the binary size is still relevant
enough to justify it.

Acked-by: Nicolas Pitre <nico@xxxxxxxxxxx>


Nicolas