Skip to contentSkip to conversation

Kbuild: lto: add make version checking

PATCH Superseded Lecopzer Chen 2 participants 7 messages Jun 30, 2021 – Jul 1, 2021

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Kbuild: lto: add make version checking

LTO with MODVERSION will fail in generating correct CRC because the makefile rule doesn't work for make with version 3.8X.

Refer to [1]:

Quoted 13 lines

When building modules(CONFIG_...=m), I found some of module versions are incorrect and set to 0.
This can be found in build log for first clean build which shows

WARNING: EXPORT symbol "XXXX" [drivers/XXX/XXX.ko] version generation failed, symbol will not be versioned.

But in second build(incremental build), the WARNING disappeared and the module version becomes valid CRC and make someone who want to change modules without updating kernel image can't insert their modules.

The problematic code is
+ $(foreach n, $(filter-out FORCE,$^), \

Review

Quoted 2 lines
(quoted diff) +2 -0
+   $(if $(wildcard $(n).symversions),      \
+     ; cat $(n).symversions >> [email protected]))

The issue fixed when make version upgrading to 4.2.

Thus we need to check make version during selecting on LTO Kconfig. The MAKE_VERSION_INT means MAKE_VERSION in canonical digits integer and implemnted by imitating CLANG_VERSION.

[1] https://lore.kernel.org/lkml/[email protected]/

Lecopzer Chen (2):
Kbuild: lto: add make-version macros
Kbuild: lto: add make version checking

 Makefile                |  2 +-
 arch/Kconfig            |  1 +
 init/Kconfig            |  4 ++++
 scripts/Kconfig.include |  3 +++
 scripts/make-version.sh | 13 +++++++++++++
 5 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100755 scripts/make-version.sh
Signature · 1 line
2.18.0
#1 lore raw

PATCH 1/2 Kbuild: lto: add make-version macros

To check the GNU make version. Used by the LTO Kconfig.

LTO with MODVERSION will fail in generating correct CRC because the makefile rule doesn't work for make with version 3.8X.[1]

Thus we need to check make version during selecting on LTO Kconfig. The MAKE_VERSION_INT means MAKE_VERSION in canonical digits integer and implemnted by imitating CLANG_VERSION.

[1] https://lore.kernel.org/lkml/[email protected]/

---
 Makefile                |  2 +-
 init/Kconfig            |  4 ++++
 scripts/Kconfig.include |  3 +++
 scripts/make-version.sh | 13 +++++++++++++
 4 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100755 scripts/make-version.sh
Makefile +1 -1
index 88888fff4c62..2402745b2ba9 100644
@@ -516,7 +516,7 @@ CLANG_FLAGS :=
 
 export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC
 export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL
-export PERL PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
+export PERL PYTHON3 CHECK CHECKFLAGS MAKE MAKE_VERSION UTS_MACHINE HOSTCXX
 export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD
 export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE
 
init/Kconfig +4 -0
index a61c92066c2e..9f2b71fdf23e 100644
@@ -83,6 +83,10 @@ config TOOLS_SUPPORT_RELR
 config CC_HAS_ASM_INLINE
 	def_bool $(success,echo 'void foo(void) { asm inline (""); }' | $(CC) -x c - -c -o /dev/null)
 
+config MAKE_VERSION_INT
+	int
+	default $(make-version)
+
 config CONSTRUCTORS
 	bool
 
scripts/Kconfig.include +3 -0
index 0496efd6e117..f956953d0236 100644
@@ -63,3 +63,6 @@ ld-version := $(shell,set -- $(ld-info) && echo $2)
 cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1))
 m32-flag := $(cc-option-bit,-m32)
 m64-flag := $(cc-option-bit,-m64)
+
+# Get the GNU make version with a canonical digit.
+make-version := $(shell,$(srctree)/scripts/make-version.sh $(MAKE_VERSION))
scripts/make-version.sh new file +13 -0
new file mode 100755
index 000000000000..ce5af96696cc
@@ -0,0 +1,13 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+#
+# Print the linker name and its version in a 5 or 6-digit form.
+
+set -e
+
+# Convert the version string x.y.z to a canonical 5 or 6-digit form.
+IFS=.
+set -- $1
+
+# If the 2nd or 3rd field is missing, fill it with a zero.
+echo $((10000 * $1 + 100 * ${2:-0} + ${3:-0}))
Signature · 1 line
2.18.0
#2 lore raw

Re: [PATCH 1/2] Kbuild: lto: add make-version macros

Hi Lecopzer,

Quoted 8 lines · Lecopzer Chen

To check the GNU make version. Used by the LTO Kconfig.

LTO with MODVERSION will fail in generating correct CRC because the makefile rule doesn't work for make with version 3.8X.[1]

Thus we need to check make version during selecting on LTO Kconfig. The MAKE_VERSION_INT means MAKE_VERSION in canonical digits integer and implemnted by imitating CLANG_VERSION.

implemented

Quoted 29 lines

[1] https://lore.kernel.org/lkml/[email protected]/

---
  Makefile                |  2 +-
  init/Kconfig            |  4 ++++
  scripts/Kconfig.include |  3 +++
  scripts/make-version.sh | 13 +++++++++++++
  4 files changed, 21 insertions(+), 1 deletion(-)

create mode 100755 scripts/make-version.sh

Makefile +1 -1
index 88888fff4c62..2402745b2ba9 100644
@@ -516,7 +516,7 @@ CLANG_FLAGS :=
 
  export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC
  export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL
-export PERL PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
+export PERL PYTHON3 CHECK CHECKFLAGS MAKE MAKE_VERSION UTS_MACHINE HOSTCXX
  export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD
  export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE
 
init/Kconfig +0 -0
index a61c92066c2e..9f2b71fdf23e 100644

init/Kconfig config TOOLS_SUPPORT_RELR · line 86

Quoted 4 lines
init/Kconfig +1 -0
@@ -83,6 +83,10 @@ config TOOLS_SUPPORT_RELR
  config CC_HAS_ASM_INLINE
  	def_bool $(success,echo 'void foo(void) { asm inline (""); }' | $(CC) -x c - -c -o /dev/null)
 
+config MAKE_VERSION_INT

It might be cleaner to make this "config MAKE_VERSION". It will not conflict with the builtin MAKE_VERSION because this is really CONFIG_MAKE_VERSION, which is how MAKE_VERSION will be handled in Kconfig.

Quoted 11 lines
init/Kconfig +3 -0
+	int
+	default $(make-version)
+
  config CONSTRUCTORS
  	bool
 
scripts/Kconfig.include +0 -0
index 0496efd6e117..f956953d0236 100644

scripts/Kconfig.include ld-version := $(shell,set -- $(ld-info) && echo $2) · line 68

Quoted 6 lines
scripts/Kconfig.include +3 -0
@@ -63,3 +63,6 @@ ld-version := $(shell,set -- $(ld-info) && echo $2)
  cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1))
  m32-flag := $(cc-option-bit,-m32)
  m64-flag := $(cc-option-bit,-m64)
+
+# Get the GNU make version with a canonical digit.
+make-version := $(shell,$(srctree)/scripts/make-version.sh $(MAKE_VERSION))

It might be better for this to just be used directly by "config MAKE_VERSION":

config MAKE_VERSION

	int
	default $(shell,$(srctree)/scripts/make-version.sh $(MAKE_VERSION))
Quoted 20 lines
scripts/make-version.sh new file +13 -0
new file mode 100755
index 000000000000..ce5af96696cc
@@ -0,0 +1,13 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+#
+# Print the linker name and its version in a 5 or 6-digit form.
+
+set -e
+
+# Convert the version string x.y.z to a canonical 5 or 6-digit form.
+IFS=.
+set -- $1
+
+# If the 2nd or 3rd field is missing, fill it with a zero.
+echo $((10000 * $1 + 100 * ${2:-0} + ${3:-0}))
#3 lore raw

Re: [PATCH 1/2] Kbuild: lto: add make-version macros

Quoted 5 lines

Hi Lecopzer,

Quoted 2 lines · Lecopzer Chen

To check the GNU make version. Used by the LTO Kconfig.

Quoted 8 lines
Quoted 6 lines

LTO with MODVERSION will fail in generating correct CRC because the makefile rule doesn't work for make with version 3.8X.[1]

Thus we need to check make version during selecting on LTO Kconfig. The MAKE_VERSION_INT means MAKE_VERSION in canonical digits integer and implemnted by imitating CLANG_VERSION.

implemented

Thanks!

Quoted 33 lines
Quoted 33 lines

[1] https://lore.kernel.org/lkml/[email protected]/

---
  Makefile                |  2 +-
  init/Kconfig            |  4 ++++
  scripts/Kconfig.include |  3 +++
  scripts/make-version.sh | 13 +++++++++++++
  4 files changed, 21 insertions(+), 1 deletion(-)

create mode 100755 scripts/make-version.sh

Makefile +1 -1
index 88888fff4c62..2402745b2ba9 100644
@@ -516,7 +516,7 @@ CLANG_FLAGS :=
 
  export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC
  export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL
-export PERL PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
+export PERL PYTHON3 CHECK CHECKFLAGS MAKE MAKE_VERSION UTS_MACHINE HOSTCXX
  export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD
  export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE
 
init/Kconfig +0 -0
index a61c92066c2e..9f2b71fdf23e 100644
@@ -83,6 +83,10 @@ config TOOLS_SUPPORT_RELR
  config CC_HAS_ASM_INLINE
  	def_bool $(success,echo 'void foo(void) { asm inline (""); }' | $(CC) -x c - -c -o /dev/null)
 
Quoted 5 lines

init/Kconfig config TOOLS_SUPPORT_RELR · line 86

Quoted 1 line
init/Kconfig +1 -0
+config MAKE_VERSION_INT

It might be cleaner to make this "config MAKE_VERSION". It will not conflict with the builtin MAKE_VERSION because this is really CONFIG_MAKE_VERSION, which is how MAKE_VERSION will be handled in Kconfig.

Okat, thanks, I'll try and fix it in patch v2.

Quoted 22 lines
Quoted 12 lines
init/Kconfig +3 -0
+	int
+	default $(make-version)
+
  config CONSTRUCTORS
  	bool
 
scripts/Kconfig.include +0 -0
index 0496efd6e117..f956953d0236 100644

scripts/Kconfig.include ld-version := $(shell,set -- $(ld-info) && echo $2) · line 68

Quoted 6 lines
scripts/Kconfig.include +3 -0
@@ -63,3 +63,6 @@ ld-version := $(shell,set -- $(ld-info) && echo $2)
  cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1))
  m32-flag := $(cc-option-bit,-m32)
  m64-flag := $(cc-option-bit,-m64)
+
+# Get the GNU make version with a canonical digit.
+make-version := $(shell,$(srctree)/scripts/make-version.sh $(MAKE_VERSION))

It might be better for this to just be used directly by "config MAKE_VERSION":

Quoted 3 lines

config MAKE_VERSION

	int
	default $(shell,$(srctree)/scripts/make-version.sh $(MAKE_VERSION))

Sure, I'll fix in patch v2, thank you.

Quoted 21 lines
Quoted 21 lines
scripts/make-version.sh new file +13 -0
new file mode 100755
index 000000000000..ce5af96696cc
@@ -0,0 +1,13 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+#
+# Print the linker name and its version in a 5 or 6-digit form.
+
+set -e
+
+# Convert the version string x.y.z to a canonical 5 or 6-digit form.
+IFS=.
+set -- $1
+
+# If the 2nd or 3rd field is missing, fill it with a zero.
+echo $((10000 * $1 + 100 * ${2:-0} + ${3:-0}))
#4 lore raw

PATCH 2/2 Kbuild: lto: add make version checking

In reply to Lecopzer Chen

LTO with MODVERSION will fail in generating correct CRC because the makefile rule doesn't work for make with version 3.8X.[1]

Thus we need to check make version during selecting on LTO Kconfig. and the suitable version should be 4.2(40200) which release in 2016[2].

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://ftp.gnu.org/gnu/make/

---
 arch/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/Kconfig +1 -0
index c45b770d3579..1571957bade5 100644
@@ -632,6 +632,7 @@ config HAS_LTO_CLANG
 	def_bool y
 	# Clang >= 11: https://github.com/ClangBuiltLinux/linux/issues/510
 	depends on CC_IS_CLANG && CLANG_VERSION >= 110000 && LD_IS_LLD && AS_IS_LLVM
+	depends on MAKE_VERSION_INT >= 40200
 	depends on $(success,$(NM) --help | head -n 1 | grep -qi llvm)
 	depends on $(success,$(AR) --help | head -n 1 | grep -qi llvm)
 	depends on ARCH_SUPPORTS_LTO_CLANG
Signature · 1 line
2.18.0
#5 lore raw
Quoted 18 lines · Lecopzer Chen

LTO with MODVERSION will fail in generating correct CRC because the makefile rule doesn't work for make with version 3.8X.[1]

Thus we need to check make version during selecting on LTO Kconfig. and the suitable version should be 4.2(40200) which release in 2016[2].

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://ftp.gnu.org/gnu/make/

---
  arch/Kconfig | 1 +
  1 file changed, 1 insertion(+)
arch/Kconfig +0 -0
index c45b770d3579..1571957bade5 100644

arch/Kconfig config HAS_LTO_CLANG · line 635

Quoted 4 lines
arch/Kconfig +1 -0
@@ -632,6 +632,7 @@ config HAS_LTO_CLANG
  	def_bool y
  	# Clang >= 11: https://github.com/ClangBuiltLinux/linux/issues/510
  	depends on CC_IS_CLANG && CLANG_VERSION >= 110000 && LD_IS_LLD && AS_IS_LLVM
+	depends on MAKE_VERSION_INT >= 40200

If the bug depends on CONFIG_MODVERSIONS, should this be

depends on !MODVERSIONS || MAKE_VERSION >= 40200

? Especially since the problematic block in your original report is gated on CONFIG_LTO_CLANG + CONFIG_MODVERSIONS.

Quoted 4 lines
arch/Kconfig +0 -0
  	depends on $(success,$(NM) --help | head -n 1 | grep -qi llvm)
  	depends on $(success,$(AR) --help | head -n 1 | grep -qi llvm)
  	depends on ARCH_SUPPORTS_LTO_CLANG
#6 lore raw
Quoted 27 lines · Lecopzer Chen
Quoted 18 lines

LTO with MODVERSION will fail in generating correct CRC because the makefile rule doesn't work for make with version 3.8X.[1]

Thus we need to check make version during selecting on LTO Kconfig. and the suitable version should be 4.2(40200) which release in 2016[2].

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://ftp.gnu.org/gnu/make/

---
  arch/Kconfig | 1 +
  1 file changed, 1 insertion(+)
arch/Kconfig +0 -0
index c45b770d3579..1571957bade5 100644

arch/Kconfig config HAS_LTO_CLANG · line 635

Quoted 4 lines
arch/Kconfig +1 -0
@@ -632,6 +632,7 @@ config HAS_LTO_CLANG
  	def_bool y
  	# Clang >= 11: https://github.com/ClangBuiltLinux/linux/issues/510
  	depends on CC_IS_CLANG && CLANG_VERSION >= 110000 && LD_IS_LLD && AS_IS_LLVM
+	depends on MAKE_VERSION_INT >= 40200

If the bug depends on CONFIG_MODVERSIONS, should this be

Quoted 5 lines

depends on !MODVERSIONS || MAKE_VERSION >= 40200

? Especially since the problematic block in your original report is gated on CONFIG_LTO_CLANG + CONFIG_MODVERSIONS.

You're right, I'll fix it in v2, thanks for reviewing.

Quoted 4 lines
Quoted 4 lines
arch/Kconfig +0 -0
  	depends on $(success,$(NM) --help | head -n 1 | grep -qi llvm)
  	depends on $(success,$(AR) --help | head -n 1 | grep -qi llvm)
  	depends on ARCH_SUPPORTS_LTO_CLANG