weak_as_needed.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/sh
  2. # weak_as_needed.sh -- a test case for version handling with weak symbols
  3. # and --as-needed libraries.
  4. # Copyright (C) 2018-2022 Free Software Foundation, Inc.
  5. # Written by Cary Coutant <ccoutant@gmail.com>.
  6. # This file is part of gold.
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 3 of the License, or
  10. # (at your option) any later version.
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  18. # MA 02110-1301, USA.
  19. # This test verifies that a weak reference is properly bound to
  20. # an as-needed library, when it is first resolved to a symbol in
  21. # a library that ends up being not needed.
  22. # Ref: https://stackoverflow.com/questions/50751421/undefined-behavior-in-shared-lib-using-libpthread-but-not-having-it-in-elf-as-d
  23. check()
  24. {
  25. if ! grep -q "$2" "$1"
  26. then
  27. echo "Did not find expected output in $1:"
  28. echo " $2"
  29. echo ""
  30. echo "Actual output below:"
  31. cat "$1"
  32. exit 1
  33. fi
  34. }
  35. check_missing()
  36. {
  37. if grep -q "$2" "$1"
  38. then
  39. echo "Found unexpected output in $1:"
  40. echo " $2"
  41. echo ""
  42. echo "Actual output below:"
  43. cat "$1"
  44. exit 1
  45. fi
  46. }
  47. check weak_as_needed.stdout "WEAK .* UND *bar@v2"
  48. check weak_as_needed.stdout "NEEDED.*weak_as_needed_c\.so"
  49. check_missing weak_as_needed.stdout "NEEDED.*weak_as_needed_b\.so"
  50. exit 0