Run more ld tests when not native
[deliverable/binutils-gdb.git] / ld / testsuite / ld-size / size.exp
1 # Expect script for linker support of size relocations.
2 #
3 # Copyright (C) 2013-2017 Free Software Foundation, Inc.
4 #
5 # This file is part of the GNU Binutils.
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
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.
16 #
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
19 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 # MA 02110-1301, USA.
21 #
22
23
24 # Size relications have only been implemented for the ix86 and x86_64,
25 # so far.
26 if {!(([istarget "i?86-*-*"]
27 || [istarget "x86_64-*-*"])
28 && ([istarget "*-*-elf*"]
29 || [istarget "*-*-nacl*"]
30 || (([istarget "*-*-linux*"]
31 || [istarget "*-*-gnu*"])
32 && ![istarget "*-*-*aout*"]
33 && ![istarget "*-*-*oldld*"]))) } {
34 verbose "Size relocations tests not run - no target support"
35 return
36 }
37
38 # So as to avoid rewriting every last test case here in a nacl variant,
39 # we use black magic to massage the generic cases into nacl-variant cases.
40 if [istarget "*-*-nacl*"] {
41 # Change all the -melf_i386 to -melf_i386_nacl so linking can succeed.
42 set options_regsub(ld) {-m(\\S+) -m\\1_nacl}
43 }
44
45 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
46 foreach t $test_list {
47 # We need to strip the ".d", but can leave the dirname.
48 verbose [file rootname $t]
49 run_dump_test [file rootname $t]
50 }
51
52 # We need a working compiler.
53 if { [which $CC] == 0 } {
54 verbose "Native size relocation tests not run - no compiler available"
55 return
56 }
57
58 # Add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if non-PIE is required.
59 global NOPIE_CFLAGS NOPIE_LDFLAGS
60
61 run_cc_link_tests [list \
62 [list \
63 "Build libsize-1.so" \
64 "-shared" \
65 "-fPIC" \
66 {size-1a.c size-1b.c} \
67 {} \
68 "libsize-1.so" \
69 ] \
70 [list \
71 "Build libsize-2.so" \
72 "-shared" \
73 "-fPIC" \
74 {size-2a.c size-2b.c} \
75 {} \
76 "libsize-2.so" \
77 ] \
78 [list \
79 "Build libsize-3a.so" \
80 "-shared" "-fPIC" \
81 {size-3a.c} \
82 {} \
83 "libsize-3a.so" \
84 ] \
85 [list \
86 "Build libsize-3b.so" \
87 "-shared" \
88 "-fPIC" \
89 {size-3b.c} \
90 {} \
91 "libsize-3b.so" \
92 ] \
93 [list \
94 "Build libsize-3c.so" \
95 "-shared" \
96 "-fPIC" \
97 {size-3c.c} \
98 {} \
99 "libsize-3c.so" \
100 ] \
101 [list \
102 "Build libsize-6b.so" \
103 "-shared" \
104 "-fPIC" \
105 {size-6b.c} \
106 {} \
107 "libsize-6b.so" \
108 ] \
109 [list \
110 "Build libsize-7.so" \
111 "-shared" \
112 "-fPIC" \
113 {size-7b.c} \
114 {} \
115 "libsize-7.so" \
116 ] \
117 [list \
118 "Build size-7" \
119 "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libsize-7.so" \
120 "$NOPIE_CFLAGS" \
121 {size-7a.c} \
122 {{readelf -rW size-7.rd}} \
123 "size-7.exe" \
124 ] \
125 [list \
126 "Build libsize-8.so" \
127 "-shared" "-fPIC" \
128 {size-8b.c} \
129 {} \
130 "libsize-8.so" \
131 ] \
132 [list \
133 "Build size-8" \
134 "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libsize-8.so" \
135 "$NOPIE_CFLAGS" \
136 {size-8a.c} \
137 {{readelf -rW size-8.rd}} \
138 "size-8.exe" \
139 ] \
140 [list \
141 "Build libsize-9.so" \
142 "-shared" \
143 "-fPIC" \
144 {size-9b.c} \
145 {{readelf -rW size-9.rd}} \
146 "libsize-9.so" \
147 ] \
148 [list \
149 "Build libsize-10.so" \
150 "-shared" \
151 "-fPIC" \
152 {size-10b.c} \
153 {{readelf -rW size-10.rd}} \
154 "libsize-10.so" \
155 ] \
156 ]
157
158 # Check if size relocation works at run-time.
159 catch "exec tmpdir/size-7.exe > tmpdir/dump.out" exec_output
160 if ![string match "" $exec_output] then {
161 send_log "No run-time size relocation support: $exec_output\n"
162 verbose "No run-time size relocation support: $exec_output" 1
163 return
164 }
165
166 if { [regexp_diff "tmpdir/dump.out" "$srcdir/$subdir/size-7.out" ] } then {
167 verbose "output is [file_contents "tmpdir/dump.out"]" 2
168 fail "Run-time size relocation"
169 return
170 }
171
172 # Run-time size relocation tests.
173 run_ld_link_exec_tests [list \
174 [list \
175 "Run size-1" \
176 "-Wl,--no-as-needed tmpdir/libsize-1.so" \
177 "" \
178 {size-1.c} \
179 "size-1" \
180 "size-1.out" \
181 ] \
182 [list \
183 "Run size-2" \
184 "-Wl,--no-as-needed tmpdir/libsize-2.so" \
185 "" \
186 {size-2.c} \
187 "size-2" \
188 "size-2.out" \
189 ] \
190 [list \
191 "Run size-3a" \
192 "" \
193 "" \
194 {size-3.c size-3a.c} \
195 "size-3a" \
196 "size-3.out" \
197 ] \
198 [list \
199 "Run size-3b" \
200 "-Wl,--no-as-needed tmpdir/libsize-3a.so" \
201 "" \
202 {size-3.c} \
203 "size-3b" \
204 "size-3.out" \
205 ] \
206 [list \
207 "Run size-3c" \
208 "" \
209 "" \
210 {size-3.c size-3b.c} \
211 "size-3c" \
212 "size-3.out" \
213 ] \
214 [list \
215 "Run size-3d (1)" \
216 "-Wl,--no-as-needed tmpdir/libsize-3b.so" \
217 "" \
218 {size-3.c} \
219 "size-3d1" \
220 "size-3.out" \
221 ] \
222 [list \
223 "Run size-3d (2)" \
224 "" \
225 "" \
226 {size-3.c size-3c.c} \
227 "size-3d2" \
228 "size-3.out" \
229 ] \
230 [list \
231 {"Run size-3e"
232 "-Wl,--no-as-needed tmpdir/libsize-3c.so" ""
233 {size-3.c} "size-3e" "size-3.out"}
234 ] \
235 [list \
236 "Run size-4a" \
237 "" \
238 "" \
239 {size-4a.c size-4b.c} \
240 "size-4a" \
241 "size-4.out" \
242 "$NOPIE_CFLAGS" \
243 ] \
244 [list \
245 "Run size-4b" \
246 "" \
247 "" \
248 {size-4b.c size-4a.c} \
249 "size-4b" \
250 "size-4.out" \
251 "$NOPIE_CFLAGS" \
252 ] \
253 [list \
254 "Run size-5a" \
255 "" \
256 "" \
257 {size-5a.c size-5b.c} \
258 "size-5a" \
259 "size-5.out" \
260 "$NOPIE_CFLAGS" \
261 ] \
262 [list \
263 "Run size-5b" \
264 "" \
265 "" \
266 {size-5b.c size-5a.c} \
267 "size-5b" \
268 "size-5.out" \
269 "$NOPIE_CFLAGS" \
270 ] \
271 [list \
272 "Run size-6" \
273 "-Wl,--no-as-needed tmpdir/libsize-6b.so" \
274 "" \
275 {size-6a.c} \
276 "size-6" \
277 "size-6.out" \
278 "$NOPIE_CFLAGS" \
279 ] \
280 [list \
281 "Run size-8" \
282 "-Wl,--no-as-needed,--hash-styl=gnu tmpdir/libsize-8.so" \
283 "" \
284 {size-8a.c} \
285 "size-8" \
286 "size-8.out" \
287 "$NOPIE_CFLAGS" \
288 ] \
289 [list \
290 "Run size-9" \
291 "-Wl,--no-as-needed tmpdir/libsize-9.so" \
292 "" \
293 {size-9a.c} \
294 "size-9" \
295 "size-9.out" \
296 ] \
297 [list \
298 "Run size-10" \
299 "-Wl,--no-as-needed tmpdir/libsize-10.so" \
300 "" \
301 {size-10a.c} \
302 "size-10" \
303 "size-10.out" \
304 ] \
305 ]
This page took 0.053799 seconds and 4 git commands to generate.