2
0

shlib_wrap.sh.in 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. NONSTOP_KERNEL)
  84. # HPE NonStop has a proprietary mechanism for specifying
  85. # the location of DLLs. It does not use PATH or variables
  86. # commonly used on other platforms. The platform has a limited
  87. # environment space keeping extraneous variables to a minimum
  88. # is recommended.
  89. _RLD_LIB_PATH="${THERE}:$LD_LIBRARY_PATH"
  90. export _RLD_LIB_PATH
  91. ;;
  92. *) LD_LIBRARY_PATH="${THERE}:$LD_LIBRARY_PATH" # Linux, ELF HP-UX
  93. DYLD_LIBRARY_PATH="${THERE}:$DYLD_LIBRARY_PATH" # MacOS X
  94. SHLIB_PATH="${THERE}:$SHLIB_PATH" # legacy HP-UX
  95. LIBPATH="${THERE}:$LIBPATH" # AIX, OS/2
  96. export LD_LIBRARY_PATH DYLD_LIBRARY_PATH SHLIB_PATH LIBPATH
  97. # Even though $PATH is adjusted [for Windows sake], it doesn't
  98. # necessarily does the trick. Trouble is that with introduction
  99. # of SafeDllSearchMode in XP/2003 it's more appropriate to copy
  100. # .DLLs in vicinity of executable, which is done elsewhere...
  101. if [ "$OSTYPE" != msdosdjgpp ]; then
  102. PATH="${THERE}:$PATH"; export PATH
  103. fi
  104. ;;
  105. esac
  106. {- output_off() unless grep (/-rpath\b/, @{$config{LDFLAGS}}); ""; -}
  107. if [ -f "$LIBCRYPTOSO" -a -z "$preload_var" ]; then
  108. # Following three lines are major excuse for isolating them into
  109. # this wrapper script. Original reason for setting LD_PRELOAD
  110. # was to make it possible to pass 'make test' when user linked
  111. # with -rpath pointing to previous version installation. Wrapping
  112. # it into a script makes it possible to do so on multi-ABI
  113. # platforms.
  114. case "$SYSNAME" in
  115. *BSD) LD_PRELOAD="$LIBCRYPTOSO:$LIBSSLSO" ;; # *BSD
  116. *) LD_PRELOAD="$LIBCRYPTOSO $LIBSSLSO" ;; # SunOS, Linux, ELF HP-UX
  117. esac
  118. _RLD_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT" # Tru64, o32 IRIX
  119. DYLD_INSERT_LIBRARIES="$LIBCRYPTOSO:$LIBSSLSO" # MacOS X
  120. export LD_PRELOAD _RLD_LIST DYLD_INSERT_LIBRARIES
  121. fi
  122. {- output_on() unless grep (/-rpath\b/, @{$config{LDFLAGS}}); ""; -}
  123. cmd="$1"; [ -x "$cmd" ] || cmd="$cmd${EXE_EXT}"
  124. shift
  125. if [ $# -eq 0 ]; then
  126. exec "$cmd" # old sh, such as Tru64 4.x, fails to expand empty "$@"
  127. else
  128. exec "$cmd" "$@"
  129. fi