script_test_3.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/sh
  2. # script_test_3.sh -- test PHDRS
  3. # Copyright (C) 2008-2015 Free Software Foundation, Inc.
  4. # Written by Ian Lance Taylor <iant@google.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. # This file goes with script_test_3.t, which is a linker script which
  19. # uses a PHDRS clause. We run objdump -p on a program linked with
  20. # that linker script.
  21. check()
  22. {
  23. if ! grep -q "$2" "$1"
  24. then
  25. echo "Did not find expected segment in $1:"
  26. echo " $2"
  27. echo ""
  28. echo "Actual output below:"
  29. cat "$1"
  30. exit 1
  31. fi
  32. }
  33. check_count()
  34. {
  35. if test "`grep -c "$2" "$1"`" != "$3"
  36. then
  37. echo "Did not find expected segment in $1:"
  38. echo " $2"
  39. echo ""
  40. echo "Actual output below:"
  41. cat "$1"
  42. exit 1
  43. fi
  44. }
  45. check_count script_test_3.stdout "^ INTERP" 1
  46. check_count script_test_3.stdout "^ LOAD" 3
  47. check_count script_test_3.stdout "^ DYNAMIC" 1
  48. # Make sure that the size of the INTERP segment is the same as the
  49. # size of the .interp section.
  50. section=`fgrep .interp script_test_3.stdout | grep PROGBITS`
  51. if test "$section" = ""; then
  52. echo "Did not find .interp section"
  53. echo ""
  54. echo "Actual output below:"
  55. cat script_test_3.stdout
  56. exit 1
  57. fi
  58. # Remove the brackets around the section number, since they can give
  59. # an unpredictable number of fields.
  60. section=`echo "$section" | sed -e 's/[][]*//g'`
  61. section_size=`echo "$section" | awk '{ print $6; }'`
  62. segment=`grep '^ INTERP' script_test_3.stdout`
  63. # We already checked above that we have an INTERP segment.
  64. segment_size=`echo "$segment" | awk '{ print $5; }'`
  65. # Now $section_size looks like 000013 and $segment_size looks like
  66. # 0x00013. Both numbers are in hex.
  67. section_size=`echo "$section_size" | sed -e 's/^0*//'`
  68. segment_size=`echo "$segment_size" | sed -e 's/^0x//' -e 's/^0*//'`
  69. if test "$section_size" != "$segment_size"; then
  70. echo ".interp size $section_size != PT_INTERP size $segment_size"
  71. exit 1
  72. fi
  73. # At least one PT_LOAD segment should have an alignment >= 0x100000.
  74. found=no
  75. for a in `grep LOAD script_test_3.stdout | sed -e 's/^.* 0x/0x/'`; do
  76. script="BEGIN { if ($a >= 0x100000) { print \"true\" } else { print \"false\" } }"
  77. x=`awk "$script" < /dev/null`
  78. if test "$x" = "true"; then
  79. found=yes
  80. fi
  81. done
  82. if test "$found" = "no"; then
  83. echo "no LOAD segment has required alignment"
  84. exit 1
  85. fi
  86. exit 0