Unify the two scripts/ld-version.sh and scripts/lld-version.sh, and check the minimum linker version like scripts/cc-version.sh did. I tested this script for some corner cases reported in the past: - GNU ld version 2.25-15.fc23 as reported by commit 8083013fc320 ("ld-version: Fix it on Fedora") - GNU ld (GNU Binutils) 2.20.1.20100303 as reported by commit 0d61ed17dd30 ("ld-version: Drop the 4th and 5th version components") This script show an error message if the linker is too old: $ make LD=ld.lld-9 SYNC include/config/auto.conf *** *** Linker is too old. *** Your LLD version: 9.0.1 *** Minimum LLD version: 10.0.1 *** scripts/Kconfig.include:50: Sorry, this linker is not supported. make[2]: *** [scripts/kconfig/Makefile:71: syncconfig] Error 1 make[1]: *** [Makefile:600: syncconfig] Error 2 make: *** [Makefile:708: include/config/auto.conf] Error 2 I also moved the check for gold to this script, so gold is still rejected: $ make LD=gold SYNC include/config/auto.conf gold linker is not supported as it is not capable of linking the kernel proper. scripts/Kconfig.include:50: Sorry, this linker is not supported. make[2]: *** [scripts/kconfig/Makefile:71: syncconfig] Error 1 make[1]: *** [Makefile:600: syncconfig] Error 2 make: *** [Makefile:708: include/config/auto.conf] Error 2 Thanks to David Laight for suggesting shell script improvements.
Showing the changes to scripts (3 of 5 files). Show all
Unified · Split
| @@ -45,8 +45,11 @@ $(error-if,$(success,test -z "$(cc-info)"),Sorry$(comma) this compiler is not su · 44 unmodified lines | |||
| 45 | cc-name := $(shell,set -- $(cc-info) && echo $1) | 45 | cc-name := $(shell,set -- $(cc-info) && echo $1) |
| 46 | cc-version := $(shell,set -- $(cc-info) && echo $2) | 46 | cc-version := $(shell,set -- $(cc-info) && echo $2) |
| 47 | 47 | ||
| 48 | # Fail if the linker is gold as it's not capable of linking the kernel proper | 48 | # Get the linker name, version, and error out if it is not supported. |
| 49 | $(error-if,$(success, $(LD) -v | grep -q gold), gold linker '$(LD)' not supported) | 49 | ld-info := $(shell,$(srctree)/scripts/ld-version.sh $(LD)) |
| 50 | $(error-if,$(success,test -z "$(ld-info)"),Sorry$(comma) this linker is not supported.) | ||
| 51 | ld-name := $(shell,set -- $(ld-info) && echo $1) | ||
| 52 | ld-version := $(shell,set -- $(ld-info) && echo $2) | ||
| 50 | 53 | ||
| 51 | # machine bit flags | 54 | # machine bit flags |
| 52 | # $(m32-flag): -m32 if the compiler supports it, or an empty string otherwise. | 55 | # $(m32-flag): -m32 if the compiler supports it, or an empty string otherwise. |
| @@ -1,11 +1,73 @@ | |||
| 1 | #!/usr/bin/awk -f | 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: GPL-2.0 | 2 | # SPDX-License-Identifier: GPL-2.0 |
| 3 | # extract linker version number from stdin and turn into single number | 3 | # |
| 4 | { | 4 | # Print the linker name and its version in a 5 or 6-digit form. |
| 5 | gsub(".*\\)", ""); | 5 | # Also, perform the minimum version check. |
| 6 | gsub(".*version ", ""); | 6 | |
| 7 | gsub("-.*", ""); | 7 | set -e |
| 8 | split($1,a, "."); | 8 | |
| 9 | print a[1]*10000 + a[2]*100 + a[3]; | 9 | # When you raise the minimum linker version, please update |
| 10 | exit | 10 | # Documentation/process/changes.rst as well. |
| 11 | } | 11 | bfd_min_version=2.23.0 |
| 12 | lld_min_version=10.0.1 | ||
| 13 | |||
| 14 | # Convert the version string x.y.z to a canonical 5 or 6-digit form. | ||
| 15 | get_canonical_version() | ||
| 16 | { | ||
| 17 | IFS=. | ||
| 18 | set -- $1 | ||
| 19 | |||
| 20 | # If the 2nd or 3rd field is missing, fill it with a zero. | ||
| 21 | # | ||
| 22 | # The 4th field, if present, is ignored. | ||
| 23 | # This occurs in development snapshots as in 2.35.1.20201116 | ||
| 24 | echo $((10000 * $1 + 100 * ${2:-0} + ${3:-0})) | ||
| 25 | } | ||
| 26 | |||
| 27 | orig_args="$@" | ||
| 28 | |||
| 29 | # Get the first line of the --version output. | ||
| 30 | IFS=' | ||
| 31 | ' | ||
| 32 | set -- $("$@" --version) | ||
| 33 | |||
| 34 | # Split the line on spaces. | ||
| 35 | IFS=' ' | ||
| 36 | set -- $1 | ||
| 37 | |||
| 38 | if [ "$1" = GNU -a "$2" = ld ]; then | ||
| 39 | shift $(($# - 1)) | ||
| 40 | version=$1 | ||
| 41 | min_version=$bfd_min_version | ||
| 42 | name=BFD | ||
| 43 | disp_name="GNU ld" | ||
| 44 | elif [ "$1" = GNU -a "$2" = gold ]; then | ||
| 45 | echo "gold linker is not supported as it is not capable of linking the kernel proper." >&2 | ||
| 46 | exit 1 | ||
| 47 | elif [ "$1" = LLD ]; then | ||
| 48 | version=$2 | ||
| 49 | min_version=$lld_min_version | ||
| 50 | name=LLD | ||
| 51 | disp_name=LLD | ||
| 52 | else | ||
| 53 | echo "$orig_args: unknown linker" >&2 | ||
| 54 | exit 1 | ||
| 55 | fi | ||
| 56 | |||
| 57 | # Some distributions append a package release number, as in 2.34-4.fc32 | ||
| 58 | # Trim the hyphen and any characters that follow. | ||
| 59 | version=${version%-*} | ||
| 60 | |||
| 61 | cversion=$(get_canonical_version $version) | ||
| 62 | min_cversion=$(get_canonical_version $min_version) | ||
| 63 | |||
| 64 | if [ "$cversion" -lt "$min_cversion" ]; then | ||
| 65 | echo >&2 "***" | ||
| 66 | echo >&2 "*** Linker is too old." | ||
| 67 | echo >&2 "*** Your $disp_name version: $version" | ||
| 68 | echo >&2 "*** Minimum $disp_name version: $min_version" | ||
| 69 | echo >&2 "***" | ||
| 70 | exit 1 | ||
| 71 | fi | ||
| 72 | |||
| 73 | echo $name $cversion | ||
| @@ -1,20 +0,0 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | # SPDX-License-Identifier: GPL-2.0 | ||
| 3 | # | ||
| 4 | # Usage: $ ./scripts/lld-version.sh ld.lld | ||
| 5 | # | ||
| 6 | # Print the linker version of `ld.lld' in a 5 or 6-digit form | ||
| 7 | # such as `100001' for ld.lld 10.0.1 etc. | ||
| 8 | |||
| 9 | linker_string="$($* --version)" | ||
| 10 | |||
| 11 | if ! ( echo $linker_string | grep -q LLD ); then | ||
| 12 | echo 0 | ||
| 13 | exit 1 | ||
| 14 | 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 | ||