Fix handling of GNU Property notes that are not in a GNU NOTE PROPERTY section.
[deliverable/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
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
NC
75
76# True if the object format is known to be 64-bit ELF.
77#
78proc is_elf64 { binary_file } {
79 global READELF
80 global READELFFLAGS
81
82 set readelf_size ""
83 catch "exec $READELF $READELFFLAGS -h $binary_file > readelf.out" got
84
85 if ![string match "" $got] then {
86 return 0
87 }
88
89 if { ![regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
90 [file_contents readelf.out] nil readelf_size] } {
91 verbose "FAILED to determine ELF size"
92 return 0
93 }
94
95 if { $readelf_size == "64" } {
96 return 1
97 }
98
99 return 0
100}
101
102if [is_elf64 tmpdir/symbol3w.a] {
103 set ASFLAGS "$ASFLAGS --defsym ALIGN=3"
104} else {
105 set ASFLAGS "$ASFLAGS --defsym ALIGN=2"
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" }
46b06a98 118} "d30v-*-*" "dlx-*-*" "pj-*-*"
93f4de39 119
46b06a98 120# Only run these tests on targets that support creating shared libraries.
dd803a24 121if { [check_shared_lib_support] } then {
5daeae9b 122 run_ld_link_tests {
dd803a24 123 {"Build pr14170a.o" "" "" "" {pr14170a.s} {} "pr14170.a" }
5daeae9b 124 }
dd803a24
AM
125 run_ld_link_tests {
126 {"Build shared library for pr14170"
127 "-shared" "" "" "pr14170b.s" {} "pr14170.so" }
46b06a98
AM
128 } "tic6x-*-*"
129
dd803a24 130 # bfin does not currently support copy relocs.
dd803a24
AM
131 run_ld_link_tests [list \
132 [list "PR ld/14170" \
133 "--no-dynamic-linker tmpdir/pr14170a.o tmpdir/pr14170.so" "" $hpux \
134 {pr14170c.s} { } "pr14170" ] \
46b06a98 135 ] "bfin-*-*"
506981af 136
46b06a98
AM
137 # Targets that use _bfd_generic_link_add_symbols won't pass pr21703 tests
138 # Not will tic6x with PIC/PID warning, or hppa64 with dot-symbols
506981af
RL
139 run_ld_link_tests {
140 {"PR ld/21703 shared"
141 "-shared --allow-multiple-definition --version-script pr21703.ver tmpdir/pr21703-3.o tmpdir/pr21703-4.o" "" "" \
142 {pr21703-3.s pr21703-4.s} {{readelf {--dyn-syms} pr21703-shared.sd}} "pr21703.so" }
46b06a98 143 } "d30v-*-*" "dlx-*-*" "pj-*-*" "tic6x-*-*" "hppa64-*-*"
83c5d36f 144
6984613a
MR
145 # This target requires extra GAS options when building non-PIC code
146 # for linking with shared libraries.
147 set AFLAGS_NONPIC ""
148 if [istarget "mips*-*-*"] {
149 append AFLAGS_NONPIC " -call_nonpic"
150 }
151
d215621e
AM
152 # Run a test to check linking a shared library with a broken linker
153 # script that accidentally marks dynamic sections as notes. The
154 # resulting executable is not expected to work, but the linker
155 # should not seg-fault whilst creating the binary.
46b06a98 156 # Note: setup_xfail before run_ld_link_tests xfails only the first test.
e54e67a9
AM
157 setup_xfail "tic6x-*-*"
158 run_ld_link_tests {
46b06a98 159 {"Build shared library for broken linker scrip test"
bab55c05 160 "-shared --hash-style=sysv" "" "" "note-3.s" {} "note-3.so" }
e54e67a9 161 {"Link using broken linker script"
897aea50 162 "--script note-3.t tmpdir/note-3.so" "" "" ""
e54e67a9
AM
163 { { ld "note-3.l" } }
164 "a.out" }
165 }
46b06a98 166
d215621e
AM
167 setup_xfail "tic6x-*-*"
168 run_ld_link_tests {
169 {"Build pr17068.so"
170 "-shared" "" ""
171 {pr17068d.s} {} "pr17068.so"}
172 {"Build pr17068a.a"
173 "" "" ""
174 {pr17068a.s pr17068c.s pr17068ez.s} {} "pr17068a.a"}
175 {"Build pr17068b.a"
176 "" "" ""
177 {pr17068b.s pr17068e.s} {} "pr17068b.a"}
1b857aee 178 }
46b06a98 179
1b857aee 180 # bfin does not currently support copy relocs.
1b857aee 181 run_ld_link_tests {
d215621e 182 {"pr17068 link --as-needed lib in group"
1a9ccd70 183 "--as-needed --no-dynamic-linker" "--start-group tmpdir/pr17068a.a tmpdir/pr17068.so tmpdir/pr17068b.a --end-group" ""
d215621e 184 {start.s pr17068.s} {} "pr17068"}
46b06a98
AM
185 } "bfin-*-*"
186
a496fbc8 187 # xfail on tic6x due to non-PIC/non-PID warnings
46b06a98 188 # Fails on MIPS because ABI trickery means that a NULL reloc is emitted.
1b857aee 189 # Fails on bfin because relocations are not created.
a496fbc8
AM
190 run_ld_link_tests {
191 {"-Bsymbolic-functions"
192 "-shared -Bsymbolic-functions" "" ""
193 {symbolic-func.s} {{readelf {-r --wide} symbolic-func.r}}
194 "symbolic-func.so"}
46b06a98
AM
195 } "tic6x-*-*" "mips*-*-*" "bfin-*-*"
196
5474d94f 197 # xfail on tic6x due to non-PIC/non-PID warnings
5474d94f
AM
198 run_ld_link_tests {
199 {"Build pr20995.so"
200 "-shared" "" ""
201 {pr20995b.s} {} "pr20995.so"}
46b06a98
AM
202 } "tic6x-*-*"
203
4471a46f
JW
204 # xfail on arm*-*-eabi*. The list can be enlarged to those targets that
205 # don't support GNU_RELRO. For more details, please see discussions at:
206 # https://sourceware.org/ml/binutils/2017-01/msg00441.html
9acc85a6
AM
207 run_ld_link_tests {
208 {"Build pr20995-2.so"
209 "-shared -z relro" "" ""
210 {pr20995c.s} {{readelf {-l --wide} pr20995-2so.r}} "pr20995-2.so"}
46b06a98
AM
211 } "tic6x-*-*" "arm*-*-eabi*" "hppa*64*-*-hpux*"
212
5474d94f
AM
213 # These targets don't copy dynamic variables into .bss.
214 setup_xfail "alpha-*-*" "bfin-*-*" "ia64-*-*" "xtensa-*-*"
dd803a24
AM
215 # or don't have .data.rel.ro
216 setup_xfail "hppa*64*-*-hpux*"
6984613a
MR
217 run_ld_link_tests [list \
218 [list \
219 "pr20995" \
220 "" "tmpdir/pr20995.so" "$AFLAGS_NONPIC" \
221 {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995"]]
46b06a98 222
4471a46f
JW
223 # xfail on arm*-*-eabi* is particularly because of no support of GNU_RELRO.
224 # Please see the link above for details.
225 setup_xfail "alpha-*-*" "bfin-*-*" "ia64-*-*" "xtensa-*-*" "arm*-*-eabi*"
dd803a24 226 setup_xfail "hppa*64*-*-hpux*"
6984613a
MR
227 run_ld_link_tests [list \
228 [list \
229 "pr20995-2" \
230 "" "tmpdir/pr20995-2.so" "$AFLAGS_NONPIC" \
231 {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995-2"]]
e48f0c8f
AM
232
233 setup_xfail "tic6x-*-*"
234 run_ld_link_tests {
235 {"Build pr22374 shared library"
236 "-shared" "" "" "pr22374b.s" {} "pr22374.so" }
237 {"pr22374 function pointer initialization"
238 "" "tmpdir/pr22374.so" "" "pr22374a.s"
239 { {readelf {--wide -r --dyn-syms} "pr22374-1.r"}
240 {readelf {--wide -r} "pr22374-2.r"} }
241 "pr22374" }
242 }
894891db
NC
243}
244
bdd32e03
AM
245if [is_underscore_target] {
246 set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1"
247}
248
782c0ebf
AM
249set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
250foreach t $test_list {
251 # We need to strip the ".d", but can leave the dirname.
252 verbose [file rootname $t]
253 run_dump_test [file rootname $t]
254}
24edc24d 255
5df1bc57
AM
256# Targets using the generic linker backend don't support generating
257# an import library.
258set xfail_implib ""
b62b1f71 259if [is_generic_elf] {
5df1bc57
AM
260 set xfail_implib "*-*-*"
261}
262
76359541 263# Check that the --out-implib option work correctly.
dd803a24
AM
264run_ld_link_tests [list \
265 [list "Generate empty import library" \
266 "--out-implib=tmpdir/implib.lib" "" \
267 [concat "--defsym NO_GLOBAL=1" $hpux] \
268 {implib.s} \
269 {{ld empty-implib.out}} \
270 "implib" ] \
271 [list "Generate import library" \
272 "--out-implib=tmpdir/implib.lib" "" \
273 $hpux \
274 {implib.s} \
275 {{readelf {-s tmpdir/implib.lib} implib.rd}} \
276 "implib" ] \
277] $xfail_implib
76359541 278
5940a93c 279if { [istarget *-*-linux*]
5a68afcf 280 || [istarget *-*-nacl*]
5940a93c 281 || [istarget *-*-gnu*] } {
a26587ba
RS
282 run_ld_link_tests {
283 {"Weak symbols in dynamic objects 1 (support)"
897aea50 284 "-shared" "" "" {weak-dyn-1a.s}
a26587ba
RS
285 {}
286 "libweakdyn1a.so"}
287 {"Weak symbols in dynamic objects 1 (main test)"
897aea50 288 "-shared tmpdir/libweakdyn1a.so -Tweak-dyn-1.ld" "" "" {weak-dyn-1b.s}
a26587ba
RS
289 {{readelf {--relocs --wide} weak-dyn-1.rd}}
290 "libweakdyn1b.so"}
291 }
292}
293
78336cd6
AM
294#v850 gas complains about .tbss.var section attributes.
295if { [check_gc_sections_available] && ![istarget "v850-*-*"] } {
430a16a5
NC
296 run_ld_link_tests {
297 {"--gc-sections on tls variable"
897aea50 298 "--gc-section" "" "" {tls_gc.s} {} "tls_gc"}
430a16a5
NC
299 }
300}
301
6b00ac5a 302if { [istarget *-*-*linux*]
b3adb10f 303 || [istarget *-*-nacl*]
9cc420b6 304 || [istarget *-*-gnu*] } {
04c3a755 305 run_ld_link_tests {
897aea50 306 {"stack exec" "-z execstack" "" "" {stack.s}
04c3a755 307 {{readelf {-Wl} stack-exec.rd}} "stack-exec.exe"}
897aea50 308 {"stack size" "-z stack-size=0x123400" "" "" {stack.s}
04c3a755
NS
309 {{readelf {-Wl} stack-size.rd}} "stack-size.exe"}
310 }
311}
312
e4970690 313set LDFLAGS $old_ldflags
dd803a24 314set ASFLAGS $old_asflags
e4970690 315
4ce6ca2c
AM
316# Check to see if the C compiler works
317if { [which $CC] == 0 } {
318 return
319}
320
a130722b
L
321if [check_gc_sections_available] {
322 run_cc_link_tests {
323 {"PR ld/13195" "-Wl,--gc-sections" ""
324 {pr13195.c} {} "pr13195"}
325 }
54e8959c
L
326}
327
24edc24d 328set array_tests {
d9816402
AM
329 {"preinit array" "" ""
330 {preinit.c} "preinit" "preinit.out"}
331 {"init array" "" ""
332 {init.c} "init" "init.out"}
333 {"fini array" "" ""
334 {fini.c} "fini" "fini.out"}
335 {"init array mixed" "" ""
336 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
310fd250
L
337}
338set array_tests_pie {
d9816402
AM
339 {"PIE preinit array" "-pie" ""
340 {preinit.c} "preinit" "preinit.out" "-fPIE"}
341 {"PIE init array" "-pie" ""
342 {init.c} "init" "init.out" "-fPIE"}
343 {"PIE fini array" "-pie" ""
344 {fini.c} "fini" "fini.out" "-fPIE"}
345 {"PIE init array mixed" "-pie" ""
346 {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"}
347 {"PIE PR ld/14525" "-pie" ""
348 {pr14525.c} "pr14525" "pr14525.out" "-fPIE"}
5940a93c
TS
349}
350set array_tests_static {
d9816402
AM
351 {"static preinit array" "-static" ""
352 {preinit.c} "preinit" "preinit.out"}
353 {"static init array" "-static" ""
354 {init.c} "init" "init.out"}
355 {"static fini array" "-static" ""
356 {fini.c} "fini" "fini.out"}
357 {"static init array mixed" "-static" ""
358 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
24edc24d
L
359}
360
c8c140d9 361# NetBSD ELF systems do not currently support the .*_array sections.
982c6f26
AM
362set xfails "*-*-netbsdelf*"
363run_ld_link_exec_tests $array_tests $xfails
310fd250 364
3fee20ef 365if { [istarget *-*-linux*]
5a68afcf 366 || [istarget *-*-nacl*]
3fee20ef 367 || [istarget *-*-gnu*] } {
982c6f26 368 run_ld_link_exec_tests $array_tests_pie $xfails
a91e1603
L
369
370 run_ld_link_exec_tests [list \
371 [list \
372 "Run mbind2a" \
373 "$NOPIE_LDFLAGS -Wl,-z,common-page-size=0x4000" \
374 "" \
375 { mbind2a.s mbind2b.c } \
376 "mbind2a" \
377 "pass.out" \
378 "-O2 -I../bfd" \
379 ] \
380 [list \
381 "Run mbind2b" \
382 "-static -Wl,-z,common-page-size=0x4000" \
383 "" \
384 { mbind2a.s mbind2b.c } \
385 "mbind2b" \
386 "pass.out" \
387 "-O2 -I../bfd" \
388 ] \
389 ]
310fd250
L
390}
391
982c6f26 392# <http://www.gnu.org/software/hurd/open_issues/binutils.html#static>
5940a93c
TS
393# Be cautious to not XFAIL for *-*-linux-gnu*, *-*-kfreebsd-gnu*, etc.
394switch -regexp $target_triplet {
395 ^\[^-\]*-\[^-\]*-gnu.*$ {
982c6f26 396 set xfails "*-*-*"
5940a93c
TS
397 }
398}
982c6f26 399run_ld_link_exec_tests $array_tests_static $xfails
9ab80182 400
02ecc8e9 401catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status
This page took 0.741126 seconds and 4 git commands to generate.