run.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/sh
  2. # Copyright 2020 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 is an example for https://stackoverflow.com/questions/64489128/automated-function-redirection-via-library-wrappers-in-c/64495628#64495628
  9. # It generates a single libC.so which redirects calls to libA.so and libB.so
  10. set -eu
  11. cd $(dirname $0)
  12. if test -n "${1:-}"; then
  13. ARCH="$1"
  14. fi
  15. . ../common.sh
  16. export LD_LIBRARY_PATH=.:${LD_LIBRARY_PATH:-}
  17. LIB_CFLAGS='-shared -fPIC -fvisibility=hidden'
  18. # Compile wrapped libs
  19. $CC $CFLAGS $LIB_CFLAGS a.c -o libA.so
  20. $CC $CFLAGS $LIB_CFLAGS b.c -o libB.so
  21. # Generate and compile wrapper
  22. ${PYTHON:-} ../../implib-gen.py -q --target $TARGET --symbol-list libA_syms.txt libA.so
  23. ${PYTHON:-} ../../implib-gen.py -q --target $TARGET --symbol-list libB_syms.txt libB.so
  24. $CC $CFLAGS $LIB_CFLAGS -DIMPLIB_EXPORT_SHIMS libA.so.* libB.so.* -o libC.so
  25. # Use it in final app
  26. $CC $CFLAGS main.c -L. -lC -ldl
  27. $INTERP ./a.out >out.log 2>&1
  28. if ! diff out.ref out.log; then
  29. echo 'Creating unified wrapper for several libraries does not work'
  30. exit 1
  31. fi
  32. echo SUCCESS