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