ld-version.sh 1.7 KB

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