This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #66604] 64bit compilation Problem on Solaris x86_64
[metaconfig.git] / U / perl / dlsrc.U
index a3746a0..c98f862 100644 (file)
 ?X:      cc -c +z module_b.c
 ?X:      ld -b module_a.o module_b.o -o module.sl
 ?X:
-?MAKE:usedl ld dlsrc cccdlflags lddlflags ccdlflags: \
-       Getfile Myread test osname sed i_dld d_dlopen Findhdr Setvar \
-       cc ccflags ldflags ls gccversion cat rsrc src
+?MAKE:usedl ld dlsrc cccdlflags lddlflags ccdlflags bin_ELF ld_can_script: \
+       rm_try Getfile Myread test osname sed i_dld d_dlopen Findhdr Setvar \
+       src run cc ccflags ldflags optimize ls gccversion cat rsrc i_stdlib \
+       i_unistd osvers
 ?MAKE: -pick add $@ %<
 ?Y:BOTTOM
 ?S:usedl:
 ?S:    It is up to the makefile to use it.  For sunos 4.1, it should
 ?S:    be empty.
 ?S:.
+?S:bin_ELF:
+?S:    This variable saves the result from configure if generated binaries
+?S:    are in ELF format. Only set to defined when the test has actually
+?S:    been performed, and the result was positive.
+?S:.
+?S:ld_can_script:
+?S:    This variable shows if the loader accepts scripts in the form of
+?S:    -Wl,--version-script=ld.script. This is currently only supported
+?S:    for GNU ld on ELF in dynamic loading builds.
+?S:.
 ?C:USE_DYNAMIC_LOADING ~ %<:
 ?C:    This symbol, if defined, indicates that dynamic loading of
 ?C:    some sort is available.
@@ -61,6 +72,7 @@
 ?H:.
 ?W:%<:dlopen
 ?T:dldir thisflag tdir
+?F:!a.out
 : determine which dynamic loading, if any, to compile in
 echo " "
 dldir="ext/DynaLoader"
@@ -73,7 +85,7 @@ $undef|n|false)
        dflt='n'
        usedl="$undef"
        ;;
-*) 
+*)
        dflt='n'
        case "$d_dlopen" in
            $define) dflt='y' ;;
@@ -88,6 +100,7 @@ esac
 rp="Do you wish to use dynamic loading?"
 . ./myread
 usedl="$ans"
+bin_ELF="$undef"
 case "$ans" in
 y*) usedl="$define"
        case "$dlsrc" in
@@ -107,14 +120,14 @@ y*) usedl="$define"
        esac
     echo "The following dynamic loading files are available:"
        : Can not go over to $dldir because getfile has path hard-coded in.
-       tdir=`pwd`; cd $rsrc; $ls -C $dldir/dl*.xs; cd $tdir
+       tdir=`pwd`; cd "$rsrc"; $ls -C $dldir/dl*.xs; cd "$tdir"
        rp="Source file to use for dynamic loading"
        fn="fne"
        gfpth="$src"
        . ./getfile
        usedl="$define"
        : emulate basename
-       dlsrc=`echo $ans | $sed -e 's@.*/\([^/]*\)$@\1@'`
+       dlsrc=`echo $ans | $sed -e 's%.*/\([^/]*\)$%\1%'`
 
        $cat << EOM
 
@@ -129,13 +142,14 @@ EOM
                        hpux)   dflt='+z' ;;
                        next)   dflt='none' ;;
                        irix*)  dflt='-KPIC' ;;
-                       svr4*|esix*|solaris) dflt='-KPIC' ;;
+                       svr4*|esix*|solaris|nonstopux) dflt='-KPIC' ;;
                        sunos)  dflt='-pic' ;;
                        *)      dflt='none' ;;
                    esac
                        ;;
                *)  case "$osname" in
-                       svr4*|esix*|solaris) dflt='-fPIC' ;;
+                       darwin) dflt='none' ;;
+                       linux*|svr4*|esix*|solaris|nonstopux) dflt='-fPIC' ;;
                        *)      dflt='-fpic' ;;
                    esac ;;
            esac ;;
@@ -156,23 +170,37 @@ Some systems use ld to create libraries that can be dynamically loaded,
 while other systems (such as those using ELF) use $cc.
 
 EOM
-       case "$ld" in
-       '')     $cat >try.c <<'EOM'
+
+: Determine if this is ELF
+       $cat >try.c <<EOM
 /* Test for whether ELF binaries are produced */
 #include <fcntl.h>
+#$i_stdlib I_STDLIB
+#ifdef I_STDLIB
 #include <stdlib.h>
+#endif
+#$i_unistd I_UNISTD
+#ifdef I_UNISTD
+#include <unistd.h>
+#endif
 int main() {
        char b[4];
        int i = open("a.out",O_RDONLY);
-       if(i == -1) 
+       if(i == -1)
                exit(1); /* fail */
        if(read(i,b,4)==4 && b[0]==127 && b[1]=='E' && b[2]=='L' && b[3]=='F')
-               exit(0); /* succeed (yes, it's ELF) */
+               exit(0); /* succeed (yes, it is ELF) */
        else
                exit(1); /* fail */
 }
 EOM
-               if $cc $ccflags try.c >/dev/null 2>&1 && ./a.out; then
+       if $cc $ccflags $ldflags try.c >/dev/null 2>&1 && $run ./a.out; then
+               bin_ELF="$define"
+       fi
+       $rm_try
+
+       case "$ld" in
+       '')     if $test $bin_ELF = "$define"; then
                        cat <<EOM
 You appear to have ELF support.  I'll use $cc to build dynamic libraries.
 EOM
@@ -181,7 +209,6 @@ EOM
                        echo "I'll use ld to build dynamic libraries."
                        dflt='ld'
                fi
-               rm -f try.c a.out
                ;;
        *)      dflt="$ld"
                ;;
@@ -202,13 +229,31 @@ use no flags, say "none".
 EOM
     case "$lddlflags" in
     '') case "$osname" in
-                       beos) dflt='-nostart' ;;
-                       hpux)  dflt='-b' ;;
-                       linux|irix*)    dflt='-shared' ;;
+                       haiku) dflt='-shared' ;;
+                       hpux) dflt='-b';
+                             case "$gccversion" in
+                             '') dflt="$dflt +vnocompatwarnings" ;;
+                             esac
+                             ;;
+                       linux|irix*|gnu*)  dflt="-shared $optimize" ;;
                        next)  dflt='none' ;;
-                       solaris) dflt='-G' ;;
+                       solaris) # See [perl #66604].
+                               # On Solaris 11, gcc -m64 on amd64 
+                               # appears not to understand -G.  gcc versions at
+                               # least as old as 3.4.3 support -shared, so just
+                               # use that with Solaris 11 and later, but keep
+                               # the old behavior for older Solaris versions.
+                               case "$gccversion" in
+                                       '') dflt='-G' ;;
+                                       *)      case "$osvers" in
+                                                       2.?|2.10) dflt='-G' ;;
+                                                       *) dflt='-shared' ;;
+                                               esac
+                                               ;;
+                               esac
+                               ;;
                        sunos) dflt='-assert nodefinitions' ;;
-                       svr4*|esix*) dflt="-G $ldflags" ;;
+                       svr4*|esix*|nonstopux) dflt="-G $ldflags" ;;
                *)     dflt='none' ;;
                        esac
                        ;;
@@ -222,7 +267,7 @@ EOM
        esac
        for thisflag in $ldflags; do
                case "$thisflag" in
-               -L*)
+               -L*|-R*|-Wl,-R*)
                        case " $dflt " in
                        *" $thisflag "*) ;;
                        *) dflt="$dflt $thisflag" ;;
@@ -235,6 +280,16 @@ EOM
        ''|' ') dflt='none' ;;
        esac
 
+       case "$ldflags" in
+       *-fstack-protector*)
+           case "$dflt" in
+                       *-fstack-protector*) ;; # Don't add it again
+                       *) dflt="$dflt -fstack-protector" ;; 
+               esac
+               ;;
+       esac
+
+
     rp="Any special flags to pass to $ld to create a dynamically loaded library?"
     . ./myread
     case "$ans" in
@@ -252,16 +307,14 @@ say "none".
 EOM
     case "$ccdlflags" in
     '') case "$osname" in
-               hpux)   dflt='-Wl,-E' ;;
-               linux)  dflt='-rdynamic' ;;
-               next)   dflt='none' ;;
-               sunos)  dflt='none' ;;
-               *)      dflt='none' ;;
+           linux|hpux|gnu*)    dflt='-Wl,-E' ;;
+           next|sunos) dflt='none' ;;
+           *)          dflt='none' ;;
            esac ;;
     ' ')  dflt='none' ;;
     *)  dflt="$ccdlflags" ;;
     esac
-    rp="Any special flags to pass to $cc to use dynamic loading?"
+    rp="Any special flags to pass to $cc to use dynamic linking?"
     . ./myread
     case "$ans" in
 ?X: Use ' ' so that a subsequent Configure run preserves the old state.
@@ -278,3 +331,31 @@ EOM
     ;;
 esac
 
+ld_can_script="$undef"
+case "$bin_ELF$usedl" in
+$define$define)
+    # Abuse try.h and a.out names for neat cleanup
+    $cat >try.c <<EOM
+void foo() {}
+void bar() {}
+EOM
+    $cat >try.h <<EOM
+LIBTEST_42 {
+ global:
+  foo;
+ local: *;
+ };
+EOM
+    if $cc $cccdlflags $ccdlflags $ccflags \
+           $ldflags $lddlflags -o a.out try.c \
+           -Wl,--version-script=try.h >/dev/null 2>&1 \
+       &&  $test -s a.out ; then
+       echo "ld supports scripting" >&4
+       ld_can_script="$define"
+    else
+       echo "ld does not support scripting" >&4
+    fi
+    $rm_try
+    ;;
+esac
+