shlib_wrap.sh.in 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #!/bin/sh
  2. # To test this OpenSSL version's applications against another version's
  3. # shared libraries, simply set
  4. #
  5. # OPENSSL_REGRESSION=/path/to/other/OpenSSL/build/tree
  6. if [ -n "$OPENSSL_REGRESSION" ]; then
  7. shlibwrap="$OPENSSL_REGRESSION/util/shlib_wrap.sh"
  8. if [ -x "$shlibwrap" ]; then
  9. # We clear OPENSSL_REGRESSION to avoid a loop, should the shlib_wrap.sh
  10. # we exec also support that mechanism...
  11. OPENSSL_REGRESSION= exec "$shlibwrap" "$@"
  12. else
  13. if [ -f "$shlibwrap" ]; then
  14. echo "Not permitted to run $shlibwrap" >&2
  15. else
  16. echo "No $shlibwrap, perhaps OPENSSL_REGRESSION isn't properly set?" >&2
  17. fi
  18. exit 1
  19. fi
  20. fi
  21. [ $# -ne 0 ] || set -x # debug mode without arguments:-)
  22. THERE="`echo $0 | sed -e 's|[^/]*$||' 2>/dev/null`.."
  23. [ -d "${THERE}" ] || exec "$@" # should never happen...
  24. # Alternative to this is to parse ${THERE}/Makefile...
  25. LIBCRYPTOSO="${THERE}/libcrypto.so"
  26. if [ -f "$LIBCRYPTOSO" ]; then
  27. while [ -h "$LIBCRYPTOSO" ]; do
  28. LIBCRYPTOSO="${THERE}/`ls -l "$LIBCRYPTOSO" | sed -e 's|.*\-> ||'`"
  29. done
  30. SOSUFFIX=`echo ${LIBCRYPTOSO} | sed -e 's|.*\.so||' 2>/dev/null`
  31. LIBSSLSO="${THERE}/libssl.so${SOSUFFIX}"
  32. fi
  33. SYSNAME=`(uname -s) 2>/dev/null`;
  34. case "$SYSNAME" in
  35. SunOS|IRIX*)
  36. # SunOS and IRIX run-time linkers evaluate alternative
  37. # variables depending on target ABI...
  38. rld_var=LD_LIBRARY_PATH
  39. case "`(/usr/bin/file "$LIBCRYPTOSO") 2>/dev/null`" in
  40. *ELF\ 64*SPARC*|*ELF\ 64*AMD64*)
  41. [ -n "$LD_LIBRARY_PATH_64" ] && rld_var=LD_LIBRARY_PATH_64
  42. LD_PRELOAD_64="$LIBCRYPTOSO $LIBSSLSO"; export LD_PRELOAD_64
  43. preload_var=LD_PRELOAD_64
  44. ;;
  45. *ELF\ 32*SPARC*|*ELF\ 32*80386*)
  46. # We only need to change LD_PRELOAD_32 and LD_LIBRARY_PATH_32
  47. # on a multi-arch system. Otherwise, trust the fallbacks.
  48. if [ -f /lib/64/ld.so.1 ]; then
  49. [ -n "$LD_LIBRARY_PATH_32" ] && rld_var=LD_LIBRARY_PATH_32
  50. LD_PRELOAD_32="$LIBCRYPTOSO $LIBSSLSO"; export LD_PRELOAD_32
  51. preload_var=LD_PRELOAD_32
  52. fi
  53. ;;
  54. # Why are newly built .so's preloaded anyway? Because run-time
  55. # .so lookup path embedded into application takes precedence
  56. # over LD_LIBRARY_PATH and as result application ends up linking
  57. # to previously installed .so's. On IRIX instead of preloading
  58. # newly built .so's we trick run-time linker to fail to find
  59. # the installed .so by setting _RLD_ROOT variable.
  60. *ELF\ 32*MIPS*)
  61. #_RLD_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT"; export _RLD_LIST
  62. _RLD_ROOT=/no/such/dir; export _RLD_ROOT
  63. eval $rld_var=\"/usr/lib'${'$rld_var':+:$'$rld_var'}'\"
  64. preload_var=_RLD_LIST
  65. ;;
  66. *ELF\ N32*MIPS*)
  67. [ -n "$LD_LIBRARYN32_PATH" ] && rld_var=LD_LIBRARYN32_PATH
  68. #_RLDN32_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT"; export _RLDN32_LIST
  69. _RLDN32_ROOT=/no/such/dir; export _RLDN32_ROOT
  70. eval $rld_var=\"/usr/lib32'${'$rld_var':+:$'$rld_var'}'\"
  71. preload_var=_RLDN32_LIST
  72. ;;
  73. *ELF\ 64*MIPS*)
  74. [ -n "$LD_LIBRARY64_PATH" ] && rld_var=LD_LIBRARY64_PATH
  75. #_RLD64_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT"; export _RLD64_LIST
  76. _RLD64_ROOT=/no/such/dir; export _RLD64_ROOT
  77. eval $rld_var=\"/usr/lib64'${'$rld_var':+:$'$rld_var'}'\"
  78. preload_var=_RLD64_LIST
  79. ;;
  80. esac
  81. eval $rld_var=\"${THERE}'${'$rld_var':+:$'$rld_var'}'\"; export $rld_var
  82. unset rld_var
  83. ;;
  84. *) LD_LIBRARY_PATH="${THERE}:$LD_LIBRARY_PATH" # Linux, ELF HP-UX
  85. DYLD_LIBRARY_PATH="${THERE}:$DYLD_LIBRARY_PATH" # MacOS X
  86. SHLIB_PATH="${THERE}:$SHLIB_PATH" # legacy HP-UX
  87. LIBPATH="${THERE}:$LIBPATH" # AIX, OS/2
  88. export LD_LIBRARY_PATH DYLD_LIBRARY_PATH SHLIB_PATH LIBPATH
  89. # Even though $PATH is adjusted [for Windows sake], it doesn't
  90. # necessarily does the trick. Trouble is that with introduction
  91. # of SafeDllSearchMode in XP/2003 it's more appropriate to copy
  92. # .DLLs in vicinity of executable, which is done elsewhere...
  93. if [ "$OSTYPE" != msdosdjgpp ]; then
  94. PATH="${THERE}:$PATH"; export PATH
  95. fi
  96. ;;
  97. esac
  98. {- output_off() if $config{ex_libs} !~ /,-rpath,/; ""; -}
  99. if [ -f "$LIBCRYPTOSO" -a -z "$preload_var" ]; then
  100. # Following three lines are major excuse for isolating them into
  101. # this wrapper script. Original reason for setting LD_PRELOAD
  102. # was to make it possible to pass 'make test' when user linked
  103. # with -rpath pointing to previous version installation. Wrapping
  104. # it into a script makes it possible to do so on multi-ABI
  105. # platforms.
  106. case "$SYSNAME" in
  107. *BSD) LD_PRELOAD="$LIBCRYPTOSO:$LIBSSLSO" ;; # *BSD
  108. *) LD_PRELOAD="$LIBCRYPTOSO $LIBSSLSO" ;; # SunOS, Linux, ELF HP-UX
  109. esac
  110. _RLD_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT" # Tru64, o32 IRIX
  111. DYLD_INSERT_LIBRARIES="$LIBCRYPTOSO:$LIBSSLSO" # MacOS X
  112. export LD_PRELOAD _RLD_LIST DYLD_INSERT_LIBRARIES
  113. fi
  114. {- output_on() if $config{ex_libs} !~ /,-rpath,/; ""; -}
  115. cmd="$1"; [ -x "$cmd" ] || cmd="$cmd${EXE_EXT}"
  116. shift
  117. if [ $# -eq 0 ]; then
  118. exec "$cmd" # old sh, such as Tru64 4.x, fails to expand empty "$@"
  119. else
  120. exec "$cmd" "$@"
  121. fi