All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 5.10] scripts/lld-version.sh: Rewrite based on upstream ld-version.sh
@ 2021-11-15 16:43 Nathan Chancellor
  2021-11-15 17:50 ` Nick Desaulniers
  2021-11-19 14:34 ` Patch "scripts/lld-version.sh: Rewrite based on upstream ld-version.sh" has been added to the 5.10-stable tree gregkh
  0 siblings, 2 replies; 4+ messages in thread
From: Nathan Chancellor @ 2021-11-15 16:43 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Sasha Levin
  Cc: Nick Desaulniers, stable, llvm, Nathan Chancellor

This patch is for linux-5.10.y only.

When scripts/lld-version.sh was initially written, it did not account
for the LLD_VENDOR cmake flag, which changes the output of ld.lld's
--version flag slightly.

Without LLD_VENDOR:

$ ld.lld --version
LLD 14.0.0 (compatible with GNU linkers)

With LLD_VENDOR:

$ ld.lld --version
Debian LLD 14.0.0 (compatible with GNU linkers)

As a result, CONFIG_LLD_VERSION is messed up and configuration values
that are dependent on it cannot be selected:

scripts/lld-version.sh: 20: printf: LLD: expected numeric value
scripts/lld-version.sh: 20: printf: LLD: expected numeric value
scripts/lld-version.sh: 20: printf: LLD: expected numeric value
init/Kconfig:52:warning: 'LLD_VERSION': number is invalid
.config:11:warning: symbol value '00000' invalid for LLD_VERSION
.config:8800:warning: override: CPU_BIG_ENDIAN changes choice state

This was fixed upstream by commit 1f09af062556 ("kbuild: Fix
ld-version.sh script if LLD was built with LLD_VENDOR") in 5.12 but that
was done to ld-version.sh after it was massively rewritten in
commit 02aff8592204 ("kbuild: check the minimum linker version in
Kconfig").

To avoid bringing in that change plus its prerequisites and fixes, just
modify lld-version.sh to make it similar to the upstream ld-version.sh,
which handles ld.lld with or without LLD_VENDOR and ld.bfd without any
errors.

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---

Our CI caught this error with newer versions of Debian's ld.lld, which
added LLD_VENDOR it seems:

https://github.com/ClangBuiltLinux/continuous-integration2/runs/4206343929?check_suite_focus=true

A similar change was done by me for Android, where it has seen no
issues:

https://android-review.googlesource.com/c/kernel/common/+/1744324

I believe this is a safer change than backporting the fixes from
upstream but if you guys feel otherwise, I can do so. This is only
needed in 5.10 as CONFIG_LLD_VERSION does not exist in 5.4 and it was
fixed in 5.12 upstream.

 scripts/lld-version.sh | 35 ++++++++++++++++++++++++++---------
 1 file changed, 26 insertions(+), 9 deletions(-)

diff --git a/scripts/lld-version.sh b/scripts/lld-version.sh
index d70edb4d8a4f..f1eeee450a23 100755
--- a/scripts/lld-version.sh
+++ b/scripts/lld-version.sh
@@ -6,15 +6,32 @@
 # Print the linker version of `ld.lld' in a 5 or 6-digit form
 # such as `100001' for ld.lld 10.0.1 etc.
 
-linker_string="$($* --version)"
+set -e
 
-if ! ( echo $linker_string | grep -q LLD ); then
+# Convert the version string x.y.z to a canonical 5 or 6-digit form.
+get_canonical_version()
+{
+	IFS=.
+	set -- $1
+
+	# If the 2nd or 3rd field is missing, fill it with a zero.
+	echo $((10000 * $1 + 100 * ${2:-0} + ${3:-0}))
+}
+
+# Get the first line of the --version output.
+IFS='
+'
+set -- $(LC_ALL=C "$@" --version)
+
+# Split the line on spaces.
+IFS=' '
+set -- $1
+
+while [ $# -gt 1 -a "$1" != "LLD" ]; do
+	shift
+done
+if [ "$1" = LLD ]; then
+	echo $(get_canonical_version ${2%-*})
+else
 	echo 0
-	exit 1
 fi
-
-VERSION=$(echo $linker_string | cut -d ' ' -f 2)
-MAJOR=$(echo $VERSION | cut -d . -f 1)
-MINOR=$(echo $VERSION | cut -d . -f 2)
-PATCHLEVEL=$(echo $VERSION | cut -d . -f 3)
-printf "%d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL

base-commit: bd816c278316f20a5575debc64dde4422229a880
-- 
2.34.0.rc0


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

* Re: [PATCH 5.10] scripts/lld-version.sh: Rewrite based on upstream ld-version.sh
  2021-11-15 16:43 [PATCH 5.10] scripts/lld-version.sh: Rewrite based on upstream ld-version.sh Nathan Chancellor
@ 2021-11-15 17:50 ` Nick Desaulniers
  2021-11-19 14:28   ` Greg Kroah-Hartman
  2021-11-19 14:34 ` Patch "scripts/lld-version.sh: Rewrite based on upstream ld-version.sh" has been added to the 5.10-stable tree gregkh
  1 sibling, 1 reply; 4+ messages in thread
From: Nick Desaulniers @ 2021-11-15 17:50 UTC (permalink / raw)
  To: Nathan Chancellor; +Cc: Greg Kroah-Hartman, Sasha Levin, stable, llvm

On Mon, Nov 15, 2021 at 8:46 AM Nathan Chancellor <nathan@kernel.org> wrote:
>
> This patch is for linux-5.10.y only.
>
> When scripts/lld-version.sh was initially written, it did not account
> for the LLD_VENDOR cmake flag, which changes the output of ld.lld's
> --version flag slightly.
>
> Without LLD_VENDOR:
>
> $ ld.lld --version
> LLD 14.0.0 (compatible with GNU linkers)
>
> With LLD_VENDOR:
>
> $ ld.lld --version
> Debian LLD 14.0.0 (compatible with GNU linkers)
>
> As a result, CONFIG_LLD_VERSION is messed up and configuration values
> that are dependent on it cannot be selected:
>
> scripts/lld-version.sh: 20: printf: LLD: expected numeric value
> scripts/lld-version.sh: 20: printf: LLD: expected numeric value
> scripts/lld-version.sh: 20: printf: LLD: expected numeric value
> init/Kconfig:52:warning: 'LLD_VERSION': number is invalid
> .config:11:warning: symbol value '00000' invalid for LLD_VERSION
> .config:8800:warning: override: CPU_BIG_ENDIAN changes choice state
>
> This was fixed upstream by commit 1f09af062556 ("kbuild: Fix
> ld-version.sh script if LLD was built with LLD_VENDOR") in 5.12 but that
> was done to ld-version.sh after it was massively rewritten in
> commit 02aff8592204 ("kbuild: check the minimum linker version in
> Kconfig").
>
> To avoid bringing in that change plus its prerequisites and fixes, just
> modify lld-version.sh to make it similar to the upstream ld-version.sh,
> which handles ld.lld with or without LLD_VENDOR and ld.bfd without any
> errors.
>
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>

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

> ---
>
> Our CI caught this error with newer versions of Debian's ld.lld, which
> added LLD_VENDOR it seems:
>
> https://github.com/ClangBuiltLinux/continuous-integration2/runs/4206343929?check_suite_focus=true
>
> A similar change was done by me for Android, where it has seen no
> issues:
>
> https://android-review.googlesource.com/c/kernel/common/+/1744324
>
> I believe this is a safer change than backporting the fixes from
> upstream but if you guys feel otherwise, I can do so. This is only
> needed in 5.10 as CONFIG_LLD_VERSION does not exist in 5.4 and it was
> fixed in 5.12 upstream.
>
>  scripts/lld-version.sh | 35 ++++++++++++++++++++++++++---------
>  1 file changed, 26 insertions(+), 9 deletions(-)
>
> diff --git a/scripts/lld-version.sh b/scripts/lld-version.sh
> index d70edb4d8a4f..f1eeee450a23 100755
> --- a/scripts/lld-version.sh
> +++ b/scripts/lld-version.sh
> @@ -6,15 +6,32 @@
>  # Print the linker version of `ld.lld' in a 5 or 6-digit form
>  # such as `100001' for ld.lld 10.0.1 etc.
>
> -linker_string="$($* --version)"
> +set -e
>
> -if ! ( echo $linker_string | grep -q LLD ); then
> +# Convert the version string x.y.z to a canonical 5 or 6-digit form.
> +get_canonical_version()
> +{
> +       IFS=.
> +       set -- $1
> +
> +       # If the 2nd or 3rd field is missing, fill it with a zero.
> +       echo $((10000 * $1 + 100 * ${2:-0} + ${3:-0}))
> +}
> +
> +# Get the first line of the --version output.
> +IFS='
> +'
> +set -- $(LC_ALL=C "$@" --version)
> +
> +# Split the line on spaces.
> +IFS=' '
> +set -- $1
> +
> +while [ $# -gt 1 -a "$1" != "LLD" ]; do
> +       shift
> +done
> +if [ "$1" = LLD ]; then
> +       echo $(get_canonical_version ${2%-*})
> +else
>         echo 0
> -       exit 1
>  fi
> -
> -VERSION=$(echo $linker_string | cut -d ' ' -f 2)
> -MAJOR=$(echo $VERSION | cut -d . -f 1)
> -MINOR=$(echo $VERSION | cut -d . -f 2)
> -PATCHLEVEL=$(echo $VERSION | cut -d . -f 3)
> -printf "%d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL
>
> base-commit: bd816c278316f20a5575debc64dde4422229a880
> --
> 2.34.0.rc0
>


-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH 5.10] scripts/lld-version.sh: Rewrite based on upstream ld-version.sh
  2021-11-15 17:50 ` Nick Desaulniers
@ 2021-11-19 14:28   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2021-11-19 14:28 UTC (permalink / raw)
  To: Nick Desaulniers; +Cc: Nathan Chancellor, Sasha Levin, stable, llvm

On Mon, Nov 15, 2021 at 09:50:01AM -0800, Nick Desaulniers wrote:
> On Mon, Nov 15, 2021 at 8:46 AM Nathan Chancellor <nathan@kernel.org> wrote:
> >
> > This patch is for linux-5.10.y only.
> >
> > When scripts/lld-version.sh was initially written, it did not account
> > for the LLD_VENDOR cmake flag, which changes the output of ld.lld's
> > --version flag slightly.
> >
> > Without LLD_VENDOR:
> >
> > $ ld.lld --version
> > LLD 14.0.0 (compatible with GNU linkers)
> >
> > With LLD_VENDOR:
> >
> > $ ld.lld --version
> > Debian LLD 14.0.0 (compatible with GNU linkers)
> >
> > As a result, CONFIG_LLD_VERSION is messed up and configuration values
> > that are dependent on it cannot be selected:
> >
> > scripts/lld-version.sh: 20: printf: LLD: expected numeric value
> > scripts/lld-version.sh: 20: printf: LLD: expected numeric value
> > scripts/lld-version.sh: 20: printf: LLD: expected numeric value
> > init/Kconfig:52:warning: 'LLD_VERSION': number is invalid
> > .config:11:warning: symbol value '00000' invalid for LLD_VERSION
> > .config:8800:warning: override: CPU_BIG_ENDIAN changes choice state
> >
> > This was fixed upstream by commit 1f09af062556 ("kbuild: Fix
> > ld-version.sh script if LLD was built with LLD_VENDOR") in 5.12 but that
> > was done to ld-version.sh after it was massively rewritten in
> > commit 02aff8592204 ("kbuild: check the minimum linker version in
> > Kconfig").
> >
> > To avoid bringing in that change plus its prerequisites and fixes, just
> > modify lld-version.sh to make it similar to the upstream ld-version.sh,
> > which handles ld.lld with or without LLD_VENDOR and ld.bfd without any
> > errors.
> >
> > Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> 
> Thanks for the fix.
> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> Tested-by: Nick Desaulniers <ndesaulniers@google.com>

Now queued up, thanks.

greg k-h

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

* Patch "scripts/lld-version.sh: Rewrite based on upstream ld-version.sh" has been added to the 5.10-stable tree
  2021-11-15 16:43 [PATCH 5.10] scripts/lld-version.sh: Rewrite based on upstream ld-version.sh Nathan Chancellor
  2021-11-15 17:50 ` Nick Desaulniers
@ 2021-11-19 14:34 ` gregkh
  1 sibling, 0 replies; 4+ messages in thread
From: gregkh @ 2021-11-19 14:34 UTC (permalink / raw)
  To: gregkh, llvm, nathan, ndesaulniers, sashal; +Cc: stable-commits


This is a note to let you know that I've just added the patch titled

    scripts/lld-version.sh: Rewrite based on upstream ld-version.sh

to the 5.10-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     scripts-lld-version.sh-rewrite-based-on-upstream-ld-version.sh.patch
and it can be found in the queue-5.10 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@vger.kernel.org> know about it.


From nathan@kernel.org  Fri Nov 19 15:27:39 2021
From: Nathan Chancellor <nathan@kernel.org>
Date: Mon, 15 Nov 2021 09:43:23 -0700
Subject: scripts/lld-version.sh: Rewrite based on upstream ld-version.sh
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Sasha Levin <sashal@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>, stable@vger.kernel.org, llvm@lists.linux.dev, Nathan Chancellor <nathan@kernel.org>
Message-ID: <20211115164322.560965-1-nathan@kernel.org>

From: Nathan Chancellor <nathan@kernel.org>

This patch is for linux-5.10.y only.

When scripts/lld-version.sh was initially written, it did not account
for the LLD_VENDOR cmake flag, which changes the output of ld.lld's
--version flag slightly.

Without LLD_VENDOR:

$ ld.lld --version
LLD 14.0.0 (compatible with GNU linkers)

With LLD_VENDOR:

$ ld.lld --version
Debian LLD 14.0.0 (compatible with GNU linkers)

As a result, CONFIG_LLD_VERSION is messed up and configuration values
that are dependent on it cannot be selected:

scripts/lld-version.sh: 20: printf: LLD: expected numeric value
scripts/lld-version.sh: 20: printf: LLD: expected numeric value
scripts/lld-version.sh: 20: printf: LLD: expected numeric value
init/Kconfig:52:warning: 'LLD_VERSION': number is invalid
.config:11:warning: symbol value '00000' invalid for LLD_VERSION
.config:8800:warning: override: CPU_BIG_ENDIAN changes choice state

This was fixed upstream by commit 1f09af062556 ("kbuild: Fix
ld-version.sh script if LLD was built with LLD_VENDOR") in 5.12 but that
was done to ld-version.sh after it was massively rewritten in
commit 02aff8592204 ("kbuild: check the minimum linker version in
Kconfig").

To avoid bringing in that change plus its prerequisites and fixes, just
modify lld-version.sh to make it similar to the upstream ld-version.sh,
which handles ld.lld with or without LLD_VENDOR and ld.bfd without any
errors.

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 scripts/lld-version.sh |   35 ++++++++++++++++++++++++++---------
 1 file changed, 26 insertions(+), 9 deletions(-)

--- a/scripts/lld-version.sh
+++ b/scripts/lld-version.sh
@@ -6,15 +6,32 @@
 # Print the linker version of `ld.lld' in a 5 or 6-digit form
 # such as `100001' for ld.lld 10.0.1 etc.
 
-linker_string="$($* --version)"
+set -e
 
-if ! ( echo $linker_string | grep -q LLD ); then
+# Convert the version string x.y.z to a canonical 5 or 6-digit form.
+get_canonical_version()
+{
+	IFS=.
+	set -- $1
+
+	# If the 2nd or 3rd field is missing, fill it with a zero.
+	echo $((10000 * $1 + 100 * ${2:-0} + ${3:-0}))
+}
+
+# Get the first line of the --version output.
+IFS='
+'
+set -- $(LC_ALL=C "$@" --version)
+
+# Split the line on spaces.
+IFS=' '
+set -- $1
+
+while [ $# -gt 1 -a "$1" != "LLD" ]; do
+	shift
+done
+if [ "$1" = LLD ]; then
+	echo $(get_canonical_version ${2%-*})
+else
 	echo 0
-	exit 1
 fi
-
-VERSION=$(echo $linker_string | cut -d ' ' -f 2)
-MAJOR=$(echo $VERSION | cut -d . -f 1)
-MINOR=$(echo $VERSION | cut -d . -f 2)
-PATCHLEVEL=$(echo $VERSION | cut -d . -f 3)
-printf "%d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL


Patches currently in stable-queue which might be from nathan@kernel.org are

queue-5.10/fortify-explicitly-disable-clang-support.patch
queue-5.10/scripts-lld-version.sh-rewrite-based-on-upstream-ld-version.sh.patch
queue-5.10/arm64-vdso32-suppress-error-message-for-make-mrproper.patch

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

end of thread, other threads:[~2021-11-19 14:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-15 16:43 [PATCH 5.10] scripts/lld-version.sh: Rewrite based on upstream ld-version.sh Nathan Chancellor
2021-11-15 17:50 ` Nick Desaulniers
2021-11-19 14:28   ` Greg Kroah-Hartman
2021-11-19 14:34 ` Patch "scripts/lld-version.sh: Rewrite based on upstream ld-version.sh" has been added to the 5.10-stable tree gregkh

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.