bfd/
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elf / elf.exp
CommitLineData
782c0ebf 1# Expect script for various ELF tests.
5a68afcf 2# Copyright 2002, 2003, 2005, 2007, 2009, 2010, 2011, 2012
5daeae9b 3# Free Software Foundation, Inc.
b7b0b729 4#
f96b4a7b
NC
5# This file is part of the GNU Binutils.
6#
7# This program is free software; you can redistribute it and/or modify
b7b0b729 8# it under the terms of the GNU General Public License as published by
f96b4a7b 9# the Free Software Foundation; either version 3 of the License, or
b7b0b729
HPN
10# (at your option) any later version.
11#
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.
16#
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
f96b4a7b
NC
19# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20# MA 02110-1301, USA.
b7b0b729 21#
b7b0b729
HPN
22
23# Exclude non-ELF targets.
24
43f9d75b 25if ![is_elf_format] {
b7b0b729
HPN
26 return
27}
28
e4970690 29set old_ldflags $LDFLAGS
9f264ea9
AM
30if { [istarget spu*-*-*] } {
31 set LDFLAGS "$LDFLAGS --local-store 0:0"
32}
991cda6c
RH
33if { [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"
38}
9f264ea9 39
7f6a71ff
JM
40if { [is_remote host] } then {
41 remote_download host merge.ld
42}
43
5daeae9b
AM
44if { ![istarget hppa64*-hpux*] } {
45 run_ld_link_tests {
46 {"Build symbol3.a"
47 "" ""
48 {symbol3.s} {} "symbol3.a"}
49 {"Build symbol3w.a"
50 "" ""
51 {symbol3w.s} {} "symbol3w.a"}
52 }
83c5d36f
L
53}
54
894891db
NC
55# Run a test to check linking a shared library with a broken linker
56# script that accidentally marks dynamic sections as notes. The
57# resulting executable is not expected to work, but the linker
58# should not seg-fault whilst creating the binary.
59#
60# Only run the test on targets thats support creating shared libraries.
1d5316ab 61if { [check_shared_lib_support] } then {
894891db
NC
62 run_ld_link_tests {
63 {"Build shared library for next test"
64 "-shared" "" "note-3.s" {} "note-3.so" }
65 {"Link using broken linker script"
66 "--script note-3.t tmpdir/note-3.so" "" ""
67 { { ld "note-3.l" } }
68 "a.out" }
69 }
70}
71
782c0ebf
AM
72set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
73foreach t $test_list {
74 # We need to strip the ".d", but can leave the dirname.
75 verbose [file rootname $t]
76 run_dump_test [file rootname $t]
77}
24edc24d 78
5940a93c 79if { [istarget *-*-linux*]
5a68afcf 80 || [istarget *-*-nacl*]
5940a93c 81 || [istarget *-*-gnu*] } {
a26587ba
RS
82 run_ld_link_tests {
83 {"Weak symbols in dynamic objects 1 (support)"
84 "-shared" "" {weak-dyn-1a.s}
85 {}
86 "libweakdyn1a.so"}
87 {"Weak symbols in dynamic objects 1 (main test)"
88 "-shared tmpdir/libweakdyn1a.so -Tweak-dyn-1.ld" "" {weak-dyn-1b.s}
89 {{readelf {--relocs --wide} weak-dyn-1.rd}}
90 "libweakdyn1b.so"}
91 }
92}
93
78336cd6
AM
94#v850 gas complains about .tbss.var section attributes.
95if { [check_gc_sections_available] && ![istarget "v850-*-*"] } {
430a16a5
NC
96 run_ld_link_tests {
97 {"--gc-sections on tls variable"
98 "--gc-section" "" {tls_gc.s} {} "tls_gc"}
99 }
100}
101
e4970690
AM
102set LDFLAGS $old_ldflags
103
24edc24d
L
104# The following tests require running the executable generated by ld.
105if ![isnative] {
106 return
107}
108
a130722b
L
109if [check_gc_sections_available] {
110 run_cc_link_tests {
111 {"PR ld/13195" "-Wl,--gc-sections" ""
112 {pr13195.c} {} "pr13195"}
113 }
54e8959c
L
114}
115
24edc24d
L
116set array_tests {
117 {"preinit array" "" "" {preinit.c} "preinit" "preinit.out"}
24edc24d 118 {"init array" "" "" {init.c} "init" "init.out"}
24edc24d 119 {"fini array" "" "" {fini.c} "fini" "fini.out"}
02ecc8e9 120 {"init array mixed" "" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
310fd250
L
121}
122set array_tests_pie {
123 {"PIE preinit array" "-pie" "" {preinit.c} "preinit" "preinit.out" "-fPIE" }
124 {"PIE init array" "-pie" "" {init.c} "init" "init.out" "-fPIE"}
125 {"PIE fini array" "-pie" "" {fini.c} "fini" "fini.out" "-fPIE"}
126 {"PIE init array mixed" "-pie" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"}
5940a93c
TS
127}
128set array_tests_static {
129 {"static preinit array" "-static" "" {preinit.c} "preinit" "preinit.out"}
130 {"static init array" "-static" "" {init.c} "init" "init.out"}
24edc24d 131 {"static fini array" "-static" "" {fini.c} "fini" "fini.out"}
310fd250 132 {"static init array mixed" "-static" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
24edc24d
L
133}
134
c8c140d9 135# NetBSD ELF systems do not currently support the .*_array sections.
5940a93c
TS
136set xfails [list "*-*-netbsdelf*"]
137run_ld_link_exec_tests $xfails $array_tests
310fd250 138
3fee20ef 139if { [istarget *-*-linux*]
5a68afcf 140 || [istarget *-*-nacl*]
3fee20ef 141 || [istarget *-*-gnu*] } {
310fd250
L
142 run_ld_link_exec_tests $xfails $array_tests_pie
143}
144
5940a93c
TS
145# Be cautious to not XFAIL for *-*-linux-gnu*, *-*-kfreebsd-gnu*, etc.
146switch -regexp $target_triplet {
147 ^\[^-\]*-\[^-\]*-gnu.*$ {
43fbacde 148 # <http://www.gnu.org/software/hurd/open_issues/binutils.html#static>
5940a93c
TS
149 lappend xfails "*-*-*"
150 }
151}
152run_ld_link_exec_tests $xfails $array_tests_static
9ab80182 153
02ecc8e9 154catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status
This page took 0.550065 seconds and 4 git commands to generate.