]>
Commit | Line | Data |
---|---|---|
782c0ebf | 1 | # Expect script for various ELF tests. |
250d07de | 2 | # Copyright (C) 2002-2021 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" | |
54975ae9 | 46 | set ASFLAGS "$ASFLAGS --defsym NO_SET=1" |
991cda6c | 47 | } |
9f264ea9 | 48 | |
56af5a30 AM |
49 | if [istarget "tic6x-*-*"] { |
50 | append ASFLAGS " -mpic -mpid=near" | |
51 | } | |
52 | ||
5cc51864 L |
53 | if { [istarget "*-*-solaris*"] } { |
54 | # Same for Solaris | |
55 | set options_regsub(ld) {-melf_x86_64 -melf_x86_64_sol2} | |
56 | } | |
57 | ||
7f6a71ff JM |
58 | if { [is_remote host] } then { |
59 | remote_download host merge.ld | |
60 | } | |
61 | ||
b77db948 NC |
62 | # Note - the output file from the second test (symbol3w.a) is |
63 | # used in the proc is_elf64 test below... | |
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 | ||
b77db948 | 73 | |
b77db948 NC |
74 | if [is_elf64 tmpdir/symbol3w.a] { |
75 | set ASFLAGS "$ASFLAGS --defsym ALIGN=3" | |
0a59decb | 76 | set pr23900_1_exp "pr23900-1-64.rd" |
b7d07216 L |
77 | set pr25490_2_exp "pr25490-2-64.rd" |
78 | set pr25490_3_exp "pr25490-3-64.rd" | |
79 | set pr25490_4_exp "pr25490-4-64.rd" | |
80 | set pr25490_5_exp "pr25490-5-64.rd" | |
81 | set pr25490_6_exp "pr25490-6-64.rd" | |
b77db948 NC |
82 | } else { |
83 | set ASFLAGS "$ASFLAGS --defsym ALIGN=2" | |
0a59decb | 84 | set pr23900_1_exp "pr23900-1-32.rd" |
b7d07216 L |
85 | if { [istarget avr-*-*] |
86 | || [istarget h8300-*-*] | |
87 | || [istarget ip2k-*-*] | |
88 | || [istarget m68hc11-*] | |
89 | || [istarget "xc16x-*"] | |
90 | || [istarget "z80-*-*"] } { | |
91 | set pr25490_2_exp "pr25490-2-16.rd" | |
92 | set pr25490_3_exp "pr25490-3-16.rd" | |
93 | set pr25490_4_exp "pr25490-4-16.rd" | |
94 | set pr25490_5_exp "pr25490-5-16.rd" | |
95 | set pr25490_6_exp "pr25490-6-16.rd" | |
96 | } else { | |
97 | set pr25490_2_exp "pr25490-2-32.rd" | |
98 | set pr25490_3_exp "pr25490-3-32.rd" | |
99 | set pr25490_4_exp "pr25490-4-32.rd" | |
100 | set pr25490_5_exp "pr25490-5-32.rd" | |
101 | set pr25490_6_exp "pr25490-6-32.rd" | |
102 | } | |
b77db948 NC |
103 | } |
104 | ||
105 | ||
106 | ||
46b06a98 | 107 | # Targets that use _bfd_generic_link_add_symbols won't pass pr21703 tests |
506981af RL |
108 | run_ld_link_tests { |
109 | {"PR ld/21703" | |
93f4de39 | 110 | "--allow-multiple-definition tmpdir/pr21703-1.o tmpdir/pr21703-2.o" "" "" \ |
506981af | 111 | {pr21703-1.s pr21703-2.s} {{readelf {-s} pr21703.sd}} "pr21703" } |
506981af | 112 | {"PR ld/21703 -r" |
93f4de39 | 113 | "-r --allow-multiple-definition tmpdir/pr21703-3.o tmpdir/pr21703-4.o" "" "" \ |
506981af | 114 | {pr21703-3.s pr21703-4.s} {{readelf {-s} pr21703-r.sd}} "pr21703.o" } |
1336939d | 115 | } \[is_generic\] |
93f4de39 | 116 | |
bdd32e03 AM |
117 | if [is_underscore_target] { |
118 | set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1" | |
119 | } | |
120 | ||
e9d644e8 L |
121 | set saved_ASFLAGS "$ASFLAGS" |
122 | if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } { | |
123 | set ASFLAGS "$ASFLAGS -mx86-used-note=no" | |
124 | } | |
125 | ||
99fabbc9 JL |
126 | # Build libraries required for SHF_GNU_RETAIN tests. |
127 | if { [check_gc_sections_available] && [supports_gnu_osabi] } { | |
128 | run_ld_link_tests [list \ | |
129 | [list "Build libretain5.a" "" "" "" \ | |
130 | {retain5lib.s} {} "libretain5.a"] \ | |
131 | [list "Build libretain6.a" "" "" "" \ | |
132 | {retain6lib.s} {} "libretain6.a"] \ | |
133 | ] | |
134 | } | |
135 | ||
782c0ebf AM |
136 | set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]] |
137 | foreach t $test_list { | |
138 | # We need to strip the ".d", but can leave the dirname. | |
139 | verbose [file rootname $t] | |
140 | run_dump_test [file rootname $t] | |
141 | } | |
24edc24d | 142 | |
e9d644e8 L |
143 | set ASFLAGS "$saved_ASFLAGS" |
144 | ||
76359541 | 145 | # Check that the --out-implib option work correctly. |
075a2b89 | 146 | # Targets that don't use elf.em won't support this. |
dd803a24 AM |
147 | run_ld_link_tests [list \ |
148 | [list "Generate empty import library" \ | |
149 | "--out-implib=tmpdir/implib.lib" "" \ | |
150 | [concat "--defsym NO_GLOBAL=1" $hpux] \ | |
151 | {implib.s} \ | |
152 | {{ld empty-implib.out}} \ | |
153 | "implib" ] \ | |
154 | [list "Generate import library" \ | |
155 | "--out-implib=tmpdir/implib.lib" "" \ | |
156 | $hpux \ | |
157 | {implib.s} \ | |
158 | {{readelf {-s tmpdir/implib.lib} implib.rd}} \ | |
159 | "implib" ] \ | |
1336939d | 160 | ] \[uses_genelf\] |
76359541 | 161 | |
78336cd6 AM |
162 | #v850 gas complains about .tbss.var section attributes. |
163 | if { [check_gc_sections_available] && ![istarget "v850-*-*"] } { | |
430a16a5 NC |
164 | run_ld_link_tests { |
165 | {"--gc-sections on tls variable" | |
897aea50 | 166 | "--gc-section" "" "" {tls_gc.s} {} "tls_gc"} |
430a16a5 NC |
167 | } |
168 | } | |
169 | ||
6b00ac5a | 170 | if { [istarget *-*-*linux*] |
b3adb10f | 171 | || [istarget *-*-nacl*] |
9cc420b6 | 172 | || [istarget *-*-gnu*] } { |
0a59decb L |
173 | run_ld_link_tests [list \ |
174 | [list "stack exec" \ | |
175 | "-z execstack" \ | |
176 | "" \ | |
177 | "" \ | |
178 | {stack.s} \ | |
179 | {{readelf {-Wl} stack-exec.rd}} \ | |
180 | "stack-exec.exe"] \ | |
181 | [list "stack noexec" \ | |
182 | "-z noexecstack" \ | |
183 | "" \ | |
184 | "" \ | |
185 | {stack.s} \ | |
186 | {{readelf {-Wl} stack-noexec.rd}} \ | |
187 | "stack-noexec.exe"] \ | |
188 | [list "stack size" \ | |
189 | "-z stack-size=0x123400" \ | |
190 | "" \ | |
191 | "" \ | |
192 | {stack.s} \ | |
193 | {{readelf {-Wl} stack-size.rd}} \ | |
194 | "stack-size.exe"] \ | |
195 | [list "PT_GNU_PROPERTY alignment" \ | |
196 | "" \ | |
197 | "" \ | |
198 | "" \ | |
199 | {pr23900-1.s} \ | |
200 | [list [list "readelf" {-Wl} $pr23900_1_exp]] \ | |
201 | "pr23900-1.exe"] \ | |
202 | ] | |
04c3a755 NS |
203 | } |
204 | ||
b7d07216 L |
205 | if [check_gc_sections_available] { |
206 | run_ld_link_tests [list \ | |
207 | [list "__patchable_function_entries section 2" \ | |
208 | "--gc-sections -e _start" \ | |
209 | "" \ | |
210 | "" \ | |
211 | {pr25490-2.s} \ | |
212 | [list [list "readelf" {-SW} $pr25490_2_exp]] \ | |
213 | "pr25490-2.exe"] \ | |
214 | [list "__patchable_function_entries section 3" \ | |
215 | "--gc-sections -e _start" \ | |
216 | "" \ | |
217 | "" \ | |
218 | {pr25490-3.s} \ | |
219 | [list [list "readelf" {-SW} $pr25490_3_exp]] \ | |
220 | "pr25490-3.exe"] \ | |
221 | [list "__patchable_function_entries section 4" \ | |
222 | "--gc-sections -e _start" \ | |
223 | "" \ | |
224 | "" \ | |
225 | {pr25490-4.s} \ | |
226 | [list [list "readelf" {-SW} $pr25490_4_exp]] \ | |
227 | "pr25490-4.exe"] \ | |
228 | [list "__patchable_function_entries section 5" \ | |
229 | "--gc-sections -e _start" \ | |
230 | "" \ | |
231 | "" \ | |
232 | {pr25490-5.s} \ | |
233 | [list [list "readelf" {-SW} $pr25490_5_exp]] \ | |
234 | "pr25490-5.exe"] \ | |
235 | [list "__patchable_function_entries section 6" \ | |
236 | "--gc-sections -e _start" \ | |
237 | "" \ | |
238 | "" \ | |
239 | {pr25490-6.s} \ | |
240 | [list [list "readelf" {-SW} $pr25490_6_exp]] \ | |
241 | "pr25490-6.exe"] \ | |
242 | ] | |
243 | } | |
244 | ||
e4970690 | 245 | set LDFLAGS $old_ldflags |
dd803a24 | 246 | set ASFLAGS $old_asflags |
e4970690 | 247 | |
4ce6ca2c | 248 | # Check to see if the C compiler works |
44ed8092 | 249 | if { ![check_compiler_available] } { |
4ce6ca2c AM |
250 | return |
251 | } | |
252 | ||
a130722b L |
253 | if [check_gc_sections_available] { |
254 | run_cc_link_tests { | |
255 | {"PR ld/13195" "-Wl,--gc-sections" "" | |
256 | {pr13195.c} {} "pr13195"} | |
257 | } | |
54e8959c L |
258 | } |
259 | ||
24edc24d | 260 | set array_tests { |
d9816402 AM |
261 | {"preinit array" "" "" |
262 | {preinit.c} "preinit" "preinit.out"} | |
263 | {"init array" "" "" | |
264 | {init.c} "init" "init.out"} | |
265 | {"fini array" "" "" | |
266 | {fini.c} "fini" "fini.out"} | |
267 | {"init array mixed" "" "" | |
268 | {init-mixed.c} "init-mixed" "init-mixed.out" "-I."} | |
310fd250 L |
269 | } |
270 | set array_tests_pie { | |
d9816402 AM |
271 | {"PIE preinit array" "-pie" "" |
272 | {preinit.c} "preinit" "preinit.out" "-fPIE"} | |
273 | {"PIE init array" "-pie" "" | |
274 | {init.c} "init" "init.out" "-fPIE"} | |
275 | {"PIE fini array" "-pie" "" | |
276 | {fini.c} "fini" "fini.out" "-fPIE"} | |
277 | {"PIE init array mixed" "-pie" "" | |
278 | {init-mixed.c} "init-mixed" "init-mixed.out" "-I. -fPIE"} | |
279 | {"PIE PR ld/14525" "-pie" "" | |
280 | {pr14525.c} "pr14525" "pr14525.out" "-fPIE"} | |
5940a93c TS |
281 | } |
282 | set array_tests_static { | |
d9816402 AM |
283 | {"static preinit array" "-static" "" |
284 | {preinit.c} "preinit" "preinit.out"} | |
285 | {"static init array" "-static" "" | |
286 | {init.c} "init" "init.out"} | |
287 | {"static fini array" "-static" "" | |
288 | {fini.c} "fini" "fini.out"} | |
289 | {"static init array mixed" "-static" "" | |
290 | {init-mixed.c} "init-mixed" "init-mixed.out" "-I."} | |
24edc24d L |
291 | } |
292 | ||
c8c140d9 | 293 | # NetBSD ELF systems do not currently support the .*_array sections. |
982c6f26 AM |
294 | set xfails "*-*-netbsdelf*" |
295 | run_ld_link_exec_tests $array_tests $xfails | |
310fd250 | 296 | |
3fee20ef | 297 | if { [istarget *-*-linux*] |
5a68afcf | 298 | || [istarget *-*-nacl*] |
3fee20ef | 299 | || [istarget *-*-gnu*] } { |
982c6f26 | 300 | run_ld_link_exec_tests $array_tests_pie $xfails |
a91e1603 | 301 | |
b3d7a867 L |
302 | if { $STATIC_PIE_LDFLAGS != "" } then { |
303 | run_ld_link_exec_tests [list \ | |
304 | [list \ | |
305 | "Static PIE preinit array" \ | |
306 | "$STATIC_PIE_LDFLAGS" \ | |
307 | "" \ | |
308 | {preinit.c} \ | |
309 | "preinit-static-pie" \ | |
310 | "preinit.out" \ | |
311 | "-fPIE" \ | |
312 | ] \ | |
313 | [list \ | |
314 | "Static PIE init array" \ | |
315 | "$STATIC_PIE_LDFLAGS" \ | |
316 | "" \ | |
317 | {init.c} \ | |
318 | "init-static-pie" \ | |
319 | "init.out" \ | |
320 | "-fPIE" \ | |
321 | ] \ | |
322 | [list \ | |
323 | "Static PIE fini array" \ | |
324 | "$STATIC_PIE_LDFLAGS" \ | |
325 | "" \ | |
326 | {fini.c} \ | |
327 | "fini-static-pie" \ | |
328 | "fini.out" \ | |
329 | "-fPIE" \ | |
330 | ] \ | |
331 | [list \ | |
332 | "Static PIE init array mixed" \ | |
333 | "$STATIC_PIE_LDFLAGS" \ | |
334 | "" \ | |
335 | {init-mixed.c} \ | |
336 | "init-mixed-static-pie" \ | |
337 | "init-mixed.out" \ | |
338 | "-I. -fPIE" \ | |
339 | ] \ | |
340 | [list \ | |
341 | "Static PIE PR ld/14525" \ | |
342 | "$STATIC_PIE_LDFLAGS" \ | |
343 | "" \ | |
344 | {pr14525.c} \ | |
345 | "pr14525-static-pie" \ | |
346 | "pr14525.out" \ | |
347 | "-fPIE" \ | |
348 | ] \ | |
349 | ] | |
350 | } | |
351 | ||
a91e1603 L |
352 | run_ld_link_exec_tests [list \ |
353 | [list \ | |
354 | "Run mbind2a" \ | |
355 | "$NOPIE_LDFLAGS -Wl,-z,common-page-size=0x4000" \ | |
356 | "" \ | |
357 | { mbind2a.s mbind2b.c } \ | |
358 | "mbind2a" \ | |
359 | "pass.out" \ | |
360 | "-O2 -I../bfd" \ | |
361 | ] \ | |
362 | [list \ | |
363 | "Run mbind2b" \ | |
364 | "-static -Wl,-z,common-page-size=0x4000" \ | |
365 | "" \ | |
366 | { mbind2a.s mbind2b.c } \ | |
367 | "mbind2b" \ | |
368 | "pass.out" \ | |
369 | "-O2 -I../bfd" \ | |
370 | ] \ | |
371 | ] | |
310fd250 L |
372 | } |
373 | ||
982c6f26 | 374 | run_ld_link_exec_tests $array_tests_static $xfails |
9ab80182 | 375 | |
496afd17 L |
376 | run_cc_link_tests [list \ |
377 | [list \ | |
378 | "Build pr26391-1" \ | |
379 | "-Wl,-z,unique-symbol" \ | |
380 | "-fno-function-sections" \ | |
381 | {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \ | |
382 | {{nm "" pr26391.nd}} \ | |
383 | "pr26391-1" \ | |
384 | ] \ | |
385 | [list \ | |
386 | "Build pr26391-2" \ | |
387 | "-Wl,-z,unique-symbol" \ | |
388 | "-ffunction-sections" \ | |
389 | {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \ | |
390 | {{nm "" pr26391.nd}} \ | |
391 | "pr26391-2" \ | |
392 | ] \ | |
393 | [list \ | |
394 | "Build pr26391-3" \ | |
395 | "-Wl,-z,unique-symbol,--emit-relocs" \ | |
396 | "-fno-function-sections" \ | |
397 | {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \ | |
398 | {{nm "" pr26391.nd}} \ | |
399 | "pr26391-3" \ | |
400 | ] \ | |
401 | [list \ | |
402 | "Build pr26391-4" \ | |
403 | "-Wl,-z,unique-symbol,--emit-relocs" \ | |
404 | "-ffunction-sections" \ | |
405 | {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \ | |
406 | {{nm "" pr26391.nd}} \ | |
407 | "pr26391-4" \ | |
408 | ] \ | |
409 | ] | |
410 | ||
411 | run_ld_link_tests [list \ | |
412 | [list \ | |
413 | "Build pr26391-5.o" \ | |
414 | "-z unique-symbol -r" \ | |
415 | "" \ | |
416 | "" \ | |
417 | {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \ | |
bcac599f L |
418 | [list \ |
419 | [list "nm" "$dep_plug_opt" "pr26391.nd"] \ | |
420 | [list "nm" "$dep_plug_opt" "pr26391.fd"] \ | |
421 | ] \ | |
496afd17 L |
422 | "pr26391-5.o" \ |
423 | "-fno-function-sections" \ | |
424 | ] \ | |
425 | [list \ | |
426 | "Build pr26391-6.o" \ | |
427 | "-z unique-symbol -r" \ | |
428 | "" \ | |
429 | "" \ | |
430 | {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \ | |
431 | {{nm "" pr26391.nd}} \ | |
432 | "pr26391-6.o" \ | |
433 | "-ffunction-sections" \ | |
434 | ] \ | |
435 | ] | |
436 | ||
437 | run_ld_link_exec_tests [list \ | |
438 | [list \ | |
439 | "Run pr26391-1" \ | |
440 | "-Wl,-z,unique-symbol" \ | |
441 | "" \ | |
442 | {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \ | |
443 | "pr26391-1" \ | |
444 | "pr26391.out" \ | |
445 | "-fno-function-sections" \ | |
446 | ] \ | |
447 | [list \ | |
448 | "Run pr26391-2" \ | |
449 | "-Wl,-z,unique-symbol" \ | |
450 | "" \ | |
451 | {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \ | |
452 | "pr26391-2" \ | |
453 | "pr26391.out" \ | |
454 | "-ffunction-sections" \ | |
455 | ] \ | |
456 | [list \ | |
457 | "Run pr26391-3" \ | |
458 | "-Wl,-z,unique-symbol,--emit-relocs" \ | |
459 | "" \ | |
460 | {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \ | |
461 | "pr26391-3" \ | |
462 | "pr26391.out" \ | |
463 | "-fno-function-sections" \ | |
464 | ] \ | |
465 | [list \ | |
466 | "Run pr26391-4" \ | |
467 | "-Wl,-z,unique-symbol,--emit-relocs" \ | |
468 | "" \ | |
469 | {pr26391a.c pr26391b.c pr26391c.c pr26391d.c} \ | |
470 | "pr26391-4" \ | |
471 | "pr26391.out" \ | |
472 | "-ffunction-sections" \ | |
473 | ] \ | |
474 | [list \ | |
475 | "Run pr26391-5" \ | |
476 | "-Wl,-z,unique-symbol" \ | |
477 | "" \ | |
478 | {dummy.c} \ | |
479 | "pr26391-5" \ | |
480 | "pr26391.out" \ | |
481 | "" \ | |
482 | "c" \ | |
483 | "" \ | |
484 | "tmpdir/pr26391-5.o" \ | |
485 | ] \ | |
486 | [list \ | |
487 | "Run pr26391-6" \ | |
488 | "-Wl,-z,unique-symbol" \ | |
489 | "" \ | |
490 | {dummy.c} \ | |
491 | "pr26391-6" \ | |
492 | "pr26391.out" \ | |
493 | "" \ | |
494 | "c" \ | |
495 | "" \ | |
496 | "tmpdir/pr26391-6.o" \ | |
497 | ] \ | |
498 | ] | |
499 | ||
02ecc8e9 | 500 | catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status |