ld: Pass -z notext to linker for tests with DT_TEXTREL
[deliverable/binutils-gdb.git] / ld / testsuite / ld-shared / shared.exp
index ebb2237ed29e8994ec16db6164df25cfa33d39bb..fa64730775cacdcf7ef9be657c2399bc840c6cdf 100644 (file)
@@ -1,7 +1,5 @@
 # Expect script for ld-shared tests
-#   Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
-#   2004, 2005, 2007, 2008, 2009, 2010, 2012
-#   Free Software Foundation, Inc.
+#   Copyright (C) 1994-2020 Free Software Foundation, Inc.
 #
 # This file is part of the GNU Binutils.
 #
 # Note that linking against ELF shared libraries is tested by the
 # bootstrap test.
 
-# This test can only be run if ld generates native executables.
-if ![isnative] then {return}
+# Check to see if the C compiler works
+if { ![check_compiler_available] } {
+    return
+}
 
 # This test can only be run on a couple of ELF platforms.
 # Square bracket expressions seem to confuse istarget.
@@ -50,7 +50,6 @@ if { ![istarget hppa*64*-*-hpux*] \
      && ![istarget powerpc*-*-sysv4*] \
      && ![istarget sparc*-*-elf] \
      && ![istarget sparc*-*-solaris2*] \
-     && ![istarget sparc*-*-sunos4*] \
      && ![istarget sparc*-*-linux*] \
      && ![istarget arm*-*-linux*] \
      && ![istarget alpha*-*-linux*] \
@@ -62,11 +61,6 @@ if { ![istarget hppa*64*-*-hpux*] \
     return
 }
 
-if { [istarget *-*-linux*aout*] \
-     || [istarget *-*-linux*oldld*] } {
-    return
-}
-
 set tmpdir tmpdir
 set SHCFLAG ""
 set shared_needs_pic "no"
@@ -139,7 +133,10 @@ proc shared_test { progname testname main sh1 sh2 dat args } {
     if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
        set shared "-bM:SRE -bE:$tmpdir/xcoff.exp"
     }
-    if {![ld_simple_link $CC $tmpdir/$progname.so "$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} {
+    if { [is_elf_format] && [check_shared_lib_support] } {
+       append shared " -Wl,-z,notext"
+    }
+    if {![ld_link $CC $tmpdir/$progname.so "$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} {
         fail "$testname"
        return
     }
@@ -152,11 +149,16 @@ proc shared_test { progname testname main sh1 sh2 dat args } {
     if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
        set rpath /lib:$tmpdir
     }
-    if ![ld_simple_link $CC $tmpdir/$progname "-Wl,-rpath,$rpath $tmpdir/$main $tmpdir/$progname.so"] {
+    if ![ld_link $CC $tmpdir/$progname "-Wl,-rpath,$rpath $tmpdir/$main $tmpdir/$progname.so"] {
        fail "$testname"
        return
     }
 
+    if ![isnative] {
+       unsupported $testname
+       return
+    }
+
     # Run the resulting program
     send_log "$tmpdir/$progname >$tmpdir/$progname.out\n"
     verbose "$tmpdir/$progname >$tmpdir/$progname.out"
@@ -200,11 +202,7 @@ if { [istarget mips*-*-*] && ! [at_least_gcc_version 4 3] } then {
         || [string match "*option ignored*" $exec_output] \
         || [string match "*unrecognized option*" $exec_output] \
         || [string match "*passed to ld*" $exec_output] } {
-       if [istarget *-*-sunos4*] {
-           set picflag "-pic"
-       } else {
-           set picflag "-KPIC"
-       }
+       set picflag "-KPIC"
     }
 }
 verbose "Using $picflag to compile PIC code"
@@ -219,16 +217,16 @@ if ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o]
     # although it will be less efficient because the dynamic linker
     # will need to do more relocation work.  However, note that not
     # using -fpic will cause some of the tests to return different
-    # results.
-    if { ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o]
-        || ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } {
+    # results.  Make sure that PLT is used since PLT is expected.
+    global PLT_CFLAGS NOPIE_CFLAGS
+    if { ![ld_compile "$CC $PLT_CFLAGS $NOPIE_CFLAGS $CFLAGS $SHCFLAG" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o]
+        || ![ld_compile "$CC $PLT_CFLAGS $CFLAGS $SHCFLAG" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } {
        unresolved "shared (non PIC)"
     } else { if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
        shared_test shnp "shared (nonPIC)" mainnp.o sh1np.o sh2np.o xcoff
     } else {
-       # SunOS non PIC shared libraries don't permit some cases of
-       # overriding.
-       setup_xfail "*-*-sunos4*"
+       # Solaris defaults to -z text.
+       setup_xfail "*-*-solaris2*"
        setup_xfail "ia64-*-linux*"
        setup_xfail "alpha*-*-linux*"
        setup_xfail "powerpc64*-*-*"
@@ -246,13 +244,13 @@ if ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o]
        if [ string match $shared_needs_pic "yes" ] {
            setup_xfail "arm*-*-linux*"
        }
+       setup_xfail "aarch64*-*-linux*"
        shared_test shnp "shared (non PIC)" mainnp.o sh1np.o sh2np.o shared
 
        # Test ELF shared library relocations with a non-zero load
        # address for the library.  Near as I can tell, the R_*_RELATIVE
        # relocations for various targets are broken in the case where
        # the load address is not zero (which is the default).
-       setup_xfail "*-*-sunos4*"
        setup_xfail "*-*-linux*libc1"
        setup_xfail "powerpc*-*-linux*"
        setup_xfail "ia64-*-linux*"
@@ -272,9 +270,12 @@ if ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o]
        if [ string match $shared_needs_pic "yes" ] {
            setup_xfail "arm*-*-linux*"
        }
+       setup_xfail "aarch64*-*-linux*"
+       # Solaris defaults to -z text.
+       setup_xfail "*-*-solaris2*"
        shared_test shnp "shared (non PIC, load offset)" \
                mainnp.o sh1np.o sh2np.o shared \
-               "-T $srcdir/$subdir/elf-offset.ld"
+               "-Wl,-T,$srcdir/$subdir/elf-offset.ld,--hash-style=sysv"
     } }
 
     # Now compile the code using -fpic.
@@ -283,10 +284,7 @@ if ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o]
         || ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh2.c $tmpdir/sh2p.o] } {
        unresolved "shared"
     } else {
-       # SunOS can not compare function pointers correctly
-       if [istarget "*-*-sunos4*"] {
-           shared_test shp "shared" mainnp.o sh1p.o sh2p.o sun4
-       } else { if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
+       if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
            shared_test shp "shared" mainnp.o sh1p.o sh2p.o xcoff
        } else {
            shared_test shp "shared" mainnp.o sh1p.o sh2p.o shared
@@ -295,7 +293,7 @@ if ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o]
            shared_test shp "shared -Bsymbolic" mainnp.o sh1p.o sh2p.o symbolic "-Bsymbolic"
            ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o
            ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o
-       } }
+       }
     }
 }
 
@@ -308,9 +306,8 @@ if ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/main.c $tmpdir/m
         if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
            shared_test shmpnp "shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o xcoff
        } else {
-           # SunOS non PIC shared libraries don't permit some cases of
-           # overriding.
-           setup_xfail "*-*-sunos4*"
+           # Solaris defaults to -z text.
+           setup_xfail "*-*-solaris2*"
            setup_xfail "ia64-*-linux*"
            setup_xfail "alpha*-*-linux*"
            setup_xfail "powerpc64*-*-*"
@@ -328,6 +325,7 @@ if ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/main.c $tmpdir/m
            if [ string match $shared_needs_pic "yes" ] {
                setup_xfail "arm*-*-linux*"
            }
+           setup_xfail "aarch64*-*-linux*"
            shared_test shmpnp "shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o shared
        }
     } else {
This page took 0.043517 seconds and 4 git commands to generate.