plugin_final_layout.sh 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 --section-ordering-file works as
  19. # intended. File plugin_final_layout.cc is in this test.
  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 in file $1\\n\";
  31. err = 1;
  32. exit 1;
  33. }
  34. }
  35. END {
  36. if (!saw1 && !err)
  37. {
  38. printf \"did not see $2 in file $1\\n\";
  39. exit 1;
  40. }
  41. if (!saw2 && !err)
  42. {
  43. printf \"did not see $3 in file $1\\n\";
  44. exit 1;
  45. }
  46. }" $1
  47. }
  48. # With readelf -l, an ELF Section to Segment mapping is printed as :
  49. ##############################################
  50. # Section to Segment mapping:
  51. # Segment Sections...
  52. # ...
  53. # 0x .text.plugin_created_unique
  54. # ...
  55. ##############################################
  56. # Check of .text.plugin_created_unique is the only section in the segment.
  57. check_unique_segment()
  58. {
  59. awk "
  60. BEGIN { saw_section = 0; saw_unique = 0; }
  61. /$2/ { saw_section = 1; }
  62. /[ ]*0[0-9][ ]*$2[ ]*\$/ { saw_unique = 1; }
  63. END {
  64. if (!saw_section)
  65. {
  66. printf \"Section $2 not seen in output file $1\\n\";
  67. exit 1;
  68. }
  69. else if (!saw_unique)
  70. {
  71. printf \"Unique segment not seen for: $2 in file $1\\n\";
  72. exit 1;
  73. }
  74. }" $1
  75. }
  76. check plugin_final_layout.stdout "_Z3foov" "_Z3barv"
  77. check plugin_final_layout.stdout "_Z3barv" "_Z3bazv"
  78. check_unique_segment plugin_final_layout_readelf.stdout ".text.plugin_created_unique"
  79. check plugin_layout_new_file.stdout "_Z3foov" "_Z3barv"
  80. check plugin_layout_new_file.stdout "_Z3barv" "_Z3bazv"
  81. check_unique_segment plugin_layout_new_file_readelf.stdout ".text.plugin_created_unique"