This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove references to GNU DLD from Configure and config.sh scripts.
[metaconfig.git] / U / perl / dlsrc.U
index 6e9c3d9..4e8302a 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 run i_stdlib
+?MAKE:usedl ld dlsrc cccdlflags lddlflags ccdlflags bin_ELF ld_can_script: \
+       rm_try Getfile Myread test osname sed 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,14 +85,11 @@ $undef|n|false)
        dflt='n'
        usedl="$undef"
        ;;
-*) 
+*)
        dflt='n'
        case "$d_dlopen" in
            $define) dflt='y' ;;
        esac
-       case "$i_dld" in
-           $define) dflt='y' ;;
-       esac
        : Does a dl_xxx.xs file exist for this operating system
        $test -f $rsrc/$dldir/dl_${osname}.xs && dflt='y'
        ;;
@@ -88,6 +97,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
@@ -96,8 +106,6 @@ y*) usedl="$define"
                        dflt="$dldir/dl_${osname}.xs"
                elif $test "$d_dlopen" = "$define" ; then
                        dflt="$dldir/dl_dlopen.xs"
-               elif $test "$i_dld" = "$define" ; then
-                       dflt="$dldir/dl_dld.xs"
                else
                        dflt=''
                fi
@@ -136,7 +144,7 @@ EOM
                        ;;
                *)  case "$osname" in
                        darwin) dflt='none' ;;
-                       svr4*|esix*|solaris|nonstopux) dflt='-fPIC' ;;
+                       linux*|svr4*|esix*|solaris|nonstopux) dflt='-fPIC' ;;
                        *)      dflt='-fpic' ;;
                    esac ;;
            esac ;;
@@ -157,26 +165,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 $ldflags try.c >/dev/null 2>&1 && $run ./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
@@ -185,7 +204,6 @@ EOM
                        echo "I'll use ld to build dynamic libraries."
                        dflt='ld'
                fi
-               rm -f try.c a.out
                ;;
        *)      dflt="$ld"
                ;;
@@ -206,15 +224,29 @@ use no flags, say "none".
 EOM
     case "$lddlflags" in
     '') case "$osname" in
-                       beos) dflt='-nostart' ;;
+                       haiku) dflt='-shared' ;;
                        hpux) dflt='-b';
                              case "$gccversion" in
                              '') dflt="$dflt +vnocompatwarnings" ;;
                              esac
-                             ;;        
-                       linux|irix*)    dflt='-shared' ;;
+                             ;;
+                       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*|nonstopux) dflt="-G $ldflags" ;;
                *)     dflt='none' ;;
@@ -243,6 +275,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
@@ -260,7 +302,7 @@ say "none".
 EOM
     case "$ccdlflags" in
     '') case "$osname" in
-           linux|hpux) dflt='-Wl,-E' ;;
+           linux|hpux|gnu*)    dflt='-Wl,-E' ;;
            next|sunos) dflt='none' ;;
            *)          dflt='none' ;;
            esac ;;
@@ -284,3 +326,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
+