]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - ld/testsuite/ld-elf/elf.exp
Use better test for usable compiler in ld testsuite.
[thirdparty/binutils-gdb.git] / ld / testsuite / ld-elf / elf.exp
CommitLineData
782c0ebf 1# Expect script for various ELF tests.
82704155 2# Copyright (C) 2002-2019 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"
46}
9f264ea9 47
7cf492ee
RM
48if { [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
5cc51864
L
55if { [istarget "*-*-solaris*"] } {
56 # Same for Solaris
57 set options_regsub(ld) {-melf_x86_64 -melf_x86_64_sol2}
58}
59
7f6a71ff
JM
60if { [is_remote host] } then {
61 remote_download host merge.ld
62}
63
b77db948
NC
64# Note - the output file from the second test (symbol3w.a) is
65# used in the proc is_elf64 test below...
dd803a24
AM
66run_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
b77db948 75
b77db948
NC
76if [is_elf64 tmpdir/symbol3w.a] {
77 set ASFLAGS "$ASFLAGS --defsym ALIGN=3"
0a59decb 78 set pr23900_1_exp "pr23900-1-64.rd"
b77db948
NC
79} else {
80 set ASFLAGS "$ASFLAGS --defsym ALIGN=2"
0a59decb 81 set pr23900_1_exp "pr23900-1-32.rd"
b77db948
NC
82}
83
84
85
46b06a98 86# Targets that use _bfd_generic_link_add_symbols won't pass pr21703 tests
506981af
RL
87run_ld_link_tests {
88 {"PR ld/21703"
93f4de39 89 "--allow-multiple-definition tmpdir/pr21703-1.o tmpdir/pr21703-2.o" "" "" \
506981af 90 {pr21703-1.s pr21703-2.s} {{readelf {-s} pr21703.sd}} "pr21703" }
506981af 91 {"PR ld/21703 -r"
93f4de39 92 "-r --allow-multiple-definition tmpdir/pr21703-3.o tmpdir/pr21703-4.o" "" "" \
506981af 93 {pr21703-3.s pr21703-4.s} {{readelf {-s} pr21703-r.sd}} "pr21703.o" }
be570f06 94} "d30v-*-*" "dlx-*-*" "pj-*-*" "xgate-*-*"
93f4de39 95
bdd32e03
AM
96if [is_underscore_target] {
97 set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1"
98}
99
e9d644e8
L
100global ASFLAGS
101set saved_ASFLAGS "$ASFLAGS"
102if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
103 set ASFLAGS "$ASFLAGS -mx86-used-note=no"
104}
105
782c0ebf
AM
106set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
107foreach 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}
24edc24d 112
e9d644e8
L
113set ASFLAGS "$saved_ASFLAGS"
114
5df1bc57
AM
115# Targets using the generic linker backend don't support generating
116# an import library.
117set xfail_implib ""
b62b1f71 118if [is_generic_elf] {
5df1bc57
AM
119 set xfail_implib "*-*-*"
120}
121
76359541 122# Check that the --out-implib option work correctly.
dd803a24
AM
123run_ld_link_tests [list \
124 [list "Generate empty import library" \
125 "--out-implib=tmpdir/implib.lib" "" \
126 [concat "--defsym NO_GLOBAL=1" $hpux] \
127 {implib.s} \
128 {{ld empty-implib.out}} \
129 "implib" ] \
130 [list "Generate import library" \
131 "--out-implib=tmpdir/implib.lib" "" \
132 $hpux \
133 {implib.s} \
134 {{readelf {-s tmpdir/implib.lib} implib.rd}} \
135 "implib" ] \
136] $xfail_implib
76359541 137
78336cd6
AM
138#v850 gas complains about .tbss.var section attributes.
139if { [check_gc_sections_available] && ![istarget "v850-*-*"] } {
430a16a5
NC
140 run_ld_link_tests {
141 {"--gc-sections on tls variable"
897aea50 142 "--gc-section" "" "" {tls_gc.s} {} "tls_gc"}
430a16a5
NC
143 }
144}
145
6b00ac5a 146if { [istarget *-*-*linux*]
b3adb10f 147 || [istarget *-*-nacl*]
9cc420b6 148 || [istarget *-*-gnu*] } {
0a59decb
L
149 run_ld_link_tests [list \
150 [list "stack exec" \
151 "-z execstack" \
152 "" \
153 "" \
154 {stack.s} \
155 {{readelf {-Wl} stack-exec.rd}} \
156 "stack-exec.exe"] \
157 [list "stack noexec" \
158 "-z noexecstack" \
159 "" \
160 "" \
161 {stack.s} \
162 {{readelf {-Wl} stack-noexec.rd}} \
163 "stack-noexec.exe"] \
164 [list "stack size" \
165 "-z stack-size=0x123400" \
166 "" \
167 "" \
168 {stack.s} \
169 {{readelf {-Wl} stack-size.rd}} \
170 "stack-size.exe"] \
171 [list "PT_GNU_PROPERTY alignment" \
172 "" \
173 "" \
174 "" \
175 {pr23900-1.s} \
176 [list [list "readelf" {-Wl} $pr23900_1_exp]] \
177 "pr23900-1.exe"] \
178 ]
04c3a755
NS
179}
180
e4970690 181set LDFLAGS $old_ldflags
dd803a24 182set ASFLAGS $old_asflags
e4970690 183
4ce6ca2c 184# Check to see if the C compiler works
44ed8092 185if { ![check_compiler_available] } {
4ce6ca2c
AM
186 return
187}
188
a130722b
L
189if [check_gc_sections_available] {
190 run_cc_link_tests {
191 {"PR ld/13195" "-Wl,--gc-sections" ""
192 {pr13195.c} {} "pr13195"}
193 }
54e8959c
L
194}
195
24edc24d 196set array_tests {
d9816402
AM
197 {"preinit array" "" ""
198 {preinit.c} "preinit" "preinit.out"}
199 {"init array" "" ""
200 {init.c} "init" "init.out"}
201 {"fini array" "" ""
202 {fini.c} "fini" "fini.out"}
203 {"init array mixed" "" ""
204 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
310fd250
L
205}
206set array_tests_pie {
d9816402
AM
207 {"PIE preinit array" "-pie" ""
208 {preinit.c} "preinit" "preinit.out" "-fPIE"}
209 {"PIE init array" "-pie" ""
210 {init.c} "init" "init.out" "-fPIE"}
211 {"PIE fini array" "-pie" ""
212 {fini.c} "fini" "fini.out" "-fPIE"}
213 {"PIE init array mixed" "-pie" ""
214 {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"}
215 {"PIE PR ld/14525" "-pie" ""
216 {pr14525.c} "pr14525" "pr14525.out" "-fPIE"}
5940a93c
TS
217}
218set array_tests_static {
d9816402
AM
219 {"static preinit array" "-static" ""
220 {preinit.c} "preinit" "preinit.out"}
221 {"static init array" "-static" ""
222 {init.c} "init" "init.out"}
223 {"static fini array" "-static" ""
224 {fini.c} "fini" "fini.out"}
225 {"static init array mixed" "-static" ""
226 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
24edc24d
L
227}
228
c8c140d9 229# NetBSD ELF systems do not currently support the .*_array sections.
982c6f26
AM
230set xfails "*-*-netbsdelf*"
231run_ld_link_exec_tests $array_tests $xfails
310fd250 232
3fee20ef 233if { [istarget *-*-linux*]
5a68afcf 234 || [istarget *-*-nacl*]
3fee20ef 235 || [istarget *-*-gnu*] } {
982c6f26 236 run_ld_link_exec_tests $array_tests_pie $xfails
a91e1603 237
b3d7a867
L
238 if { $STATIC_PIE_LDFLAGS != "" } then {
239 run_ld_link_exec_tests [list \
240 [list \
241 "Static PIE preinit array" \
242 "$STATIC_PIE_LDFLAGS" \
243 "" \
244 {preinit.c} \
245 "preinit-static-pie" \
246 "preinit.out" \
247 "-fPIE" \
248 ] \
249 [list \
250 "Static PIE init array" \
251 "$STATIC_PIE_LDFLAGS" \
252 "" \
253 {init.c} \
254 "init-static-pie" \
255 "init.out" \
256 "-fPIE" \
257 ] \
258 [list \
259 "Static PIE fini array" \
260 "$STATIC_PIE_LDFLAGS" \
261 "" \
262 {fini.c} \
263 "fini-static-pie" \
264 "fini.out" \
265 "-fPIE" \
266 ] \
267 [list \
268 "Static PIE init array mixed" \
269 "$STATIC_PIE_LDFLAGS" \
270 "" \
271 {init-mixed.c} \
272 "init-mixed-static-pie" \
273 "init-mixed.out" \
274 "-I. -fPIE" \
275 ] \
276 [list \
277 "Static PIE PR ld/14525" \
278 "$STATIC_PIE_LDFLAGS" \
279 "" \
280 {pr14525.c} \
281 "pr14525-static-pie" \
282 "pr14525.out" \
283 "-fPIE" \
284 ] \
285 ]
286 }
287
a91e1603
L
288 run_ld_link_exec_tests [list \
289 [list \
290 "Run mbind2a" \
291 "$NOPIE_LDFLAGS -Wl,-z,common-page-size=0x4000" \
292 "" \
293 { mbind2a.s mbind2b.c } \
294 "mbind2a" \
295 "pass.out" \
296 "-O2 -I../bfd" \
297 ] \
298 [list \
299 "Run mbind2b" \
300 "-static -Wl,-z,common-page-size=0x4000" \
301 "" \
302 { mbind2a.s mbind2b.c } \
303 "mbind2b" \
304 "pass.out" \
305 "-O2 -I../bfd" \
306 ] \
307 ]
310fd250
L
308}
309
982c6f26 310run_ld_link_exec_tests $array_tests_static $xfails
9ab80182 311
02ecc8e9 312catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status