section_sorting_name.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/sh
  2. # section_sorting_name.sh -- test
  3. # Copyright (C) 2013-2015 Free Software Foundation, Inc.
  4. # Written by Alexander Ivchenko <alexander.ivchenko@intel.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 that when using --sort-section=name
  19. # option all .text, .data, and .bss sections are sorted by name
  20. set -e
  21. check()
  22. {
  23. awk "
  24. BEGIN { saw1 = 0; saw2 = 0; err = 0; }
  25. /.*$2\$/ { saw1 = 1; }
  26. /.*$3\$/ {
  27. saw2 = 1;
  28. if (!saw1)
  29. {
  30. printf \"layout of $2 and $3 is not right\\n\";
  31. err = 1;
  32. exit 1;
  33. }
  34. }
  35. END {
  36. if (!saw1 && !err)
  37. {
  38. printf \"did not see $2\\n\";
  39. exit 1;
  40. }
  41. if (!saw2 && !err)
  42. {
  43. printf \"did not see $3\\n\";
  44. exit 1;
  45. }
  46. }" $1
  47. }
  48. # addr (hot_foo_0001) < addr (hot_foo_0002) < addr (hot_foo_0003)
  49. check section_sorting_name.stdout "hot_foo_0001" "hot_foo_0002"
  50. check section_sorting_name.stdout "hot_foo_0002" "hot_foo_0003"
  51. check section_sorting_name.stdout "vdata_0001" "vdata_0002"
  52. check section_sorting_name.stdout "vdata_0002" "vdata_0003"
  53. check section_sorting_name.stdout "vbss_0001" "vbss_0002"
  54. check section_sorting_name.stdout "vbss_0002" "vbss_0003"