]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/testsuite/ld-size/size.exp
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / ld / testsuite / ld-size / size.exp
1 # Expect script for linker support of size relocations.
2 #
3 # Copyright (C) 2013-2021 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 { ![check_compiler_available] } {
52 verbose "Native size relocation tests not run - no compiler available"
53 return
54 }
55
56 run_cc_link_tests [list \
57 [list \
58 "Build libsize-1.so" \
59 "-shared" \
60 "-fPIC" \
61 {size-1a.c size-1b.c} \
62 {} \
63 "libsize-1.so" \
64 ] \
65 [list \
66 "Build libsize-2.so" \
67 "-shared" \
68 "-fPIC" \
69 {size-2a.c size-2b.c} \
70 {} \
71 "libsize-2.so" \
72 ] \
73 [list \
74 "Build libsize-3a.so" \
75 "-shared" "-fPIC" \
76 {size-3a.c} \
77 {} \
78 "libsize-3a.so" \
79 ] \
80 [list \
81 "Build libsize-3b.so" \
82 "-shared" \
83 "-fPIC" \
84 {size-3b.c} \
85 {} \
86 "libsize-3b.so" \
87 ] \
88 [list \
89 "Build libsize-3c.so" \
90 "-shared" \
91 "-fPIC" \
92 {size-3c.c} \
93 {} \
94 "libsize-3c.so" \
95 ] \
96 [list \
97 "Build libsize-6b.so" \
98 "-shared" \
99 "-fPIC" \
100 {size-6b.c} \
101 {} \
102 "libsize-6b.so" \
103 ] \
104 [list \
105 "Build libsize-7.so" \
106 "-shared" \
107 "-fPIC" \
108 {size-7b.c} \
109 {} \
110 "libsize-7.so" \
111 ] \
112 [list \
113 "Build size-7" \
114 "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,notext tmpdir/libsize-7.so" \
115 "$NOPIE_CFLAGS" \
116 {size-7a.c} \
117 {{readelf -rW size-7.rd}} \
118 "size-7.exe" \
119 ] \
120 [list \
121 "Build libsize-8.so" \
122 "-shared" "-fPIC" \
123 {size-8b.c} \
124 {} \
125 "libsize-8.so" \
126 ] \
127 [list \
128 "Build size-8" \
129 "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,notext tmpdir/libsize-8.so" \
130 "$NOPIE_CFLAGS" \
131 {size-8a.c} \
132 {{readelf -rW size-8.rd}} \
133 "size-8.exe" \
134 ] \
135 [list \
136 "Build libsize-9.so" \
137 "-shared $NOSANITIZE_CFLAGS" \
138 "-fPIC $NOSANITIZE_CFLAGS" \
139 {size-9b.c} \
140 {{readelf -rW size-9.rd}} \
141 "libsize-9.so" \
142 ] \
143 [list \
144 "Build libsize-10.so" \
145 "-shared" \
146 "-fPIC" \
147 {size-10b.c} \
148 {{readelf -rW size-10.rd}} \
149 "libsize-10.so" \
150 ] \
151 ]
152
153 # Check if size relocation works at run-time.
154 catch "exec tmpdir/size-7.exe > tmpdir/dump.out" exec_output
155 if ![string match "" $exec_output] then {
156 send_log "No run-time size relocation support: $exec_output\n"
157 verbose "No run-time size relocation support: $exec_output" 1
158 return
159 }
160
161 if { [regexp_diff "tmpdir/dump.out" "$srcdir/$subdir/size-7.out" ] } then {
162 verbose "output is [file_contents "tmpdir/dump.out"]" 2
163 fail "Run-time size relocation"
164 return
165 }
166
167 # Run-time size relocation tests.
168 run_ld_link_exec_tests [list \
169 [list \
170 "Run size-1" \
171 "-Wl,--no-as-needed tmpdir/libsize-1.so" \
172 "" \
173 {size-1.c} \
174 "size-1" \
175 "size-1.out" \
176 ] \
177 [list \
178 "Run size-2" \
179 "-Wl,--no-as-needed tmpdir/libsize-2.so" \
180 "" \
181 {size-2.c} \
182 "size-2" \
183 "size-2.out" \
184 ] \
185 [list \
186 "Run size-3a" \
187 "" \
188 "" \
189 {size-3.c size-3a.c} \
190 "size-3a" \
191 "size-3.out" \
192 ] \
193 [list \
194 "Run size-3b" \
195 "-Wl,--no-as-needed tmpdir/libsize-3a.so" \
196 "" \
197 {size-3.c} \
198 "size-3b" \
199 "size-3.out" \
200 ] \
201 [list \
202 "Run size-3c" \
203 "" \
204 "" \
205 {size-3.c size-3b.c} \
206 "size-3c" \
207 "size-3.out" \
208 ] \
209 [list \
210 "Run size-3d (1)" \
211 "-Wl,--no-as-needed tmpdir/libsize-3b.so" \
212 "" \
213 {size-3.c} \
214 "size-3d1" \
215 "size-3.out" \
216 ] \
217 [list \
218 "Run size-3d (2)" \
219 "" \
220 "" \
221 {size-3.c size-3c.c} \
222 "size-3d2" \
223 "size-3.out" \
224 ] \
225 [list \
226 {"Run size-3e" \
227 "-Wl,--no-as-needed tmpdir/libsize-3c.so" "" \
228 {size-3.c} "size-3e" "size-3.out"} \
229 ] \
230 [list \
231 "Run size-4a" \
232 "$NOPIE_LDFLAGS" \
233 "" \
234 {size-4a.c size-4b.c} \
235 "size-4a" \
236 "size-4.out" \
237 "$NOPIE_CFLAGS" \
238 ] \
239 [list \
240 "Run size-4b" \
241 "$NOPIE_LDFLAGS" \
242 "" \
243 {size-4b.c size-4a.c} \
244 "size-4b" \
245 "size-4.out" \
246 "$NOPIE_CFLAGS" \
247 ] \
248 [list \
249 "Run size-5a" \
250 "$NOPIE_LDFLAGS" \
251 "" \
252 {size-5a.c size-5b.c} \
253 "size-5a" \
254 "size-5.out" \
255 "$NOPIE_CFLAGS" \
256 ] \
257 [list \
258 "Run size-5b" \
259 "$NOPIE_LDFLAGS" \
260 "" \
261 {size-5b.c size-5a.c} \
262 "size-5b" \
263 "size-5.out" \
264 "$NOPIE_CFLAGS" \
265 ] \
266 [list \
267 "Run size-6" \
268 "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libsize-6b.so" \
269 "" \
270 {size-6a.c} \
271 "size-6" \
272 "size-6.out" \
273 "$NOPIE_CFLAGS" \
274 ] \
275 [list \
276 "Run size-8" \
277 "$NOPIE_LDFLAGS -Wl,--no-as-needed,--hash-styl=gnu,-z,notext \
278 tmpdir/libsize-8.so" \
279 "" \
280 {size-8a.c} \
281 "size-8" \
282 "size-8.out" \
283 "$NOPIE_CFLAGS" \
284 ] \
285 [list \
286 "Run size-9" \
287 "-Wl,--no-as-needed tmpdir/libsize-9.so $NOSANITIZE_CFLAGS" \
288 "" \
289 {size-9a.c} \
290 "size-9" \
291 "size-9.out" \
292 "$NOSANITIZE_CFLAGS" \
293 ] \
294 [list \
295 "Run size-10" \
296 "-Wl,--no-as-needed tmpdir/libsize-10.so" \
297 "" \
298 {size-10a.c} \
299 "size-10" \
300 "size-10.out" \
301 ] \
302 ]