shlib_wrap.sh.in 5.1 KB

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