1 # Expect script for various ELF tests.
2 # Copyright (C) 2002-2021 Free Software Foundation, Inc.
4 # This file is part of the GNU Binutils.
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.
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.
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,
22 # Exclude non-ELF targets.
28 set old_ldflags $LDFLAGS
29 if { [istarget spu*-*-*] } {
30 set LDFLAGS "$LDFLAGS --local-store 0:0"
33 # hpux .comm differs from everyone else
35 set old_asflags $ASFLAGS
36 if [istarget "*-*-hpux*"] {
37 set hpux "--defsym HPUX=1"
38 set ASFLAGS "$ASFLAGS --defsym HPUX=1"
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"
49 if [istarget "tic6x-*-*"] {
50 append ASFLAGS " -mpic -mpid=near"
53 if { [istarget "*-*-solaris*"] } {
55 set options_regsub(ld) {-melf_x86_64 -melf_x86_64_sol2}
58 if { [is_remote host] } then {
59 remote_download host merge.ld
62 # Note - the output file from the second test (symbol3w.a) is
63 # used in the proc is_elf64 test below...
64 run_ld_link_tests [list \
65 [list "Build symbol3.a" \
67 {symbol3.s} {} "symbol3.a" ] \
68 [list "Build symbol3w.a" \
70 {symbol3w.s} {} "symbol3w.a" ] \
74 if [is_elf64 tmpdir/symbol3w.a] {
75 set ASFLAGS "$ASFLAGS --defsym ALIGN=3"
76 set pr23900_1_exp "pr23900-1-64.rd"
77 set pr25490_2_exp "pr25490-2-64.rd"
78 set pr25490_3_exp "pr25490-3-64.rd"
79 set pr25490_4_exp "pr25490-4-64.rd"
80 set pr25490_5_exp "pr25490-5-64.rd"
81 set pr25490_6_exp "pr25490-6-64.rd"
83 set ASFLAGS "$ASFLAGS --defsym ALIGN=2"
84 set pr23900_1_exp "pr23900-1-32.rd"
85 if { [istarget avr-*-*]
86 || [istarget h8300-*-*]
87 || [istarget ip2k-*-*]
88 || [istarget m68hc11-*]
89 || [istarget "xc16x-*"]
90 || [istarget "z80-*-*"] } {
91 set pr25490_2_exp "pr25490-2-16.rd"
92 set pr25490_3_exp "pr25490-3-16.rd"
93 set pr25490_4_exp "pr25490-4-16.rd"
94 set pr25490_5_exp "pr25490-5-16.rd"
95 set pr25490_6_exp "pr25490-6-16.rd"
97 set pr25490_2_exp "pr25490-2-32.rd"
98 set pr25490_3_exp "pr25490-3-32.rd"
99 set pr25490_4_exp "pr25490-4-32.rd"
100 set pr25490_5_exp "pr25490-5-32.rd"
101 set pr25490_6_exp "pr25490-6-32.rd"
107 # Targets that use _bfd_generic_link_add_symbols won't pass pr21703 tests
110 "--allow-multiple-definition tmpdir/pr21703-1.o tmpdir/pr21703-2.o" "" "" \
111 {pr21703-1.s pr21703-2.s} {{readelf {-s} pr21703.sd}} "pr21703" }
113 "-r --allow-multiple-definition tmpdir/pr21703-3.o tmpdir/pr21703-4.o" "" "" \
114 {pr21703-3.s pr21703-4.s} {{readelf {-s} pr21703-r.sd}} "pr21703.o" }
117 if [is_underscore_target] {
118 set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1"
121 set saved_ASFLAGS "$ASFLAGS"
122 if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
123 set ASFLAGS "$ASFLAGS -mx86-used-note=no"
126 # Build libraries required for SHF_GNU_RETAIN tests.
127 if { [check_gc_sections_available] && [supports_gnu_osabi] } {
128 run_ld_link_tests [list \
129 [list "Build libretain5.a" "" "" "" \
130 {retain5lib.s} {} "libretain5.a"] \
131 [list "Build libretain6.a" "" "" "" \
132 {retain6lib.s} {} "libretain6.a"] \
136 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
137 foreach t $test_list {
138 # We need to strip the ".d", but can leave the dirname.
139 verbose [file rootname $t]
140 run_dump_test [file rootname $t]
143 set ASFLAGS "$saved_ASFLAGS"
145 # Check that the --out-implib option work correctly.
146 # Targets that don't use elf.em won't support this.
147 run_ld_link_tests [list \
148 [list "Generate empty import library" \
149 "--out-implib=tmpdir/implib.lib" "" \
150 [concat "--defsym NO_GLOBAL=1" $hpux] \
152 {{ld empty-implib.out}} \
154 [list "Generate import library" \
155 "--out-implib=tmpdir/implib.lib" "" \
158 {{readelf {-s tmpdir/implib.lib} implib.rd}} \
162 #v850 gas complains about .tbss.var section attributes.
163 if { [check_gc_sections_available] && ![istarget "v850-*-*"] } {
165 {"--gc-sections on tls variable"
166 "--gc-section" "" "" {tls_gc.s} {} "tls_gc"}
170 if { [istarget *-*-*linux*]
171 || [istarget *-*-nacl*]
172 || [istarget *-*-gnu*] } {
173 run_ld_link_tests [list \
179 {{readelf {-Wl} stack-exec.rd}} \
181 [list "stack noexec" \
186 {{readelf {-Wl} stack-noexec.rd}} \
187 "stack-noexec.exe"] \
189 "-z stack-size=0x123400" \
193 {{readelf {-Wl} stack-size.rd}} \
195 [list "PT_GNU_PROPERTY alignment" \
200 [list [list "readelf" {-Wl} $pr23900_1_exp]] \
205 if [check_gc_sections_available] {
206 run_ld_link_tests [list \
207 [list "__patchable_function_entries section 2" \
208 "--gc-sections -e _start" \
212 [list [list "readelf" {-SW} $pr25490_2_exp]] \
214 [list "__patchable_function_entries section 3" \
215 "--gc-sections -e _start" \
219 [list [list "readelf" {-SW} $pr25490_3_exp]] \
221 [list "__patchable_function_entries section 4" \
222 "--gc-sections -e _start" \
226 [list [list "readelf" {-SW} $pr25490_4_exp]] \
228 [list "__patchable_function_entries section 5" \
229 "--gc-sections -e _start" \
233 [list [list "readelf" {-SW} $pr25490_5_exp]] \
235 [list "__patchable_function_entries section 6" \
236 "--gc-sections -e _start" \
240 [list [list "readelf" {-SW} $pr25490_6_exp]] \
245 set LDFLAGS $old_ldflags
246 set ASFLAGS $old_asflags
248 # Check to see if the C compiler works
249 if { ![check_compiler_available] } {
253 if [check_gc_sections_available] {
255 {"PR ld/13195" "-Wl,--gc-sections" ""
256 {pr13195.c} {} "pr13195"}
261 {"preinit array" "" ""
262 {preinit.c} "preinit" "preinit.out"}
264 {init.c} "init" "init.out"}
266 {fini.c} "fini" "fini.out"}
267 {"init array mixed" "" ""
268 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
270 set array_tests_pie {
271 {"PIE preinit array" "-pie" ""
272 {preinit.c} "preinit" "preinit.out" "-fPIE"}
273 {"PIE init array" "-pie" ""
274 {init.c} "init" "init.out" "-fPIE"}
275 {"PIE fini array" "-pie" ""
276 {fini.c} "fini" "fini.out" "-fPIE"}
277 {"PIE init array mixed" "-pie" ""
278 {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"}
279 {"PIE PR ld/14525" "-pie" ""
280 {pr14525.c} "pr14525" "pr14525.out" "-fPIE"}
282 set array_tests_static {
283 {"static preinit array" "-static" ""
284 {preinit.c} "preinit" "preinit.out"}
285 {"static init array" "-static" ""
286 {init.c} "init" "init.out"}
287 {"static fini array" "-static" ""
288 {fini.c} "fini" "fini.out"}
289 {"static init array mixed" "-static" ""
290 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
293 # NetBSD ELF systems do not currently support the .*_array sections.
294 set xfails "*-*-netbsdelf*"
295 run_ld_link_exec_tests $array_tests $xfails
297 if { [istarget *-*-linux*]
298 || [istarget *-*-nacl*]
299 || [istarget *-*-gnu*] } {
300 run_ld_link_exec_tests $array_tests_pie $xfails
302 if { $STATIC_PIE_LDFLAGS != "" } then {
303 run_ld_link_exec_tests [list \
305 "Static PIE preinit array" \
306 "$STATIC_PIE_LDFLAGS" \
309 "preinit-static-pie" \
314 "Static PIE init array" \
315 "$STATIC_PIE_LDFLAGS" \
323 "Static PIE fini array" \
324 "$STATIC_PIE_LDFLAGS" \
332 "Static PIE init array mixed" \
333 "$STATIC_PIE_LDFLAGS" \
336 "init-mixed-static-pie" \
341 "Static PIE PR ld/14525" \
342 "$STATIC_PIE_LDFLAGS" \
345 "pr14525-static-pie" \
352 run_ld_link_exec_tests [list \
355 "$NOPIE_LDFLAGS -Wl,-z,common-page-size=0x4000" \
357 { mbind2a.s mbind2b.c } \
364 "-static -Wl,-z,common-page-size=0x4000" \
366 { mbind2a.s mbind2b.c } \
374 run_ld_link_exec_tests $array_tests_static $xfails
376 run_cc_link_tests [list \
379 "-Wl,-z,unique-symbol" \
380 "-fno-function-sections" \
381 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
382 {{nm "" pr26391.nd}} \
387 "-Wl,-z,unique-symbol" \
388 "-ffunction-sections" \
389 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
390 {{nm "" pr26391.nd}} \
395 "-Wl,-z,unique-symbol,--emit-relocs" \
396 "-fno-function-sections" \
397 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
398 {{nm "" pr26391.nd}} \
403 "-Wl,-z,unique-symbol,--emit-relocs" \
404 "-ffunction-sections" \
405 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
406 {{nm "" pr26391.nd}} \
411 run_ld_link_tests [list \
413 "Build pr26391-5.o" \
414 "-z unique-symbol -r" \
417 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
419 [list "nm" "$dep_plug_opt" "pr26391.nd"] \
420 [list "nm" "$dep_plug_opt" "pr26391.fd"] \
423 "-fno-function-sections" \
426 "Build pr26391-6.o" \
427 "-z unique-symbol -r" \
430 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
431 {{nm "" pr26391.nd}} \
433 "-ffunction-sections" \
437 run_ld_link_exec_tests [list \
440 "-Wl,-z,unique-symbol" \
442 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
445 "-fno-function-sections" \
449 "-Wl,-z,unique-symbol" \
451 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
454 "-ffunction-sections" \
458 "-Wl,-z,unique-symbol,--emit-relocs" \
460 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
463 "-fno-function-sections" \
467 "-Wl,-z,unique-symbol,--emit-relocs" \
469 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
472 "-ffunction-sections" \
476 "-Wl,-z,unique-symbol" \
484 "tmpdir/pr26391-5.o" \
488 "-Wl,-z,unique-symbol" \
496 "tmpdir/pr26391-6.o" \
500 catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status