Support tcl procedure calls in run_dump_test xfail
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elf / elf.exp
1 # Expect script for various ELF tests.
2 # Copyright (C) 2002-2019 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
33 # hpux .comm differs from everyone else
34 set hpux ""
35 set old_asflags $ASFLAGS
36 if [istarget "*-*-hpux*"] {
37 set hpux "--defsym HPUX=1"
38 set ASFLAGS "$ASFLAGS --defsym HPUX=1"
39 }
40
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 }
47
48 if { [istarget "*-*-nacl*"] } {
49 # The eh[1-4] cases are written to expect ELFCLASS64 layout on x86-64.
50 # But the target default is ELFCLASS32. So the cases explicitly use
51 # -melf_x86_64 to select that, but NaCl needs a different emulation name.
52 set options_regsub(ld) {-melf_x86_64 -melf_x86_64_nacl}
53 }
54
55 if { [istarget "*-*-solaris*"] } {
56 # Same for Solaris
57 set options_regsub(ld) {-melf_x86_64 -melf_x86_64_sol2}
58 }
59
60 if { [is_remote host] } then {
61 remote_download host merge.ld
62 }
63
64 # Note - the output file from the second test (symbol3w.a) is
65 # used in the proc is_elf64 test below...
66 run_ld_link_tests [list \
67 [list "Build symbol3.a" \
68 "" "" $hpux \
69 {symbol3.s} {} "symbol3.a" ] \
70 [list "Build symbol3w.a" \
71 "" "" "" \
72 {symbol3w.s} {} "symbol3w.a" ] \
73 ]
74
75
76 if [is_elf64 tmpdir/symbol3w.a] {
77 set ASFLAGS "$ASFLAGS --defsym ALIGN=3"
78 set pr23900_1_exp "pr23900-1-64.rd"
79 } else {
80 set ASFLAGS "$ASFLAGS --defsym ALIGN=2"
81 set pr23900_1_exp "pr23900-1-32.rd"
82 }
83
84
85
86 # Targets that use _bfd_generic_link_add_symbols won't pass pr21703 tests
87 run_ld_link_tests {
88 {"PR ld/21703"
89 "--allow-multiple-definition tmpdir/pr21703-1.o tmpdir/pr21703-2.o" "" "" \
90 {pr21703-1.s pr21703-2.s} {{readelf {-s} pr21703.sd}} "pr21703" }
91 {"PR ld/21703 -r"
92 "-r --allow-multiple-definition tmpdir/pr21703-3.o tmpdir/pr21703-4.o" "" "" \
93 {pr21703-3.s pr21703-4.s} {{readelf {-s} pr21703-r.sd}} "pr21703.o" }
94 } \[is_generic\]
95
96 if [is_underscore_target] {
97 set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1"
98 }
99
100 global ASFLAGS
101 set saved_ASFLAGS "$ASFLAGS"
102 if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
103 set ASFLAGS "$ASFLAGS -mx86-used-note=no"
104 }
105
106 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
107 foreach t $test_list {
108 # We need to strip the ".d", but can leave the dirname.
109 verbose [file rootname $t]
110 run_dump_test [file rootname $t]
111 }
112
113 set ASFLAGS "$saved_ASFLAGS"
114
115 # Check that the --out-implib option work correctly.
116 # Targets that don't use elf32.em won't support this.
117 run_ld_link_tests [list \
118 [list "Generate empty import library" \
119 "--out-implib=tmpdir/implib.lib" "" \
120 [concat "--defsym NO_GLOBAL=1" $hpux] \
121 {implib.s} \
122 {{ld empty-implib.out}} \
123 "implib" ] \
124 [list "Generate import library" \
125 "--out-implib=tmpdir/implib.lib" "" \
126 $hpux \
127 {implib.s} \
128 {{readelf {-s tmpdir/implib.lib} implib.rd}} \
129 "implib" ] \
130 ] \[uses_genelf\]
131
132 #v850 gas complains about .tbss.var section attributes.
133 if { [check_gc_sections_available] && ![istarget "v850-*-*"] } {
134 run_ld_link_tests {
135 {"--gc-sections on tls variable"
136 "--gc-section" "" "" {tls_gc.s} {} "tls_gc"}
137 }
138 }
139
140 if { [istarget *-*-*linux*]
141 || [istarget *-*-nacl*]
142 || [istarget *-*-gnu*] } {
143 run_ld_link_tests [list \
144 [list "stack exec" \
145 "-z execstack" \
146 "" \
147 "" \
148 {stack.s} \
149 {{readelf {-Wl} stack-exec.rd}} \
150 "stack-exec.exe"] \
151 [list "stack noexec" \
152 "-z noexecstack" \
153 "" \
154 "" \
155 {stack.s} \
156 {{readelf {-Wl} stack-noexec.rd}} \
157 "stack-noexec.exe"] \
158 [list "stack size" \
159 "-z stack-size=0x123400" \
160 "" \
161 "" \
162 {stack.s} \
163 {{readelf {-Wl} stack-size.rd}} \
164 "stack-size.exe"] \
165 [list "PT_GNU_PROPERTY alignment" \
166 "" \
167 "" \
168 "" \
169 {pr23900-1.s} \
170 [list [list "readelf" {-Wl} $pr23900_1_exp]] \
171 "pr23900-1.exe"] \
172 ]
173 }
174
175 set LDFLAGS $old_ldflags
176 set ASFLAGS $old_asflags
177
178 # Check to see if the C compiler works
179 if { ![check_compiler_available] } {
180 return
181 }
182
183 if [check_gc_sections_available] {
184 run_cc_link_tests {
185 {"PR ld/13195" "-Wl,--gc-sections" ""
186 {pr13195.c} {} "pr13195"}
187 }
188 }
189
190 set array_tests {
191 {"preinit array" "" ""
192 {preinit.c} "preinit" "preinit.out"}
193 {"init array" "" ""
194 {init.c} "init" "init.out"}
195 {"fini array" "" ""
196 {fini.c} "fini" "fini.out"}
197 {"init array mixed" "" ""
198 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
199 }
200 set array_tests_pie {
201 {"PIE preinit array" "-pie" ""
202 {preinit.c} "preinit" "preinit.out" "-fPIE"}
203 {"PIE init array" "-pie" ""
204 {init.c} "init" "init.out" "-fPIE"}
205 {"PIE fini array" "-pie" ""
206 {fini.c} "fini" "fini.out" "-fPIE"}
207 {"PIE init array mixed" "-pie" ""
208 {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"}
209 {"PIE PR ld/14525" "-pie" ""
210 {pr14525.c} "pr14525" "pr14525.out" "-fPIE"}
211 }
212 set array_tests_static {
213 {"static preinit array" "-static" ""
214 {preinit.c} "preinit" "preinit.out"}
215 {"static init array" "-static" ""
216 {init.c} "init" "init.out"}
217 {"static fini array" "-static" ""
218 {fini.c} "fini" "fini.out"}
219 {"static init array mixed" "-static" ""
220 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
221 }
222
223 # NetBSD ELF systems do not currently support the .*_array sections.
224 set xfails "*-*-netbsdelf*"
225 run_ld_link_exec_tests $array_tests $xfails
226
227 if { [istarget *-*-linux*]
228 || [istarget *-*-nacl*]
229 || [istarget *-*-gnu*] } {
230 run_ld_link_exec_tests $array_tests_pie $xfails
231
232 if { $STATIC_PIE_LDFLAGS != "" } then {
233 run_ld_link_exec_tests [list \
234 [list \
235 "Static PIE preinit array" \
236 "$STATIC_PIE_LDFLAGS" \
237 "" \
238 {preinit.c} \
239 "preinit-static-pie" \
240 "preinit.out" \
241 "-fPIE" \
242 ] \
243 [list \
244 "Static PIE init array" \
245 "$STATIC_PIE_LDFLAGS" \
246 "" \
247 {init.c} \
248 "init-static-pie" \
249 "init.out" \
250 "-fPIE" \
251 ] \
252 [list \
253 "Static PIE fini array" \
254 "$STATIC_PIE_LDFLAGS" \
255 "" \
256 {fini.c} \
257 "fini-static-pie" \
258 "fini.out" \
259 "-fPIE" \
260 ] \
261 [list \
262 "Static PIE init array mixed" \
263 "$STATIC_PIE_LDFLAGS" \
264 "" \
265 {init-mixed.c} \
266 "init-mixed-static-pie" \
267 "init-mixed.out" \
268 "-I. -fPIE" \
269 ] \
270 [list \
271 "Static PIE PR ld/14525" \
272 "$STATIC_PIE_LDFLAGS" \
273 "" \
274 {pr14525.c} \
275 "pr14525-static-pie" \
276 "pr14525.out" \
277 "-fPIE" \
278 ] \
279 ]
280 }
281
282 run_ld_link_exec_tests [list \
283 [list \
284 "Run mbind2a" \
285 "$NOPIE_LDFLAGS -Wl,-z,common-page-size=0x4000" \
286 "" \
287 { mbind2a.s mbind2b.c } \
288 "mbind2a" \
289 "pass.out" \
290 "-O2 -I../bfd" \
291 ] \
292 [list \
293 "Run mbind2b" \
294 "-static -Wl,-z,common-page-size=0x4000" \
295 "" \
296 { mbind2a.s mbind2b.c } \
297 "mbind2b" \
298 "pass.out" \
299 "-O2 -I../bfd" \
300 ] \
301 ]
302 }
303
304 run_ld_link_exec_tests $array_tests_static $xfails
305
306 catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status
This page took 0.037038 seconds and 5 git commands to generate.