1
# Expect script for various ELF tests.
2
# Copyright 2002, 2003, 2005, 2007, 2009, 2010, 2011, 2012
3
# Free Software Foundation, Inc.
5
# This file is part of the GNU Binutils.
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
23
# Exclude non-ELF targets.
29
set old_ldflags $LDFLAGS
30
if { [istarget spu*-*-*] } {
31
set LDFLAGS "$LDFLAGS --local-store 0:0"
33
if { [istarget alpha*-*-* ] } {
34
# The compress1 test is written expecting 32-bit addresses; force the
35
# executable down into the low address space to match.
36
# ??? How can we adjust just the one testcase?
37
set LDFLAGS "$LDFLAGS -Ttext-segment 0x1000000"
40
if { [istarget "*-*-nacl*"] } {
41
# The eh[1-4] cases are written to expect ELFCLASS64 layout on x86-64.
42
# But the target default is ELFCLASS32. So the cases explicitly use
43
# -melf_x86_64 to select that, but NaCl needs a different emulation name.
44
set options_regsub(ld) {-melf_x86_64 -melf_x86_64_nacl}
47
if { [istarget "*-*-solaris*"] } {
49
set options_regsub(ld) {-melf_x86_64 -melf_x86_64_sol2}
52
if { [is_remote host] } then {
53
remote_download host merge.ld
56
if { ![istarget hppa64*-hpux*] } {
60
{symbol3.s} {} "symbol3.a"}
63
{symbol3w.s} {} "symbol3w.a"}
66
if { [check_shared_lib_support] } then {
68
{"Build pr14170a.o" "" "" "" "pr14170a.s" {} "pr14170.a" }
70
setup_xfail "tic6x-*-*"
72
{"Build shared library for pr14170"
73
"-shared" "" "" "pr14170b.s" {} "pr14170.so" }
75
"tmpdir/pr14170a.o tmpdir/pr14170.so" "" "" "pr14170c.s"
81
# Run a test to check linking a shared library with a broken linker
82
# script that accidentally marks dynamic sections as notes. The
83
# resulting executable is not expected to work, but the linker
84
# should not seg-fault whilst creating the binary.
86
# Only run the test on targets thats support creating shared libraries.
87
if { [check_shared_lib_support] } then {
88
setup_xfail "tic6x-*-*"
90
{"Build shared library for next test"
91
"-shared" "" "" "note-3.s" {} "note-3.so" }
92
{"Link using broken linker script"
93
"--script note-3.t tmpdir/note-3.so" "" "" ""
99
set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
100
foreach t $test_list {
101
# We need to strip the ".d", but can leave the dirname.
102
verbose [file rootname $t]
103
run_dump_test [file rootname $t]
106
if { [istarget *-*-linux*]
107
|| [istarget *-*-nacl*]
108
|| [istarget *-*-gnu*] } {
110
{"Weak symbols in dynamic objects 1 (support)"
111
"-shared" "" "" {weak-dyn-1a.s}
114
{"Weak symbols in dynamic objects 1 (main test)"
115
"-shared tmpdir/libweakdyn1a.so -Tweak-dyn-1.ld" "" "" {weak-dyn-1b.s}
116
{{readelf {--relocs --wide} weak-dyn-1.rd}}
121
#v850 gas complains about .tbss.var section attributes.
122
if { [check_gc_sections_available] && ![istarget "v850-*-*"] } {
124
{"--gc-sections on tls variable"
125
"--gc-section" "" "" {tls_gc.s} {} "tls_gc"}
129
if { [istarget *-*-*linux*]
130
|| [istarget *-*-nacl*]
131
|| [istarget *-*-gnu*] } {
133
{"stack exec" "-z execstack" "" "" {stack.s}
134
{{readelf {-Wl} stack-exec.rd}} "stack-exec.exe"}
135
{"stack size" "-z stack-size=0x123400" "" "" {stack.s}
136
{{readelf {-Wl} stack-size.rd}} "stack-size.exe"}
140
set LDFLAGS $old_ldflags
142
# The following tests require running the executable generated by ld.
147
if [check_gc_sections_available] {
149
{"PR ld/13195" "-Wl,--gc-sections" ""
150
{pr13195.c} {} "pr13195"}
155
{"preinit array" "" "" {preinit.c} "preinit" "preinit.out"}
156
{"init array" "" "" {init.c} "init" "init.out"}
157
{"fini array" "" "" {fini.c} "fini" "fini.out"}
158
{"init array mixed" "" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
160
set array_tests_pie {
161
{"PIE preinit array" "-pie" "" {preinit.c} "preinit" "preinit.out" "-fPIE" }
162
{"PIE init array" "-pie" "" {init.c} "init" "init.out" "-fPIE"}
163
{"PIE fini array" "-pie" "" {fini.c} "fini" "fini.out" "-fPIE"}
164
{"PIE init array mixed" "-pie" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"}
165
{"PIE PR ld/14525" "-pie" "" {pr14525.c} "pr14525" "pr14525.out" "-fPIE"}
167
set array_tests_static {
168
{"static preinit array" "-static" "" {preinit.c} "preinit" "preinit.out"}
169
{"static init array" "-static" "" {init.c} "init" "init.out"}
170
{"static fini array" "-static" "" {fini.c} "fini" "fini.out"}
171
{"static init array mixed" "-static" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
174
# NetBSD ELF systems do not currently support the .*_array sections.
175
set xfails [list "*-*-netbsdelf*"]
176
run_ld_link_exec_tests $xfails $array_tests
178
if { [istarget *-*-linux*]
179
|| [istarget *-*-nacl*]
180
|| [istarget *-*-gnu*] } {
181
run_ld_link_exec_tests $xfails $array_tests_pie
184
# Be cautious to not XFAIL for *-*-linux-gnu*, *-*-kfreebsd-gnu*, etc.
185
switch -regexp $target_triplet {
186
^\[^-\]*-\[^-\]*-gnu.*$ {
187
# <http://www.gnu.org/software/hurd/open_issues/binutils.html#static>
188
lappend xfails "*-*-*"
191
run_ld_link_exec_tests $xfails $array_tests_static
193
catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status