]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/testsuite/ld-elf/elf.exp
Tidy elf.exp
[thirdparty/binutils-gdb.git] / ld / testsuite / ld-elf / elf.exp
1 # Expect script for various ELF tests.
2 # Copyright (C) 2002-2017 Free Software Foundation, Inc.
3 #
4 # This file is part of the GNU Binutils.
5 #
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.
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
18 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20 #
21
22 # Exclude non-ELF targets.
23
24 if ![is_elf_format] {
25 return
26 }
27
28 set old_ldflags $LDFLAGS
29 if { [istarget spu*-*-*] } {
30 set LDFLAGS "$LDFLAGS --local-store 0:0"
31 }
32
33 # hpux .comm differs from everyone else
34 set hpux ""
35 set old_asflags $ASFLAGS
36 if [istarget "*-*-hpux*"] {
37 set hpux "--defsym HPUX=1"
38 set ASFLAGS "$ASFLAGS --defsym HPUX=1"
39 }
40
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"
46 }
47
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}
53 }
54
55 if { [istarget "*-*-solaris*"] } {
56 # Same for Solaris
57 set options_regsub(ld) {-melf_x86_64 -melf_x86_64_sol2}
58 }
59
60 if { [is_remote host] } then {
61 remote_download host merge.ld
62 }
63
64 run_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
73 # Targets that use _bfd_generic_link_add_symbols won't pass pr21703 tests
74 run_ld_link_tests {
75 {"PR ld/21703"
76 "--allow-multiple-definition tmpdir/pr21703-1.o tmpdir/pr21703-2.o" "" "" \
77 {pr21703-1.s pr21703-2.s} {{readelf {-s} pr21703.sd}} "pr21703" }
78 {"PR ld/21703 -r"
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-*-*"
82
83 # Only run these tests on targets that support creating shared libraries.
84 if { [check_shared_lib_support] } then {
85 run_ld_link_tests {
86 {"Build pr14170a.o" "" "" "" {pr14170a.s} {} "pr14170.a" }
87 }
88 run_ld_link_tests {
89 {"Build shared library for pr14170"
90 "-shared" "" "" "pr14170b.s" {} "pr14170.so" }
91 } "tic6x-*-*"
92
93 # bfin does not currently support copy relocs.
94 run_ld_link_tests [list \
95 [list "PR ld/14170" \
96 "--no-dynamic-linker tmpdir/pr14170a.o tmpdir/pr14170.so" "" $hpux \
97 {pr14170c.s} { } "pr14170" ] \
98 ] "bfin-*-*"
99
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
102 run_ld_link_tests {
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-*-*"
107
108 # This target requires extra GAS options when building non-PIC code
109 # for linking with shared libraries.
110 set AFLAGS_NONPIC ""
111 if [istarget "mips*-*-*"] {
112 append AFLAGS_NONPIC " -call_nonpic"
113 }
114
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-*-*"
121 run_ld_link_tests {
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" } }
127 "a.out" }
128 }
129
130 setup_xfail "tic6x-*-*"
131 run_ld_link_tests {
132 {"Build pr17068.so"
133 "-shared" "" ""
134 {pr17068d.s} {} "pr17068.so"}
135 {"Build pr17068a.a"
136 "" "" ""
137 {pr17068a.s pr17068c.s pr17068ez.s} {} "pr17068a.a"}
138 {"Build pr17068b.a"
139 "" "" ""
140 {pr17068b.s pr17068e.s} {} "pr17068b.a"}
141 }
142
143 # bfin does not currently support copy relocs.
144 run_ld_link_tests {
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"}
148 } "bfin-*-*"
149
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.
153 run_ld_link_tests {
154 {"-Bsymbolic-functions"
155 "-shared -Bsymbolic-functions" "" ""
156 {symbolic-func.s} {{readelf {-r --wide} symbolic-func.r}}
157 "symbolic-func.so"}
158 } "tic6x-*-*" "mips*-*-*" "bfin-*-*"
159
160 # xfail on tic6x due to non-PIC/non-PID warnings
161 run_ld_link_tests {
162 {"Build pr20995.so"
163 "-shared" "" ""
164 {pr20995b.s} {} "pr20995.so"}
165 } "tic6x-*-*"
166
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
170 run_ld_link_tests {
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*"
175
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 \
181 [list \
182 "pr20995" \
183 "" "tmpdir/pr20995.so" "$AFLAGS_NONPIC" \
184 {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995"]]
185
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 \
191 [list \
192 "pr20995-2" \
193 "" "tmpdir/pr20995-2.so" "$AFLAGS_NONPIC" \
194 {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995-2"]]
195 }
196
197 if [is_underscore_target] {
198 set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1"
199 }
200
201 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
202 foreach t $test_list {
203 # We need to strip the ".d", but can leave the dirname.
204 verbose [file rootname $t]
205 run_dump_test [file rootname $t]
206 }
207
208 # Targets using the generic linker backend don't support generating
209 # an import library.
210 set xfail_implib ""
211 if [is_generic_elf] {
212 set xfail_implib "*-*-*"
213 }
214
215 # Check that the --out-implib option work correctly.
216 run_ld_link_tests [list \
217 [list "Generate empty import library" \
218 "--out-implib=tmpdir/implib.lib" "" \
219 [concat "--defsym NO_GLOBAL=1" $hpux] \
220 {implib.s} \
221 {{ld empty-implib.out}} \
222 "implib" ] \
223 [list "Generate import library" \
224 "--out-implib=tmpdir/implib.lib" "" \
225 $hpux \
226 {implib.s} \
227 {{readelf {-s tmpdir/implib.lib} implib.rd}} \
228 "implib" ] \
229 ] $xfail_implib
230
231 if { [istarget *-*-linux*]
232 || [istarget *-*-nacl*]
233 || [istarget *-*-gnu*] } {
234 run_ld_link_tests {
235 {"Weak symbols in dynamic objects 1 (support)"
236 "-shared" "" "" {weak-dyn-1a.s}
237 {}
238 "libweakdyn1a.so"}
239 {"Weak symbols in dynamic objects 1 (main test)"
240 "-shared tmpdir/libweakdyn1a.so -Tweak-dyn-1.ld" "" "" {weak-dyn-1b.s}
241 {{readelf {--relocs --wide} weak-dyn-1.rd}}
242 "libweakdyn1b.so"}
243 }
244 }
245
246 #v850 gas complains about .tbss.var section attributes.
247 if { [check_gc_sections_available] && ![istarget "v850-*-*"] } {
248 run_ld_link_tests {
249 {"--gc-sections on tls variable"
250 "--gc-section" "" "" {tls_gc.s} {} "tls_gc"}
251 }
252 }
253
254 if { [istarget *-*-*linux*]
255 || [istarget *-*-nacl*]
256 || [istarget *-*-gnu*] } {
257 run_ld_link_tests {
258 {"stack exec" "-z execstack" "" "" {stack.s}
259 {{readelf {-Wl} stack-exec.rd}} "stack-exec.exe"}
260 {"stack size" "-z stack-size=0x123400" "" "" {stack.s}
261 {{readelf {-Wl} stack-size.rd}} "stack-size.exe"}
262 }
263 }
264
265 set LDFLAGS $old_ldflags
266 set ASFLAGS $old_asflags
267
268 # Check to see if the C compiler works
269 if { [which $CC] == 0 } {
270 return
271 }
272
273 if [check_gc_sections_available] {
274 run_cc_link_tests {
275 {"PR ld/13195" "-Wl,--gc-sections" ""
276 {pr13195.c} {} "pr13195"}
277 }
278 }
279
280 set array_tests {
281 {"preinit array" "" ""
282 {preinit.c} "preinit" "preinit.out"}
283 {"init array" "" ""
284 {init.c} "init" "init.out"}
285 {"fini array" "" ""
286 {fini.c} "fini" "fini.out"}
287 {"init array mixed" "" ""
288 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
289 }
290 set array_tests_pie {
291 {"PIE preinit array" "-pie" ""
292 {preinit.c} "preinit" "preinit.out" "-fPIE"}
293 {"PIE init array" "-pie" ""
294 {init.c} "init" "init.out" "-fPIE"}
295 {"PIE fini array" "-pie" ""
296 {fini.c} "fini" "fini.out" "-fPIE"}
297 {"PIE init array mixed" "-pie" ""
298 {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"}
299 {"PIE PR ld/14525" "-pie" ""
300 {pr14525.c} "pr14525" "pr14525.out" "-fPIE"}
301 }
302 set array_tests_static {
303 {"static preinit array" "-static" ""
304 {preinit.c} "preinit" "preinit.out"}
305 {"static init array" "-static" ""
306 {init.c} "init" "init.out"}
307 {"static fini array" "-static" ""
308 {fini.c} "fini" "fini.out"}
309 {"static init array mixed" "-static" ""
310 {init-mixed.c} "init-mixed" "init-mixed.out" "-I."}
311 }
312
313 # NetBSD ELF systems do not currently support the .*_array sections.
314 set xfails "*-*-netbsdelf*"
315 run_ld_link_exec_tests $array_tests $xfails
316
317 if { [istarget *-*-linux*]
318 || [istarget *-*-nacl*]
319 || [istarget *-*-gnu*] } {
320 run_ld_link_exec_tests $array_tests_pie $xfails
321
322 run_ld_link_exec_tests [list \
323 [list \
324 "Run mbind2a" \
325 "$NOPIE_LDFLAGS -Wl,-z,common-page-size=0x4000" \
326 "" \
327 { mbind2a.s mbind2b.c } \
328 "mbind2a" \
329 "pass.out" \
330 "-O2 -I../bfd" \
331 ] \
332 [list \
333 "Run mbind2b" \
334 "-static -Wl,-z,common-page-size=0x4000" \
335 "" \
336 { mbind2a.s mbind2b.c } \
337 "mbind2b" \
338 "pass.out" \
339 "-O2 -I../bfd" \
340 ] \
341 ]
342 }
343
344 # <http://www.gnu.org/software/hurd/open_issues/binutils.html#static>
345 # Be cautious to not XFAIL for *-*-linux-gnu*, *-*-kfreebsd-gnu*, etc.
346 switch -regexp $target_triplet {
347 ^\[^-\]*-\[^-\]*-gnu.*$ {
348 set xfails "*-*-*"
349 }
350 }
351 run_ld_link_exec_tests $array_tests_static $xfails
352
353 catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status