text_unlikely_segment.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/sh
  2. # plugin_final_layout.sh -- test
  3. # Copyright (C) 2011-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 -z,text-unlikely-segment works as
  19. # intended. File text_unlikely_segment.cc is part of this test.
  20. set -e
  21. # With readelf -l, an ELF Section to Segment mapping is printed as :
  22. ##############################################
  23. # Section to Segment mapping:
  24. # Segment Sections...
  25. # ...
  26. # 0x .text.unlikely
  27. # ...
  28. ##############################################
  29. # Check if .text.unlikely is the only section in the segment.
  30. check_unique_segment()
  31. {
  32. awk "
  33. BEGIN { saw_section = 0; saw_unique = 0; }
  34. /$2/ { saw_section = 1; }
  35. /[ ]*0[0-9][ ]*$2[ ]*\$/ { saw_unique = 1; }
  36. END {
  37. if (!saw_section)
  38. {
  39. printf \"Section $2 not seen in output\\n\";
  40. exit 1;
  41. }
  42. else if (!saw_unique)
  43. {
  44. printf \"Unique segment not seen for: $2\\n\";
  45. exit 1;
  46. }
  47. }" $1
  48. }
  49. check_unique_segment text_unlikely_segment_readelf.stdout ".text.unlikely"