Skip to content

Commit df58fb4

Browse files
nathanchancegregkh
authored andcommitted
scripts/lld-version.sh: Rewrite based on upstream ld-version.sh
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 1f09af0 ("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 02aff85 ("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>
1 parent be3f603 commit df58fb4

1 file changed

Lines changed: 26 additions & 9 deletions

File tree

scripts/lld-version.sh

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,32 @@
66
# Print the linker version of `ld.lld' in a 5 or 6-digit form
77
# such as `100001' for ld.lld 10.0.1 etc.
88

9-
linker_string="$($* --version)"
9+
set -e
1010

11-
if ! ( echo $linker_string | grep -q LLD ); then
11+
# Convert the version string x.y.z to a canonical 5 or 6-digit form.
12+
get_canonical_version()
13+
{
14+
IFS=.
15+
set -- $1
16+
17+
# If the 2nd or 3rd field is missing, fill it with a zero.
18+
echo $((10000 * $1 + 100 * ${2:-0} + ${3:-0}))
19+
}
20+
21+
# Get the first line of the --version output.
22+
IFS='
23+
'
24+
set -- $(LC_ALL=C "$@" --version)
25+
26+
# Split the line on spaces.
27+
IFS=' '
28+
set -- $1
29+
30+
while [ $# -gt 1 -a "$1" != "LLD" ]; do
31+
shift
32+
done
33+
if [ "$1" = LLD ]; then
34+
echo $(get_canonical_version ${2%-*})
35+
else
1236
echo 0
13-
exit 1
1437
fi
15-
16-
VERSION=$(echo $linker_string | cut -d ' ' -f 2)
17-
MAJOR=$(echo $VERSION | cut -d . -f 1)
18-
MINOR=$(echo $VERSION | cut -d . -f 2)
19-
PATCHLEVEL=$(echo $VERSION | cut -d . -f 3)
20-
printf "%d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL

0 commit comments

Comments
 (0)