daily update
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elfcomm / elfcomm.exp
CommitLineData
09bf9720 1# Expect script for common symbol tests
22fe6da0
KK
2# Copyright 2003, 2005, 2006, 2007, 2008, 2009
3# Free Software Foundation, Inc.
ca4fa240 4#
f96b4a7b
NC
5# This file is part of the GNU Binutils.
6#
7# This program is free software; you can redistribute it and/or modify
ca4fa240 8# it under the terms of the GNU General Public License as published by
f96b4a7b 9# the Free Software Foundation; either version 3 of the License, or
ca4fa240 10# (at your option) any later version.
f96b4a7b 11#
ca4fa240
NC
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
f96b4a7b 16#
ca4fa240
NC
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
f96b4a7b
NC
19# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20# MA 02110-1301, USA.
ca4fa240
NC
21#
22# Written by H.J. Lu (hjl@gnu.org)
23#
24
25# Make sure that ld correctly handles common symbols in ELF.
26
27# This test can only be run on ELF platforms.
43f9d75b 28if ![is_elf_format] {
ca4fa240
NC
29 return
30}
31
78336cd6
AM
32# hpux assembly is weird
33if [istarget "hppa*-*-hpux*"] {
34 return
35}
36
de7dd2bd
NC
37proc test_sort_common {} {
38 global exec_output
39 global objdump
40 global srcdir
41 global subdir
42 global as
43 global ld
44
45 set test "--sort-common (descending)"
46
47 verbose "Check to see that --sort-common sorts in descending alignment"
48
49 # We do not run the sort common tests for the DLX target because we know that the linker
50 # will seg-fault. The built-in DLX linker script requires that there be something in the
51 # .text section and our sort-common.s file does not provide anything.
52 if [istarget dlx-*-*] {
53 untested "$test"
54 return 0
55 }
56
57 if { ![ld_assemble $as $srcdir/$subdir/sort-common.s tmpdir/sort-common.o] } {
58 unresolved "$test"
59 return 0
60 }
61
62 if { ![ld_simple_link $ld tmpdir/sort-common.dx "--sort-common=descending tmpdir/sort-common.o"] } {
63 fail "$test"
64 return 0
65 }
66
67 send_log "$objdump --syms tmpdir/sort-common.dx | grep var | sort\n"
68 set exec_output [run_host_cmd "$objdump" "--syms tmpdir/sort-common.dx | grep var | sort"]
69
70 # Don't know why, but the CR ports fail this test.
71 setup_xfail "cr16-*-*" "crx-*-*"
72
73 # Note: The second regexp is for targets which put small commons in a .sbss
74 # section and large commons in a .bss section.
75 if { ![regexp ".*var_16.*var_8.*var_4.*var_2.*var_1.*" $exec_output]
76 && ![regexp ".*sbss.*var_8.*var_4.*var_2.*var_1.*bss.*var_16.*" $exec_output] } {
77 fail $test
78 } else {
79 pass $test
80 }
81
82 set test "--sort-common (ascending)"
83
84 verbose "Check to see that --sort-common=ascending sorts in ascending alignment"
85
86 if { ![ld_simple_link $ld tmpdir/sort-common.ax "--sort-common=ascending tmpdir/sort-common.o"] } {
87 fail "$test"
88 return 0
89 }
90
91 send_log "$objdump --syms tmpdir/sort-common.ax | grep var | sort\n"
92 set exec_output [run_host_cmd "$objdump" "--syms tmpdir/sort-common.ax | grep var | sort"]
93
94 if {![regexp ".*var_1.*var_2.*var_4.*var_8.*var_16.*" $exec_output]} {
95 fail $test
96 return 0
97 }
98
99 pass $test
100 return 1
101}
102
103test_sort_common
104
b814bbcb
L
105set test1 "size/aligment change of common symbols"
106set test1w1 "$test1 (warning 1)"
107set test1w2 "$test1 (warning 2)"
108set test1c1 "$test1 (change 1)"
109set test1c2 "$test1 (change 2)"
110
7f6a71ff 111if { ![is_remote host] && [which $CC] == 0 } {
b814bbcb
L
112 untested $test1w1
113 untested $test1w2
114 untested $test1c1
115 untested $test1c2
116 return
117}
1c0d3aa6
NC
118if { [istarget score-*-*] } {
119 untested $test1w1
120 untested $test1w2
121 untested $test1c1
122 untested $test1c2
123 return
124}
b814bbcb 125
ca4fa240
NC
126proc dump_common1 { testname } {
127 global exec_output
a42ec05b 128 global READELF
ca4fa240 129
504b7d20 130 send_log "$READELF --syms tmpdir/common1.o | grep foo\n"
5c817830 131 set exec_output [run_host_cmd "$READELF" "--syms tmpdir/common1.o | grep foo"]
7f6a71ff 132
504b7d20
NC
133 if { ![regexp "(\[ \]*)(\[0-9\]+):(\[ \]*)(\[0\]*)80(\[ \]+)4(\[ \]+)(COMMON|OBJECT)(\[ \]+)GLOBAL(\[ \]+)DEFAULT(\[ \]+)(PRC\\\[0xff03\\\]|COM|SCOM)(\[ \]+)_?foo2" $exec_output]
134 || ![regexp "(\[ \]*)(\[0-9\]+):(\[ \]*)(\[0-9\]+)(\[ \]+)21(\[ \]+)OBJECT(\[ \]+)GLOBAL(\[ \]+)DEFAULT(\[ \]+)(\[0-9\]+)(\[ \]+)_?foo1" $exec_output] } {
ca4fa240
NC
135 verbose $exec_output
136 fail $testname
137 return 0
138 }
139
140 return 1
141}
142
504b7d20
NC
143proc stt_common_test { options testname } {
144 global exec_output
145 global READELF
146 global ld
147
148 set options "$options tmpdir/common1a.o"
149
150 if { ! [ld_simple_link $ld tmpdir/common.exe $options] } {
151 unresolved $testname
152 return 0
153 }
154
155 send_log "$READELF --syms tmpdir/common.exe | grep foo\n"
5c817830 156 set exec_output [run_host_cmd "$READELF" "--syms tmpdir/common.exe | grep foo"]
504b7d20
NC
157
158 if {![regexp "(\[ \]*)(\[0-9\]+):(\[ \]*)(\[0-9\]+)(\[ \]+)(\[0-9\]+)(\[ \]+)COMMON(\[ \]+)GLOBAL(\[ \]+)DEFAULT(\[ \]+)(\[0-9\]+)(\[ \]+)_?foo2" $exec_output] } {
159 fail $testname
160 return 0
161 }
162
163 pass $testname
164 return 1
165}
166
167# Check to see if the assembler is generating symbols with the STT_COMMON type.
168proc assembler_generates_commons {} {
169 global exec_output
170 global READELF
171
172 verbose "Check to see if STT_COMMON symbols are being generated:"
5c817830 173 set exec_output [run_host_cmd "$READELF" "--syms tmpdir/common1a.o | grep foo"]
504b7d20
NC
174
175 if { ![regexp "(\[ \]*)(\[0-9\]+):(\[ \]*)(\[0\]*)80(\[ \]+).(\[ \]+)COMMON(\[ \]+)GLOBAL(\[ \]+)DEFAULT(\[ \]+)(PRC\\\[0xff03\\\]|COM|SCOM)(\[ \]+)_?foo2" $exec_output] } {
176 verbose "STT_COMMON not generated"
177 return 0
178 }
179
180 verbose "STT_COMMON's are generated"
181 return 1
182}
183
698be22a
NS
184# Explicitly use "-fcommon" so that even if $CFLAGS includes
185# "-fno-common", these tests are compiled as expected.
186if { ![ld_compile "$CC $CFLAGS -fcommon" $srcdir/$subdir/common1a.c tmpdir/common1a.o]
187 || ![ld_compile "$CC $CFLAGS -fcommon" $srcdir/$subdir/common1b.c tmpdir/common1b.o] } {
ca4fa240
NC
188 unresolved $test1
189 return
190}
191
192global ld
193global link_output
194
22fe6da0
KK
195set options "-r tmpdir/common1a.o tmpdir/common1b.o"
196
197# SH64 targets needs an extra ld option for this test.
198if [istarget sh64*-*-*] {
199 if [istarget sh64*l*-*-*] {
200 set options "-mshlelf32 $options"
201 } else {
202 set options "-mshelf32 $options"
203 }
204}
205
206if { [ld_simple_link $ld tmpdir/common1.o $options] } {
b814bbcb 207 unresolved $test1w1
ca4fa240
NC
208 return
209}
210
674e82fc 211# This test fails on MIPS because the backend sets type_change_ok.
70a274ec
DA
212# The size change warning is suppressed. Same on hppa64.
213if {[istarget mips*-*-*] || [istarget hppa*64*-*-*]} {
674e82fc
TS
214 if { ![regexp "Warning: alignment (\[0-9\]+) of symbol \`_?foo1\' in tmpdir/common1b.o is smaller than 64 in tmpdir/common1a.o" $link_output] } {
215 fail $test1w1
a5e0d269 216 } else {
674e82fc 217 pass $test1w1
a5e0d269 218 }
ca4fa240 219} else {
674e82fc
TS
220 if { ![regexp "Warning: alignment (\[0-9\]+) of symbol \`_?foo1\' in tmpdir/common1b.o is smaller than 64 in tmpdir/common1a.o" $link_output]
221 || ![regexp "Warning: size of symbol \`_?foo1\' changed from 2 in tmpdir/common1a.o to 21 in tmpdir/common1b.o" $link_output] } {
222 fail $test1w1
223 } else {
224 pass $test1w1
225 }
ca4fa240
NC
226}
227
b814bbcb
L
228if { [dump_common1 $test1c1] } {
229 pass $test1c1
ca4fa240
NC
230}
231
22fe6da0
KK
232set options "-r tmpdir/common1b.o tmpdir/common1a.o"
233
234# SH64 targets needs an extra ld option for this test.
235if [istarget sh64*-*-*] {
236 if [istarget sh64*l*-*-*] {
237 set options "-mshlelf32 $options"
238 } else {
239 set options "-mshelf32 $options"
240 }
241}
242
243if { [ld_simple_link $ld tmpdir/common1.o $options] } {
b814bbcb 244 unresolved $test1w2
ca4fa240
NC
245 return
246}
247
09bf9720 248if { ![regexp "Warning: alignment (\[0-9\]+) of symbol \`_?foo1\' in tmpdir/common1b.o is smaller than 64 in tmpdir/common1a.o" $link_output] } {
b814bbcb 249 fail $test1w2
ca4fa240 250} else {
b814bbcb 251 pass $test1w2
ca4fa240
NC
252}
253
b814bbcb
L
254if { [dump_common1 $test1c2] } {
255 pass $test1c2
ca4fa240 256}
504b7d20
NC
257
258#
259# The following tests are for when we are generating STT_COMMON symbols only.
260#
261
262if { ![assembler_generates_commons] } {
263 return
264}
265
266stt_common_test "-static -e 0" "static link of common symbols"
267stt_common_test "-shared" "shared link of common symbols"
268stt_common_test "-pie" "position independent link of common symbols"
269
This page took 0.434818 seconds and 4 git commands to generate.