02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 1) #!/bin/sh
b24413180f560 (Greg Kroah-Hartman 2017-11-01 15:07:57 +0100 2) # SPDX-License-Identifier: GPL-2.0
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 3) #
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 4) # Print the linker name and its version in a 5 or 6-digit form.
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 5) # Also, perform the minimum version check.
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 6)
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 7) set -e
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 8)
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 9) # Convert the version string x.y.z to a canonical 5 or 6-digit form.
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 10) get_canonical_version()
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 11) {
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 12) IFS=.
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 13) set -- $1
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 14)
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 15) # If the 2nd or 3rd field is missing, fill it with a zero.
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 16) #
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 17) # The 4th field, if present, is ignored.
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 18) # This occurs in development snapshots as in 2.35.1.20201116
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 19) echo $((10000 * $1 + 100 * ${2:-0} + ${3:-0}))
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 20) }
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 21)
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 22) orig_args="$@"
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 23)
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 24) # Get the first line of the --version output.
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 25) IFS='
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 26) '
bcbcf50f52184 (Masahiro Yamada 2021-03-13 04:38:14 +0900 27) set -- $(LC_ALL=C "$@" --version)
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 28)
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 29) # Split the line on spaces.
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 30) IFS=' '
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 31) set -- $1
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 32)
e24b3ffcf4216 (Masahiro Yamada 2021-03-16 01:12:55 +0900 33) min_tool_version=$(dirname $0)/min-tool-version.sh
e24b3ffcf4216 (Masahiro Yamada 2021-03-16 01:12:55 +0900 34)
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 35) if [ "$1" = GNU -a "$2" = ld ]; then
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 36) shift $(($# - 1))
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 37) version=$1
e24b3ffcf4216 (Masahiro Yamada 2021-03-16 01:12:55 +0900 38) min_version=$($min_tool_version binutils)
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 39) name=BFD
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 40) disp_name="GNU ld"
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 41) elif [ "$1" = GNU -a "$2" = gold ]; then
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 42) echo "gold linker is not supported as it is not capable of linking the kernel proper." >&2
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 43) exit 1
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 44) else
1f09af062556f (Bernhard Rosenkränzer 2021-03-02 23:12:11 +0100 45) while [ $# -gt 1 -a "$1" != "LLD" ]; do
1f09af062556f (Bernhard Rosenkränzer 2021-03-02 23:12:11 +0100 46) shift
1f09af062556f (Bernhard Rosenkränzer 2021-03-02 23:12:11 +0100 47) done
1f09af062556f (Bernhard Rosenkränzer 2021-03-02 23:12:11 +0100 48)
1f09af062556f (Bernhard Rosenkränzer 2021-03-02 23:12:11 +0100 49) if [ "$1" = LLD ]; then
1f09af062556f (Bernhard Rosenkränzer 2021-03-02 23:12:11 +0100 50) version=$2
e24b3ffcf4216 (Masahiro Yamada 2021-03-16 01:12:55 +0900 51) min_version=$($min_tool_version llvm)
1f09af062556f (Bernhard Rosenkränzer 2021-03-02 23:12:11 +0100 52) name=LLD
1f09af062556f (Bernhard Rosenkränzer 2021-03-02 23:12:11 +0100 53) disp_name=LLD
1f09af062556f (Bernhard Rosenkränzer 2021-03-02 23:12:11 +0100 54) else
1f09af062556f (Bernhard Rosenkränzer 2021-03-02 23:12:11 +0100 55) echo "$orig_args: unknown linker" >&2
1f09af062556f (Bernhard Rosenkränzer 2021-03-02 23:12:11 +0100 56) exit 1
1f09af062556f (Bernhard Rosenkränzer 2021-03-02 23:12:11 +0100 57) fi
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 58) fi
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 59)
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 60) # Some distributions append a package release number, as in 2.34-4.fc32
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 61) # Trim the hyphen and any characters that follow.
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 62) version=${version%-*}
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 63)
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 64) cversion=$(get_canonical_version $version)
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 65) min_cversion=$(get_canonical_version $min_version)
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 66)
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 67) if [ "$cversion" -lt "$min_cversion" ]; then
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 68) echo >&2 "***"
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 69) echo >&2 "*** Linker is too old."
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 70) echo >&2 "*** Your $disp_name version: $version"
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 71) echo >&2 "*** Minimum $disp_name version: $min_version"
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 72) echo >&2 "***"
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 73) exit 1
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 74) fi
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 75)
02aff85922043 (Masahiro Yamada 2021-02-16 12:10:04 +0900 76) echo $name $cversion