]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - ld/testsuite/ld-elf/elf.exp
Support ELF SHF_GNU_MBIND and PT_GNU_MBIND_XXX
[thirdparty/binutils-gdb.git] / ld / testsuite / ld-elf / elf.exp
CommitLineData
782c0ebf 1# Expect script for various ELF tests.
2571583a 2# Copyright (C) 2002-2017 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
dd803a24
AM
64run_ld_link_tests [list \
65 [list "Build symbol3.a" \
66 "" "" $hpux \
67 {symbol3.s} {} "symbol3.a" ] \
68 [list "Build symbol3w.a" \
69 "" "" "" \
70 {symbol3w.s} {} "symbol3w.a" ] \
71]
72
73if { [check_shared_lib_support] } then {
5daeae9b 74 run_ld_link_tests {
dd803a24 75 {"Build pr14170a.o" "" "" "" {pr14170a.s} {} "pr14170.a" }
5daeae9b 76 }
dd803a24
AM
77 setup_xfail "tic6x-*-*"
78 run_ld_link_tests {
79 {"Build shared library for pr14170"
80 "-shared" "" "" "pr14170b.s" {} "pr14170.so" }
e54e67a9 81 }
dd803a24
AM
82 # bfin does not currently support copy relocs.
83 setup_xfail "bfin-*-*"
84 run_ld_link_tests [list \
85 [list "PR ld/14170" \
86 "--no-dynamic-linker tmpdir/pr14170a.o tmpdir/pr14170.so" "" $hpux \
87 {pr14170c.s} { } "pr14170" ] \
88 ]
83c5d36f
L
89}
90
a496fbc8 91# Only run these tests on targets that support creating shared libraries.
1d5316ab 92if { [check_shared_lib_support] } then {
6984613a
MR
93 # This target requires extra GAS options when building non-PIC code
94 # for linking with shared libraries.
95 set AFLAGS_NONPIC ""
96 if [istarget "mips*-*-*"] {
97 append AFLAGS_NONPIC " -call_nonpic"
98 }
99
d215621e
AM
100 # Run a test to check linking a shared library with a broken linker
101 # script that accidentally marks dynamic sections as notes. The
102 # resulting executable is not expected to work, but the linker
103 # should not seg-fault whilst creating the binary.
e54e67a9
AM
104 setup_xfail "tic6x-*-*"
105 run_ld_link_tests {
106 {"Build shared library for next test"
897aea50 107 "-shared" "" "" "note-3.s" {} "note-3.so" }
e54e67a9 108 {"Link using broken linker script"
897aea50 109 "--script note-3.t tmpdir/note-3.so" "" "" ""
e54e67a9
AM
110 { { ld "note-3.l" } }
111 "a.out" }
112 }
d215621e
AM
113 setup_xfail "tic6x-*-*"
114 run_ld_link_tests {
115 {"Build pr17068.so"
116 "-shared" "" ""
117 {pr17068d.s} {} "pr17068.so"}
118 {"Build pr17068a.a"
119 "" "" ""
120 {pr17068a.s pr17068c.s pr17068ez.s} {} "pr17068a.a"}
121 {"Build pr17068b.a"
122 "" "" ""
123 {pr17068b.s pr17068e.s} {} "pr17068b.a"}
1b857aee
NC
124 }
125 # bfin does not currently support copy relocs.
126 setup_xfail "bfin-*-*"
127 run_ld_link_tests {
d215621e 128 {"pr17068 link --as-needed lib in group"
1a9ccd70 129 "--as-needed --no-dynamic-linker" "--start-group tmpdir/pr17068a.a tmpdir/pr17068.so tmpdir/pr17068b.a --end-group" ""
d215621e
AM
130 {start.s pr17068.s} {} "pr17068"}
131 }
a496fbc8
AM
132 # xfail on tic6x due to non-PIC/non-PID warnings
133 setup_xfail "tic6x-*-*"
84054199
NC
134 # Fails on MIPS because ABI trickery means that a NULL reloc is also emitted.
135 setup_xfail "mips*-*-*"
1b857aee
NC
136 # Fails on bfin because relocations are not created.
137 setup_xfail "bfin-*-*"
a496fbc8
AM
138 run_ld_link_tests {
139 {"-Bsymbolic-functions"
140 "-shared -Bsymbolic-functions" "" ""
141 {symbolic-func.s} {{readelf {-r --wide} symbolic-func.r}}
142 "symbolic-func.so"}
143 }
5474d94f
AM
144 # xfail on tic6x due to non-PIC/non-PID warnings
145 setup_xfail "tic6x-*-*"
146 run_ld_link_tests {
147 {"Build pr20995.so"
148 "-shared" "" ""
149 {pr20995b.s} {} "pr20995.so"}
150 }
9acc85a6 151 setup_xfail "tic6x-*-*"
4471a46f
JW
152 # xfail on arm*-*-eabi*. The list can be enlarged to those targets that
153 # don't support GNU_RELRO. For more details, please see discussions at:
154 # https://sourceware.org/ml/binutils/2017-01/msg00441.html
dd803a24 155 setup_xfail "arm*-*-eabi*" "hppa*64*-*-hpux*"
9acc85a6
AM
156 run_ld_link_tests {
157 {"Build pr20995-2.so"
158 "-shared -z relro" "" ""
159 {pr20995c.s} {{readelf {-l --wide} pr20995-2so.r}} "pr20995-2.so"}
160 }
5474d94f
AM
161 # These targets don't copy dynamic variables into .bss.
162 setup_xfail "alpha-*-*" "bfin-*-*" "ia64-*-*" "xtensa-*-*"
dd803a24
AM
163 # or don't have .data.rel.ro
164 setup_xfail "hppa*64*-*-hpux*"
6984613a
MR
165 run_ld_link_tests [list \
166 [list \
167 "pr20995" \
168 "" "tmpdir/pr20995.so" "$AFLAGS_NONPIC" \
169 {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995"]]
4471a46f
JW
170 # xfail on arm*-*-eabi* is particularly because of no support of GNU_RELRO.
171 # Please see the link above for details.
172 setup_xfail "alpha-*-*" "bfin-*-*" "ia64-*-*" "xtensa-*-*" "arm*-*-eabi*"
dd803a24 173 setup_xfail "hppa*64*-*-hpux*"
6984613a
MR
174 run_ld_link_tests [list \
175 [list \
176 "pr20995-2" \
177 "" "tmpdir/pr20995-2.so" "$AFLAGS_NONPIC" \
178 {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995-2"]]
894891db
NC
179}
180
782c0ebf
AM
181set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
182foreach t $test_list {
183 # We need to strip the ".d", but can leave the dirname.
184 verbose [file rootname $t]
185 run_dump_test [file rootname $t]
186}
24edc24d 187
5df1bc57
AM
188# Targets using the generic linker backend don't support generating
189# an import library.
190set xfail_implib ""
b62b1f71 191if [is_generic_elf] {
5df1bc57
AM
192 set xfail_implib "*-*-*"
193}
194
76359541 195# Check that the --out-implib option work correctly.
dd803a24
AM
196run_ld_link_tests [list \
197 [list "Generate empty import library" \
198 "--out-implib=tmpdir/implib.lib" "" \
199 [concat "--defsym NO_GLOBAL=1" $hpux] \
200 {implib.s} \
201 {{ld empty-implib.out}} \
202 "implib" ] \
203 [list "Generate import library" \
204 "--out-implib=tmpdir/implib.lib" "" \
205 $hpux \
206 {implib.s} \
207 {{readelf {-s tmpdir/implib.lib} implib.rd}} \
208 "implib" ] \
209] $xfail_implib
76359541 210
5940a93c 211if { [istarget *-*-linux*]
5a68afcf 212 || [istarget *-*-nacl*]
5940a93c 213 || [istarget *-*-gnu*] } {
a26587ba
RS
214 run_ld_link_tests {
215 {"Weak symbols in dynamic objects 1 (support)"
897aea50 216 "-shared" "" "" {weak-dyn-1a.s}
a26587ba
RS
217 {}
218 "libweakdyn1a.so"}
219 {"Weak symbols in dynamic objects 1 (main test)"
897aea50 220 "-shared tmpdir/libweakdyn1a.so -Tweak-dyn-1.ld" "" "" {weak-dyn-1b.s}
a26587ba
RS
221 {{readelf {--relocs --wide} weak-dyn-1.rd}}
222 "libweakdyn1b.so"}
223 }
224}
225
78336cd6
AM
226#v850 gas complains about .tbss.var section attributes.
227if { [check_gc_sections_available] && ![istarget "v850-*-*"] } {
430a16a5
NC
228 run_ld_link_tests {
229 {"--gc-sections on tls variable"
897aea50 230 "--gc-section" "" "" {tls_gc.s} {} "tls_gc"}
430a16a5
NC
231 }
232}
233
6b00ac5a 234if { [istarget *-*-*linux*]
b3adb10f 235 || [istarget *-*-nacl*]
9cc420b6 236 || [istarget *-*-gnu*] } {
04c3a755 237 run_ld_link_tests {
897aea50 238 {"stack exec" "-z execstack" "" "" {stack.s}
04c3a755 239 {{readelf {-Wl} stack-exec.rd}} "stack-exec.exe"}
897aea50 240 {"stack size" "-z stack-size=0x123400" "" "" {stack.s}
04c3a755
NS
241 {{readelf {-Wl} stack-size.rd}} "stack-size.exe"}
242 }
243}
244
e4970690 245set LDFLAGS $old_ldflags
dd803a24 246set ASFLAGS $old_asflags
e4970690 247
4ce6ca2c
AM
248# Check to see if the C compiler works
249if { [which $CC] == 0 } {
250 return
251}
252
a130722b
L
253if [check_gc_sections_available] {
254 run_cc_link_tests {
255 {"PR ld/13195" "-Wl,--gc-sections" ""
256 {pr13195.c} {} "pr13195"}
257 }
54e8959c
L
258}
259
24edc24d 260set array_tests {
d9816402
AM
261 {"preinit array" "" ""
262 {preinit.c} "preinit" "preinit.out"}
263 {"init array" "" ""
264 {init.c} "init" "init.out"}
265 {"fini array" "" ""
266 {fini.c} "fini" "fini.out"}
267 {"init array mixed" "" ""
268 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
310fd250
L
269}
270set array_tests_pie {
d9816402
AM
271 {"PIE preinit array" "-pie" ""
272 {preinit.c} "preinit" "preinit.out" "-fPIE"}
273 {"PIE init array" "-pie" ""
274 {init.c} "init" "init.out" "-fPIE"}
275 {"PIE fini array" "-pie" ""
276 {fini.c} "fini" "fini.out" "-fPIE"}
277 {"PIE init array mixed" "-pie" ""
278 {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"}
279 {"PIE PR ld/14525" "-pie" ""
280 {pr14525.c} "pr14525" "pr14525.out" "-fPIE"}
5940a93c
TS
281}
282set array_tests_static {
d9816402
AM
283 {"static preinit array" "-static" ""
284 {preinit.c} "preinit" "preinit.out"}
285 {"static init array" "-static" ""
286 {init.c} "init" "init.out"}
287 {"static fini array" "-static" ""
288 {fini.c} "fini" "fini.out"}
289 {"static init array mixed" "-static" ""
290 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
24edc24d
L
291}
292
c8c140d9 293# NetBSD ELF systems do not currently support the .*_array sections.
982c6f26
AM
294set xfails "*-*-netbsdelf*"
295run_ld_link_exec_tests $array_tests $xfails
310fd250 296
3fee20ef 297if { [istarget *-*-linux*]
5a68afcf 298 || [istarget *-*-nacl*]
3fee20ef 299 || [istarget *-*-gnu*] } {
982c6f26 300 run_ld_link_exec_tests $array_tests_pie $xfails
a91e1603
L
301
302 run_ld_link_exec_tests [list \
303 [list \
304 "Run mbind2a" \
305 "$NOPIE_LDFLAGS -Wl,-z,common-page-size=0x4000" \
306 "" \
307 { mbind2a.s mbind2b.c } \
308 "mbind2a" \
309 "pass.out" \
310 "-O2 -I../bfd" \
311 ] \
312 [list \
313 "Run mbind2b" \
314 "-static -Wl,-z,common-page-size=0x4000" \
315 "" \
316 { mbind2a.s mbind2b.c } \
317 "mbind2b" \
318 "pass.out" \
319 "-O2 -I../bfd" \
320 ] \
321 ]
310fd250
L
322}
323
982c6f26 324# <http://www.gnu.org/software/hurd/open_issues/binutils.html#static>
5940a93c
TS
325# Be cautious to not XFAIL for *-*-linux-gnu*, *-*-kfreebsd-gnu*, etc.
326switch -regexp $target_triplet {
327 ^\[^-\]*-\[^-\]*-gnu.*$ {
982c6f26 328 set xfails "*-*-*"
5940a93c
TS
329 }
330}
982c6f26 331run_ld_link_exec_tests $array_tests_static $xfails
9ab80182 332
02ecc8e9 333catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status