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