diff mbox series

[21/27] kbuild: record symbol versions in *.cmd files

Message ID 20220424190811.1678416-22-masahiroy@kernel.org (mailing list archive)
State New, archived
Headers show
Series kbuild: yet another series of cleanups (modpost and LTO) | expand

Commit Message

Masahiro Yamada April 24, 2022, 7:08 p.m. UTC
When CONFIG_MODVERSIONS=y, the output from genksyms is saved in
separate *.symversions files, and will be used much later when
CONFIG_LTO_CLANG=y because it is impossible to update LLVM bit code
here.

This approach is not robust because:

 - *.symversions may or may not exist. If *.symversions does not
   exist, we never know if it is missing for legitimate reason
   (i.e. no EXPORT_SYMBOL) or something bad has happened (for
   example, the user accidentally deleted it). Once it occurs,
   it is not self-healing because *.symversions is generated
   as a side effect of the build rule of the object.

 - stale (i.e. invalid) *.symversions might be picked up if an
   object is generated in a non-ordinary way, and corresponding
   *.symversions (, which was generated by old builds) just happen
   to exist.

A more robust approach is to save symbol versions in *.cmd files
because:

 - *.cmd always exists (if the object is generated by if_changed
   rule or friends). Even if the user accidentally deletes it,
   it will be regenerated in the next build.

 - *.cmd is always re-generated when the object is updated. This
   avoid stale version information being picked up.

I will remove *.symversions later.

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

 scripts/Makefile.build | 2 ++
 1 file changed, 2 insertions(+)

Comments

Nicolas Schier April 27, 2022, 8:08 p.m. UTC | #1
On ma. 25. april 2022 kl. 04.08 +0000 Masahiro Yamada wrote:
> When CONFIG_MODVERSIONS=y, the output from genksyms is saved in
> separate *.symversions files, and will be used much later when
> CONFIG_LTO_CLANG=y because it is impossible to update LLVM bit code
> here.
> 
> This approach is not robust because:
> 
>  - *.symversions may or may not exist. If *.symversions does not
>    exist, we never know if it is missing for legitimate reason
>    (i.e. no EXPORT_SYMBOL) or something bad has happened (for
>    example, the user accidentally deleted it). Once it occurs,
>    it is not self-healing because *.symversions is generated
>    as a side effect of the build rule of the object.
> 
>  - stale (i.e. invalid) *.symversions might be picked up if an
>    object is generated in a non-ordinary way, and corresponding
>    *.symversions (, which was generated by old builds) just happen
>    to exist.
> 
> A more robust approach is to save symbol versions in *.cmd files
> because:
> 
>  - *.cmd always exists (if the object is generated by if_changed
>    rule or friends). Even if the user accidentally deletes it,
>    it will be regenerated in the next build.
> 
>  - *.cmd is always re-generated when the object is updated. This
>    avoid stale version information being picked up.
> 
> I will remove *.symversions later.
> 
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
> 
>  scripts/Makefile.build | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> index f6a506318795..e03e85c90b26 100644
> --- a/scripts/Makefile.build
> +++ b/scripts/Makefile.build
> @@ -175,6 +175,8 @@ gen_symversions =								\
>  	if $(NM) $@ 2>/dev/null | grep -q __ksymtab; then			\
>  		$(call cmd_gensymtypes_$(1),$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
>  		    > $@.symversions;						\
> +		echo >> $(dot-target).cmd ;					\
> +		sed 's/\(.*\) = \(.*\);/$(pound)\1=\2/' $@.symversions >> $(dot-target).cmd ; \
>  	else									\
>  		rm -f $@.symversions;						\
>  	fi

While reviewing this patch, I was missing the update of the comment a 
few lines above.  But I understand that it makes more sense to update 
it in the follow-up patch.

Tested-by: Nicolas Schier <nicolas@fjasle.eu>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>

> -- 
> 2.32.0
diff mbox series

Patch

diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index f6a506318795..e03e85c90b26 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -175,6 +175,8 @@  gen_symversions =								\
 	if $(NM) $@ 2>/dev/null | grep -q __ksymtab; then			\
 		$(call cmd_gensymtypes_$(1),$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
 		    > $@.symversions;						\
+		echo >> $(dot-target).cmd ;					\
+		sed 's/\(.*\) = \(.*\);/$(pound)\1=\2/' $@.symversions >> $(dot-target).cmd ; \
 	else									\
 		rm -f $@.symversions;						\
 	fi