aarch64_tlsdesc.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/sh
  2. # aarch64_tlsdesc.sh -- test R_AARCH64_TLSDESC_* relocations.
  3. # Copyright (C) 2017-2022 Free Software Foundation, Inc.
  4. # Written by Igor Kudrin <ikudrin@accesssoftek.com>.
  5. # This file is part of gold.
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or
  9. # (at your option) any later version.
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  17. # MA 02110-1301, USA.
  18. file=aarch64_tlsdesc.stdout
  19. get_address_by_reloc()
  20. {
  21. var=$1
  22. pattern="\<R_AARCH64_TLSDESC\>"
  23. found=$(grep "$pattern" "$file")
  24. if test -z "$found"; then
  25. echo "GOT entry for a TLS symbol is not found in file $file."
  26. echo "Search pattern: $pattern"
  27. echo ""
  28. echo "Actual output below:"
  29. cat "$file"
  30. exit 1
  31. fi
  32. eval $var="0x0$(echo $found | awk -F'[: ]' '{ print $1 }')"
  33. }
  34. check_adrp()
  35. {
  36. pattern="\<adrp[[:space:]]\+x0, 0\>"
  37. found=$(grep "$pattern" "$file")
  38. if test -z "$found"; then
  39. echo "An ADRP immediate is supposed to be 0"
  40. echo "Search pattern: $pattern"
  41. echo ""
  42. echo "Actual output below:"
  43. cat "$file"
  44. exit 1
  45. fi
  46. }
  47. get_address_from_ldr()
  48. {
  49. var=$1
  50. pattern="\<ldr[[:space:]]\+x1\>"
  51. found=$(grep "$pattern" "$file")
  52. if test -z "$found"; then
  53. echo "An LDR instruction is not found in file $file."
  54. echo "Search pattern: $pattern"
  55. echo ""
  56. echo "Actual output below:"
  57. cat "$file"
  58. exit 1
  59. fi
  60. eval $var="$(echo $found | awk -F'[#\\]]' '{ print $2 }')"
  61. }
  62. get_address_from_add()
  63. {
  64. var=$1
  65. pattern="\<add[[:space:]]\+x0\>"
  66. found=$(grep "$pattern" "$file")
  67. if test -z "$found"; then
  68. echo "An ADD instruction is not found in file $file."
  69. echo "Search pattern: $pattern"
  70. echo ""
  71. echo "Actual output below:"
  72. cat "$file"
  73. exit 1
  74. fi
  75. eval $var="$(echo $found | awk -F'#' '{ print $2 }')"
  76. }
  77. check_adrp
  78. get_address_by_reloc address_by_reloc
  79. get_address_from_ldr address_from_ldr
  80. get_address_from_add address_from_add
  81. if test $(($address_by_reloc)) -ne $(($address_from_ldr)); then
  82. echo "The address in LDR instruction is wrong."
  83. echo ""
  84. echo "Actual output below:"
  85. cat "$file"
  86. exit 1
  87. fi
  88. if test $(($address_by_reloc)) -ne $(($address_from_add)); then
  89. echo "The address in ADD instruction is wrong."
  90. echo ""
  91. echo "Actual output below:"
  92. cat "$file"
  93. exit 1
  94. fi
  95. exit 0