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