bfd:
[external/binutils.git] / ld / testsuite / ld-elfcomm / elfcomm.exp
1 # Expect script for common symbol tests
2 #   Copyright 2003, 2005, 2006, 2007 Free Software Foundation, Inc.
3 #
4 # This file is part of the GNU Binutils.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20 #
21 # Written by H.J. Lu (hjl@gnu.org)
22 #
23
24 # Make sure that ld correctly handles common symbols in ELF.
25
26 # This test can only be run on ELF platforms.
27 if ![is_elf_format] {
28     return
29 }
30
31 set test1       "size/aligment change of common symbols"
32 set test1w1     "$test1 (warning 1)"
33 set test1w2     "$test1 (warning 2)"
34 set test1c1     "$test1 (change 1)"
35 set test1c2     "$test1 (change 2)"
36
37 if { ![is_remote host] && [which $CC] == 0 } {
38     untested $test1w1
39     untested $test1w2
40     untested $test1c1
41     untested $test1c2
42     return
43 }
44 if { [istarget score-*-*] } {
45     untested $test1w1
46     untested $test1w2
47     untested $test1c1
48     untested $test1c2
49     return
50 }
51
52 proc dump_common1 { testname } {
53     global exec_output
54     global READELF
55
56     send_log "$READELF -s tmpdir/common1.o | grep foo\n"
57     set exec_output [run_host_cmd "readelf" "-s tmpdir/common1.o | grep foo"]
58
59     if { ![regexp "(\[  \]*)(\[0-9\]+):(\[      \]*)(\[0\]*)80(\[       \]+)4(\[        \]+)OBJECT(\[   \]+)GLOBAL(\[   \]+)DEFAULT(\[  \]+)(PRC\\\[0xff03\\\]|COM|SCOM)(\[     \]+)_?foo2" $exec_output]
60          || ![regexp "(\[       \]*)(\[0-9\]+):(\[      \]*)(\[0-9\]+)(\[       \]+)21(\[       \]+)OBJECT(\[   \]+)GLOBAL(\[   \]+)DEFAULT(\[  \]+)(\[0-9\]+)(\[       \]+)_?foo1" $exec_output] } {
61         send_log "$exec_output\n"
62         verbose $exec_output
63         fail $testname
64         return 0
65     }
66
67     return 1
68 }
69
70 if { ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/common1a.c tmpdir/common1a.o]
71     || ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/common1b.c tmpdir/common1b.o] } {
72     unresolved $test1
73     return
74 }
75
76 global ld
77 global link_output
78
79 if { [ld_simple_link $ld tmpdir/common1.o "-r tmpdir/common1a.o tmpdir/common1b.o"] } {
80     unresolved $test1w1
81     return
82 }
83
84 # This test fails on MIPS because the backend sets type_change_ok.
85 # The size change warning is suppressed.
86 if {[istarget mips*-*-*]} {
87     if { ![regexp "Warning: alignment (\[0-9\]+) of symbol \`_?foo1\' in tmpdir/common1b.o is smaller than 64 in tmpdir/common1a.o" $link_output] } {
88         fail $test1w1
89     } else {
90         pass $test1w1
91     }
92 } else {
93     pass $test1w1
94     if { ![regexp "Warning: alignment (\[0-9\]+) of symbol \`_?foo1\' in tmpdir/common1b.o is smaller than 64 in tmpdir/common1a.o" $link_output]
95          || ![regexp "Warning: size of symbol \`_?foo1\' changed from 2 in tmpdir/common1a.o to 21 in tmpdir/common1b.o" $link_output] } {
96         fail $test1w1
97     } else {
98         pass $test1w1
99     }
100 }
101
102 if { [dump_common1 $test1c1] } {
103     pass $test1c1
104 }
105
106 if { [ld_simple_link $ld tmpdir/common1.o "-r tmpdir/common1b.o tmpdir/common1a.o"] } {
107     unresolved $test1w2
108     return
109 }
110
111 if { ![regexp "Warning: alignment (\[0-9\]+) of symbol \`_?foo1\' in tmpdir/common1b.o is smaller than 64 in tmpdir/common1a.o" $link_output] } {
112     fail $test1w2
113 } else {
114     pass $test1w2
115 }
116
117 if { [dump_common1 $test1c2] } {
118     pass $test1c2
119 }