[v2,2/5] kbuild: implement {gcc,clang}-min-version only with built-in functions

Message ID 20221123151828.509565-2-masahiroy@kernel.org
State New
Headers
Series [v2,1/5] kbuild: add test-{le,ge,lt,gt} macros |

Commit Message

Masahiro Yamada Nov. 23, 2022, 3:18 p.m. UTC
  Converting clang-min-version is straightforward because the versions
are always 6-digit.

gcc-min-version is somewhat tricky because the minimal GCC version
is GCC 5.2; prepend '0' to the version that is less than 10 so that
test-ge is always passed with 6-digit versions.

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

Changes in v2:
  - Covert gcc-min-version in a different way

 scripts/Makefile.compiler | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
  

Comments

Nicolas Schier Nov. 23, 2022, 8:37 p.m. UTC | #1
On Thu 24 Nov 2022 00:18:25 GMT, Masahiro Yamada wrote:
> Converting clang-min-version is straightforward because the versions
> are always 6-digit.
> 
> gcc-min-version is somewhat tricky because the minimal GCC version
> is GCC 5.2; prepend '0' to the version that is less than 10 so that
> test-ge is always passed with 6-digit versions.
> 
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
> 
> Changes in v2:
>   - Covert gcc-min-version in a different way
> 
>  scripts/Makefile.compiler | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/Makefile.compiler b/scripts/Makefile.compiler
> index 20d353dcabfb..cd75f81e88ef 100644
> --- a/scripts/Makefile.compiler
> +++ b/scripts/Makefile.compiler
> @@ -63,11 +63,15 @@ cc-disable-warning = $(call try-run,\
>  
>  # gcc-min-version
>  # Usage: cflags-$(call gcc-min-version, 70100) += -foo
> -gcc-min-version = $(shell [ $(CONFIG_GCC_VERSION)0 -ge $(1)0 ] && echo y)
> +
> +# Preprend 0 to the version that is less than 10 so test-ge works.
> +gcc-min-version = $(call test-ge, \
> +                  $(or $(filter 1%, $(CONFIG_GCC_VERSION)), 0$(CONFIG_GCC_VERSION)), \
> +                  $(or $(filter 1%, $1), 0$(strip $1)))

Hm, this silently expects a gcc version < 20, which we should expect in 
about seven-eight years [1].   I am thinking about the possibility of 
silent (but unlikely) breaks when someone in far future uses a gcc 20 
against a kernel with this line.  Probably we should not care about 
that today, yet, right?

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

[1]: https://gcc.gnu.org/develop.html#timeline

>  
>  # clang-min-version
>  # Usage: cflags-$(call clang-min-version, 110000) += -foo
> -clang-min-version = $(shell [ $(CONFIG_CLANG_VERSION)0 -ge $(1)0 ] && echo y)
> +clang-min-version = $(call test-ge, $(CONFIG_CLANG_VERSION), $1)
>  
>  # ld-option
>  # Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y)
> -- 
> 2.34.1
  
Masahiro Yamada Nov. 23, 2022, 9:17 p.m. UTC | #2
On Thu, Nov 24, 2022 at 5:37 AM Nicolas Schier <nicolas@fjasle.eu> wrote:
>
> On Thu 24 Nov 2022 00:18:25 GMT, Masahiro Yamada wrote:
> > Converting clang-min-version is straightforward because the versions
> > are always 6-digit.
> >
> > gcc-min-version is somewhat tricky because the minimal GCC version
> > is GCC 5.2; prepend '0' to the version that is less than 10 so that
> > test-ge is always passed with 6-digit versions.
> >
> > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> > ---
> >
> > Changes in v2:
> >   - Covert gcc-min-version in a different way
> >
> >  scripts/Makefile.compiler | 8 ++++++--
> >  1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/scripts/Makefile.compiler b/scripts/Makefile.compiler
> > index 20d353dcabfb..cd75f81e88ef 100644
> > --- a/scripts/Makefile.compiler
> > +++ b/scripts/Makefile.compiler
> > @@ -63,11 +63,15 @@ cc-disable-warning = $(call try-run,\
> >
> >  # gcc-min-version
> >  # Usage: cflags-$(call gcc-min-version, 70100) += -foo
> > -gcc-min-version = $(shell [ $(CONFIG_GCC_VERSION)0 -ge $(1)0 ] && echo y)
> > +
> > +# Preprend 0 to the version that is less than 10 so test-ge works.
> > +gcc-min-version = $(call test-ge, \
> > +                  $(or $(filter 1%, $(CONFIG_GCC_VERSION)), 0$(CONFIG_GCC_VERSION)), \
> > +                  $(or $(filter 1%, $1), 0$(strip $1)))
>
> Hm, this silently expects a gcc version < 20, which we should expect in
> about seven-eight years [1].   I am thinking about the possibility of
> silent (but unlikely) breaks when someone in far future uses a gcc 20
> against a kernel with this line.  Probably we should not care about
> that today, yet, right?

Yeah, I thought of it.

It depends on which of the following two will happen first.

 (a) We raise the min gcc version to 10.0.0 and remove this hack
 (b) GCC 20 is released

I am guessing (a) will occur first, so we do not need to care about (b).


If (b) happens first, we will need to add "2%".
It means that the window of supported GCC versions will get larger than 10.
Presumably, we do not want to support such a wide range of compiler
versions.


GCC 5.1 was released in 2015.
So, the current window of GCC versions is 7 years.
I hope it will not get even larger...
  

Patch

diff --git a/scripts/Makefile.compiler b/scripts/Makefile.compiler
index 20d353dcabfb..cd75f81e88ef 100644
--- a/scripts/Makefile.compiler
+++ b/scripts/Makefile.compiler
@@ -63,11 +63,15 @@  cc-disable-warning = $(call try-run,\
 
 # gcc-min-version
 # Usage: cflags-$(call gcc-min-version, 70100) += -foo
-gcc-min-version = $(shell [ $(CONFIG_GCC_VERSION)0 -ge $(1)0 ] && echo y)
+
+# Preprend 0 to the version that is less than 10 so test-ge works.
+gcc-min-version = $(call test-ge, \
+                  $(or $(filter 1%, $(CONFIG_GCC_VERSION)), 0$(CONFIG_GCC_VERSION)), \
+                  $(or $(filter 1%, $1), 0$(strip $1)))
 
 # clang-min-version
 # Usage: cflags-$(call clang-min-version, 110000) += -foo
-clang-min-version = $(shell [ $(CONFIG_CLANG_VERSION)0 -ge $(1)0 ] && echo y)
+clang-min-version = $(call test-ge, $(CONFIG_CLANG_VERSION), $1)
 
 # ld-option
 # Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y)