]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/testsuite/ld-elf/elf.exp
Support SHF_GNU_RETAIN ELF section flag
[thirdparty/binutils-gdb.git] / ld / testsuite / ld-elf / elf.exp
1 # Expect script for various ELF tests.
2 # Copyright (C) 2002-2020 Free Software Foundation, Inc.
3 #
4 # This file is part of the GNU Binutils.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20 #
21
22 # Exclude non-ELF targets.
23
24 if ![is_elf_format] {
25 return
26 }
27
28 set old_ldflags $LDFLAGS
29 if { [istarget spu*-*-*] } {
30 set LDFLAGS "$LDFLAGS --local-store 0:0"
31 }
32
33 # hpux .comm differs from everyone else
34 set hpux ""
35 set old_asflags $ASFLAGS
36 if [istarget "*-*-hpux*"] {
37 set hpux "--defsym HPUX=1"
38 set ASFLAGS "$ASFLAGS --defsym HPUX=1"
39 }
40
41 if { [istarget alpha*-*-* ] } {
42 # The compress1 test is written expecting 32-bit addresses; force the
43 # executable down into the low address space to match.
44 # ??? How can we adjust just the one testcase?
45 set LDFLAGS "$LDFLAGS -Ttext-segment 0x1000000"
46 set ASFLAGS "$ASFLAGS --defsym NO_SET=1"
47 }
48
49 if { [istarget "*-*-solaris*"] } {
50 # Same for Solaris
51 set options_regsub(ld) {-melf_x86_64 -melf_x86_64_sol2}
52 }
53
54 if { [is_remote host] } then {
55 remote_download host merge.ld
56 }
57
58 # Note - the output file from the second test (symbol3w.a) is
59 # used in the proc is_elf64 test below...
60 run_ld_link_tests [list \
61 [list "Build symbol3.a" \
62 "" "" $hpux \
63 {symbol3.s} {} "symbol3.a" ] \
64 [list "Build symbol3w.a" \
65 "" "" "" \
66 {symbol3w.s} {} "symbol3w.a" ] \
67 ]
68
69
70 if [is_elf64 tmpdir/symbol3w.a] {
71 set ASFLAGS "$ASFLAGS --defsym ALIGN=3"
72 set pr23900_1_exp "pr23900-1-64.rd"
73 set pr25490_2_exp "pr25490-2-64.rd"
74 set pr25490_3_exp "pr25490-3-64.rd"
75 set pr25490_4_exp "pr25490-4-64.rd"
76 set pr25490_5_exp "pr25490-5-64.rd"
77 set pr25490_6_exp "pr25490-6-64.rd"
78 } else {
79 set ASFLAGS "$ASFLAGS --defsym ALIGN=2"
80 set pr23900_1_exp "pr23900-1-32.rd"
81 if { [istarget avr-*-*]
82 || [istarget h8300-*-*]
83 || [istarget ip2k-*-*]
84 || [istarget m68hc11-*]
85 || [istarget "xc16x-*"]
86 || [istarget "z80-*-*"] } {
87 set pr25490_2_exp "pr25490-2-16.rd"
88 set pr25490_3_exp "pr25490-3-16.rd"
89 set pr25490_4_exp "pr25490-4-16.rd"
90 set pr25490_5_exp "pr25490-5-16.rd"
91 set pr25490_6_exp "pr25490-6-16.rd"
92 } else {
93 set pr25490_2_exp "pr25490-2-32.rd"
94 set pr25490_3_exp "pr25490-3-32.rd"
95 set pr25490_4_exp "pr25490-4-32.rd"
96 set pr25490_5_exp "pr25490-5-32.rd"
97 set pr25490_6_exp "pr25490-6-32.rd"
98 }
99 }
100
101
102
103 # Targets that use _bfd_generic_link_add_symbols won't pass pr21703 tests
104 run_ld_link_tests {
105 {"PR ld/21703"
106 "--allow-multiple-definition tmpdir/pr21703-1.o tmpdir/pr21703-2.o" "" "" \
107 {pr21703-1.s pr21703-2.s} {{readelf {-s} pr21703.sd}} "pr21703" }
108 {"PR ld/21703 -r"
109 "-r --allow-multiple-definition tmpdir/pr21703-3.o tmpdir/pr21703-4.o" "" "" \
110 {pr21703-3.s pr21703-4.s} {{readelf {-s} pr21703-r.sd}} "pr21703.o" }
111 } \[is_generic\]
112
113 if [is_underscore_target] {
114 set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1"
115 }
116
117 set saved_ASFLAGS "$ASFLAGS"
118 if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
119 set ASFLAGS "$ASFLAGS -mx86-used-note=no"
120 }
121
122 # Build libraries required for SHF_GNU_RETAIN tests.
123 if { [check_gc_sections_available] && [supports_gnu_osabi] } {
124 run_ld_link_tests [list \
125 [list "Build libretain5.a" "" "" "" \
126 {retain5lib.s} {} "libretain5.a"] \
127 [list "Build libretain6.a" "" "" "" \
128 {retain6lib.s} {} "libretain6.a"] \
129 ]
130 }
131
132 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
133 foreach t $test_list {
134 # We need to strip the ".d", but can leave the dirname.
135 verbose [file rootname $t]
136 run_dump_test [file rootname $t]
137 }
138
139 set ASFLAGS "$saved_ASFLAGS"
140
141 # Check that the --out-implib option work correctly.
142 # Targets that don't use elf.em won't support this.
143 run_ld_link_tests [list \
144 [list "Generate empty import library" \
145 "--out-implib=tmpdir/implib.lib" "" \
146 [concat "--defsym NO_GLOBAL=1" $hpux] \
147 {implib.s} \
148 {{ld empty-implib.out}} \
149 "implib" ] \
150 [list "Generate import library" \
151 "--out-implib=tmpdir/implib.lib" "" \
152 $hpux \
153 {implib.s} \
154 {{readelf {-s tmpdir/implib.lib} implib.rd}} \
155 "implib" ] \
156 ] \[uses_genelf\]
157
158 #v850 gas complains about .tbss.var section attributes.
159 if { [check_gc_sections_available] && ![istarget "v850-*-*"] } {
160 run_ld_link_tests {
161 {"--gc-sections on tls variable"
162 "--gc-section" "" "" {tls_gc.s} {} "tls_gc"}
163 }
164 }
165
166 if { [istarget *-*-*linux*]
167 || [istarget *-*-nacl*]
168 || [istarget *-*-gnu*] } {
169 run_ld_link_tests [list \
170 [list "stack exec" \
171 "-z execstack" \
172 "" \
173 "" \
174 {stack.s} \
175 {{readelf {-Wl} stack-exec.rd}} \
176 "stack-exec.exe"] \
177 [list "stack noexec" \
178 "-z noexecstack" \
179 "" \
180 "" \
181 {stack.s} \
182 {{readelf {-Wl} stack-noexec.rd}} \
183 "stack-noexec.exe"] \
184 [list "stack size" \
185 "-z stack-size=0x123400" \
186 "" \
187 "" \
188 {stack.s} \
189 {{readelf {-Wl} stack-size.rd}} \
190 "stack-size.exe"] \
191 [list "PT_GNU_PROPERTY alignment" \
192 "" \
193 "" \
194 "" \
195 {pr23900-1.s} \
196 [list [list "readelf" {-Wl} $pr23900_1_exp]] \
197 "pr23900-1.exe"] \
198 ]
199 }
200
201 if [check_gc_sections_available] {
202 run_ld_link_tests [list \
203 [list "__patchable_function_entries section 2" \
204 "--gc-sections -e _start" \
205 "" \
206 "" \
207 {pr25490-2.s} \
208 [list [list "readelf" {-SW} $pr25490_2_exp]] \
209 "pr25490-2.exe"] \
210 [list "__patchable_function_entries section 3" \
211 "--gc-sections -e _start" \
212 "" \
213 "" \
214 {pr25490-3.s} \
215 [list [list "readelf" {-SW} $pr25490_3_exp]] \
216 "pr25490-3.exe"] \
217 [list "__patchable_function_entries section 4" \
218 "--gc-sections -e _start" \
219 "" \
220 "" \
221 {pr25490-4.s} \
222 [list [list "readelf" {-SW} $pr25490_4_exp]] \
223 "pr25490-4.exe"] \
224 [list "__patchable_function_entries section 5" \
225 "--gc-sections -e _start" \
226 "" \
227 "" \
228 {pr25490-5.s} \
229 [list [list "readelf" {-SW} $pr25490_5_exp]] \
230 "pr25490-5.exe"] \
231 [list "__patchable_function_entries section 6" \
232 "--gc-sections -e _start" \
233 "" \
234 "" \
235 {pr25490-6.s} \
236 [list [list "readelf" {-SW} $pr25490_6_exp]] \
237 "pr25490-6.exe"] \
238 ]
239 }
240
241 set LDFLAGS $old_ldflags
242 set ASFLAGS $old_asflags
243
244 # Check to see if the C compiler works
245 if { ![check_compiler_available] } {
246 return
247 }
248
249 if [check_gc_sections_available] {
250 run_cc_link_tests {
251 {"PR ld/13195" "-Wl,--gc-sections" ""
252 {pr13195.c} {} "pr13195"}
253 }
254 }
255
256 set array_tests {
257 {"preinit array" "" ""
258 {preinit.c} "preinit" "preinit.out"}
259 {"init array" "" ""
260 {init.c} "init" "init.out"}
261 {"fini array" "" ""
262 {fini.c} "fini" "fini.out"}
263 {"init array mixed" "" ""
264 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
265 }
266 set array_tests_pie {
267 {"PIE preinit array" "-pie" ""
268 {preinit.c} "preinit" "preinit.out" "-fPIE"}
269 {"PIE init array" "-pie" ""
270 {init.c} "init" "init.out" "-fPIE"}
271 {"PIE fini array" "-pie" ""
272 {fini.c} "fini" "fini.out" "-fPIE"}
273 {"PIE init array mixed" "-pie" ""
274 {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"}
275 {"PIE PR ld/14525" "-pie" ""
276 {pr14525.c} "pr14525" "pr14525.out" "-fPIE"}
277 }
278 set array_tests_static {
279 {"static preinit array" "-static" ""
280 {preinit.c} "preinit" "preinit.out"}
281 {"static init array" "-static" ""
282 {init.c} "init" "init.out"}
283 {"static fini array" "-static" ""
284 {fini.c} "fini" "fini.out"}
285 {"static init array mixed" "-static" ""
286 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
287 }
288
289 # NetBSD ELF systems do not currently support the .*_array sections.
290 set xfails "*-*-netbsdelf*"
291 run_ld_link_exec_tests $array_tests $xfails
292
293 if { [istarget *-*-linux*]
294 || [istarget *-*-nacl*]
295 || [istarget *-*-gnu*] } {
296 run_ld_link_exec_tests $array_tests_pie $xfails
297
298 if { $STATIC_PIE_LDFLAGS != "" } then {
299 run_ld_link_exec_tests [list \
300 [list \
301 "Static PIE preinit array" \
302 "$STATIC_PIE_LDFLAGS" \
303 "" \
304 {preinit.c} \
305 "preinit-static-pie" \
306 "preinit.out" \
307 "-fPIE" \
308 ] \
309 [list \
310 "Static PIE init array" \
311 "$STATIC_PIE_LDFLAGS" \
312 "" \
313 {init.c} \
314 "init-static-pie" \
315 "init.out" \
316 "-fPIE" \
317 ] \
318 [list \
319 "Static PIE fini array" \
320 "$STATIC_PIE_LDFLAGS" \
321 "" \
322 {fini.c} \
323 "fini-static-pie" \
324 "fini.out" \
325 "-fPIE" \
326 ] \
327 [list \
328 "Static PIE init array mixed" \
329 "$STATIC_PIE_LDFLAGS" \
330 "" \
331 {init-mixed.c} \
332 "init-mixed-static-pie" \
333 "init-mixed.out" \
334 "-I. -fPIE" \
335 ] \
336 [list \
337 "Static PIE PR ld/14525" \
338 "$STATIC_PIE_LDFLAGS" \
339 "" \
340 {pr14525.c} \
341 "pr14525-static-pie" \
342 "pr14525.out" \
343 "-fPIE" \
344 ] \
345 ]
346 }
347
348 run_ld_link_exec_tests [list \
349 [list \
350 "Run mbind2a" \
351 "$NOPIE_LDFLAGS -Wl,-z,common-page-size=0x4000" \
352 "" \
353 { mbind2a.s mbind2b.c } \
354 "mbind2a" \
355 "pass.out" \
356 "-O2 -I../bfd" \
357 ] \
358 [list \
359 "Run mbind2b" \
360 "-static -Wl,-z,common-page-size=0x4000" \
361 "" \
362 { mbind2a.s mbind2b.c } \
363 "mbind2b" \
364 "pass.out" \
365 "-O2 -I../bfd" \
366 ] \
367 ]
368 }
369
370 run_ld_link_exec_tests $array_tests_static $xfails
371
372 run_cc_link_tests [list \
373 [list \
374 "Build pr26391-1" \
375 "-Wl,-z,unique-symbol" \
376 "-fno-function-sections" \
377 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
378 {{nm "" pr26391.nd}} \
379 "pr26391-1" \
380 ] \
381 [list \
382 "Build pr26391-2" \
383 "-Wl,-z,unique-symbol" \
384 "-ffunction-sections" \
385 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
386 {{nm "" pr26391.nd}} \
387 "pr26391-2" \
388 ] \
389 [list \
390 "Build pr26391-3" \
391 "-Wl,-z,unique-symbol,--emit-relocs" \
392 "-fno-function-sections" \
393 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
394 {{nm "" pr26391.nd}} \
395 "pr26391-3" \
396 ] \
397 [list \
398 "Build pr26391-4" \
399 "-Wl,-z,unique-symbol,--emit-relocs" \
400 "-ffunction-sections" \
401 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
402 {{nm "" pr26391.nd}} \
403 "pr26391-4" \
404 ] \
405 ]
406
407 run_ld_link_tests [list \
408 [list \
409 "Build pr26391-5.o" \
410 "-z unique-symbol -r" \
411 "" \
412 "" \
413 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
414 {{nm "" pr26391.nd}} \
415 "pr26391-5.o" \
416 "-fno-function-sections" \
417 ] \
418 [list \
419 "Build pr26391-6.o" \
420 "-z unique-symbol -r" \
421 "" \
422 "" \
423 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
424 {{nm "" pr26391.nd}} \
425 "pr26391-6.o" \
426 "-ffunction-sections" \
427 ] \
428 ]
429
430 run_ld_link_exec_tests [list \
431 [list \
432 "Run pr26391-1" \
433 "-Wl,-z,unique-symbol" \
434 "" \
435 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
436 "pr26391-1" \
437 "pr26391.out" \
438 "-fno-function-sections" \
439 ] \
440 [list \
441 "Run pr26391-2" \
442 "-Wl,-z,unique-symbol" \
443 "" \
444 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
445 "pr26391-2" \
446 "pr26391.out" \
447 "-ffunction-sections" \
448 ] \
449 [list \
450 "Run pr26391-3" \
451 "-Wl,-z,unique-symbol,--emit-relocs" \
452 "" \
453 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
454 "pr26391-3" \
455 "pr26391.out" \
456 "-fno-function-sections" \
457 ] \
458 [list \
459 "Run pr26391-4" \
460 "-Wl,-z,unique-symbol,--emit-relocs" \
461 "" \
462 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
463 "pr26391-4" \
464 "pr26391.out" \
465 "-ffunction-sections" \
466 ] \
467 [list \
468 "Run pr26391-5" \
469 "-Wl,-z,unique-symbol" \
470 "" \
471 {dummy.c} \
472 "pr26391-5" \
473 "pr26391.out" \
474 "" \
475 "c" \
476 "" \
477 "tmpdir/pr26391-5.o" \
478 ] \
479 [list \
480 "Run pr26391-6" \
481 "-Wl,-z,unique-symbol" \
482 "" \
483 {dummy.c} \
484 "pr26391-6" \
485 "pr26391.out" \
486 "" \
487 "c" \
488 "" \
489 "tmpdir/pr26391-6.o" \
490 ] \
491 ]
492
493 catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status