Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # SPDX-License-Identifier: GPL-2.0
0003 #
0004 # Print the linker name and its version in a 5 or 6-digit form.
0005 # Also, perform the minimum version check.
0006 
0007 set -e
0008 
0009 # Convert the version string x.y.z to a canonical 5 or 6-digit form.
0010 get_canonical_version()
0011 {
0012         IFS=.
0013         set -- $1
0014 
0015         # If the 2nd or 3rd field is missing, fill it with a zero.
0016         #
0017         # The 4th field, if present, is ignored.
0018         # This occurs in development snapshots as in 2.35.1.20201116
0019         echo $((10000 * $1 + 100 * ${2:-0} + ${3:-0}))
0020 }
0021 
0022 orig_args="$@"
0023 
0024 # Get the first line of the --version output.
0025 IFS='
0026 '
0027 set -- $(LC_ALL=C "$@" --version)
0028 
0029 # Split the line on spaces.
0030 IFS=' '
0031 set -- $1
0032 
0033 min_tool_version=$(dirname $0)/min-tool-version.sh
0034 
0035 if [ "$1" = GNU -a "$2" = ld ]; then
0036         shift $(($# - 1))
0037         version=$1
0038         min_version=$($min_tool_version binutils)
0039         name=BFD
0040         disp_name="GNU ld"
0041 elif [ "$1" = GNU -a "$2" = gold ]; then
0042         echo "gold linker is not supported as it is not capable of linking the kernel proper." >&2
0043         exit 1
0044 else
0045         while [ $# -gt 1 -a "$1" != "LLD" ]; do
0046                 shift
0047         done
0048 
0049         if [ "$1" = LLD ]; then
0050                 version=$2
0051                 min_version=$($min_tool_version llvm)
0052                 name=LLD
0053                 disp_name=LLD
0054         else
0055                 echo "$orig_args: unknown linker" >&2
0056                 exit 1
0057         fi
0058 fi
0059 
0060 # Some distributions append a package release number, as in 2.34-4.fc32
0061 # Trim the hyphen and any characters that follow.
0062 version=${version%-*}
0063 
0064 cversion=$(get_canonical_version $version)
0065 min_cversion=$(get_canonical_version $min_version)
0066 
0067 if [ "$cversion" -lt "$min_cversion" ]; then
0068         echo >&2 "***"
0069         echo >&2 "*** Linker is too old."
0070         echo >&2 "***   Your $disp_name version:    $version"
0071         echo >&2 "***   Minimum $disp_name version: $min_version"
0072         echo >&2 "***"
0073         exit 1
0074 fi
0075 
0076 echo $name $cversion