]>
Commit | Line | Data |
---|---|---|
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 ([email protected]) | |
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 | 28 | if ![is_elf_format] { |
ca4fa240 NC |
29 | return |
30 | } | |
31 | ||
78336cd6 AM |
32 | # hpux assembly is weird |
33 | if [istarget "hppa*-*-hpux*"] { | |
34 | return | |
35 | } | |
36 | ||
de7dd2bd NC |
37 | proc 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 | ||
103 | test_sort_common | |
104 | ||
b814bbcb L |
105 | set test1 "size/aligment change of common symbols" |
106 | set test1w1 "$test1 (warning 1)" | |
107 | set test1w2 "$test1 (warning 2)" | |
108 | set test1c1 "$test1 (change 1)" | |
109 | set test1c2 "$test1 (change 2)" | |
110 | ||
7f6a71ff | 111 | if { ![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 |
118 | if { [istarget score-*-*] } { |
119 | untested $test1w1 | |
120 | untested $test1w2 | |
121 | untested $test1c1 | |
122 | untested $test1c2 | |
123 | return | |
124 | } | |
b814bbcb | 125 | |
ca4fa240 NC |
126 | proc 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 |
143 | proc 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. | |
168 | proc 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 | ||
36591ba1 SL |
184 | if [istarget nios2*-*-*] { |
185 | set CFLAGS "$CFLAGS -G0" | |
186 | } | |
187 | ||
698be22a NS |
188 | # Explicitly use "-fcommon" so that even if $CFLAGS includes |
189 | # "-fno-common", these tests are compiled as expected. | |
190 | if { ![ld_compile "$CC $CFLAGS -fcommon" $srcdir/$subdir/common1a.c tmpdir/common1a.o] | |
191 | || ![ld_compile "$CC $CFLAGS -fcommon" $srcdir/$subdir/common1b.c tmpdir/common1b.o] } { | |
ca4fa240 NC |
192 | unresolved $test1 |
193 | return | |
194 | } | |
195 | ||
196 | global ld | |
197 | global link_output | |
198 | ||
22fe6da0 KK |
199 | set options "-r tmpdir/common1a.o tmpdir/common1b.o" |
200 | ||
201 | # SH64 targets needs an extra ld option for this test. | |
202 | if [istarget sh64*-*-*] { | |
203 | if [istarget sh64*l*-*-*] { | |
204 | set options "-mshlelf32 $options" | |
205 | } else { | |
206 | set options "-mshelf32 $options" | |
207 | } | |
208 | } | |
209 | ||
210 | if { [ld_simple_link $ld tmpdir/common1.o $options] } { | |
b814bbcb | 211 | unresolved $test1w1 |
ca4fa240 NC |
212 | return |
213 | } | |
214 | ||
674e82fc | 215 | # This test fails on MIPS because the backend sets type_change_ok. |
70a274ec DA |
216 | # The size change warning is suppressed. Same on hppa64. |
217 | if {[istarget mips*-*-*] || [istarget hppa*64*-*-*]} { | |
674e82fc TS |
218 | if { ![regexp "Warning: alignment (\[0-9\]+) of symbol \`_?foo1\' in tmpdir/common1b.o is smaller than 64 in tmpdir/common1a.o" $link_output] } { |
219 | fail $test1w1 | |
a5e0d269 | 220 | } else { |
674e82fc | 221 | pass $test1w1 |
a5e0d269 | 222 | } |
ca4fa240 | 223 | } else { |
674e82fc TS |
224 | if { ![regexp "Warning: alignment (\[0-9\]+) of symbol \`_?foo1\' in tmpdir/common1b.o is smaller than 64 in tmpdir/common1a.o" $link_output] |
225 | || ![regexp "Warning: size of symbol \`_?foo1\' changed from 2 in tmpdir/common1a.o to 21 in tmpdir/common1b.o" $link_output] } { | |
226 | fail $test1w1 | |
227 | } else { | |
228 | pass $test1w1 | |
229 | } | |
ca4fa240 NC |
230 | } |
231 | ||
b814bbcb L |
232 | if { [dump_common1 $test1c1] } { |
233 | pass $test1c1 | |
ca4fa240 NC |
234 | } |
235 | ||
22fe6da0 KK |
236 | set options "-r tmpdir/common1b.o tmpdir/common1a.o" |
237 | ||
238 | # SH64 targets needs an extra ld option for this test. | |
239 | if [istarget sh64*-*-*] { | |
240 | if [istarget sh64*l*-*-*] { | |
241 | set options "-mshlelf32 $options" | |
242 | } else { | |
243 | set options "-mshelf32 $options" | |
244 | } | |
245 | } | |
246 | ||
247 | if { [ld_simple_link $ld tmpdir/common1.o $options] } { | |
b814bbcb | 248 | unresolved $test1w2 |
ca4fa240 NC |
249 | return |
250 | } | |
251 | ||
09bf9720 | 252 | if { ![regexp "Warning: alignment (\[0-9\]+) of symbol \`_?foo1\' in tmpdir/common1b.o is smaller than 64 in tmpdir/common1a.o" $link_output] } { |
b814bbcb | 253 | fail $test1w2 |
ca4fa240 | 254 | } else { |
b814bbcb | 255 | pass $test1w2 |
ca4fa240 NC |
256 | } |
257 | ||
b814bbcb L |
258 | if { [dump_common1 $test1c2] } { |
259 | pass $test1c2 | |
ca4fa240 | 260 | } |
504b7d20 NC |
261 | |
262 | # | |
263 | # The following tests are for when we are generating STT_COMMON symbols only. | |
264 | # | |
265 | ||
266 | if { ![assembler_generates_commons] } { | |
267 | return | |
268 | } | |
269 | ||
270 | stt_common_test "-static -e 0" "static link of common symbols" | |
271 | stt_common_test "-shared" "shared link of common symbols" | |
272 | stt_common_test "-pie" "position independent link of common symbols" | |
273 |