daily update
[external/binutils.git] / ld / testsuite / ld-elfcomm / elfcomm.exp
index f7de6fc..572931b 100644 (file)
@@ -1,5 +1,6 @@
 # Expect script for common symbol tests
-#   Copyright 2003, 2005, 2006, 2007 Free Software Foundation, Inc.
+#   Copyright 2003, 2005, 2006, 2007, 2008, 2009
+#   Free Software Foundation, Inc.
 #
 # This file is part of the GNU Binutils.
 #
@@ -28,6 +29,79 @@ if ![is_elf_format] {
     return
 }
 
+# hpux assembly is weird
+if [istarget "hppa*-*-hpux*"] {
+    return
+}
+
+proc test_sort_common {} {
+    global exec_output
+    global objdump
+    global srcdir
+    global subdir
+    global as
+    global ld
+  
+    set test "--sort-common (descending)"
+  
+    verbose "Check to see that --sort-common sorts in descending alignment"
+
+    # We do not run the sort common tests for the DLX target because we know that the linker
+    # will seg-fault.  The built-in DLX linker script requires that there be something in the
+    # .text section and our sort-common.s file does not provide anything.
+    if [istarget dlx-*-*] {
+       untested "$test"
+       return 0
+    }
+    
+    if { ![ld_assemble $as $srcdir/$subdir/sort-common.s tmpdir/sort-common.o] } {
+       unresolved "$test"
+       return 0
+    }
+
+    if { ![ld_simple_link $ld tmpdir/sort-common.dx "--sort-common=descending tmpdir/sort-common.o"] } {
+       fail "$test"
+       return 0
+    }
+
+    send_log "$objdump --syms tmpdir/sort-common.dx | grep var | sort\n"
+    set exec_output [run_host_cmd "$objdump" "--syms tmpdir/sort-common.dx | grep var | sort"]
+
+    # Don't know why, but the CR ports fail this test.
+    setup_xfail "cr16-*-*" "crx-*-*"
+
+    # Note: The second regexp is for targets which put small commons in a .sbss
+    #  section and large commons in a .bss section.
+    if {   ![regexp ".*var_16.*var_8.*var_4.*var_2.*var_1.*" $exec_output]
+        && ![regexp ".*sbss.*var_8.*var_4.*var_2.*var_1.*bss.*var_16.*" $exec_output] } {      
+       fail $test
+    } else {
+       pass $test
+    }
+
+    set test "--sort-common (ascending)"
+  
+    verbose "Check to see that --sort-common=ascending sorts in ascending alignment"
+
+    if { ![ld_simple_link $ld tmpdir/sort-common.ax "--sort-common=ascending tmpdir/sort-common.o"] } {
+       fail "$test"
+       return 0
+    }
+
+    send_log "$objdump --syms tmpdir/sort-common.ax | grep var | sort\n"
+    set exec_output [run_host_cmd "$objdump" "--syms tmpdir/sort-common.ax | grep var | sort"]
+
+    if {![regexp ".*var_1.*var_2.*var_4.*var_8.*var_16.*" $exec_output]} {      
+       fail $test
+       return 0
+    }
+
+    pass $test
+    return 1
+}
+
+test_sort_common
+
 set test1      "size/aligment change of common symbols"
 set test1w1    "$test1 (warning 1)"
 set test1w2    "$test1 (warning 2)"
@@ -107,9 +181,10 @@ proc assembler_generates_commons {} {
     return 1
 }
 
-
-if {   ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/common1a.c tmpdir/common1a.o]
-    || ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/common1b.c tmpdir/common1b.o] } {
+# Explicitly use "-fcommon" so that even if $CFLAGS includes
+# "-fno-common", these tests are compiled as expected.
+if {   ![ld_compile "$CC $CFLAGS -fcommon" $srcdir/$subdir/common1a.c tmpdir/common1a.o]
+    || ![ld_compile "$CC $CFLAGS -fcommon" $srcdir/$subdir/common1b.c tmpdir/common1b.o] } {
     unresolved $test1
     return
 }
@@ -117,14 +192,25 @@ if {   ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/common1a.c tmpdir/common1a.o]
 global ld
 global link_output
 
-if { [ld_simple_link $ld tmpdir/common1.o "-r tmpdir/common1a.o tmpdir/common1b.o"] } {
+set options "-r tmpdir/common1a.o tmpdir/common1b.o"
+
+# SH64 targets needs an extra ld option for this test.
+if [istarget sh64*-*-*] {
+    if [istarget sh64*l*-*-*] {
+       set options "-mshlelf32 $options"
+    } else {
+       set options "-mshelf32 $options"
+    }
+}
+
+if { [ld_simple_link $ld tmpdir/common1.o $options] } {
     unresolved $test1w1
     return
 }
 
 # This test fails on MIPS because the backend sets type_change_ok.
-# The size change warning is suppressed.
-if {[istarget mips*-*-*]} {
+# The size change warning is suppressed.  Same on hppa64.
+if {[istarget mips*-*-*] || [istarget hppa*64*-*-*]} {
     if { ![regexp "Warning: alignment (\[0-9\]+) of symbol \`_?foo1\' in tmpdir/common1b.o is smaller than 64 in tmpdir/common1a.o" $link_output] } {
         fail $test1w1
     } else {
@@ -143,7 +229,18 @@ if { [dump_common1 $test1c1] } {
     pass $test1c1
 }
 
-if { [ld_simple_link $ld tmpdir/common1.o "-r tmpdir/common1b.o tmpdir/common1a.o"] } {
+set options "-r tmpdir/common1b.o tmpdir/common1a.o"
+
+# SH64 targets needs an extra ld option for this test.
+if [istarget sh64*-*-*] {
+    if [istarget sh64*l*-*-*] {
+       set options "-mshlelf32 $options"
+    } else {
+       set options "-mshelf32 $options"
+    }
+}
+
+if { [ld_simple_link $ld tmpdir/common1.o $options] } {
     unresolved $test1w2
     return
 }