LD_PRELOAD hack, still badly flawed / a solution
Adrian M. Enache [Thu, 3 Apr 2003 15:50:48 +0000 (18:50 +0300)]
Message-ID: <20030403125048.GA6107@ratsnest.hole>

On linux, when building a shared library, generate
a small shell wrapper, "preload", that preloads libperl.so
only if it exists. Useful when the 'make' process stops
before the link phase.

p4raw-id: //depot/perl@19150

Makefile.SH

index 63e3176..676eb52 100644 (file)
@@ -96,26 +96,32 @@ true)
            ldlibpth=`echo $ldlibpth | sed 's/:*$//'`
            ;;
         esac
-       ;;
-*)     pldlflags=''
-       static_target='static'
-       ;;
-esac
 
-case "$ldlibpth" in
-# Protect any spaces
-*" "*) ldlibpth=`echo $ldlibpth|sed 's/ /\\\\ /g'` ;;
-esac
+       case "$ldlibpth" in
+       # Protect any spaces
+       *" "*) ldlibpth=`echo $ldlibpth|sed 's/ /\\\\ /g'` ;;
+       esac
 
-case "$osname" in
-linux)
-       case "$useshrplib" in
-       true)
-           ldlibpth="LD_PRELOAD=\"\$\$LD_PRELOAD `pwd`/$libperl\" $ldlibpth"
-           ;;
+       case "$osname" in
+       linux)
+               cat <<-'EOT' >| preload
+               #! /bin/sh
+               lib=$1
+               shift
+               test -r $lib && export LD_PRELOAD="$lib $LD_PRELOAD"
+               exec "$@"
+               EOT
+               chmod 755 preload
+               ldlibpth="$ldlibpth `pwd`/preload `pwd`/$libperl"
+               ;;
+       os390)  test -f /bin/env && ldlibpth="/bin/env $ldlibpth"
+               ;;
        esac
+
        ;;
-os390) test -f /bin/env && ldlibpth="/bin/env $ldlibpth"
+
+*)     pldlflags=''
+       static_target='static'
        ;;
 esac
 
@@ -944,6 +950,7 @@ _cleaner2:
        rm -f lib/.exists lib/*/.exists lib/*/*/.exists
        rm -f h2ph.man pstruct
        rm -rf .config
+       rm -f preload
        rm -f testcompile compilelog
        -rmdir lib/B lib/Data lib/Digest
        rm -rf lib/Encode