1 # Expect script
for various ELF tests.
2 # Copyright
(C
) 2002-2024 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 #
Return true
if target is riscv little endian.
29 # xfail the riscv little endain targets
for the compressed1d1 test
;
30 # The riscv big endian targets and others should pass.
31 proc riscv_little_endian
{ } {
32 if { [istarget
"riscv32-*-*"]
33 ||
[istarget
"riscv64-*-*"]
34 ||
[istarget
"riscv32le-*-*"]
35 ||
[istarget
"riscv64le-*-*"] } {
41 set old_ldflags $LDFLAGS
42 if { [istarget spu
*-*-*] } {
43 set LDFLAGS
"$LDFLAGS --local-store 0:0"
46 # hpux .comm differs from everyone
else
48 set old_asflags $ASFLAGS
49 if [istarget
"*-*-hpux*"] {
50 set hpux
"--defsym HPUX=1"
51 set ASFLAGS
"$ASFLAGS --defsym HPUX=1"
54 if { [istarget alpha
*-*-* ] } {
55 # The compress1 test is written expecting
32-bit addresses
; force the
56 # executable down into the low address space to match.
57 # ??? How can we adjust just the one testcase?
58 set LDFLAGS
"$LDFLAGS -Ttext-segment 0x1000000"
59 set ASFLAGS
"$ASFLAGS --defsym NO_SET=1"
62 if [istarget
"tic6x-*-*"] {
63 append ASFLAGS
" -mpic -mpid=near"
66 if { [istarget
"*-*-solaris*"] } {
68 set options_regsub
(ld) {-melf_x86_64
-melf_x86_64_sol2
}
71 if { [is_remote host
] } then {
72 remote_download host merge.
ld
75 # Note
- the output file from the second test
(symbol3w.a
) is
76 # used in the proc is_elf64 test below...
77 run_ld_link_tests
[list \
78 [list
"Build symbol3.a" \
80 {symbol3.s
} {} "symbol3.a" ] \
81 [list
"Build symbol3w.a" \
83 {symbol3w.s
} {} "symbol3w.a" ] \
87 if [is_elf64 tmpdir
/symbol3w.a
] {
88 set ASFLAGS
"$ASFLAGS --defsym ALIGN=3"
89 set pr23900_1_exp
"pr23900-1-64.rd"
90 set pr25490_2_exp
"pr25490-2-64.rd"
91 set pr25490_3_exp
"pr25490-3-64.rd"
92 set pr25490_4_exp
"pr25490-4-64.rd"
93 set pr25490_5_exp
"pr25490-5-64.rd"
94 set pr25490_6_exp
"pr25490-6-64.rd"
96 set ASFLAGS
"$ASFLAGS --defsym ALIGN=2"
97 set pr23900_1_exp
"pr23900-1-32.rd"
98 if { [istarget avr
-*-*]
99 ||
[istarget h8300
-*-*]
100 ||
[istarget ip2k
-*-*]
101 ||
[istarget m68hc11
-*]
102 ||
[istarget
"z80-*-*"] } {
103 set pr25490_2_exp
"pr25490-2-16.rd"
104 set pr25490_3_exp
"pr25490-3-16.rd"
105 set pr25490_4_exp
"pr25490-4-16.rd"
106 set pr25490_5_exp
"pr25490-5-16.rd"
107 set pr25490_6_exp
"pr25490-6-16.rd"
109 set pr25490_2_exp
"pr25490-2-32.rd"
110 set pr25490_3_exp
"pr25490-3-32.rd"
111 set pr25490_4_exp
"pr25490-4-32.rd"
112 set pr25490_5_exp
"pr25490-5-32.rd"
113 set pr25490_6_exp
"pr25490-6-32.rd"
119 # Targets that use _bfd_generic_link_add_symbols won
't pass pr21703 tests
122 "--allow-multiple-definition tmpdir/pr21703-1.o tmpdir/pr21703-2.o" "" "" \
123 {pr21703-1.s pr21703-2.s} {{readelf {-s} pr21703.sd}} "pr21703" }
125 "-r --allow-multiple-definition tmpdir/pr21703-3.o tmpdir/pr21703-4.o" "" "" \
126 {pr21703-3.s pr21703-4.s} {{readelf {-s} pr21703-r.sd}} "pr21703.o" }
129 if [is_underscore_target] {
130 set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1"
133 set saved_ASFLAGS "$ASFLAGS"
134 if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
135 set ASFLAGS "$ASFLAGS -mx86-used-note=no"
138 # Build libraries required for SHF_GNU_RETAIN tests.
139 if { [check_gc_sections_available] && [supports_gnu_osabi] } {
140 run_ld_link_tests [list \
141 [list "Build libretain5.a" "" "" "" \
142 {retain5lib.s} {} "libretain5.a"] \
143 [list "Build libretain6.a" "" "" "" \
144 {retain6lib.s} {} "libretain6.a"] \
148 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
149 foreach t $test_list {
150 # We need to strip the ".d", but can leave the dirname.
151 verbose [file rootname $t]
152 run_dump_test [file rootname $t]
155 set ASFLAGS "$saved_ASFLAGS"
157 # Check that the --out-implib option work correctly.
158 # Targets that don't use elf.em won
't support this.
159 run_ld_link_tests [list \
160 [list "Generate empty import library" \
161 "--out-implib=tmpdir/implib.lib" "" \
162 [concat "--defsym NO_GLOBAL=1" $hpux] \
164 {{ld empty-implib.out}} \
166 [list "Generate import library" \
167 "--out-implib=tmpdir/implib.lib" "" \
170 {{readelf {-s tmpdir/implib.lib} implib.rd}} \
174 run_ld_link_tests [list \
175 [list "Generate undefweak-1.a" \
181 [list "Generate undefweak-1.o" \
182 "-r" "tmpdir/undefweak-1.a" \
185 {{readelf {-rsW} undefweak-1.rd}} \
189 #v850 gas complains about .tbss.var section attributes.
190 if { [check_gc_sections_available] && ![istarget "v850-*-*"] } {
192 {"--gc-sections on tls variable"
193 "--gc-section" "" "" {tls_gc.s} {} "tls_gc"}
197 proc target_defaults_to_execstack {} {
200 # If the linker has been configured with --enable-default-execstack=no then
201 # this proc should always return 0.
202 if { [file exists $base_dir/config.status] } {
203 set status [remote_exec host grep "enable-default-execstack=no" $base_dir/config.status]
204 if { [lindex $status 0] == 0 } {
207 verbose -log "$base_dir/config.status does not contain enable-default-execstack=no"
210 verbose -log "there is no file $base_dir/config.status"
213 if { [istarget "aarch64*-*-*"]
214 || [istarget "arc*-*-*"]
215 || [istarget "cris*-*-*"]
216 || [istarget "ia64*-*-*"]
217 || [istarget "kvx*-*-*"]
218 || [istarget "loongarch*-*-*"]
219 || [istarget "powerpc64*-*-*"]
220 || [istarget "pru*-*-*"]
221 || [istarget "riscv*-*-*"]
222 || [istarget "tilegx*-*-*"]
223 || [istarget "tilepro*-*-*"] } {
229 if { [istarget *-*-*linux*]
230 || [istarget *-*-nacl*]
231 || [istarget *-*-gnu*] } {
232 run_ld_link_tests [list \
234 "-z execstack --no-error-execstack" \
238 {{readelf {-Wl} stack-exec.rd}} \
240 [list "stack noexec" \
245 {{readelf {-Wl} stack-noexec.rd}} \
246 "stack-noexec.exe"] \
248 "-z stack-size=0x123400 -z noexecstack" \
252 {{readelf {-Wl} stack-size.rd}} \
254 [list "PT_GNU_PROPERTY alignment" \
259 [list [list "readelf" {-Wl} $pr23900_1_exp]] \
263 # Test the linker's generation of execstack and executable segment warnings.
264 # Since these are normally pruned from the linker
's output we temporarily
265 # disable tha action here.
266 rename prune_warnings_extra old_prune_warnings_extra
267 proc prune_warnings_extra { text } {
271 set curr_ldflags $LDFLAGS
272 if { [istarget powerpc*-*-*] && ![istarget powerpc64*-*-*] } {
273 # Don't generate an executable .plt section
274 set LDFLAGS
"$LDFLAGS --secure-plt"
277 # Since the warnings can be disabled by configure
, ensure consistency
278 # of the first test by forcing the flags.
279 run_ld_link_tests
[list \
280 [list
"PR ld/29072 (warn about an executable .note.GNU-stack)" \
281 "-e 0 --warn-execstack --warn-rwx-segments --no-error-rwx-segments --no-error-execstack" \
285 {{ld pr29072.a.warn
}} \
287 [list
"PR 29072 (warn about -z execstack)" \
288 "-z execstack --warn-execstack --no-error-execstack" \
292 {{ld pr29072.c.warn
}} \
294 [list
"PR ld/29072 (suppress warnings about executable stack)" \
295 "-e 0 --no-warn-execstack" \
301 [list
"Ensure that a warning issued when creating a segment with RWX permissions" \
302 "-e 0 -Tnobits-1.t --warn-rwx-segments --no-error-rwx-segments" \
306 {{ld rwx
-segments
-1.l
}} \
307 "rwx-segments-1.exe"] \
308 [list
"Ensure that a warning issued when creating a TLS segment with execute permission" \
309 "-e 0 -T rwx-segments-2.t --warn-rwx-segments --no-error-rwx-segments" \
313 {{ld rwx
-segments
-2.l
}} \
314 "rwx-segments-2.exe"] \
315 [list
"Ensure that the RWX warning can be suppressed" \
316 "-e 0 -Tnobits-1.t --no-warn-rwx-segments" \
321 "rwx-segments-3.exe"] \
324 set LDFLAGS $curr_ldflags
326 if { [target_defaults_to_execstack
] } {
327 run_ld_link_tests
[list \
328 [list
"PR ld/29072 (warn about absent .note.GNU-stack)" \
329 "-e 0 -z stack-size=0x123400 --warn-execstack --no-error-execstack" \
333 {{ld pr29072.b.warn
}} \
337 run_ld_link_tests
[list \
338 [list
"PR ld/29072 (ignore absent .note.GNU-stack)" \
339 "-e 0 -z stack-size=0x123400 --no-error-execstack" \
348 # Restore the
normal pruning behaviour.
349 rename prune_warnings_extra
""
350 rename old_prune_warnings_extra prune_warnings_extra
353 if [check_gc_sections_available
] {
354 run_ld_link_tests
[list \
355 [list
"__patchable_function_entries section 2" \
356 "--gc-sections -e _start" \
360 [list
[list
"readelf" {-SW} $pr25490_2_exp]] \
362 [list
"__patchable_function_entries section 3" \
363 "--gc-sections -e _start" \
367 [list
[list
"readelf" {-SW} $pr25490_3_exp]] \
369 [list
"__patchable_function_entries section 4" \
370 "--gc-sections -e _start" \
374 [list
[list
"readelf" {-SW} $pr25490_4_exp]] \
376 [list
"__patchable_function_entries section 5" \
377 "--gc-sections -e _start" \
381 [list
[list
"readelf" {-SW} $pr25490_5_exp]] \
383 [list
"__patchable_function_entries section 6" \
384 "--gc-sections -e _start" \
388 [list
[list
"readelf" {-SW} $pr25490_6_exp]] \
393 set LDFLAGS $old_ldflags
394 set ASFLAGS $old_asflags
396 # Check to see
if the C compiler works
397 if { ![check_compiler_available
] } {
401 if [check_gc_sections_available
] {
403 {"PR ld/13195" "-Wl,--gc-sections" ""
404 {pr13195.c
} {} "pr13195"}
409 {"preinit array" "" ""
410 {preinit.c
} "preinit" "preinit.out"}
412 {init.c
} "init" "init.out"}
414 {fini.c
} "fini" "fini.out"}
415 {"init array mixed" "" ""
416 {init
-mixed.c
} "init-mixed" "init-mixed.out" "-I."}
418 set array_tests_pie
{
419 {"PIE preinit array" "-pie" ""
420 {preinit.c
} "preinit" "preinit.out" "-fPIE"}
421 {"PIE init array" "-pie" ""
422 {init.c
} "init" "init.out" "-fPIE"}
423 {"PIE fini array" "-pie" ""
424 {fini.c
} "fini" "fini.out" "-fPIE"}
425 {"PIE init array mixed" "-pie" ""
426 {init
-mixed.c
} "init-mixed" "init-mixed.out" "-I. -fPIE"}
427 {"PIE PR ld/14525" "-pie" ""
428 {pr14525.c
} "pr14525" "pr14525.out" "-fPIE"}
430 set array_tests_static
{
431 {"static preinit array" "-static" ""
432 {preinit.c
} "preinit" "preinit.out"}
433 {"static init array" "-static" ""
434 {init.c
} "init" "init.out"}
435 {"static fini array" "-static" ""
436 {fini.c
} "fini" "fini.out"}
437 {"static init array mixed" "-static" ""
438 {init
-mixed.c
} "init-mixed" "init-mixed.out" "-I."}
441 # NetBSD ELF systems
do not currently support the .
*_array sections.
442 set xfails
"*-*-netbsd*"
443 run_ld_link_exec_tests $array_tests $xfails
445 if { [istarget
*-*-linux
*]
446 ||
[istarget
*-*-nacl
*]
447 ||
[istarget
*-*-gnu
*] } {
448 run_ld_link_exec_tests $array_tests_pie $xfails
450 if { $STATIC_PIE_LDFLAGS
!= "" } then {
451 run_ld_link_exec_tests
[list \
453 "Static PIE preinit array" \
454 "$STATIC_PIE_LDFLAGS" \
457 "preinit-static-pie" \
462 "Static PIE init array" \
463 "$STATIC_PIE_LDFLAGS" \
471 "Static PIE fini array" \
472 "$STATIC_PIE_LDFLAGS" \
480 "Static PIE init array mixed" \
481 "$STATIC_PIE_LDFLAGS" \
484 "init-mixed-static-pie" \
489 "Static PIE PR ld/14525" \
490 "$STATIC_PIE_LDFLAGS" \
493 "pr14525-static-pie" \
500 run_ld_link_exec_tests
[list \
503 "$NOPIE_LDFLAGS -Wl,-z,common-page-size=0x4000 -Wl,-z,noexecstack" \
505 { mbind2a.s mbind2b.c
} \
512 "-static -Wl,-z,common-page-size=0x4000 -Wl,-z,noexecstack" \
514 { mbind2a.s mbind2b.c
} \
522 run_ld_link_exec_tests $array_tests_static $xfails
524 run_cc_link_tests
[list \
527 "-Wl,-z,unique-symbol" \
528 "-fno-function-sections" \
529 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c
} \
530 {{nm
"" pr26391.nd}} \
535 "-Wl,-z,unique-symbol" \
536 "-ffunction-sections" \
537 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c
} \
538 {{nm
"" pr26391.nd}} \
543 "-Wl,-z,unique-symbol,--emit-relocs" \
544 "-fno-function-sections" \
545 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c
} \
546 {{nm
"" pr26391.nd}} \
551 "-Wl,-z,unique-symbol,--emit-relocs" \
552 "-ffunction-sections" \
553 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c
} \
554 {{nm
"" pr26391.nd}} \
558 "Build pr26391-5.o" \
559 "-Wl,-z,unique-symbol -r -nostdlib -nostartfiles" \
560 "-fno-function-sections" \
561 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c
} \
563 [list
"nm" "$dep_plug_opt" "pr26391.nd"] \
564 [list
"nm" "$dep_plug_opt" "pr26391.fd"] \
569 "Build pr26391-6.o" \
570 "-Wl,-z,unique-symbol -r -nostdlib -nostartfiles" \
571 "-ffunction-sections" \
572 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c
} \
573 {{nm
"" pr26391.nd}} \
578 run_ld_link_exec_tests
[list \
581 "-Wl,-z,unique-symbol" \
583 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c
} \
586 "-fno-function-sections" \
590 "-Wl,-z,unique-symbol" \
592 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c
} \
595 "-ffunction-sections" \
599 "-Wl,-z,unique-symbol,--emit-relocs" \
601 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c
} \
604 "-fno-function-sections" \
608 "-Wl,-z,unique-symbol,--emit-relocs" \
610 {pr26391a.c pr26391b.c pr26391c.c pr26391d.c
} \
613 "-ffunction-sections" \
617 "-Wl,-z,unique-symbol" \
625 "tmpdir/pr26391-5.o" \
629 "-Wl,-z,unique-symbol" \
637 "tmpdir/pr26391-6.o" \
641 set merge_exec_tests
{
643 {merge4a.c merge4b.s
} "merge4" "merge4.out"}
645 run_ld_link_exec_tests $merge_exec_tests
647 catch
"exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status