icf_safe_so_test.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/bin/sh
  2. # icf_safe_so_test.sh -- test --icf=safe
  3. # Copyright (C) 2010-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 --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. set -e
  23. error_if_symbol_absent()
  24. {
  25. if ! is_symbol_present $1 $2;
  26. then
  27. echo "Symbol" $2 "not present, possibly folded."
  28. exit 1
  29. fi
  30. }
  31. is_symbol_present()
  32. {
  33. grep $2 $1 > /dev/null 2>&1
  34. return $?
  35. }
  36. check_nofold()
  37. {
  38. error_if_symbol_absent $1 $2
  39. error_if_symbol_absent $1 $3
  40. func_addr_1=`grep $2 $1 | awk '{print $1}'`
  41. func_addr_2=`grep $3 $1 | awk '{print $1}'`
  42. if [ $func_addr_1 = $func_addr_2 ];
  43. then
  44. echo "Safe Identical Code Folding folded" $2 "and" $3
  45. exit 1
  46. fi
  47. }
  48. check_fold()
  49. {
  50. map=$1
  51. shift
  52. num_syms=$#
  53. save_IFS="$IFS"
  54. IFS='|'
  55. sym_patt="$*"
  56. IFS="$save_IFS"
  57. awk "
  58. BEGIN { discard = 0; }
  59. /^Discarded input/ { discard = 1; }
  60. /^Memory map/ { discard = 0; }
  61. /.*\\.text\\..*($sym_patt).*/ { act[discard] = act[discard] \" \" \$0; cnt[discard] = cnt[discard] + 1 }
  62. END {
  63. printf \"kept\" act[0] \"\\nfolded\" act[1] \"\\n\";
  64. if (cnt[0] != 1 || cnt[1] != $num_syms - 1)
  65. {
  66. printf \"Safe Identical Code Folding failed\\n\"
  67. exit 1;
  68. }
  69. }" $map
  70. }
  71. arch_specific_safe_fold()
  72. {
  73. if grep -q -e "Advanced Micro Devices X86-64" -e "Intel 80386" -e "ARM" -e "PowerPC" $1;
  74. then
  75. shift
  76. shift
  77. #echo check_fold $*
  78. check_fold $*
  79. else
  80. shift
  81. nm_output=$1
  82. shift
  83. shift
  84. while test $# -gt 1; do
  85. sym1=$1
  86. shift
  87. for sym2 in $*; do
  88. #echo check_nofold $nm_output $sym1 $sym2
  89. check_nofold $nm_output $sym1 $sym2
  90. done
  91. done
  92. fi
  93. }
  94. 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 foo_internal foo_static
  95. check_nofold icf_safe_so_test_1.stdout foo_glob bar_glob