]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - ld/testsuite/ld-elfvsb/elfvsb.exp
config:
[thirdparty/binutils-gdb.git] / ld / testsuite / ld-elfvsb / elfvsb.exp
index 3c45e511e1d71071b60aa3cd63e2f63f109c1c8b..fe146bf42fb8475edbcfe35caa78fb446666b4ab 100644 (file)
@@ -1,19 +1,23 @@
 # Expect script for ld-visibility tests
-#   Copyright (C) 2000 Free Software Foundation
+#   Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+#   Free Software Foundation, Inc.
 #
-# This file is free software; you can redistribute it and/or modify
+# This file is part of the GNU Binutils.
+#
+# This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
+# the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
-# 
+#
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
 #
 # Written by Ian Lance Taylor (ian@cygnus.com)
 #           and H.J. Lu (hjl@gnu.org)
 
 # Make sure that ld can generate ELF shared libraries with visibility.
 
-# This test can only be run if ld generates native executables.
-if ![isnative] then {return}
-
 # This test can only be run on a couple of ELF platforms.
 # Square bracket expressions seem to confuse istarget.
-if { ![istarget i386-*-linux*] \
-     && ![istarget i486-*-linux*] \
-     && ![istarget i586-*-linux*] \
-     && ![istarget i686-*-linux*] \
+if { ![istarget hppa*64*-*-hpux*] \
+     && ![istarget hppa*-*-linux*] \
+     && ![istarget i?86-*-linux*] \
+     && ![istarget ia64-*-linux*] \
      && ![istarget m68k-*-linux*] \
-     && ![istarget powerpc-*-linux*] \
-     && ![istarget sparc*-*-linux*] } {
+     && ![istarget mips*-*-linux*] \
+     && ![istarget powerpc*-*-linux*] \
+     && ![istarget arm*-*-linux*] \
+     && ![istarget alpha*-*-linux*] \
+     && ![istarget sparc*-*-linux*] \
+     && ![istarget s390*-*-linux*] \
+     && ![istarget sh\[34\]*-*-linux*] \
+     && ![istarget x86_64-*-linux*] } {
     return
 }
 
@@ -41,6 +48,16 @@ if { [istarget *-*-linux*aout*] \
     return
 }
 
+set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
+foreach t $test_list {
+    # We need to strip the ".d", but can leave the dirname.
+    verbose [file rootname $t]
+    run_dump_test [file rootname $t]
+}
+
+# The remaining tests can only be run if ld generates native executables.
+if ![isnative] then {return}
+
 set tmpdir tmpdir
 set SHCFLAG ""
 
@@ -74,9 +91,19 @@ if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
     close $file
 }
 
+set support_protected "no"
+
+if [istarget *-*-linux*] {
+    if [ld_compile "$CC -g $CFLAGS -DPROTECTED_CHECK" $srcdir/$subdir/main.c $tmpdir/main.o] {
+      if [ld_simple_link $CC $tmpdir/main "$tmpdir/main.o"] {
+       catch "exec $tmpdir/main" support_protected
+      }
+    }
+}
+
 # The test procedure.
 proc visibility_test { visibility progname testname main sh1 sh2 dat args } {
-    global ld
+    global CC
     global srcdir
     global subdir
     global exec_output
@@ -92,14 +119,14 @@ proc visibility_test { visibility 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 $ld $tmpdir/$progname.so "$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} {
+    if {![ld_simple_link $CC $tmpdir/$progname.so "$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} {
        if { [ string match $visibility "hidden_undef" ]
-            && [regexp ".*/sh1.c.*: undefined reference to \`visibility\'" $link_output]
-            && [regexp ".*/sh1.c.*: undefined reference to \`visibility_var\'" $link_output] } {
+            && [regexp "undefined reference to \`\.?visibility\'" $link_output]
+            && [regexp "undefined reference to \`visibility_var\'" $link_output] } {
            pass "$testname"
        } else { if { [ string match $visibility "protected_undef" ]
-            && [regexp ".*/sh1.c.*: undefined reference to \`visibility\'" $link_output]
-            && [regexp ".*/sh1.c.*: undefined reference to \`visibility_var\'" $link_output] } {
+            && [regexp "undefined reference to \`\.?visibility\'" $link_output]
+            && [regexp "undefined reference to \`visibility_var\'" $link_output] } {
            pass "$testname"
        } else {
            fail "$testname"
@@ -115,14 +142,16 @@ proc visibility_test { visibility progname testname main sh1 sh2 dat args } {
     if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
        set rpath /lib:$tmpdir
     }
-    if ![ld_link $ld $tmpdir/$progname "-rpath $rpath $tmpdir/$main $tmpdir/$progname.so"] {
+    if ![ld_simple_link $CC $tmpdir/$progname "-Wl,-rpath,$rpath $tmpdir/$main $tmpdir/$progname.so"] {
        if { [ string match $visibility "hidden" ]
-            && [regexp ".*/main.c.*: undefined reference to \`visibility\'" $link_output]
-            && [regexp ".*/main.c.*: undefined reference to \`visibility_var\'" $link_output] } {
+            && [regexp "undefined reference to \`\.?visibility\'" $link_output]
+            && [regexp "undefined reference to \`visibility_var\'" $link_output] } {
            pass "$testname"
        } else { if { [ string match $visibility "hidden_undef_def" ]
-            && [regexp ".*/main.c.*: undefined reference to \`visibility\'" $link_output]
-            && [regexp ".*/main.c.*: undefined reference to \`visibility_var\'" $link_output] } {
+            && [regexp "undefined reference to \`\.?visibility\'" $link_output]
+            && [regexp "undefined reference to \`visibility_def\'" $link_output]
+            && [regexp "undefined reference to \`\.?visibility_func\'" $link_output]
+            && [regexp "undefined reference to \`visibility_var\'" $link_output] } {
            pass "$testname"
        } else {
            fail "$testname"
@@ -171,6 +200,7 @@ proc visibility_run {visibility} {
     global tmpdir
     global picflag
     global target_triplet
+    global support_protected
 
     if [ string match $visibility "hidden" ] {
        set VSBCFLAG "-DHIDDEN_TEST"
@@ -195,7 +225,7 @@ proc visibility_run {visibility} {
     }}}}}}}}}
 
     # Compile the main program.
-    if ![ld_compile "$CC $CFLAGS $SHCFLAG $VSBCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o] {
+    if ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o] {
        unresolved "visibility ($visibility) (non PIC)"
        unresolved "visibility ($visibility)"
     } else {
@@ -205,31 +235,83 @@ proc visibility_run {visibility} {
        # 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 $VSBCFLAG" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o]
-            || ![ld_compile "$CC $CFLAGS $SHCFLAG $VSBCFLAG" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } {
+       if { ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o]
+            || ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } {
            unresolved "visibility ($visibility) (non PIC)"
        } else { if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
-           visibility_test $visibility vnp "visibility ($visibility) (nonPIC)" mainnp.o sh1np.o sh2np.o xcoff
+           visibility_test $visibility vnp "visibility ($visibility) (non PIC)" mainnp.o sh1np.o sh2np.o xcoff
        } else {
            # SunOS non PIC shared libraries don't permit some cases of
            # overriding.
-           if [ string match $visibility "protected" ] {
-               setup_xfail $target_triplet
+           if { [ string match $visibility "protected" ]
+                || [ string match $visibility "protected_undef_def" ] } {
+               if [ string match $support_protected "no" ] {
+                   setup_xfail $target_triplet
+               }
            } else {
                setup_xfail "*-*-sunos4*"
            }
+
+           # Non-pic code uses name binding rules for applications to
+           # reference variables by gp-relative relocs, which can't be
+           # used with overridable symbols.
+           if { ![ string match $visibility "hidden_undef" ]
+                && ![ string match $visibility "protected_undef" ] } {
+               setup_xfail "ia64-*-linux*"
+               setup_xfail "alpha*-*-linux*"
+           }
+           if { ![ string match $visibility "hidden" ]
+                && ![ string match $visibility "hidden_undef" ]
+                && ![ string match $visibility "hidden_undef_def" ]
+                && ![ string match $visibility "protected_undef" ] } {
+               setup_xfail "s390x-*-linux*"
+               if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainnp.o] } {
+                   setup_xfail "sparc*-*-linux*"
+               }
+           }
+           setup_xfail "x86_64-*-linux*"
+           if { ![istarget hppa*64*-*-linux*] } {
+               setup_xfail "hppa*-*-linux*"
+           }
+
            visibility_test $visibility vnp "visibility ($visibility) (non PIC)" mainnp.o sh1np.o sh2np.o elfvsb
 
            # 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).
-           if [ string match $visibility "protected" ] {
-               setup_xfail $target_triplet
+           if { [ string match $visibility "protected" ]
+                || [ string match $visibility "protected_undef_def" ] } {
+               if [ string match $support_protected "no" ] {
+                   setup_xfail $target_triplet
+               }
            } else {
                setup_xfail "*-*-sunos4*"
                setup_xfail "*-*-linux*libc1"
            }
+           if { [ string match $visibility "hidden_normal" ]
+                || [ string match $visibility "hidden_weak" ]
+                || [ string match $visibility "protected" ]
+                || [ string match $visibility "protected_undef_def" ]
+                || [ string match $visibility "protected_weak" ]
+                || [ string match $visibility "normal" ] } {
+               setup_xfail "powerpc-*-linux*"
+               setup_xfail "s390x-*-linux*"
+               if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainnp.o] } {
+                   setup_xfail "sparc*-*-linux*"
+               }
+           }
+           if { ![ string match $visibility "hidden_undef" ]
+                && ![ string match $visibility "protected_undef" ] } {
+               setup_xfail "ia64-*-linux*"
+               setup_xfail "alpha*-*-linux*"
+               setup_xfail "mips*-*-linux*"
+           }
+           setup_xfail "x86_64-*-linux*"
+           if { ![istarget hppa*64*-*-linux*] } {
+               setup_xfail "hppa*-*-linux*"
+           }
+
            visibility_test $visibility vnp "visibility ($visibility) (non PIC, load offset)" \
                mainnp.o sh1np.o sh2np.o elfvsb \
                "-T $srcdir/$subdir/elf-offset.ld"
@@ -237,12 +319,15 @@ proc visibility_run {visibility} {
 
        # Now compile the code using -fpic.
 
-       if { ![ld_compile "$CC $CFLAGS $SHCFLAG $VSBCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o] 
-           || ![ld_compile "$CC $CFLAGS $SHCFLAG $VSBCFLAG $picflag" $srcdir/$subdir/sh2.c $tmpdir/sh2p.o] } {
+       if { ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG -DSHARED $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o] 
+           || ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG -DSHARED $picflag" $srcdir/$subdir/sh2.c $tmpdir/sh2p.o] } {
            unresolved "visibility ($visibility)"
        } else {
-           if [ string match $visibility "protected" ] {
-               setup_xfail $target_triplet
+           if { [ string match $visibility "protected" ]
+                || [ string match $visibility "protected_undef_def" ] } {
+               if [ string match $support_protected "no" ] {
+                   setup_xfail $target_triplet
+               }
            }
            # SunOS can not compare function pointers correctly
            if [istarget "*-*-sunos4*"] {
@@ -256,7 +341,7 @@ proc visibility_run {visibility} {
     }
 
     # Now do the same tests again, but this time compile main.c PIC.
-    if ![ld_compile "$CC $CFLAGS $SHCFLAG $VSBCFLAG $picflag" $srcdir/$subdir/main.c $tmpdir/mainp.o] {
+    if ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG -DSHARED $picflag" $srcdir/$subdir/main.c $tmpdir/mainp.o] {
        unresolved "visibility ($visibility) (PIC main, non PIC so)"
        unresolved "visibility ($visibility) (PIC main)"
     } else {
@@ -266,11 +351,33 @@ proc visibility_run {visibility} {
            } else {
                # SunOS non PIC shared libraries don't permit some cases of
                # overriding.
-               if [ string match $visibility "protected" ] {
-                   setup_xfail $target_triplet
+               if { [ string match $visibility "protected" ]
+                    || [ string match $visibility "protected_undef_def" ] } {
+                   if [ string match $support_protected "no" ] {
+                       setup_xfail $target_triplet
+                   }
                } else {
                    setup_xfail "*-*-sunos4*"
                }
+               if { ![ string match $visibility "hidden_undef" ]
+                    && ![ string match $visibility "protected_undef" ] } {
+                   setup_xfail "ia64-*-linux*"
+                   setup_xfail "alpha*-*-linux*"
+               }
+               if { ![ string match $visibility "hidden" ]
+                    && ![ string match $visibility "hidden_undef" ]
+                    && ![ string match $visibility "hidden_undef_def" ]
+                    && ![ string match $visibility "protected_undef" ] } {
+                   setup_xfail "s390x-*-linux*"
+                   if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainp.o] } {
+                       setup_xfail "sparc*-*-linux*"
+                   }
+               }
+               setup_xfail "x86_64-*-linux*"
+               if { ![istarget hppa*64*-*-linux*] } {
+                   setup_xfail "hppa*-*-linux*"
+               }
+
                visibility_test $visibility vmpnp "visibility ($visibility) (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o elfvsb
            }
        } else {
@@ -278,8 +385,11 @@ proc visibility_run {visibility} {
        }
 
        if { [file exists $tmpdir/sh1p.o ] && [ file exists $tmpdir/sh2p.o ] } {
-           if [ string match $visibility "protected" ] {
-               setup_xfail $target_triplet
+           if { [ string match $visibility "protected" ]
+                || [ string match $visibility "protected_undef_def" ] } {
+               if [ string match $support_protected "no" ] {
+                   setup_xfail $target_triplet
+               }
            }
            if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
                visibility_test $visibility vmpp "visibility ($visibility) (PIC main)" mainp.o sh1p.o sh2p.o xcoff
@@ -327,6 +437,39 @@ visibility_run protected_undef_def
 visibility_run protected_weak
 visibility_run normal
 
+if { ![ld_compile "$CC -g $CFLAGS" $srcdir/$subdir/common.c tmpdir/common.o] } {
+    unresolved "common hidden symbol"
+} else {
+    if ![ld_simple_link $ld tmpdir/common "tmpdir/common.o"] {
+       fail "common hidden symbol"
+    } else {
+       pass "common hidden symbol"
+    }
+}
+
+if { ![ld_compile "$CC -g $CFLAGS" $srcdir/$subdir/test.c tmpdir/test.o] } {
+    unresolved "weak hidden symbol"
+} else {
+   if { ![ld_compile "$CC -g $CFLAGS -DSHARED $picflag" $srcdir/$subdir/sh3.c tmpdir/sh3.o] } {
+       unresolved "weak hidden symbol"
+    } else {
+       if ![ld_simple_link $ld tmpdir/sh3.so "-shared tmpdir/sh3.o"] {
+           fail "weak hidden symbol"
+       } else {
+           if ![ld_simple_link $ld tmpdir/weak "tmpdir/test.o tmpdir/sh3.o"] {
+               fail "weak hidden symbol DSO last"
+           } else {
+               pass "weak hidden symbol DSO last"
+           }
+           if ![ld_simple_link $ld tmpdir/weak "tmpdir/sh3.so tmpdir/test.o"] {
+               fail "weak hidden symbol DSO first"
+           } else {
+               pass "weak hidden symbol DSO first"
+           }
+       }
+    }
+}
+
 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
     # Remove the temporary directory.
     catch "exec rm -rf $tmpdir" exec_status