shlib_wrap.sh.in 4.7 KB

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