script_test_14.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/sh
  2. # script_test_14.sh -- test SORT_BY_INIT_PRIORITY
  3. # Copyright (C) 2016-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="script_test_14.stdout"
  19. check()
  20. {
  21. section=$1
  22. pattern=$2
  23. found=`fgrep "Contents of section $section:" -A1 $file | tail -n 1`
  24. if test -z "$found"; then
  25. echo "Section \"$section\" not found in file $file"
  26. echo ""
  27. echo "Actual output below:"
  28. cat "$file"
  29. exit 1
  30. fi
  31. match_pattern=`echo "$found" | grep -e "$pattern"`
  32. if test -z "$match_pattern"; then
  33. echo "Expected pattern was not found in section \"$section\":"
  34. echo " $pattern"
  35. echo ""
  36. echo "Actual output below:"
  37. cat "$file"
  38. exit 1
  39. fi
  40. }
  41. # Sort order for .init_array:
  42. # * .init_array -- Doesn't have a numeric part, compared with others as strings.
  43. # * .init_array.101 -- The numeric part is less than in the two others.
  44. # * .init_array.0103 -- These names have numeric parts with the same value,
  45. # * .init_array.103 / so they are compared as strings.
  46. check ".init_array" "\<00010304\b"
  47. # Sort order for .fini_array, the same consideration as for .init_array:
  48. # * .fini_array
  49. # * .fini_array.101
  50. # * .fini_array.0103
  51. # * .fini_array.103
  52. check ".fini_array" "\<f0f1f3f4\b"
  53. # Sort order for .ctors:
  54. # * .ctors -- Doesn't have a numeric part, compared with others as strings
  55. # * .ctors.0103 -- The numeric parts have the same value, which is greater than
  56. # * .ctors.103 / in the last section's name. This pair is compared as strings.
  57. # * .ctors.101 -- The least numeric part among all sections which contain them.
  58. check ".ctors" "\<c0c3c4c1\b"
  59. # Sort order for .dtors, the same considerations as for .ctors:
  60. # * .dtors
  61. # * .dtors.0103
  62. # * .dtors.103
  63. # * .dtors.101
  64. check ".dtors" "\<d0d3d4d1\b"
  65. # Sort order for .sec, just sort as strings, because it's not the reserved name:
  66. # * .sec
  67. # * .sec.0103
  68. # * .sec.101
  69. # * .sec.103
  70. check ".sec" "\<a0a3a1a4\b"