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 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
123 foreach t $test_list {
124 # We need to strip the ".d", but can leave the dirname.
125 verbose [file rootname $t]
126 run_dump_test [file rootname $t]
129 set ASFLAGS "$saved_ASFLAGS"
131 # Check that the --out-implib option work correctly.
132 # Targets that don't use elf.em won't support this.
133 run_ld_link_tests [list \
134 [list "Generate empty import library" \
135 "--out-implib=tmpdir/implib.lib" "" \
136 [concat "--defsym NO_GLOBAL=1" $hpux] \
138 {{ld empty-implib.out}} \
140 [list "Generate import library" \
141 "--out-implib=tmpdir/implib.lib" "" \
144 {{readelf {-s tmpdir/implib.lib} implib.rd}} \
148 #v850 gas complains about .tbss.var section attributes.
149 if { [check_gc_sections_available] && ![istarget "v850-*-*"] } {
151 {"--gc-sections on tls variable"
152 "--gc-section" "" "" {tls_gc.s} {} "tls_gc"}
156 if { [istarget *-*-*linux*]
157 || [istarget *-*-nacl*]
158 || [istarget *-*-gnu*] } {
159 run_ld_link_tests [list \
165 {{readelf {-Wl} stack-exec.rd}} \
167 [list "stack noexec" \
172 {{readelf {-Wl} stack-noexec.rd}} \
173 "stack-noexec.exe"] \
175 "-z stack-size=0x123400" \
179 {{readelf {-Wl} stack-size.rd}} \
181 [list "PT_GNU_PROPERTY alignment" \
186 [list [list "readelf" {-Wl} $pr23900_1_exp]] \
191 if [check_gc_sections_available] {
192 run_ld_link_tests [list \
193 [list "__patchable_function_entries section 2" \
194 "--gc-sections -e _start" \
198 [list [list "readelf" {-SW} $pr25490_2_exp]] \
200 [list "__patchable_function_entries section 3" \
201 "--gc-sections -e _start" \
205 [list [list "readelf" {-SW} $pr25490_3_exp]] \
207 [list "__patchable_function_entries section 4" \
208 "--gc-sections -e _start" \
212 [list [list "readelf" {-SW} $pr25490_4_exp]] \
214 [list "__patchable_function_entries section 5" \
215 "--gc-sections -e _start" \
219 [list [list "readelf" {-SW} $pr25490_5_exp]] \
221 [list "__patchable_function_entries section 6" \
222 "--gc-sections -e _start" \
226 [list [list "readelf" {-SW} $pr25490_6_exp]] \
231 set LDFLAGS $old_ldflags
232 set ASFLAGS $old_asflags
234 # Check to see if the C compiler works
235 if { ![check_compiler_available] } {
239 if [check_gc_sections_available] {
241 {"PR ld/13195" "-Wl,--gc-sections" ""
242 {pr13195.c} {} "pr13195"}
247 {"preinit array" "" ""
248 {preinit.c} "preinit" "preinit.out"}
250 {init.c} "init" "init.out"}
252 {fini.c} "fini" "fini.out"}
253 {"init array mixed" "" ""
254 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
256 set array_tests_pie {
257 {"PIE preinit array" "-pie" ""
258 {preinit.c} "preinit" "preinit.out" "-fPIE"}
259 {"PIE init array" "-pie" ""
260 {init.c} "init" "init.out" "-fPIE"}
261 {"PIE fini array" "-pie" ""
262 {fini.c} "fini" "fini.out" "-fPIE"}
263 {"PIE init array mixed" "-pie" ""
264 {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"}
265 {"PIE PR ld/14525" "-pie" ""
266 {pr14525.c} "pr14525" "pr14525.out" "-fPIE"}
268 set array_tests_static {
269 {"static preinit array" "-static" ""
270 {preinit.c} "preinit" "preinit.out"}
271 {"static init array" "-static" ""
272 {init.c} "init" "init.out"}
273 {"static fini array" "-static" ""
274 {fini.c} "fini" "fini.out"}
275 {"static init array mixed" "-static" ""
276 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
279 # NetBSD ELF systems do not currently support the .*_array sections.
280 set xfails "*-*-netbsdelf*"
281 run_ld_link_exec_tests $array_tests $xfails
283 if { [istarget *-*-linux*]
284 || [istarget *-*-nacl*]
285 || [istarget *-*-gnu*] } {
286 run_ld_link_exec_tests $array_tests_pie $xfails
288 if { $STATIC_PIE_LDFLAGS != "" } then {
289 run_ld_link_exec_tests [list \
291 "Static PIE preinit array" \
292 "$STATIC_PIE_LDFLAGS" \
295 "preinit-static-pie" \
300 "Static PIE init array" \
301 "$STATIC_PIE_LDFLAGS" \
309 "Static PIE fini array" \
310 "$STATIC_PIE_LDFLAGS" \
318 "Static PIE init array mixed" \
319 "$STATIC_PIE_LDFLAGS" \
322 "init-mixed-static-pie" \
327 "Static PIE PR ld/14525" \
328 "$STATIC_PIE_LDFLAGS" \
331 "pr14525-static-pie" \
338 run_ld_link_exec_tests [list \
341 "$NOPIE_LDFLAGS -Wl,-z,common-page-size=0x4000" \
343 { mbind2a.s mbind2b.c } \
350 "-static -Wl,-z,common-page-size=0x4000" \
352 { mbind2a.s mbind2b.c } \
360 run_ld_link_exec_tests $array_tests_static $xfails
362 run_cc_link_tests [list \
365 "-Wl,-z,unique-symbol" \
366 "-fno-function-sections" \
367 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
368 {{nm "" pr26391.nd}} \
373 "-Wl,-z,unique-symbol" \
374 "-ffunction-sections" \
375 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
376 {{nm "" pr26391.nd}} \
381 "-Wl,-z,unique-symbol,--emit-relocs" \
382 "-fno-function-sections" \
383 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
384 {{nm "" pr26391.nd}} \
389 "-Wl,-z,unique-symbol,--emit-relocs" \
390 "-ffunction-sections" \
391 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
392 {{nm "" pr26391.nd}} \
397 run_ld_link_tests [list \
399 "Build pr26391-5.o" \
400 "-z unique-symbol -r" \
403 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
404 {{nm "" pr26391.nd}} \
406 "-fno-function-sections" \
409 "Build pr26391-6.o" \
410 "-z unique-symbol -r" \
413 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
414 {{nm "" pr26391.nd}} \
416 "-ffunction-sections" \
420 run_ld_link_exec_tests [list \
423 "-Wl,-z,unique-symbol" \
425 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
428 "-fno-function-sections" \
432 "-Wl,-z,unique-symbol" \
434 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
437 "-ffunction-sections" \
441 "-Wl,-z,unique-symbol,--emit-relocs" \
443 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
446 "-fno-function-sections" \
450 "-Wl,-z,unique-symbol,--emit-relocs" \
452 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \
455 "-ffunction-sections" \
459 "-Wl,-z,unique-symbol" \
467 "tmpdir/pr26391-5.o" \
471 "-Wl,-z,unique-symbol" \
479 "tmpdir/pr26391-6.o" \
483 catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status