run.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/sh
  2. # Copyright 2020-2021 Yury Gribov
  3. #
  4. # The MIT License (MIT)
  5. #
  6. # Use of this source code is governed by MIT license that can be
  7. # found in the LICENSE.txt file.
  8. # This test checks that linker wrapper works.
  9. set -eu
  10. cd $(dirname $0)
  11. if test -n "${1:-}"; then
  12. ARCH="$1"
  13. fi
  14. . ../common.sh
  15. export LD_LIBRARY_PATH=.:${LD_LIBRARY_PATH:-}
  16. $CC $CFLAGS -shared -fPIC interposed.c -o libinterposed.so
  17. $CC $CFLAGS main.c -L. -linterposed
  18. $INTERP ./a.out 2>&1 | tee ref.log
  19. ${PYTHON:-} ../../implib-gen.py -q --target $TARGET libinterposed.so
  20. ln -sf ../../scripts/ld ${PREFIX}ld
  21. trap "rm -f $PWD/${PREFIX}ld" EXIT
  22. if $CC --version | grep -q 'clang\|^lcc'; then
  23. # Some compilers do not allow overriding ld via playing with PATH
  24. CFLAGS="$CFLAGS -B."
  25. fi
  26. PATH=.:../..:$PATH $CC $CFLAGS -Wno-deprecated main.c -L. -linterposed
  27. if readelf -d a.out | grep -q libinterposed; then
  28. echo "Linker wrapper failed to wrap library"
  29. exit 1
  30. fi
  31. $INTERP ./a.out 2>&1 | tee new.log
  32. if ! diff ref.log new.log; then
  33. echo "Linker wrapper failed to intercept functions"
  34. exit 1
  35. fi
  36. echo SUCCESS