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