1 # Expect script for various ELF tests.
2 # Copyright (C) 2002-2015 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"
32 if { [istarget alpha*-*-* ] } {
33 # The compress1 test is written expecting 32-bit addresses; force the
34 # executable down into the low address space to match.
35 # ??? How can we adjust just the one testcase?
36 set LDFLAGS "$LDFLAGS -Ttext-segment 0x1000000"
39 if { [istarget "*-*-nacl*"] } {
40 # The eh[1-4] cases are written to expect ELFCLASS64 layout on x86-64.
41 # But the target default is ELFCLASS32. So the cases explicitly use
42 # -melf_x86_64 to select that, but NaCl needs a different emulation name.
43 set options_regsub(ld) {-melf_x86_64 -melf_x86_64_nacl}
46 if { [istarget "*-*-solaris*"] } {
48 set options_regsub(ld) {-melf_x86_64 -melf_x86_64_sol2}
51 if { [is_remote host] } then {
52 remote_download host merge.ld
55 if { ![istarget hppa64*-hpux*] } {
59 {symbol3.s} {} "symbol3.a"}
62 {symbol3w.s} {} "symbol3w.a"}
65 if { [check_shared_lib_support] } then {
67 {"Build pr14170a.o" "" "" "" "pr14170a.s" {} "pr14170.a" }
69 setup_xfail "tic6x-*-*"
71 {"Build shared library for pr14170"
72 "-shared" "" "" "pr14170b.s" {} "pr14170.so" }
74 "tmpdir/pr14170a.o tmpdir/pr14170.so" "" "" "pr14170c.s"
80 # Only run these tests on targets thats support creating shared libraries.
81 if { [check_shared_lib_support] } then {
82 # Run a test to check linking a shared library with a broken linker
83 # script that accidentally marks dynamic sections as notes. The
84 # resulting executable is not expected to work, but the linker
85 # should not seg-fault whilst creating the binary.
86 setup_xfail "tic6x-*-*"
88 {"Build shared library for next test"
89 "-shared" "" "" "note-3.s" {} "note-3.so" }
90 {"Link using broken linker script"
91 "--script note-3.t tmpdir/note-3.so" "" "" ""
95 setup_xfail "tic6x-*-*"
99 {pr17068d.s} {} "pr17068.so"}
102 {pr17068a.s pr17068c.s pr17068ez.s} {} "pr17068a.a"}
105 {pr17068b.s pr17068e.s} {} "pr17068b.a"}
106 {"pr17068 link --as-needed lib in group"
107 "--as-needed" "--start-group tmpdir/pr17068a.a tmpdir/pr17068.so tmpdir/pr17068b.a --end-group" ""
108 {start.s pr17068.s} {} "pr17068"}
112 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
113 foreach t $test_list {
114 # We need to strip the ".d", but can leave the dirname.
115 verbose [file rootname $t]
116 run_dump_test [file rootname $t]
119 # Check that the --warn-orphan option works correctly.
121 {"Report orphan sections"
122 "--script orphan.ld --warn-orphan"
126 { { ld "orphan-5.l" } }
131 if { [istarget *-*-linux*]
132 || [istarget *-*-nacl*]
133 || [istarget *-*-gnu*] } {
135 {"Weak symbols in dynamic objects 1 (support)"
136 "-shared" "" "" {weak-dyn-1a.s}
139 {"Weak symbols in dynamic objects 1 (main test)"
140 "-shared tmpdir/libweakdyn1a.so -Tweak-dyn-1.ld" "" "" {weak-dyn-1b.s}
141 {{readelf {--relocs --wide} weak-dyn-1.rd}}
146 #v850 gas complains about .tbss.var section attributes.
147 if { [check_gc_sections_available] && ![istarget "v850-*-*"] } {
149 {"--gc-sections on tls variable"
150 "--gc-section" "" "" {tls_gc.s} {} "tls_gc"}
154 if { [istarget *-*-*linux*]
155 || [istarget *-*-nacl*]
156 || [istarget *-*-gnu*] } {
158 {"stack exec" "-z execstack" "" "" {stack.s}
159 {{readelf {-Wl} stack-exec.rd}} "stack-exec.exe"}
160 {"stack size" "-z stack-size=0x123400" "" "" {stack.s}
161 {{readelf {-Wl} stack-size.rd}} "stack-size.exe"}
165 set LDFLAGS $old_ldflags
167 # The following tests require running the executable generated by ld.
172 if [check_gc_sections_available] {
174 {"PR ld/13195" "-Wl,--gc-sections" ""
175 {pr13195.c} {} "pr13195"}
180 {"preinit array" "" "" {preinit.c} "preinit" "preinit.out"}
181 {"init array" "" "" {init.c} "init" "init.out"}
182 {"fini array" "" "" {fini.c} "fini" "fini.out"}
183 {"init array mixed" "" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
185 set array_tests_pie {
186 {"PIE preinit array" "-pie" "" {preinit.c} "preinit" "preinit.out" "-fPIE" }
187 {"PIE init array" "-pie" "" {init.c} "init" "init.out" "-fPIE"}
188 {"PIE fini array" "-pie" "" {fini.c} "fini" "fini.out" "-fPIE"}
189 {"PIE init array mixed" "-pie" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"}
190 {"PIE PR ld/14525" "-pie" "" {pr14525.c} "pr14525" "pr14525.out" "-fPIE"}
192 set array_tests_static {
193 {"static preinit array" "-static" "" {preinit.c} "preinit" "preinit.out"}
194 {"static init array" "-static" "" {init.c} "init" "init.out"}
195 {"static fini array" "-static" "" {fini.c} "fini" "fini.out"}
196 {"static init array mixed" "-static" "" {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
199 # NetBSD ELF systems do not currently support the .*_array sections.
200 set xfails [list "*-*-netbsdelf*"]
201 run_ld_link_exec_tests $xfails $array_tests
203 if { [istarget *-*-linux*]
204 || [istarget *-*-nacl*]
205 || [istarget *-*-gnu*] } {
206 run_ld_link_exec_tests $xfails $array_tests_pie
209 # Be cautious to not XFAIL for *-*-linux-gnu*, *-*-kfreebsd-gnu*, etc.
210 switch -regexp $target_triplet {
211 ^\[^-\]*-\[^-\]*-gnu.*$ {
212 # <http://www.gnu.org/software/hurd/open_issues/binutils.html#static>
213 lappend xfails "*-*-*"
216 run_ld_link_exec_tests $xfails $array_tests_static
218 catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status