ld-version.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. # There may be something after the version, such as a distribution's package
  51. # release number (like Fedora's "2.34-4.fc32") or punctuation (like LLD briefly
  52. # added before the "compatible with GNU linkers" string), so remove everything
  53. # after just numbers and periods.
  54. version=${version%%[!0-9.]*}
  55. cversion=$(get_canonical_version $version)
  56. min_cversion=$(get_canonical_version $min_version)
  57. if [ "$cversion" -lt "$min_cversion" ]; then
  58. echo >&2 "***"
  59. echo >&2 "*** Linker is too old."
  60. echo >&2 "*** Your $disp_name version: $version"
  61. echo >&2 "*** Minimum $disp_name version: $min_version"
  62. echo >&2 "***"
  63. exit 1
  64. fi
  65. echo $name $cversion