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