tcl global directive outside proc body does nothing (ld)
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elf / elf.exp
CommitLineData
782c0ebf 1# Expect script for various ELF tests.
b3adc24a 2# Copyright (C) 2002-2020 Free Software Foundation, Inc.
b7b0b729 3#
f96b4a7b
NC
4# This file is part of the GNU Binutils.
5#
6# This program is free software; you can redistribute it and/or modify
b7b0b729 7# it under the terms of the GNU General Public License as published by
f96b4a7b 8# the Free Software Foundation; either version 3 of the License, or
b7b0b729
HPN
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
f96b4a7b
NC
18# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19# MA 02110-1301, USA.
b7b0b729 20#
b7b0b729
HPN
21
22# Exclude non-ELF targets.
23
43f9d75b 24if ![is_elf_format] {
b7b0b729
HPN
25 return
26}
27
e4970690 28set old_ldflags $LDFLAGS
9f264ea9
AM
29if { [istarget spu*-*-*] } {
30 set LDFLAGS "$LDFLAGS --local-store 0:0"
31}
dd803a24
AM
32
33# hpux .comm differs from everyone else
34set hpux ""
35set old_asflags $ASFLAGS
36if [istarget "*-*-hpux*"] {
37 set hpux "--defsym HPUX=1"
38 set ASFLAGS "$ASFLAGS --defsym HPUX=1"
39}
40
991cda6c
RH
41if { [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"
54975ae9 46 set ASFLAGS "$ASFLAGS --defsym NO_SET=1"
991cda6c 47}
9f264ea9 48
7cf492ee
RM
49if { [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
5cc51864
L
56if { [istarget "*-*-solaris*"] } {
57 # Same for Solaris
58 set options_regsub(ld) {-melf_x86_64 -melf_x86_64_sol2}
59}
60
7f6a71ff
JM
61if { [is_remote host] } then {
62 remote_download host merge.ld
63}
64
b77db948
NC
65# Note - the output file from the second test (symbol3w.a) is
66# used in the proc is_elf64 test below...
dd803a24
AM
67run_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
b77db948 76
b77db948
NC
77if [is_elf64 tmpdir/symbol3w.a] {
78 set ASFLAGS "$ASFLAGS --defsym ALIGN=3"
0a59decb 79 set pr23900_1_exp "pr23900-1-64.rd"
b7d07216
L
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"
b77db948
NC
85} else {
86 set ASFLAGS "$ASFLAGS --defsym ALIGN=2"
0a59decb 87 set pr23900_1_exp "pr23900-1-32.rd"
b7d07216
L
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 }
b77db948
NC
106}
107
108
109
46b06a98 110# Targets that use _bfd_generic_link_add_symbols won't pass pr21703 tests
506981af
RL
111run_ld_link_tests {
112 {"PR ld/21703"
93f4de39 113 "--allow-multiple-definition tmpdir/pr21703-1.o tmpdir/pr21703-2.o" "" "" \
506981af 114 {pr21703-1.s pr21703-2.s} {{readelf {-s} pr21703.sd}} "pr21703" }
506981af 115 {"PR ld/21703 -r"
93f4de39 116 "-r --allow-multiple-definition tmpdir/pr21703-3.o tmpdir/pr21703-4.o" "" "" \
506981af 117 {pr21703-3.s pr21703-4.s} {{readelf {-s} pr21703-r.sd}} "pr21703.o" }
1336939d 118} \[is_generic\]
93f4de39 119
bdd32e03
AM
120if [is_underscore_target] {
121 set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1"
122}
123
e9d644e8
L
124set saved_ASFLAGS "$ASFLAGS"
125if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
126 set ASFLAGS "$ASFLAGS -mx86-used-note=no"
127}
128
782c0ebf
AM
129set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
130foreach 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}
24edc24d 135
e9d644e8
L
136set ASFLAGS "$saved_ASFLAGS"
137
76359541 138# Check that the --out-implib option work correctly.
075a2b89 139# Targets that don't use elf.em won't support this.
dd803a24
AM
140run_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" ] \
1336939d 153] \[uses_genelf\]
76359541 154
78336cd6
AM
155#v850 gas complains about .tbss.var section attributes.
156if { [check_gc_sections_available] && ![istarget "v850-*-*"] } {
430a16a5
NC
157 run_ld_link_tests {
158 {"--gc-sections on tls variable"
897aea50 159 "--gc-section" "" "" {tls_gc.s} {} "tls_gc"}
430a16a5
NC
160 }
161}
162
6b00ac5a 163if { [istarget *-*-*linux*]
b3adb10f 164 || [istarget *-*-nacl*]
9cc420b6 165 || [istarget *-*-gnu*] } {
0a59decb
L
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 ]
04c3a755
NS
196}
197
b7d07216
L
198if [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
e4970690 238set LDFLAGS $old_ldflags
dd803a24 239set ASFLAGS $old_asflags
e4970690 240
4ce6ca2c 241# Check to see if the C compiler works
44ed8092 242if { ![check_compiler_available] } {
4ce6ca2c
AM
243 return
244}
245
a130722b
L
246if [check_gc_sections_available] {
247 run_cc_link_tests {
248 {"PR ld/13195" "-Wl,--gc-sections" ""
249 {pr13195.c} {} "pr13195"}
250 }
54e8959c
L
251}
252
24edc24d 253set array_tests {
d9816402
AM
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."}
310fd250
L
262}
263set array_tests_pie {
d9816402
AM
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"}
5940a93c
TS
274}
275set array_tests_static {
d9816402
AM
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."}
24edc24d
L
284}
285
c8c140d9 286# NetBSD ELF systems do not currently support the .*_array sections.
982c6f26
AM
287set xfails "*-*-netbsdelf*"
288run_ld_link_exec_tests $array_tests $xfails
310fd250 289
3fee20ef 290if { [istarget *-*-linux*]
5a68afcf 291 || [istarget *-*-nacl*]
3fee20ef 292 || [istarget *-*-gnu*] } {
982c6f26 293 run_ld_link_exec_tests $array_tests_pie $xfails
a91e1603 294
b3d7a867
L
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
a91e1603
L
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 ]
310fd250
L
365}
366
982c6f26 367run_ld_link_exec_tests $array_tests_static $xfails
9ab80182 368
02ecc8e9 369catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status
This page took 0.787941 seconds and 4 git commands to generate.