exclude_libs_test.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/sh
  2. # exclude_libs_test.sh -- test that library symbols are not exported.
  3. # Copyright (C) 2009-2022 Free Software Foundation, Inc.
  4. # Written by Doug Kwan <dougkwan@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. # This file goes with exclude_libs_test.c, a C source file
  19. # linked with option -Wl,--exclude-libs. We run readelf on
  20. # the resulting executable and check that symbols from two test library
  21. # archives are correctly hidden or left unmodified.
  22. check()
  23. {
  24. file=$1
  25. sym=$2
  26. vis=$3
  27. found=`grep " $sym\$" $file`
  28. if test -z "$found"; then
  29. echo "Symbol $sym not found."
  30. exit 1
  31. fi
  32. match_vis=`grep " $sym\$" $file | grep " $vis "`
  33. if test -z "$match_vis"; then
  34. echo "Expected symbol $sym to have visibility $vis but found"
  35. echo "$found"
  36. exit 1
  37. fi
  38. }
  39. check "exclude_libs_test.syms" "lib1_default" "HIDDEN"
  40. check "exclude_libs_test.syms" "lib1_protected" "HIDDEN"
  41. check "exclude_libs_test.syms" "lib1_internal" "INTERNAL"
  42. check "exclude_libs_test.syms" "lib1_hidden" "HIDDEN"
  43. check "exclude_libs_test.syms" "lib2_default" "DEFAULT"
  44. check "exclude_libs_test.syms" "lib2_protected" "PROTECTED"
  45. check "exclude_libs_test.syms" "lib2_internal" "INTERNAL"
  46. check "exclude_libs_test.syms" "lib2_hidden" "HIDDEN"
  47. check "exclude_libs_test.syms" "lib3_default" "HIDDEN"
  48. check "exclude_libs_test.syms" "lib3_protected" "HIDDEN"
  49. check "exclude_libs_test.syms" "lib3_internal" "INTERNAL"
  50. check "exclude_libs_test.syms" "lib3_hidden" "HIDDEN"
  51. exit 0