]>
Commit | Line | Data |
---|---|---|
02aff859 | 1 | #!/bin/sh |
b2441318 | 2 | # SPDX-License-Identifier: GPL-2.0 |
02aff859 MY |
3 | # |
4 | # Print the linker name and its version in a 5 or 6-digit form. | |
5 | # Also, perform the minimum version check. | |
6 | ||
7 | set -e | |
8 | ||
9 | # When you raise the minimum linker version, please update | |
10 | # Documentation/process/changes.rst as well. | |
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 | ' | |
bcbcf50f | 32 | set -- $(LC_ALL=C "$@" --version) |
02aff859 MY |
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 | |
02aff859 | 47 | else |
1f09af06 BR |
48 | while [ $# -gt 1 -a "$1" != "LLD" ]; do |
49 | shift | |
50 | done | |
51 | ||
52 | if [ "$1" = LLD ]; then | |
53 | version=$2 | |
54 | min_version=$lld_min_version | |
55 | name=LLD | |
56 | disp_name=LLD | |
57 | else | |
58 | echo "$orig_args: unknown linker" >&2 | |
59 | exit 1 | |
60 | fi | |
02aff859 MY |
61 | fi |
62 | ||
63 | # Some distributions append a package release number, as in 2.34-4.fc32 | |
64 | # Trim the hyphen and any characters that follow. | |
65 | version=${version%-*} | |
66 | ||
67 | cversion=$(get_canonical_version $version) | |
68 | min_cversion=$(get_canonical_version $min_version) | |
69 | ||
70 | if [ "$cversion" -lt "$min_cversion" ]; then | |
71 | echo >&2 "***" | |
72 | echo >&2 "*** Linker is too old." | |
73 | echo >&2 "*** Your $disp_name version: $version" | |
74 | echo >&2 "*** Minimum $disp_name version: $min_version" | |
75 | echo >&2 "***" | |
76 | exit 1 | |
77 | fi | |
78 | ||
79 | echo $name $cversion |