1 # Expect script for various ELF tests.
2 # Copyright (C) 2002-2017 Free Software Foundation, Inc.
4 # This file is part of the GNU Binutils.
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.
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.
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,
22 # Exclude non-ELF targets.
28 set old_ldflags $LDFLAGS
29 if { [istarget spu*-*-*] } {
30 set LDFLAGS "$LDFLAGS --local-store 0:0"
33 # hpux .comm differs from everyone else
35 set old_asflags $ASFLAGS
36 if [istarget "*-*-hpux*"] {
37 set hpux "--defsym HPUX=1"
38 set ASFLAGS "$ASFLAGS --defsym HPUX=1"
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"
48 if { [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}
55 if { [istarget "*-*-solaris*"] } {
57 set options_regsub(ld) {-melf_x86_64 -melf_x86_64_sol2}
60 if { [is_remote host] } then {
61 remote_download host merge.ld
64 run_ld_link_tests [list \
65 [list "Build symbol3.a" \
67 {symbol3.s} {} "symbol3.a" ] \
68 [list "Build symbol3w.a" \
70 {symbol3w.s} {} "symbol3w.a" ] \
73 # Targets that use _bfd_generic_link_add_symbols won't pass pr21703 tests
76 "--allow-multiple-definition tmpdir/pr21703-1.o tmpdir/pr21703-2.o" "" "" \
77 {pr21703-1.s pr21703-2.s} {{readelf {-s} pr21703.sd}} "pr21703" }
79 "-r --allow-multiple-definition tmpdir/pr21703-3.o tmpdir/pr21703-4.o" "" "" \
80 {pr21703-3.s pr21703-4.s} {{readelf {-s} pr21703-r.sd}} "pr21703.o" }
81 } "d30v-*-*" "dlx-*-*" "pj-*-*"
83 # Only run these tests on targets that support creating shared libraries.
84 if { [check_shared_lib_support] } then {
86 {"Build pr14170a.o" "" "" "" {pr14170a.s} {} "pr14170.a" }
89 {"Build shared library for pr14170"
90 "-shared" "" "" "pr14170b.s" {} "pr14170.so" }
93 # bfin does not currently support copy relocs.
94 run_ld_link_tests [list \
96 "--no-dynamic-linker tmpdir/pr14170a.o tmpdir/pr14170.so" "" $hpux \
97 {pr14170c.s} { } "pr14170" ] \
100 # Targets that use _bfd_generic_link_add_symbols won't pass pr21703 tests
101 # Not will tic6x with PIC/PID warning, or hppa64 with dot-symbols
103 {"PR ld/21703 shared"
104 "-shared --allow-multiple-definition --version-script pr21703.ver tmpdir/pr21703-3.o tmpdir/pr21703-4.o" "" "" \
105 {pr21703-3.s pr21703-4.s} {{readelf {--dyn-syms} pr21703-shared.sd}} "pr21703.so" }
106 } "d30v-*-*" "dlx-*-*" "pj-*-*" "tic6x-*-*" "hppa64-*-*"
108 # This target requires extra GAS options when building non-PIC code
109 # for linking with shared libraries.
111 if [istarget "mips*-*-*"] {
112 append AFLAGS_NONPIC " -call_nonpic"
115 # Run a test to check linking a shared library with a broken linker
116 # script that accidentally marks dynamic sections as notes. The
117 # resulting executable is not expected to work, but the linker
118 # should not seg-fault whilst creating the binary.
119 # Note: setup_xfail before run_ld_link_tests xfails only the first test.
120 setup_xfail "tic6x-*-*"
122 {"Build shared library for broken linker scrip test"
123 "-shared --hash-style=sysv" "" "" "note-3.s" {} "note-3.so" }
124 {"Link using broken linker script"
125 "--script note-3.t tmpdir/note-3.so" "" "" ""
126 { { ld "note-3.l" } }
130 setup_xfail "tic6x-*-*"
134 {pr17068d.s} {} "pr17068.so"}
137 {pr17068a.s pr17068c.s pr17068ez.s} {} "pr17068a.a"}
140 {pr17068b.s pr17068e.s} {} "pr17068b.a"}
143 # bfin does not currently support copy relocs.
145 {"pr17068 link --as-needed lib in group"
146 "--as-needed --no-dynamic-linker" "--start-group tmpdir/pr17068a.a tmpdir/pr17068.so tmpdir/pr17068b.a --end-group" ""
147 {start.s pr17068.s} {} "pr17068"}
150 # xfail on tic6x due to non-PIC/non-PID warnings
151 # Fails on MIPS because ABI trickery means that a NULL reloc is emitted.
152 # Fails on bfin because relocations are not created.
154 {"-Bsymbolic-functions"
155 "-shared -Bsymbolic-functions" "" ""
156 {symbolic-func.s} {{readelf {-r --wide} symbolic-func.r}}
158 } "tic6x-*-*" "mips*-*-*" "bfin-*-*"
160 # xfail on tic6x due to non-PIC/non-PID warnings
164 {pr20995b.s} {} "pr20995.so"}
167 # xfail on arm*-*-eabi*. The list can be enlarged to those targets that
168 # don't support GNU_RELRO. For more details, please see discussions at:
169 # https://sourceware.org/ml/binutils/2017-01/msg00441.html
171 {"Build pr20995-2.so"
172 "-shared -z relro" "" ""
173 {pr20995c.s} {{readelf {-l --wide} pr20995-2so.r}} "pr20995-2.so"}
174 } "tic6x-*-*" "arm*-*-eabi*" "hppa*64*-*-hpux*"
176 # These targets don't copy dynamic variables into .bss.
177 setup_xfail "alpha-*-*" "bfin-*-*" "ia64-*-*" "xtensa-*-*"
178 # or don't have .data.rel.ro
179 setup_xfail "hppa*64*-*-hpux*"
180 run_ld_link_tests [list \
183 "" "tmpdir/pr20995.so" "$AFLAGS_NONPIC" \
184 {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995"]]
186 # xfail on arm*-*-eabi* is particularly because of no support of GNU_RELRO.
187 # Please see the link above for details.
188 setup_xfail "alpha-*-*" "bfin-*-*" "ia64-*-*" "xtensa-*-*" "arm*-*-eabi*"
189 setup_xfail "hppa*64*-*-hpux*"
190 run_ld_link_tests [list \
193 "" "tmpdir/pr20995-2.so" "$AFLAGS_NONPIC" \
194 {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995-2"]]
196 setup_xfail "tic6x-*-*"
198 {"Build pr22374 shared library"
199 "-shared" "" "" "pr22374b.s" {} "pr22374.so" }
200 {"pr22374 function pointer initialization"
201 "" "tmpdir/pr22374.so" "" "pr22374a.s"
202 { {readelf {--wide -r --dyn-syms} "pr22374-1.r"}
203 {readelf {--wide -r} "pr22374-2.r"} }
208 if [is_underscore_target] {
209 set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1"
212 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
213 foreach t $test_list {
214 # We need to strip the ".d", but can leave the dirname.
215 verbose [file rootname $t]
216 run_dump_test [file rootname $t]
219 # Targets using the generic linker backend don't support generating
222 if [is_generic_elf] {
223 set xfail_implib "*-*-*"
226 # Check that the --out-implib option work correctly.
227 run_ld_link_tests [list \
228 [list "Generate empty import library" \
229 "--out-implib=tmpdir/implib.lib" "" \
230 [concat "--defsym NO_GLOBAL=1" $hpux] \
232 {{ld empty-implib.out}} \
234 [list "Generate import library" \
235 "--out-implib=tmpdir/implib.lib" "" \
238 {{readelf {-s tmpdir/implib.lib} implib.rd}} \
242 if { [istarget *-*-linux*]
243 || [istarget *-*-nacl*]
244 || [istarget *-*-gnu*] } {
246 {"Weak symbols in dynamic objects 1 (support)"
247 "-shared" "" "" {weak-dyn-1a.s}
250 {"Weak symbols in dynamic objects 1 (main test)"
251 "-shared tmpdir/libweakdyn1a.so -Tweak-dyn-1.ld" "" "" {weak-dyn-1b.s}
252 {{readelf {--relocs --wide} weak-dyn-1.rd}}
257 #v850 gas complains about .tbss.var section attributes.
258 if { [check_gc_sections_available] && ![istarget "v850-*-*"] } {
260 {"--gc-sections on tls variable"
261 "--gc-section" "" "" {tls_gc.s} {} "tls_gc"}
265 if { [istarget *-*-*linux*]
266 || [istarget *-*-nacl*]
267 || [istarget *-*-gnu*] } {
269 {"stack exec" "-z execstack" "" "" {stack.s}
270 {{readelf {-Wl} stack-exec.rd}} "stack-exec.exe"}
271 {"stack size" "-z stack-size=0x123400" "" "" {stack.s}
272 {{readelf {-Wl} stack-size.rd}} "stack-size.exe"}
276 set LDFLAGS $old_ldflags
277 set ASFLAGS $old_asflags
279 # Check to see if the C compiler works
280 if { [which $CC] == 0 } {
284 if [check_gc_sections_available] {
286 {"PR ld/13195" "-Wl,--gc-sections" ""
287 {pr13195.c} {} "pr13195"}
292 {"preinit array" "" ""
293 {preinit.c} "preinit" "preinit.out"}
295 {init.c} "init" "init.out"}
297 {fini.c} "fini" "fini.out"}
298 {"init array mixed" "" ""
299 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
301 set array_tests_pie {
302 {"PIE preinit array" "-pie" ""
303 {preinit.c} "preinit" "preinit.out" "-fPIE"}
304 {"PIE init array" "-pie" ""
305 {init.c} "init" "init.out" "-fPIE"}
306 {"PIE fini array" "-pie" ""
307 {fini.c} "fini" "fini.out" "-fPIE"}
308 {"PIE init array mixed" "-pie" ""
309 {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"}
310 {"PIE PR ld/14525" "-pie" ""
311 {pr14525.c} "pr14525" "pr14525.out" "-fPIE"}
313 set array_tests_static {
314 {"static preinit array" "-static" ""
315 {preinit.c} "preinit" "preinit.out"}
316 {"static init array" "-static" ""
317 {init.c} "init" "init.out"}
318 {"static fini array" "-static" ""
319 {fini.c} "fini" "fini.out"}
320 {"static init array mixed" "-static" ""
321 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
324 # NetBSD ELF systems do not currently support the .*_array sections.
325 set xfails "*-*-netbsdelf*"
326 run_ld_link_exec_tests $array_tests $xfails
328 if { [istarget *-*-linux*]
329 || [istarget *-*-nacl*]
330 || [istarget *-*-gnu*] } {
331 run_ld_link_exec_tests $array_tests_pie $xfails
333 run_ld_link_exec_tests [list \
336 "$NOPIE_LDFLAGS -Wl,-z,common-page-size=0x4000" \
338 { mbind2a.s mbind2b.c } \
345 "-static -Wl,-z,common-page-size=0x4000" \
347 { mbind2a.s mbind2b.c } \
355 # <http://www.gnu.org/software/hurd/open_issues/binutils.html#static>
356 # Be cautious to not XFAIL for *-*-linux-gnu*, *-*-kfreebsd-gnu*, etc.
357 switch -regexp $target_triplet {
358 ^\[^-\]*-\[^-\]*-gnu.*$ {
362 run_ld_link_exec_tests $array_tests_static $xfails
364 catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status