icf_safe_so_test.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/sh
  2. # icf_safe_so_test.sh -- test --icf=safe
  3. # Copyright (C) 2010-2015 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 --icf=safe works as expected.
  19. # File icf_safe_so_test.cc is in this test. The goal of this script is
  20. # to verify if identical code folding in safe mode correctly folds
  21. # functions in a shared object.
  22. error_if_symbol_absent()
  23. {
  24. if ! is_symbol_present $1 $2;
  25. then
  26. echo "Symbol" $2 "not present, possibly folded."
  27. exit 1
  28. fi
  29. }
  30. is_symbol_present()
  31. {
  32. grep $2 $1 > /dev/null 2>&1
  33. return $?
  34. }
  35. check_nofold()
  36. {
  37. error_if_symbol_absent $1 $2
  38. error_if_symbol_absent $1 $3
  39. func_addr_1=`grep $2 $1 | awk '{print $1}'`
  40. func_addr_2=`grep $3 $1 | awk '{print $1}'`
  41. if [ $func_addr_1 = $func_addr_2 ];
  42. then
  43. echo "Safe Identical Code Folding folded" $2 "and" $3
  44. exit 1
  45. fi
  46. }
  47. check_fold()
  48. {
  49. if ! is_symbol_present $1 $2
  50. then
  51. return 0
  52. fi
  53. if ! is_symbol_present $1 $3
  54. then
  55. return 0
  56. fi
  57. awk "
  58. BEGIN { discard = 0; }
  59. /^Discarded input/ { discard = 1; }
  60. /^Memory map/ { discard = 0; }
  61. /.*\\.text\\..*($2|$3).*/ { act[discard] = act[discard] \" \" \$0; }
  62. END {
  63. # printf \"kept\" act[0] \"\\nfolded\" act[1] \"\\n\";
  64. if (length(act[0]) == 0 || length(act[1]) == 0)
  65. {
  66. printf \"Safe Identical Code Folding did not fold $2 and $3\\n\"
  67. exit 1;
  68. }
  69. }" $4
  70. }
  71. arch_specific_safe_fold()
  72. {
  73. grep -e "Intel 80386" -e "ARM" -e "PowerPC" $1 > /dev/null 2>&1
  74. if [ $? -eq 0 ];
  75. then
  76. check_fold $2 $4 $5 $3
  77. else
  78. check_nofold $2 $4 $5
  79. fi
  80. }
  81. arch_specific_safe_fold icf_safe_so_test_2.stdout icf_safe_so_test_1.stdout icf_safe_so_test.map "foo_prot" "foo_hidden"
  82. arch_specific_safe_fold icf_safe_so_test_2.stdout icf_safe_so_test_1.stdout icf_safe_so_test.map "foo_prot" "foo_internal"
  83. arch_specific_safe_fold icf_safe_so_test_2.stdout icf_safe_so_test_1.stdout icf_safe_so_test.map "foo_prot" "foo_static"
  84. arch_specific_safe_fold icf_safe_so_test_2.stdout icf_safe_so_test_1.stdout icf_safe_so_test.map "foo_hidden" "foo_internal"
  85. arch_specific_safe_fold icf_safe_so_test_2.stdout icf_safe_so_test_1.stdout icf_safe_so_test.map "foo_hidden" "foo_static"
  86. arch_specific_safe_fold icf_safe_so_test_2.stdout icf_safe_so_test_1.stdout icf_safe_so_test.map "foo_internal" "foo_static"
  87. check_nofold icf_safe_so_test_1.stdout "foo_glob" "bar_glob"