1 # Expect script for various ELF tests.
2 # Copyright (C) 2002-2020 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 "*-*-solaris*"] } {
51 set options_regsub(ld) {-melf_x86_64 -melf_x86_64_sol2}
54 if { [is_remote host] } then {
55 remote_download host merge.ld
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" \
63 {symbol3.s} {} "symbol3.a" ] \
64 [list "Build symbol3w.a" \
66 {symbol3w.s} {} "symbol3w.a" ] \
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"
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"
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"
103 # Targets that use _bfd_generic_link_add_symbols won't pass pr21703 tests
106 "--allow-multiple-definition tmpdir/pr21703-1.o tmpdir/pr21703-2.o" "" "" \
107 {pr21703-1.s pr21703-2.s} {{readelf {-s} pr21703.sd}} "pr21703" }
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" }
113 if [is_underscore_target] {
114 set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1"
117 set saved_ASFLAGS "$ASFLAGS"
118 if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
119 set ASFLAGS "$ASFLAGS -mx86-used-note=no"
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"] \
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]
139 set ASFLAGS "$saved_ASFLAGS"
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] \
148 {{ld empty-implib.out}} \
150 [list "Generate import library" \
151 "--out-implib=tmpdir/implib.lib" "" \
154 {{readelf {-s tmpdir/implib.lib} implib.rd}} \
158 #v850 gas complains about .tbss.var section attributes.
159 if { [check_gc_sections_available] && ![istarget "v850-*-*"] } {
161 {"--gc-sections on tls variable"
162 "--gc-section" "" "" {tls_gc.s} {} "tls_gc"}
166 if { [istarget *-*-*linux*]
167 || [istarget *-*-nacl*]
168 || [istarget *-*-gnu*] } {
169 run_ld_link_tests [list \
175 {{readelf {-Wl} stack-exec.rd}} \
177 [list "stack noexec" \
182 {{readelf {-Wl} stack-noexec.rd}} \
183 "stack-noexec.exe"] \
185 "-z stack-size=0x123400" \
189 {{readelf {-Wl} stack-size.rd}} \
191 [list "PT_GNU_PROPERTY alignment" \
196 [list [list "readelf" {-Wl} $pr23900_1_exp]] \
201 if [check_gc_sections_available] {
202 run_ld_link_tests [list \
203 [list "__patchable_function_entries section 2" \
204 "--gc-sections -e _start" \
208 [list [list "readelf" {-SW} $pr25490_2_exp]] \
210 [list "__patchable_function_entries section 3" \
211 "--gc-sections -e _start" \
215 [list [list "readelf" {-SW} $pr25490_3_exp]] \
217 [list "__patchable_function_entries section 4" \
218 "--gc-sections -e _start" \
222 [list [list "readelf" {-SW} $pr25490_4_exp]] \
224 [list "__patchable_function_entries section 5" \
225 "--gc-sections -e _start" \
229 [list [list "readelf" {-SW} $pr25490_5_exp]] \
231 [list "__patchable_function_entries section 6" \
232 "--gc-sections -e _start" \
236 [list [list "readelf" {-SW} $pr25490_6_exp]] \
241 set LDFLAGS $old_ldflags
242 set ASFLAGS $old_asflags
244 # Check to see if the C compiler works
245 if { ![check_compiler_available] } {
249 if [check_gc_sections_available] {
251 {"PR ld/13195" "-Wl,--gc-sections" ""
252 {pr13195.c} {} "pr13195"}
257 {"preinit array" "" ""
258 {preinit.c} "preinit" "preinit.out"}
260 {init.c} "init" "init.out"}
262 {fini.c} "fini" "fini.out"}
263 {"init array mixed" "" ""
264 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
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"}
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."}
289 # NetBSD ELF systems do not currently support the .*_array sections.
290 set xfails "*-*-netbsdelf*"
291 run_ld_link_exec_tests $array_tests $xfails
293 if { [istarget *-*-linux*]
294 || [istarget *-*-nacl*]
295 || [istarget *-*-gnu*] } {
296 run_ld_link_exec_tests $array_tests_pie $xfails
298 if { $STATIC_PIE_LDFLAGS != "" } then {
299 run_ld_link_exec_tests [list \
301 "Static PIE preinit array" \
302 "$STATIC_PIE_LDFLAGS" \
305 "preinit-static-pie" \
310 "Static PIE init array" \
311 "$STATIC_PIE_LDFLAGS" \
319 "Static PIE fini array" \
320 "$STATIC_PIE_LDFLAGS" \
328 "Static PIE init array mixed" \
329 "$STATIC_PIE_LDFLAGS" \
332 "init-mixed-static-pie" \
337 "Static PIE PR ld/14525" \
338 "$STATIC_PIE_LDFLAGS" \
341 "pr14525-static-pie" \
348 run_ld_link_exec_tests [list \
351 "$NOPIE_LDFLAGS -Wl,-z,common-page-size=0x4000" \
353 { mbind2a.s mbind2b.c } \
360 "-static -Wl,-z,common-page-size=0x4000" \
362 { mbind2a.s mbind2b.c } \
370 run_ld_link_exec_tests $array_tests_static $xfails
372 run_cc_link_tests [list \
375 "-Wl,-z,unique-symbol" \
376 "-fno-function-sections" \
377 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
378 {{nm "" pr26391.nd}} \
383 "-Wl,-z,unique-symbol" \
384 "-ffunction-sections" \
385 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
386 {{nm "" pr26391.nd}} \
391 "-Wl,-z,unique-symbol,--emit-relocs" \
392 "-fno-function-sections" \
393 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
394 {{nm "" pr26391.nd}} \
399 "-Wl,-z,unique-symbol,--emit-relocs" \
400 "-ffunction-sections" \
401 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
402 {{nm "" pr26391.nd}} \
407 run_ld_link_tests [list \
409 "Build pr26391-5.o" \
410 "-z unique-symbol -r" \
413 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
414 {{nm "" pr26391.nd}} \
416 "-fno-function-sections" \
419 "Build pr26391-6.o" \
420 "-z unique-symbol -r" \
423 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
424 {{nm "" pr26391.nd}} \
426 "-ffunction-sections" \
430 run_ld_link_exec_tests [list \
433 "-Wl,-z,unique-symbol" \
435 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
438 "-fno-function-sections" \
442 "-Wl,-z,unique-symbol" \
444 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
447 "-ffunction-sections" \
451 "-Wl,-z,unique-symbol,--emit-relocs" \
453 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
456 "-fno-function-sections" \
460 "-Wl,-z,unique-symbol,--emit-relocs" \
462 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
465 "-ffunction-sections" \
469 "-Wl,-z,unique-symbol" \
477 "tmpdir/pr26391-5.o" \
481 "-Wl,-z,unique-symbol" \
489 "tmpdir/pr26391-6.o" \
493 catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status