text_section_grouping.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/sh
  2. # text_section_grouping.sh -- test
  3. # Copyright (C) 2012-2022 Free Software Foundation, Inc.
  4. # Written by Sriraman Tallam <tmsriram@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. # The goal of this program is to verify if .text sections are grouped
  19. # according to prefix. .text.unlikely, .text.startup and .text.hot should
  20. # be grouped and placed together.
  21. # Also check if the functions do not get grouped with option --no-text-reorder.
  22. set -e
  23. check()
  24. {
  25. awk "
  26. BEGIN { saw1 = 0; saw2 = 0; err = 0; }
  27. /.*$2\$/ { saw1 = 1; }
  28. /.*$3\$/ {
  29. saw2 = 1;
  30. if (!saw1)
  31. {
  32. printf \"layout of $2 and $3 is not right\\n\";
  33. err = 1;
  34. exit 1;
  35. }
  36. }
  37. END {
  38. if (!saw1 && !err)
  39. {
  40. printf \"did not see $2\\n\";
  41. exit 1;
  42. }
  43. if (!saw2 && !err)
  44. {
  45. printf \"did not see $3\\n\";
  46. exit 1;
  47. }
  48. }" $1
  49. }
  50. # addr (unlikely_*) < addr (startup_*) < addr (hot_*)
  51. check text_section_grouping.stdout "unlikely_foo" "startup_foo"
  52. check text_section_grouping.stdout "startup_foo" "hot_foo"
  53. check text_section_grouping.stdout "unlikely_bar" "startup_bar"
  54. check text_section_grouping.stdout "startup_bar" "hot_bar"
  55. check text_section_grouping.stdout "unlikely_foo" "startup_bar"
  56. check text_section_grouping.stdout "startup_foo" "hot_bar"
  57. check text_section_no_grouping.stdout "hot_foo" "startup_foo"
  58. check text_section_no_grouping.stdout "startup_foo" "unlikely_foo"
  59. check text_section_no_grouping.stdout "unlikely_foo" "hot_bar"
  60. check text_section_no_grouping.stdout "hot_bar" "startup_bar"
  61. check text_section_no_grouping.stdout "startup_bar" "unlikely_bar"