2003-04-22 H.J. Lu <hjl@gnu.org>
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elfcomm / elfcomm.exp
1 # Expect script for commom symbol tests
2 # Copyright 2003 Free Software Foundation, Inc.
3 #
4 # This file is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #
18 # Written by H.J. Lu (hjl@gnu.org)
19 #
20
21 # Make sure that ld correctly handles common symbols in ELF.
22
23 # This test can only be run on ELF platforms.
24 # Square bracket expressions seem to confuse istarget.
25 if { ![istarget hppa*64*-*-hpux*] \
26 && ![istarget *-*-gnu] \
27 && ![istarget *-*-linux*] \
28 && ![istarget *-*-elf] } {
29 return
30 }
31
32 if { [istarget *-*-linux*aout*] \
33 || [istarget *-*-linux*oldld*] } {
34 return
35 }
36
37 proc dump_common1 { testname } {
38 global exec_output
39
40 send_log "readelf -s tmpdir/common1.o | grep foo\n"
41 catch "exec readelf -s tmpdir/common1.o | grep foo" exec_output
42 if { ![regexp "(\[ \]*)(\[0-9\]+):(\[ \]*)(\[0\]*)80(\[ \]+)4(\[ \]+)OBJECT(\[ \]+)GLOBAL(\[ \]+)DEFAULT(\[ \]+)COM(\[ \]+)foo2" $exec_output]
43 || ![regexp "(\[ \]*)(\[0-9\]+):(\[ \]*)(\[0-9\]+)(\[ \]+)21(\[ \]+)OBJECT(\[ \]+)GLOBAL(\[ \]+)DEFAULT(\[ \]+)(\[0-9\]+)(\[ \]+)foo1" $exec_output] } {
44 send_log "$exec_output\n"
45 verbose $exec_output
46 fail $testname
47 return 0
48 }
49
50 return 1
51 }
52
53 set test1 "size/aligment change of commom symbols"
54 if { ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/common1a.c tmpdir/common1a.o]
55 || ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/common1b.c tmpdir/common1b.o] } {
56 unresolved $test1
57 return
58 }
59
60 global ld
61 global link_output
62
63 if { [ld_simple_link $ld tmpdir/common1.o "-r tmpdir/common1a.o tmpdir/common1b.o"] } {
64 unresolved "$test1 (warning 1)"
65 return
66 }
67
68 if { ![regexp "Warning: alignment (\[0-9\]+) of symbol \`foo1\' in tmpdir/common1b.o is smaller than 64 in tmpdir/common1a.o" $link_output]
69 || ![regexp "Warning: size of symbol \`foo1\' changed from 2 in tmpdir/common1a.o to 21 in tmpdir/common1b.o" $link_output] } {
70 fail "$test1 (warning 1)"
71 } else {
72 pass "$test1 (warning 1)"
73 }
74
75 if { [dump_common1 "$test1 (change 1)"] } {
76 pass "$test1 (change 1)"
77 }
78
79 if { [ld_simple_link $ld tmpdir/common1.o "-r tmpdir/common1b.o tmpdir/common1a.o"] } {
80 unresolved "$test1 (warning 2)"
81 return
82 }
83
84 if { ![regexp "Warning: alignment (\[0-9\]+) of symbol \`foo1\' in tmpdir/common1b.o is smaller than 64 in tmpdir/common1a.o" $link_output] } {
85 fail "$test1 (warning 2)"
86 } else {
87 pass "$test1 (warning 2)"
88 }
89
90 if { [dump_common1 "$test1 (change 2)"] } {
91 pass "$test1 (change 2)"
92 }
This page took 0.0864 seconds and 5 git commands to generate.