Update copyright years
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elf / elf.exp
1 # Expect script for various ELF tests.
2 # Copyright (C) 2002-2014 Free Software Foundation, Inc.
3 #
4 # This file is part of the GNU Binutils.
5 #
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.
10 #
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.
15 #
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,
19 # MA 02110-1301, USA.
20 #
21
22 # Exclude non-ELF targets.
23
24 if ![is_elf_format] {
25 return
26 }
27
28 set old_ldflags $LDFLAGS
29 if { [istarget spu*-*-*] } {
30 set LDFLAGS "$LDFLAGS --local-store 0:0"
31 }
32 if { [istarget alpha*-*-* ] } {
33 # The compress1 test is written expecting 32-bit addresses; force the
34 # executable down into the low address space to match.
35 # ??? How can we adjust just the one testcase?
36 set LDFLAGS "$LDFLAGS -Ttext-segment 0x1000000"
37 }
38
39 if { [istarget "*-*-nacl*"] } {
40 # The eh[1-4] cases are written to expect ELFCLASS64 layout on x86-64.
41 # But the target default is ELFCLASS32. So the cases explicitly use
42 # -melf_x86_64 to select that, but NaCl needs a different emulation name.
43 set options_regsub(ld) {-melf_x86_64 -melf_x86_64_nacl}
44 }
45
46 if { [istarget "*-*-solaris*"] } {
47 # Same for Solaris
48 set options_regsub(ld) {-melf_x86_64 -melf_x86_64_sol2}
49 }
50
51 if { [is_remote host] } then {
52 remote_download host merge.ld
53 }
54
55 if { ![istarget hppa64*-hpux*] } {
56 run_ld_link_tests {
57 {"Build symbol3.a"
58 "" "" ""
59 {symbol3.s} {} "symbol3.a"}
60 {"Build symbol3w.a"
61 "" "" ""
62 {symbol3w.s} {} "symbol3w.a"}
63 }
64
65 if { [check_shared_lib_support] } then {
66 run_ld_link_tests {
67 {"Build pr14170a.o" "" "" "" "pr14170a.s" {} "pr14170.a" }
68 }
69 setup_xfail "tic6x-*-*"
70 run_ld_link_tests {
71 {"Build shared library for pr14170"
72 "-shared" "" "" "pr14170b.s" {} "pr14170.so" }
73 {"PR ld/14170"
74 "tmpdir/pr14170a.o tmpdir/pr14170.so" "" "" "pr14170c.s"
75 { } "pr14170" }
76 }
77 }
78 }
79
80 # Run a test to check linking a shared library with a broken linker
81 # script that accidentally marks dynamic sections as notes. The
82 # resulting executable is not expected to work, but the linker
83 # should not seg-fault whilst creating the binary.
84 #
85 # Only run the test on targets thats support creating shared libraries.
86 if { [check_shared_lib_support] } then {
87 setup_xfail "tic6x-*-*"
88 run_ld_link_tests {
89 {"Build shared library for next test"
90 "-shared" "" "" "note-3.s" {} "note-3.so" }
91 {"Link using broken linker script"
92 "--script note-3.t tmpdir/note-3.so" "" "" ""
93 { { ld "note-3.l" } }
94 "a.out" }
95 }
96 }
97
98 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
99 foreach t $test_list {
100 # We need to strip the ".d", but can leave the dirname.
101 verbose [file rootname $t]
102 run_dump_test [file rootname $t]
103 }
104
105 if { [istarget *-*-linux*]
106 || [istarget *-*-nacl*]
107 || [istarget *-*-gnu*] } {
108 run_ld_link_tests {
109 {"Weak symbols in dynamic objects 1 (support)"
110 "-shared" "" "" {weak-dyn-1a.s}
111 {}
112 "libweakdyn1a.so"}
113 {"Weak symbols in dynamic objects 1 (main test)"
114 "-shared tmpdir/libweakdyn1a.so -Tweak-dyn-1.ld" "" "" {weak-dyn-1b.s}
115 {{readelf {--relocs --wide} weak-dyn-1.rd}}
116 "libweakdyn1b.so"}
117 }
118 }
119
120 #v850 gas complains about .tbss.var section attributes.
121 if { [check_gc_sections_available] && ![istarget "v850-*-*"] } {
122 run_ld_link_tests {
123 {"--gc-sections on tls variable"
124 "--gc-section" "" "" {tls_gc.s} {} "tls_gc"}
125 }
126 }
127
128 if { [istarget *-*-*linux*]
129 || [istarget *-*-nacl*]
130 || [istarget *-*-gnu*] } {
131 run_ld_link_tests {
132 {"stack exec" "-z execstack" "" "" {stack.s}
133 {{readelf {-Wl} stack-exec.rd}} "stack-exec.exe"}
134 {"stack size" "-z stack-size=0x123400" "" "" {stack.s}
135 {{readelf {-Wl} stack-size.rd}} "stack-size.exe"}
136 }
137 }
138
139 set LDFLAGS $old_ldflags
140
141 # The following tests require running the executable generated by ld.
142 if ![isnative] {
143 return
144 }
145
146 if [check_gc_sections_available] {
147 run_cc_link_tests {
148 {"PR ld/13195" "-Wl,--gc-sections" ""
149 {pr13195.c} {} "pr13195"}
150 }
151 }
152
153 set array_tests {
154 {"preinit array" "" "" {preinit.c} "preinit" "preinit.out"}
155 {"init array" "" "" {init.c} "init" "init.out"}
156 {"fini array" "" "" {fini.c} "fini" "fini.out"}
157 {"init array mixed" "" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
158 }
159 set array_tests_pie {
160 {"PIE preinit array" "-pie" "" {preinit.c} "preinit" "preinit.out" "-fPIE" }
161 {"PIE init array" "-pie" "" {init.c} "init" "init.out" "-fPIE"}
162 {"PIE fini array" "-pie" "" {fini.c} "fini" "fini.out" "-fPIE"}
163 {"PIE init array mixed" "-pie" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"}
164 {"PIE PR ld/14525" "-pie" "" {pr14525.c} "pr14525" "pr14525.out" "-fPIE"}
165 }
166 set array_tests_static {
167 {"static preinit array" "-static" "" {preinit.c} "preinit" "preinit.out"}
168 {"static init array" "-static" "" {init.c} "init" "init.out"}
169 {"static fini array" "-static" "" {fini.c} "fini" "fini.out"}
170 {"static init array mixed" "-static" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
171 }
172
173 # NetBSD ELF systems do not currently support the .*_array sections.
174 set xfails [list "*-*-netbsdelf*"]
175 run_ld_link_exec_tests $xfails $array_tests
176
177 if { [istarget *-*-linux*]
178 || [istarget *-*-nacl*]
179 || [istarget *-*-gnu*] } {
180 run_ld_link_exec_tests $xfails $array_tests_pie
181 }
182
183 # Be cautious to not XFAIL for *-*-linux-gnu*, *-*-kfreebsd-gnu*, etc.
184 switch -regexp $target_triplet {
185 ^\[^-\]*-\[^-\]*-gnu.*$ {
186 # <http://www.gnu.org/software/hurd/open_issues/binutils.html#static>
187 lappend xfails "*-*-*"
188 }
189 }
190 run_ld_link_exec_tests $xfails $array_tests_static
191
192 catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status
This page took 0.036718 seconds and 5 git commands to generate.