1 # Expect script for various ELF tests.
2 # Copyright (C) 2006-2020 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 # Skip targets where -shared is not supported
30 if ![check_shared_lib_support] {
34 set old_ASFLAGS $ASFLAGS
36 # This target requires extra GAS options when building code for shared
39 if [istarget "nds32*-*"] {
40 append AFLAGS_PIC " -mpic"
42 if [istarget "tic6x-*-*"] {
43 append AFLAGS_PIC " -mpic -mpid=near"
45 if [istarget "sparc*-*-*"] {
46 append AFLAGS_PIC " -K PIC -Av9"
49 # GAS options to disable program property note.
51 if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
52 append AFLAGS_NOTE "-mx86-used-note=no"
55 # This target requires a non-default emulation for successful shared
56 # library/executable builds.
58 if [istarget "tic6x-*-*"] {
59 append LFLAGS " -melf32_tic6x_le"
61 # HPUX targets use a different .comm syntax.
63 if [istarget "*-*-hpux*"] {
64 set hpux "--defsym HPUX=1"
66 # These targets do not default to linking with shared libraries.
67 if { [istarget "mips*vr4100*-*-elf*"] \
68 || [istarget "mips*vr4300*-*-elf*"] \
69 || [istarget "mips*vr5000*-*-elf*"] } {
70 append LFLAGS " -call_shared"
73 if [is_underscore_target] {
74 set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1"
77 run_ld_link_tests [list \
89 "$LFLAGS -shared --version-script pr22471.t" \
90 "tmpdir/pr22471a.so" \
98 "$LFLAGS -rpath-link ." \
99 "tmpdir/pr22471b.so" \
106 "Build pr22649-1.so" \
116 if { [check_gc_sections_available] } {
117 if [istarget mips*-*-*] {
118 set actions {{ld pr22649-2ab-mips.msg}}
120 set actions {{ld pr22649.msg}}
122 run_ld_link_tests [list \
124 "Build pr22649-2a.so" \
125 "$LFLAGS -shared -gc-sections -print-gc-sections" \
133 "Build pr22649-2b.so" \
134 "$LFLAGS -shared -gc-sections -print-gc-sections" \
135 "tmpdir/pr22649-1.so" \
142 if { [istarget mips*-*-*] && ![istarget *-*-elf*] } {
143 set actions {{ld pr22649-2cd-mips.msg}}
147 run_ld_link_tests [list \
149 "Build pr22649-2c.so" \
150 "$LFLAGS -shared -gc-sections -print-gc-sections" \
158 "Build pr22649-2d.so" \
159 "$LFLAGS -shared -gc-sections -print-gc-sections" \
160 "tmpdir/pr22649-1.so" \
169 run_ld_link_tests [list \
171 "DT_TEXTREL in shared lib" \
172 "$LFLAGS -shared --warn-shared-textrel" \
177 {readelf {-d --wide} textrel.rd}} \
182 # The MIPS backend sets SHF_WRITE, in `mips_elf_create_dynamic_relocation',
183 # for any section that has a dynamic relocation attached and consequently
184 # this test is irrelevant for MIPS targets. We don't have a clean way to
185 # request UNSUPPORTED result, which would be the most appropriate here,
186 # so we just XFAIL the test instead.
187 run_ld_link_tests [list \
189 "DT_TEXTREL map file warning" \
190 "$LFLAGS -shared -M" \
197 ] "cris*-*-*" "mips*-*-*"
199 # PR ld/20828 check for correct dynamic symbol table entries where:
200 # - symbols have been defined with a linker script,
201 # - the same symbols have been seen in shared library used in the link,
202 # - the shared library symbols have been swept in section garbage collection.
203 # Verify that the symbols are global rather than local and that a version
204 # script adjusts them accordingly.
205 # Also verify that a version definition supplied by an object rather than
206 # a version script and forcibly exported is unaffected by section GC.
207 if { [check_gc_sections_available] } {
208 run_ld_link_tests [list \
210 "PR ld/20828 dynamic symbols with section GC\
211 (auxiliary shared library)" \
212 "$LFLAGS -shared --gc-sections -T pr20828.ld" "" "$AFLAGS_PIC" \
214 {{readelf --dyn-syms pr20828-a.sd} \
215 {readelf --dyn-syms pr20828-b.sd}} \
218 "PR ld/20828 dynamic symbols with section GC (plain)" \
219 "$LFLAGS -shared --gc-sections -T pr20828.ld" \
220 "tmpdir/libpr20828.so" "$AFLAGS_PIC" \
222 {{readelf --dyn-syms pr20828-a.sd} \
223 {readelf --dyn-syms pr20828-b.sd}} \
226 "PR ld/20828 dynamic symbols with section GC (version script)" \
227 "$LFLAGS -shared --gc-sections -T pr20828.ld\
228 --version-script=pr20828.ver" \
229 "tmpdir/libpr20828.so" \
232 {{readelf --dyn-syms pr20828-b.sd} \
233 {readelf --dyn-syms pr20828-c.sd}} \
236 "PR ld/20828 dynamic symbols with section GC\
237 (versioned shared library)" \
238 "$LFLAGS -shared --gc-sections -T pr20828.ld\
239 --version-script=pr20828-v.ver" \
242 {{readelf --dyn-syms pr20828-c.sd} \
243 {readelf --dyn-syms pr20828-d.sd} \
244 {readelf --dyn-syms pr20828-e.sd}} \
247 "PR ld/20828 dynamic symbols with section GC (versioned)" \
248 "$LFLAGS -shared --gc-sections -T pr20828.ld\
249 --version-script=pr20828-v.ver" \
250 "tmpdir/libpr20828-v.so" \
253 {{readelf --dyn-syms pr20828-c.sd} \
254 {readelf --dyn-syms pr20828-d.sd} \
255 {readelf --dyn-syms pr20828-e.sd}} \
258 "PR ld/20828 forcibly exported symbol version without section GC" \
259 "$LFLAGS --no-dynamic-linker -e foo -E -T pr20828-v.ld" "" "" \
261 {{objdump -p pr20828-v.od}} \
264 "PR ld/20828 forcibly exported symbol version with section GC" \
265 "$LFLAGS --no-dynamic-linker -e foo --gc-sections -E -T pr20828-v.ld" "" "" \
267 {{objdump -p pr20828-v.od}} \
270 # PR ld/21233 check for correct dynamic symbol table entries where:
271 # - a symbol has been defined in a shared library used in the link,
272 # - the symbol has been referenced from a section swept in garbage collection,
273 # - the symbol has also been forced to be entered in the output file as an
274 # undefined symbol, either with a command-line option or a linker script
276 # Verify that the undefined symbol is global rather than local.
277 if { [check_gc_sections_available] } {
278 run_ld_link_tests [list \
280 "PR ld/21233 dynamic symbols with section GC\
281 (auxiliary shared library)" \
282 "$LFLAGS -shared -T pr21233.ld" "" "$AFLAGS_PIC" \
284 {{readelf --dyn-syms pr21233-l.sd}} \
287 run_ld_link_tests [list \
289 "PR ld/21233 dynamic symbols with section GC (--undefined)" \
290 "$LFLAGS --gc-sections -e foo --undefined=bar -T pr21233.ld" \
291 "tmpdir/libpr21233.so" "" \
293 {{readelf --dyn-syms pr21233.sd}} \
296 run_ld_link_tests [list \
298 "PR ld/21233 dynamic symbols with section GC (--require-defined)" \
299 "$LFLAGS --gc-sections -e foo --require-defined=bar\
301 "tmpdir/libpr21233.so" "" \
303 {{readelf --dyn-syms pr21233.sd}} \
306 run_ld_link_tests [list \
308 "PR ld/21233 dynamic symbols with section GC (EXTERN)" \
309 "$LFLAGS --gc-sections -e foo -T pr21233-e.ld" \
310 "tmpdir/libpr21233.so" "" \
312 {{readelf --dyn-syms pr21233.sd}} \
316 if { [check_gc_sections_available] } {
317 run_ld_link_tests [list \
320 "$LFLAGS -shared --version-script pr22150.ver" \
329 "$LFLAGS -e _start --gc-sections" \
330 "tmpdir/pr22150.so" \
333 {{readelf -V pr22150.vd}} \
338 switch -glob $target_triplet {
339 # exclude targets that don't support copy relocs
347 run_ld_link_tests [list \
350 "$LFLAGS -shared --version-script=pr25458.map" \
359 "$LFLAGS -e _start --gc-sections" \
360 "tmpdir/pr25458.so" \
363 {{readelf {--dyn-sym --wide} pr25458.rd}} \
371 set ASFLAGS $old_ASFLAGS
374 {"Build pr14170a.o" "" "" "" {pr14170a.s} {} "pr14170.a" }
376 run_ld_link_tests [list \
377 [list "Build shared library for pr14170" \
378 "-shared" "" "$AFLAGS_PIC" "pr14170b.s" {} "pr14170.so" ] \
381 # bfin does not currently support copy relocs.
382 run_ld_link_tests [list \
383 [list "PR ld/14170" \
384 "$LFLAGS --no-dynamic-linker tmpdir/pr14170a.o tmpdir/pr14170.so" "" \
386 {pr14170c.s} { } "pr14170" ] \
389 # Targets that use _bfd_generic_link_add_symbols won't pass pr21703 tests
390 # Nor will hppa64 with dot-symbols.
391 run_ld_link_tests [list \
392 [list "PR ld/21703 shared" \
393 "-shared --allow-multiple-definition --version-script pr21703.ver\
394 tmpdir/pr21703-3.o tmpdir/pr21703-4.o" "" "$AFLAGS_PIC" \
395 {pr21703-3.s pr21703-4.s} {{readelf {--dyn-syms} pr21703-shared.sd}} \
397 ] \[is_generic\] hppa64-*-*
399 # This target requires extra GAS options when building non-PIC code
400 # for linking with shared libraries.
402 if [istarget "mips*-*-*"] {
403 append AFLAGS_NONPIC " -call_nonpic"
406 # Run a test to check linking a shared library with a broken linker
407 # script that accidentally marks dynamic sections as notes. The
408 # resulting executable is not expected to work, but the linker
409 # should not seg-fault whilst creating the binary.
410 run_ld_link_tests [list \
411 [list "Build shared library for broken linker script test" \
412 "-shared --hash-style=sysv" "" "$AFLAGS_PIC" "note-3.s" \
415 [list "Link using broken linker script" \
416 "$LFLAGS --script note-3.t tmpdir/note-3.so" "" "" "" \
417 { { ld "note-3.l" } } \
421 run_ld_link_tests [list \
422 [list "Build pr17068.so" \
423 "-shared" "" "$AFLAGS_PIC" \
424 {pr17068d.s} {} "pr17068.so"] \
425 [list "Build pr17068a.a" \
427 {pr17068a.s pr17068c.s pr17068ez.s} {} "pr17068a.a"] \
428 [list "Build pr17068b.a" \
430 {pr17068b.s pr17068e.s} {} "pr17068b.a"] \
433 # bfin does not currently support copy relocs.
435 {"pr17068 link --as-needed lib in group"
436 "$LFLAGS --as-needed --no-dynamic-linker"
437 "--start-group tmpdir/pr17068a.a tmpdir/pr17068.so tmpdir/pr17068b.a\
439 {start.s pr17068.s} {} "pr17068"}
442 # Fails on MIPS because ABI trickery means that a NULL reloc is emitted.
443 # Fails on bfin because relocations are not created.
444 run_ld_link_tests [list \
445 [list "-Bsymbolic-functions" \
446 "-shared -Bsymbolic-functions" "" "$AFLAGS_PIC" \
447 {symbolic-func.s} {{readelf {-r --wide} symbolic-func.r}} \
448 "symbolic-func.so"] \
449 ] "mips*-*-*" "bfin-*-*"
451 run_ld_link_tests [list \
452 [list "Build pr20995.so" \
453 "-shared" "" "$AFLAGS_PIC" \
454 {pr20995b.s} {} "pr20995.so"] \
457 # xfail on arm*-*-eabi*. The list can be enlarged to those targets that
458 # don't support GNU_RELRO. For more details, please see discussions at:
459 # https://sourceware.org/ml/binutils/2017-01/msg00441.html
460 run_ld_link_tests [list \
461 [list "Build pr20995-2.so" \
462 "-shared -z relro" "" "$AFLAGS_PIC" \
463 {pr20995c.s} {{readelf {-l --wide} pr20995-2so.r}} "pr20995-2.so"] \
464 ] "tic6x-*-*" "arm*-*-eabi*" "hppa*64*-*-hpux*" "aarch64*-*-elf*" \
465 "*-*-lynxos*" "arm*-*-nto*" "i?86-*-nto*" "sh*-*-nto*"
467 # These targets don't copy dynamic variables into .bss.
468 setup_xfail "alpha-*-*" "bfin-*-*" "ia64-*-*" "xtensa-*-*"
469 # or don't have .data.rel.ro
470 setup_xfail "hppa*64*-*-hpux*"
471 run_ld_link_tests [list \
474 "$LFLAGS" "tmpdir/pr20995.so" "$AFLAGS_NONPIC" \
475 {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995"]]
477 # xfail on arm*-*-eabi* is particularly because of no support of GNU_RELRO.
478 # Please see the link above for details.
479 setup_xfail "alpha-*-*" "bfin-*-*" "ia64-*-*" "xtensa-*-*" "arm*-*-eabi*"
480 setup_xfail "hppa*64*-*-hpux*" "aarch64*-*-elf*"
481 run_ld_link_tests [list \
484 "$LFLAGS" "tmpdir/pr20995-2.so" "$AFLAGS_NONPIC" \
485 {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995-2"]
486 ] "*-*-lynxos*" "arm*-*-nto*" "i?86-*-nto*" "sh*-*-nto*"
488 run_ld_link_tests [list \
489 [list "Build pr22374 shared library" \
490 "-shared" "" "$AFLAGS_PIC" "pr22374b.s" {} "pr22374.so" ] \
492 if { ![istarget "alpha-*-*"]
493 && ![istarget "csky-*-*"]
494 && ![istarget "frv-*-*"]
495 && ![istarget "hppa*-*-*"]
496 && ![istarget "i?86-*-*"]
497 && ![istarget "ia64-*-*"]
498 && ![istarget "microblaze-*-*"]
499 && ![istarget "powerpc*-*-*"]
500 && ![istarget "x86_64-*-*"]
501 && ![istarget "xtensa-*-*"] } {
502 # The next test checks that copy relocs are not used unnecessarily,
503 # but that is just an optimization so don't complain loudly.
507 {"pr22374 function pointer initialization"
508 "" "tmpdir/pr22374.so" "" "pr22374a.s"
509 { {readelf {--wide -r --dyn-syms} "pr22374-1.r"}
510 {readelf {--wide -r} "pr22374-2.r"} }
514 if { [istarget *-*-linux*]
515 || [istarget *-*-nacl*]
516 || [istarget *-*-gnu*] } {
518 {"Weak symbols in dynamic objects 1 (support)"
519 "-shared" "" "" {weak-dyn-1a.s}
522 {"Weak symbols in dynamic objects 1 (main test)"
523 "-shared tmpdir/libweakdyn1a.so -Tweak-dyn-1.ld" "" "" {weak-dyn-1b.s}
524 {{readelf {--relocs --wide} weak-dyn-1.rd}}
529 # Check to see if the C compiler works
530 if { ![check_compiler_available] } {
534 # Add -ldl to extralibs if needed
536 if { ![istarget *-*-freebsd*]} {
543 {foo.c} {} "libfoo.so"}
544 {"Build versioned libfoo.so"
545 "-shared -Wl,--version-script=foo.map" "-fPIC"
546 {foo.c} {} "libfoov.so"}
549 {begin.c end.c} {} "libbar.so"}
550 {"Build warn libbar.so"
553 {{readelf {-S --wide} libbarw.rd}
554 {warning "^.*beginwarn.c:7: warning: function foo is deprecated\n?$"}}
556 {"Build hidden libbar.so"
558 {begin.c endhidden.c} {} "libbarh.so"}
559 {"Build protected libbar.so"
561 {begin.c endprotected.c} {} "libbarp.so"}
562 {"Build libbar.so with libfoo.so"
563 "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
564 {end.c} {} "libbarfoo.so"}
565 {"Build libar.so with versioned libfoo.so"
566 "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
567 {end.c} {} "libbarfoov.so"}
568 {"Build hidden libbar.so with libfoo.so"
569 "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
570 {endhidden.c} {} "libbarhfoo.so"}
571 {"Build hidden libar.so with versioned libfoo.so"
572 "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
573 {endhidden.c} {} "libbarhfoov.so"}
574 {"Build protected libbar.so with libfoo.so"
575 "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
576 {endprotected.c} {} "libbarpfoo.so"}
577 {"Build protected libbar.so with versioned libfoo.so"
578 "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
579 {endprotected.c} {} "libbarpfoov.so"}
582 {dl1.c} {} "libdl1.so"}
583 {"Build libdl2a.so with --dynamic-list=dl2.list"
584 "-shared -Wl,--dynamic-list=dl2.list" "-fPIC"
585 {dl2.c dl2xxx.c} {} "libdl2a.so"}
586 {"Build libdl2a.so with --dynamic-list=dl2a.list"
587 "-shared -Wl,--dynamic-list=dl2a.list" "-fPIC"
588 {dl2.c dl2xxx.c} {} "libdl2a.so"}
589 {"Build libdl2a.so with --dynamic-list-data"
590 "-shared -Wl,--dynamic-list-data" "-fPIC"
591 {dl2.c dl2xxx.c} {} "libdl2a.so"}
592 {"Build libdl2b.so with --dynamic-list=dl2.list and dl2xxx.list"
593 "-shared -Wl,--dynamic-list=dl2.list,--dynamic-list=dl2xxx.list" "-fPIC"
594 {dl2.c dl2xxx.c} {} "libdl2b.so"}
595 {"Build libdl2c.so with --dynamic-list-data and dl2xxx.list"
596 "-shared -Wl,--dynamic-list-data,--dynamic-list=dl2xxx.list" "-fPIC"
597 {dl2.c dl2xxx.c} {} "libdl2c.so"}
598 {"Build libdl2d.so with --dynamic-list-data -Bsymbolic"
599 "-shared -Wl,-Bsymbolic,--dynamic-list-data" "-fPIC"
600 {dl2.c dl2xxx.c} {} "libdl2d.so"}
601 {"Build libdl2e.so with --export-dynamic-symbol=foo"
602 "-shared -Wl,--export-dynamic-symbol=foo" "-fPIC"
603 {dl2.c dl2xxx.c} {} "libdl2e.so"}
604 {"Build libdl2f.so with --dynamic-list=dlempty.list and --export-dynamic-symbol=foo"
605 "-shared -Wl,--dynamic-list=dlempty.list,--export-dynamic-symbol=foo" "-fPIC"
606 {dl2.c dl2xxx.c} {} "libdl2f.so"}
607 {"Build libdl2g.so with --export-dynamic-symbol-list=dl2.list"
608 "-shared -Wl,--export-dynamic-symbol-list=dl2.list" "-fPIC"
609 {dl2.c dl2xxx.c} {} "libdl2g.so"}
610 {"Build libdl2h.so with --dynamic-list=dlempty.list and --export-dynamic-symbol-list=dl2.list"
611 "-shared -Wl,--dynamic-list=dlempty.list,--export-dynamic-symbol-list=dl2.list" "-fPIC"
612 {dl2.c dl2xxx.c} {} "libdl2h.so"}
613 {"Build libdl2i.so with -Bsymbolic and --export-dynamic-symbol=foo"
614 "-shared -Wl,-Bsymbolic,--export-dynamic-symbol=foo" "-fPIC"
615 {dl2.c dl2xxx.c} {} "libdl2i.so"}
616 {"Build libdl2j.so with -Bsymbolic and --export-dynamic-symbol-list=dl2.list"
617 "-shared -Wl,-Bsymbolic,--export-dynamic-symbol-list=dl2.list" "-fPIC"
618 {dl2.c dl2xxx.c} {} "libdl2j.so"}
619 {"Build libdl2k.so with --export-dynamic-symbol-list=dl2.list and -Bsymbolic"
620 "-shared -Wl,--export-dynamic-symbol-list=dl2.list,-Bsymbolic" "-fPIC"
621 {dl2.c dl2xxx.c} {} "libdl2k.so"}
622 {"Build libdl4a.so with --dynamic-list=dl4.list"
623 "-shared -Wl,--dynamic-list=dl4.list" "-fPIC"
624 {dl4.c dl4xxx.c} {} "libdl4a.so"}
625 {"Build libdl4b.so with --dynamic-list-data"
626 "-shared -Wl,--dynamic-list-data" "-fPIC"
627 {dl4.c dl4xxx.c} {} "libdl4b.so"}
628 {"Build libdl4c.so with --dynamic-list=dl4.list and dl4xxx.list"
629 "-shared -Wl,--dynamic-list=dl4.list,--dynamic-list=dl4xxx.list" "-fPIC"
630 {dl4.c dl4xxx.c} {} "libdl4c.so"}
631 {"Build libdl4d.so with --dynamic-list-data and dl4xxx.list"
632 "-shared -Wl,--dynamic-list-data,--dynamic-list=dl4xxx.list" "-fPIC"
633 {dl4.c dl4xxx.c} {} "libdl4d.so"}
634 {"Build libdl4e.so with -Bsymbolic-functions --dynamic-list-cpp-new"
635 "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC"
636 {dl4.c dl4xxx.c} {} "libdl4e.so"}
637 {"Build libdl4f.so with --dynamic-list-cpp-new -Bsymbolic-functions"
638 "-shared -Wl,--dynamic-list-cpp-new,-Bsymbolic-functions" "-fPIC"
639 {dl4.c dl4xxx.c} {} "libdl4f.so"}
642 {dl6.c} {} "libdl6a.so"}
643 {"Build libdl6b.so with -Bsymbolic --dynamic-list-data"
644 "-shared -Wl,-Bsymbolic,--dynamic-list-data" "-fPIC"
645 {dl6.c} {} "libdl6b.so"}
646 {"Build libdl6c.so with -Bsymbolic"
647 "-shared -Wl,-Bsymbolic" "-fPIC"
648 {dl6.c} {} "libdl6c.so"}
649 {"Build libdl6d.so with --dynamic-list-data -Bsymbolic"
650 "-shared -Wl,--dynamic-list-data,-Bsymbolic" "-fPIC"
651 {dl6.c} {} "libdl6d.so"}
654 {data1.c} {} "libdata1.so"}
657 {data2.c} {} "libdata2.so"}
659 "-r -nostdlib" "-fcommon"
660 {comm1.c} {} "libcomm1.o"}
663 {func1.c} {} "libfunc1.so"}
664 {"Build libpr9676-1.a"
666 {pr9676-1.c} {} "libpr9676-1.a"}
667 {"Build libpr9676-2.a"
669 {pr9676-2.c} {} "libpr9676-2.a"}
670 {"Build libpr9676-3.so"
672 {pr9676-3.c} {} "libpr9676-3.so"}
673 {"Build libpr9676-4.so"
675 {pr9676-4.c} {} "libpr9676-4.so"}
676 {"Build libpr9676-4a.so"
677 "-shared tmpdir/pr9676-4.o -Ltmpdir -lpr9676-3 -Wl,--start-group -lpr9676-1 -lpr9676-2 -Wl,--end-group"
679 {dummy.c} {{readelf {-s} pr9676.rd}} "libpr9676-4a.so"}
680 {"Build libpr9679.so"
681 "-shared" "-fPIC -O0"
682 {pr9679-1.c pr9679-2.c} {{readelf {-s} pr9679.rd}} "libpr9679.so"}
683 {"Build libpr11138-1.so"
684 "-shared -Wl,--version-script=pr11138-1.map" "-fPIC"
685 {pr11138-1.c} {} "libpr11138-1.so"}
686 {"Build libpr11138-2.o"
688 {pr11138-2.c} {} "libpr11138-2.o"}
689 {"Build pr13250-1.so"
690 "-shared" "-fPIC -fcommon"
691 {pr13250-1.c} {} "libpr13250-1.so"}
692 {"Build pr13250-2.so with libpr13250-1.so"
693 "-shared -Wl,--no-as-needed tmpdir/libpr13250-1.so" "-fPIC -fcommon"
694 {pr13250-2.c} {} "libpr13250-2.so"}
695 {"Build libpr13250-3.o"
696 "-r -nostdlib" "-fcommon"
697 {pr13250-3.c} {} "libpr13250-3.o"}
698 {"Build libpr14323-2.so"
699 "-shared" "-fPIC -fcommon"
700 {pr14323-2.c} {} "libpr14323-2.so"}
703 {pr14862-1.c} {} "libpr14862-1.o"}
704 {"Build libpr14862.so"
705 "-shared -Wl,--version-script=pr11138-1.map" "-fPIC"
706 {pr14862-2.c} {} "libpr14862.so"}
707 {"Build libneeded1b.so"
709 {needed1b.c} {} "libneeded1b.so"}
710 {"Build libneeded1a.so"
711 "-shared -Wl,--add-needed,--no-as-needed -Ltmpdir -lneeded1b" "-fPIC"
712 {needed1a.c} {} "libneeded1a.so"}
713 {"Build libneeded1c.o"
715 {needed1c.c} {} "libneeded1c.o"}
716 {"Build libneeded1pic.o"
717 "-r -nostdlib" "-fPIC"
718 {needed1c.c} {} "libneeded1pic.o"}
719 {"Build needed1a.so with --add-needed"
720 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--add-needed,-rpath=tmpdir,-rpath-link=tmpdir,-z,defs -Ltmpdir -lneeded1a" ""
721 {dummy.c} {} "needed1a.so"}
722 {"Build needed1b.so with --copy-dt-needed-entries"
723 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--copy-dt-needed-entries,-rpath=tmpdir,-rpath-link=tmpdir,-z,defs -Ltmpdir -lneeded1a" ""
724 {dummy.c} {} "needed1b.so"}
725 {"Build needed1a.so with --no-add-needed"
726 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--no-add-needed -Ltmpdir -lneeded1a" ""
727 {dummy.c} {} "needed1c.so"}
728 {"Build needed1b.so with --no-copy-dt-needed-entries"
729 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--no-copy-dt-needed-entries -Ltmpdir -lneeded1a" ""
730 {dummy.c} {} "needed1d.so"}
733 {rel.c} {} "librel.so"}
734 {"Build libneeded2a.so"
736 {needed2a.c} {} "libneeded2a.so"}
737 {"Build libneeded2b.so"
738 "-shared -Wl,--version-script,needed2.ver" "-fPIC"
739 {needed2b.c} {} "libneeded2b.so"}
740 {"Build libneeded2c.o"
742 {needed2c.c} {} "libneeded2c.o"}
744 "tmpdir/libneeded2c.o -Wl,--as-needed tmpdir/libneeded2a.so tmpdir/libneeded2b.so" ""
745 {dummy.c} {} "needed2"}
746 {"Build libneeded3a.so"
747 "-shared -Wl,--no-add-needed" "-fPIC"
748 {needed1a.c} {} "libneeded3a.so"}
749 {"Build libneeded3b.so"
750 "-shared -Wl,--no-as-needed,--add-needed -Ltmpdir -lneeded1b" "-fPIC"
751 {dummy.c} {} "libneeded3b.so"}
754 {needed3.c} {} "libneeded3.so"}
756 "tmpdir/needed3.o -Wl,--as-needed -Ltmpdir -lneeded3a -lneeded3b -lneeded1b" ""
757 {dummy.c} {} "needed3"}
758 {"Build libpr2404a.so"
760 {pr2404a.c} {} "libpr2404a.so"}
761 {"Build libpr2404n.so"
762 "-shared -Wl,-z,now" "-fPIC"
763 {pr2404a.c} {} "libpr2404n.so"}
764 {"Build libpr2404b.a"
766 {pr2404b.c} {} "libpr2404b.a"}
768 "-Wl,--no-dynamic-linker,-export-dynamic,--gc-sections" "-ffunction-sections"
769 {rdynamic-1.c} {{readelf {-s} rdynamic-1.rd}} "rdynamic-1"}
771 "-Wl,--no-dynamic-linker,--dynamic-list,dynamic-1.syms -Wl,--gc-sections" "-ffunction-sections"
772 {dynamic-1.c} {{readelf {-s} dynamic-1.rd}} "dynamic-1"}
773 {"Build libpr16496a.so"
774 "-shared -Wl,--version-script=pr16496a.map" "-fPIC"
775 {pr16496a.c} {} "libpr16496a.so"}
776 {"Build libpr16496b.a"
778 {pr16496b.c} {} "libpr16496b.a"}
779 {"Build libpr16496b.so"
780 "-shared -Wl,--no-as-needed tmpdir/pr16496b.o tmpdir/libpr16496a.so" ""
781 {dummy.c} {{objdump {-R} pr16496b.od}} "libpr16496b.so"}
782 {"Build libpr16452a.so"
783 "-shared -Wl,-soname,libpr16452a.so,--version-script=pr16452.map" "-fPIC"
784 {pr16452a.c} {} "libpr16452a.so"}
785 {"Build libpr16452b.so"
786 "-shared -Wl,-soname,libpr16452b.so,--no-as-needed tmpdir/libpr16452a.so" "-fPIC"
787 {dummy.c} {} "libpr16452b.so"}
789 "-Wl,--no-as-needed,-rpath=tmpdir,-rpath-link=tmpdir tmpdir/libpr16452b.so" ""
790 {pr16452b.c} {{objdump {-p} pr16452.od}} "pr16452"}
792 "-Wl,--no-as-needed,-rpath=tmpdir,-rpath-link=tmpdir tmpdir/libpr16452b.so" ""
793 {pr16452b.c} {{objdump {-p} pr16457.od}} "pr16457"}
794 {"Build libpr18458a.so"
795 "-shared -Wl,-z,now" "-fPIC"
796 {pr18458a.c} {} "libpr18458a.so"}
797 {"Build libpr18458b.so"
798 "-shared -Wl,-z,now tmpdir/libpr18458a.so" "-fPIC"
799 {pr18458b.c} {} "libpr18458b.so"}
801 # pr19073.s uses .set, which has a different meaning on alpha.
802 if { ![istarget alpha-*-*] } {
806 {pr19073.s} {} "pr19073a.o"}
807 {"Build libpr19073.so"
808 "-shared -Wl,--version-script=pr19073.map tmpdir/pr19073a.o" "-fPIC"
809 {dummy.c} {{readelf {--dyn-syms --wide} pr19073.rd}} "libpr19073.so"}
813 {"Build pr21964-1a.so"
815 {pr21964-1a.c} {} "pr21964-1a.so"}
816 {"Build pr21964-1b.so"
818 {pr21964-1b.c} {} "pr21964-1b.so"}
819 {"Build pr21964-2a.so"
821 {pr21964-2a.c} {} "pr21964-2a.so"}
822 {"Build pr21964-2b.so"
824 {pr21964-2b.c} {} "pr21964-2b.so"}
825 {"Build pr21964-3a.so"
827 {pr21964-3a.c} {} "pr21964-3a.so"}
829 "-shared" "-fPIC -g -O2"
830 {pr21978a.c pr21978b.c} {{objdump {-Sl} pr21978.od}} "pr21978.so"}
833 run_cc_link_tests $build_tests
835 run_ld_link_tests [list \
837 "pr22269-1 (static pie undefined weak)" \
838 "-pie -e _start --no-dynamic-linker -z text -z nocombreloc " \
842 {{readelf -rW pr22269-1.rd}} \
848 set run_tests [list \
849 [list "Run normal with libfoo.so" \
850 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/end.o" "" \
851 {main.c} "normal" "normal.out" ] \
852 [list "Run protected with libfoo.so" \
853 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/endprotected.o" "" \
854 {main.c} "protected" "normal.out" ] \
855 [list "Run hidden with libfoo.so" \
856 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/endhidden.o" "" \
857 {main.c} "hidden" "hidden.out" ] \
858 [list "Run normal with versioned libfoo.so" \
859 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/end.o" "" \
860 {main.c} "normalv" "normal.out" ] \
861 [list "Run warn with versioned libfoo.so" \
862 "-Wl,--no-as-needed tmpdir/beginwarn.o tmpdir/libfoov.so" "" \
863 {main.c} "warn" "warn.out" \
864 "" "c" {^.*beginwarn.c:7: warning: function foo is deprecated\n?$} ] \
865 [list "Run protected with versioned libfoo.so" \
866 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/endprotected.o" "" \
867 {main.c} "protected" "normal.out" ] \
868 [list "Run hidden with versioned libfoo.so" \
869 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/endhidden.o" "" \
870 {main.c} "hiddenv" "hidden.out" ] \
871 [list "Run normal libbar.so with libfoo.so" \
872 "-Wl,--no-as-needed tmpdir/libbarfoo.so tmpdir/libfoo.so" "" \
873 {main.c} "normal" "normal.out" ] \
874 [list "Run protected libbar.so with libfoo.so" \
875 "-Wl,--no-as-needed tmpdir/libbarpfoo.so tmpdir/libfoo.so" "" \
876 {main.c} "protected" "normal.out" ] \
877 [list "Run hidden libbar.so with libfoo.so" \
878 "-Wl,--no-as-needed tmpdir/libbarhfoo.so tmpdir/libfoo.so" "" \
879 {main.c} "hidden" "hidden.out" ] \
880 [list "Run normal libbar.so with versioned libfoo.so" \
881 "-Wl,--no-as-needed tmpdir/libbarfoov.so tmpdir/libfoov.so" "" \
882 {main.c} "normal" "normal.out" ] \
883 [list "Run protected libbar.so with versioned libfoo.so" \
884 "-Wl,--no-as-needed tmpdir/libbarpfoov.so tmpdir/libfoov.so" "" \
885 {main.c} "protected" "normal.out" ] \
886 [list "Run hidden libbar.so with versioned libfoo.so" \
887 "-Wl,--no-as-needed tmpdir/libbarhfoov.so tmpdir/libfoov.so" "" \
888 {main.c} "hidden" "hidden.out" ] \
889 [list "Run with libdl2a.so" \
890 "-Wl,--no-as-needed tmpdir/libdl2a.so" "" \
891 {dl2main.c} "dl2a" "dl2a.out" ] \
892 [list "Run with libdl2b.so" \
893 "-Wl,--no-as-needed tmpdir/libdl2b.so" "" \
894 {dl2main.c} "dl2b" "dl2b.out" ] \
895 [list "Run with libdl2c.so" \
896 "-Wl,--no-as-needed tmpdir/libdl2c.so" "" \
897 {dl2main.c} "dl2c" "dl2b.out" ] \
898 [list "Run with libdl2d.so" \
899 "-Wl,--no-as-needed tmpdir/libdl2d.so" "" \
900 {dl2main.c} "dl2d" "dl2a.out" ] \
901 [list "Run with libdl2e.so" \
902 "-Wl,--no-as-needed tmpdir/libdl2e.so" "" \
903 {dl2main.c} "dl2e" "dl2b.out" ] \
904 [list "Run with libdl2f.so" \
905 "-Wl,--no-as-needed tmpdir/libdl2f.so" "" \
906 {dl2main.c} "dl2f" "dl2a.out" ] \
907 [list "Run with libdl2g.so" \
908 "-Wl,--no-as-needed tmpdir/libdl2g.so" "" \
909 {dl2main.c} "dl2g" "dl2b.out" ] \
910 [list "Run with libdl2h.so" \
911 "-Wl,--no-as-needed tmpdir/libdl2h.so" "" \
912 {dl2main.c} "dl2h" "dl2a.out" ] \
913 [list "Run with libdl2i.so" \
914 "-Wl,--no-as-needed tmpdir/libdl2i.so" "" \
915 {dl2main.c} "dl2i" "dl2a.out" ] \
916 [list "Run with libdl2j.so" \
917 "-Wl,--no-as-needed tmpdir/libdl2j.so" "" \
918 {dl2main.c} "dl2j" "dl2a.out" ] \
919 [list "Run with libdl2k.so" \
920 "-Wl,--no-as-needed tmpdir/libdl2k.so" "" \
921 {dl2main.c} "dl2k" "dl2a.out" ] \
922 [list "Run with libdl4a.so" \
923 "-Wl,--no-as-needed tmpdir/libdl4a.so" "" \
924 {dl4main.c} "dl4a" "dl4a.out" ] \
925 [list "Run with libdl4b.so" \
926 "-Wl,--no-as-needed tmpdir/libdl4b.so" "" \
927 {dl4main.c} "dl4b" "dl4a.out" ] \
928 [list "Run with libdl4c.so" \
929 "-Wl,--no-as-needed tmpdir/libdl4c.so" "" \
930 {dl4main.c} "dl4c" "dl4b.out" ] \
931 [list "Run with libdl4d.so" \
932 "-Wl,--no-as-needed tmpdir/libdl4d.so" "" \
933 {dl4main.c} "dl4d" "dl4b.out" ] \
934 [list "Run with libdl4e.so" \
935 "-Wl,--no-as-needed tmpdir/libdl4e.so" "" \
936 {dl4main.c} "dl4e" "dl4e.out" ] \
937 [list "Run with libdl4f.so" \
938 "-Wl,--no-as-needed tmpdir/libdl4f.so" "" \
939 {dl4main.c} "dl4f" "dl4e.out" ] \
940 [list "Run with libdata1.so" \
941 "-Wl,--no-as-needed tmpdir/libdata1.so" "" \
942 {dynbss1.c} "dynbss1" "pass.out" ] \
943 [list "Run with libdata2.so" \
944 "-Wl,--no-as-needed tmpdir/libdata2.so" "" \
945 {weakdef1.c} "weakdef1" "pass.out" ] \
946 [list "Run with libfunc1.so comm1.o" \
947 "-Wl,--no-as-needed tmpdir/libfunc1.so tmpdir/comm1.o" "" \
948 {dummy.c} "comm1" "pass.out" ] \
949 [list "Run with comm1.o libfunc1.so" \
950 "-Wl,--no-as-needed tmpdir/comm1.o tmpdir/libfunc1.so" "" \
951 {dummy.c} "comm1" "pass.out" ] \
952 [list "Run with pr11138-2.c libpr11138-1.so" \
953 "-Wl,--no-as-needed,--version-script=pr11138-2.map tmpdir/pr11138-2.o tmpdir/libpr11138-1.so" "" \
954 {dummy.c} "pr11138a" "pr11138.out" ] \
955 [list "Run with libpr11138-1.so pr11138-2.c" \
956 "-Wl,--no-as-needed,--version-script=pr11138-2.map tmpdir/libpr11138-1.so tmpdir/pr11138-2.o" "" \
957 {dummy.c} "pr11138b" "pr11138.out" ] \
958 [list "Run with pr13250-3.c, libpr13250-1.so and libpr13250-2.so" \
959 "-Wl,--as-needed tmpdir/pr13250-3.o tmpdir/libpr13250-1.so tmpdir/libpr13250-2.so" "-fcommon" \
960 {dummy.c} "pr13250" "pass.out" ] \
961 [list "Run with pr14323-1.c pr14323-2.so" \
962 "-Wl,--no-as-needed tmpdir/libpr14323-2.so" "" \
963 {pr14323-1.c} "pr14323" "pass.out" ] \
964 [list "Run with pr14862-1.c libpr14862.so" \
965 "-Wl,--as-needed tmpdir/libpr14862-1.o tmpdir/libpr14862.so" "" \
966 {dummy.c} "pr14862" "pr14862.out" ] \
967 [list "Link with --add-needed" \
968 "tmpdir/libneeded1c.o -Wl,--no-as-needed,--add-needed,-rpath=tmpdir,-rpath-link=tmpdir -Ltmpdir -lneeded1a" "" \
969 {dummy.c} "needed1a" "needed1.out" ] \
970 [list "Link with --copy-dt-needed-entries" \
971 "tmpdir/libneeded1c.o -Wl,--no-as-needed,--copy-dt-needed-entries,-rpath=tmpdir,-rpath-link=tmpdir -Ltmpdir -lneeded1a" "" \
972 {dummy.c} "needed1b" "needed1.out" ] \
973 [list "Run relmain" \
974 "-Wl,--no-as-needed,-rpath=tmpdir -Ltmpdir -lrel" "" \
975 {relmain.c} "relmain" "relmain.out" ] \
977 "-Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404a.so" "" \
978 {dummy.c} "pr2404" "pr2404.out" ] \
979 [list "Run pr2404n" \
980 "-Wl,-z,now -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404n.so" "" \
981 {dummy.c} "pr2404n" "pr2404.out" ] \
982 [list "Run pr18458" \
983 "-Wl,--no-as-needed,-z,now tmpdir/libpr18458a.so tmpdir/libpr18458b.so" "" \
984 {pr18458c.c} "pr18458" "pass.out" ] \
985 [list "Run pr21964-1" \
986 "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-1a.so tmpdir/pr21964-1b.so" "" \
987 {pr21964-1c.c} "pr21964-1" "pass.out" ] \
988 [list "Run pr21964-3" \
989 "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-1a.so tmpdir/pr21964-1b.so tmpdir/pr21964-3a.so" "" \
990 {pr21964-3c.c} "pr21964-3" "pass.out" ] \
993 # NetBSD ELF systems do not currently support the .*_array sections.
994 run_ld_link_exec_tests $run_tests "*-*-netbsdelf*"
996 # These tests require dlopen support.
997 set dlopen_run_tests [list \
998 [list "Run dl1a with --dynamic-list=dl1.list and dlopen on libdl1.so" \
999 "-Wl,--no-as-needed,--dynamic-list=dl1.list $extralibs" "" \
1000 {dl1main.c} "dl1a" "dl1.out" ] \
1001 [list "Run dl1b with --dynamic-list-data and dlopen on libdl1.so" \
1002 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
1003 {dl1main.c} "dl1b" "dl1.out" ] \
1004 [list "Run dl6a1 with --dynamic-list-data and dlopen on libdl6a.so" \
1005 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
1006 {dl6amain.c} "dl6a1" "dl6a.out" ] \
1007 [list "Run dl6a2 with -Bsymbolic-functions and dlopen on libdl6a.so" \
1008 "$NOPIE_LDFLAGS -Wl,--no-as-needed,-Bsymbolic-functions $extralibs" "" \
1009 {dl6amain.c} "dl6a2" "dl6b.out" "$NOPIE_CFLAGS" ] \
1010 [list "Run dl6a3 with -Bsymbolic and dlopen on libdl6a.so" \
1011 "-Wl,--no-as-needed,-Bsymbolic $extralibs" "" \
1012 {dl6amain.c} "dl6a3" "dl6b.out" ] \
1013 [list "Run dl6a4 with -Bsymbolic --dynamic-list-data and dlopen on libdl6a.so" \
1014 "-Wl,--no-as-needed,-Bsymbolic,--dynamic-list-data $extralibs" "" \
1015 {dl6amain.c} "dl6a4" "dl6a.out" ] \
1016 [list "Run dl6a5 with -Bsymbolic-functions --dynamic-list-cpp-new and dlopen on libdl6a.so" \
1017 "$NOPIE_LDFLAGS -Wl,--no-as-needed,-Bsymbolic-functions,--dynamic-list-cpp-new $extralibs" "" \
1018 {dl6amain.c} "dl6a5" "dl6b.out" "$NOPIE_CFLAGS" ] \
1019 [list "Run dl6a6 with --dynamic-list-cpp-new -Bsymbolic-functions and dlopen on libdl6a.so" \
1020 "$NOPIE_LDFLAGS -Wl,--no-as-needed,--dynamic-list-cpp-new,-Bsymbolic-functions $extralibs" "" \
1021 {dl6amain.c} "dl6a6" "dl6b.out" "$NOPIE_CFLAGS" ] \
1022 [list "Run dl6a7 with --dynamic-list-data -Bsymbolic and dlopen on libdl6a.so" \
1023 "$NOPIE_LDFLAGS -Wl,--no-as-needed,--dynamic-list-data,-Bsymbolic $extralibs" "" \
1024 {dl6amain.c} "dl6a7" "dl6a.out" "$NOPIE_CFLAGS" ] \
1025 [list "Run dl6b1 with --dynamic-list-data and dlopen on libdl6b.so" \
1026 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
1027 {dl6bmain.c} "dl6b1" "dl6a.out" ] \
1028 [list "Run dl6b2 with dlopen on libdl6b.so" \
1029 "-Wl,--no-as-needed $extralibs" "" \
1030 {dl6bmain.c} "dl6b2" "dl6b.out" ] \
1031 [list "Run dl6c1 with --dynamic-list-data and dlopen on libdl6c.so" \
1032 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
1033 {dl6cmain.c} "dl6c1" "dl6b.out" ] \
1034 [list "Run dl6d1 with --dynamic-list-data and dlopen on libdl6d.so" \
1035 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
1036 {dl6dmain.c} "dl6d1" "dl6a.out" ] \
1037 [list "Run pr21964-2" \
1038 "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-2a.so $extralibs" "" \
1039 {pr21964-2c.c} "pr21964-2" "pass.out" ] \
1040 [list "Run pr21964-5" \
1041 "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-1a.so $extralibs" "" \
1042 {pr21964-5.c} "pr21964-5" "pass.out" ] \
1045 # Only run them when libdl is available.
1046 if [check_libdl_available] {
1047 # XFAIL on NetBSD ELF systems as they do not currently support the .*_array
1049 run_ld_link_exec_tests $dlopen_run_tests "*-*-netbsdelf*"
1052 # Check --no-add-needed and --no-copy-dt-needed-entries
1053 set testname "--no-add-needed"
1054 set exec_output [run_host_cmd "$CC" "tmpdir/libneeded1c.o -Wl,--no-add-needed,-rpath-link=tmpdir -Ltmpdir -lneeded1a"]
1055 if { [ regexp "tmpdir/libneeded1b.so: .*: DSO missing" $exec_output ] } {
1060 set testname "--no-copy-dt-needed-entries"
1061 set exec_output [run_host_cmd "$CC" "tmpdir/libneeded1c.o -Wl,--no-copy-dt-needed-entries,-rpath-link=tmpdir -Ltmpdir -lneeded1a"]
1062 if { [ regexp "tmpdir/libneeded1b.so: .*: DSO missing" $exec_output ] } {
1067 set testname "--no-add-needed -shared"
1068 set exec_output [run_host_cmd "$CC" "-shared tmpdir/libneeded1pic.o -Wl,--no-add-needed,-z,defs -Ltmpdir -lneeded1a"]
1069 if { [ regexp "undefined reference to `\.?bar'" $exec_output ] } {
1074 set testname "--no-copy-dt-needed-entries -shared"
1075 set exec_output [run_host_cmd "$CC" "-shared tmpdir/libneeded1pic.o -Wl,--no-copy-dt-needed-entries,-z,defs -Ltmpdir -lneeded1a"]
1076 if { [ regexp "undefined reference to `\.?bar'" $exec_output ] } {
1082 # Check to see if the C++ compiler works
1083 if { [which $CXX] == 0 } {
1087 set build_cxx_tests {
1088 {"Build libdl3a.so with --dynamic-list=dl3.list"
1089 "-shared -Wl,--dynamic-list=dl3.list" "-fPIC"
1090 {dl3.cc} {} "libdl3a.so" "c++"}
1091 {"Build libdl3b.so with -Bsymbolic"
1092 "-shared -Wl,-Bsymbolic" "-fPIC"
1093 {dl3.cc} {} "libdl3b.so" "c++"}
1094 {"Build libdl3a.so with --dynamic-list-cpp-typeinfo"
1095 "-shared -Wl,--dynamic-list-cpp-typeinfo" "-fPIC"
1096 {dl3.cc} {} "libdl3c.so" "c++"}
1097 {"Build libdnew1a.so with --Bsymbolic-functions --dynamic-list-cpp-new"
1098 "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC -ansi"
1099 {del.cc new.cc} {} "libnew1a.so" "c++"}
1100 {"Build libdnew1b.so with --dynamic-list-data --dynamic-list-cpp-new"
1101 "-shared -Wl,--dynamic-list-data,--dynamic-list-cpp-new" "-fPIC -ansi"
1102 {del.cc new.cc} {} "libnew1b.so" "c++"}
1105 # "-shared -Bsymbolic" only works with gcc 4.5.0 and newer.
1106 # {"Run with libdl3b.so"
1107 # "tmpdir/libdl3b.so" ""
1108 # {dl3main.cc} "dl3b" "dl3b.out" "" "c++"}
1110 {"Run with libdl3a.so"
1111 "-Wl,--no-as-needed tmpdir/libdl3a.so" ""
1112 {dl3main.cc} "dl3a" "dl3a.out" "" "c++"}
1113 {"Run with libdl3c.so"
1114 "-Wl,--no-as-needed tmpdir/libdl3c.so" ""
1115 {dl3main.cc} "dl3c" "dl3a.out" "" "c++"}
1116 {"Run with libnew1a.so"
1117 "-Wl,--no-as-needed tmpdir/libnew1a.so" ""
1118 {dl5.cc} "dl5a" "dl5.out" "-ansi" "c++"}
1119 {"Run with libnew1b.so"
1120 "-Wl,--no-as-needed tmpdir/libnew1b.so" ""
1121 {dl5.cc} "dl5b" "dl5.out" "-ansi" "c++"}
1124 run_cc_link_tests $build_cxx_tests
1125 run_ld_link_exec_tests $run_cxx_tests
1127 if { [istarget *-*-linux*]
1128 || [istarget *-*-nacl*]
1129 || [istarget *-*-gnu*] } {
1130 run_cc_link_tests [list \
1132 "Build libpr2404b.a with PIE" \
1140 "Build pr19579a.o" \
1141 "" "-fPIE -fcommon" \
1147 "Build libpr19579.so" \
1155 "Build libpr19579now.so" \
1156 "-shared -Wl,-z,now" \
1163 "Build pr22393-2a.so" \
1164 "-shared -Wl,-z,separate-code" \
1167 {{readelf -lW pr22393-2a.rd} \
1168 {readelf -lW pr22393-2b.rd}} \
1172 "Build pr22393-2a-now.so" \
1173 "-shared -Wl,-z,separate-code,-z,now" \
1176 {{readelf -lW pr22393-2a.rd} \
1177 {readelf -lW pr22393-2b.rd}} \
1178 "pr22393-2a-now.so" \
1182 "$NOPIE_LDFLAGS -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a.so" \
1185 {{readelf -lW pr22393-2a.rd} \
1186 {readelf -lW pr22393-2b.rd}} \
1190 "Build pr22393-2 (PIE)" \
1191 "-pie -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a-now.so" \
1194 {{readelf -lW pr22393-2a.rd} \
1195 {readelf -lW pr22393-2b.rd}} \
1199 "Build pr22393-2 (static)" \
1200 "-static -Wl,-z,separate-code" \
1202 {pr22393-2a.c pr22393-2b.c} \
1203 {{readelf -lW pr22393-2a.rd} \
1204 {readelf -lW pr22393-2b.rd}} \
1205 "pr22393-2-static" \
1208 run_ld_link_exec_tests [list \
1210 "Run pr18458 with PIE" \
1211 "-pie -Wl,--no-as-needed,-z,now tmpdir/libpr18458a.so tmpdir/libpr18458b.so" \
1219 "Run pr2404 with PIE" \
1220 "-pie -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404a.so" \
1228 "Run pr2404 with PIE (-z now)" \
1229 "-pie -Wl,-z,now -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404n.so" \
1240 { pr18718.c check-ptr-eq.c } \
1246 "Run pr18718 (-z now)" \
1249 { pr18718.c check-ptr-eq.c } \
1255 "Run pr18718 with PIE (1)" \
1258 { pr18718.c check-ptr-eq.c } \
1261 "-O2 -fPIE -I../bfd" \
1264 "Run pr18718 with PIE (2)" \
1267 { pr18718.c check-ptr-eq.c } \
1270 "-O2 -fPIE -I../bfd" \
1273 "Run pr18718 with PIE (3)" \
1276 { pr18718.c check-ptr-eq.c } \
1279 "-O2 -fPIE -I../bfd" \
1282 "Run pr18718 with PIE (4)" \
1285 { pr18718.c check-ptr-eq.c } \
1288 "-O2 -fPIE -I../bfd" \
1291 "Run pr18718 with PIC (1)" \
1294 { pr18718.c check-ptr-eq.c } \
1297 "-O2 -fPIC -I../bfd" \
1300 "Run pr18718 with PIC (2)" \
1303 { pr18718.c check-ptr-eq.c } \
1306 "-O2 -fPIC -I../bfd" \
1309 "Run pr18718 with PIC (3)" \
1312 { pr18718.c check-ptr-eq.c } \
1315 "-O2 -fPIC -I../bfd" \
1318 "Run pr18718 with PIC (4)" \
1321 { pr18718.c check-ptr-eq.c } \
1324 "-O2 -fPIC -I../bfd" \
1328 "-pie -Wl,--no-as-needed,-z,text tmpdir/pr19579a.o tmpdir/libpr19579.so" \
1336 "Run pr19579 (-z now)" \
1337 "-pie -Wl,-z,now -Wl,--no-as-needed,-z,text tmpdir/pr19579a.o tmpdir/libpr19579.so" \
1346 "$NOPIE_LDFLAGS -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a.so" \
1354 "Run pr22393-2 (PIE)" \
1355 "-pie -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a-now.so" \
1363 "Run pr22393-2 (static)" \
1364 "-static -Wl,-z,separate-code" \
1366 {pr22393-2a.c pr22393-2b.c} \
1367 "pr22393-2-static" \
1385 proc mix_pic_and_non_pic {xfails cflags ldflags exe} {
1386 run_cc_link_tests [list \
1388 "Build libpr19719a.so" \
1389 "-shared -Wl,-soname,libpr19719.so" \
1396 "Build libpr19719b.so" \
1397 "-shared -Wl,-soname,libpr19719.so" \
1404 "Build libpr19719b.o" \
1413 send_log "cp tmpdir/libpr19719b.so tmpdir/libpr19719.so\n"
1414 exec cp tmpdir/libpr19719b.so tmpdir/libpr19719.so
1416 run_ld_link_exec_tests [list \
1418 "Run $exe fun defined" \
1419 "-Wl,--no-as-needed,-rpath,tmpdir $ldflags tmpdir/libpr19719b.o tmpdir/libpr19719.so" \
1421 { pr19719a.c pr19719c.c } \
1428 send_log "cp tmpdir/libpr19719a.so tmpdir/libpr19719.so\n"
1429 exec cp tmpdir/libpr19719a.so tmpdir/libpr19719.so
1431 foreach targ $xfails {
1436 unsupported "Run $exe fun undefined"
1440 set exec_output [run_host_cmd "tmpdir/$exe" ""]
1441 if {![string match "PASS" $exec_output]} {
1442 fail "Run $exe fun undefined"
1444 pass "Run $exe fun undefined"
1448 mix_pic_and_non_pic [list "arm*-*-*" "aarch64*-*-*"] "" "" "pr19719"
1449 mix_pic_and_non_pic [] "-fPIE" "-pie" "pr19719pie"
1452 if { [istarget "i?86-*-*"]
1453 || [istarget "x86_64-*-*"] } {
1454 set AFLAGS_PIE "-mrelax-relocations=yes"
1457 if { ([istarget "*-*-linux*"]
1458 || [istarget "*-*-nacl*"]
1459 || [istarget "*-*-gnu*"])
1460 && ![istarget "mips*-*-*"] } {
1461 run_ld_link_tests [list \
1463 "Build libpr23162a.so" \
1474 "-pie --no-as-needed tmpdir/libpr23162a.so" \
1478 {{readelf {-rW} pr23162.rd}} \
1483 "Build libpr23162b.so" \
1484 "-shared --version-script=pr23162.map" \
1494 "-pie --no-as-needed tmpdir/libpr23162b.so" \
1498 {{readelf {-rW} pr23162.rd}} \
1503 "Build libpr23161a.so" \
1508 {{readelf {--dyn-syms -rW} pr23161a.rd}} \
1510 "-fPIC -O2 $NOSANTIZE_CFLAGS" \
1514 "-pie --no-as-needed tmpdir/libpr23161a.so" \
1518 {{readelf {--dyn-syms -rW} pr23161b.rd}} \
1520 "-fPIC -O0 $NOSANTIZE_CFLAGS" \
1523 "Build libpr23161b.so" \
1524 "-shared --version-script=pr23161.map" \
1528 {{readelf {--dyn-syms -rW} pr23161a.rd}} \
1530 "-fPIC -O2 $NOSANTIZE_CFLAGS" \
1534 "-pie --no-as-needed tmpdir/libpr23161b.so" \
1538 {{readelf {--dyn-syms -rW} pr23161b.rd}} \
1540 "-fPIC -O0 $NOSANTIZE_CFLAGS" \
1545 if { [istarget "i?86-*-*"]
1546 || [istarget "x86_64-*-*"] } {
1547 run_ld_link_tests [list \
1549 "Build libpr23161c.so" \
1554 {{readelf {--dyn-syms -rW} pr23161c.rd}} \
1556 "-fPIC -O2 $NOSANTIZE_CFLAGS" \
1560 "-pie --no-as-needed tmpdir/libpr23161c.so" \
1564 {{readelf {--dyn-syms -rW} pr23161d.rd}} \
1566 "-fPIC -O0 $NOSANTIZE_CFLAGS" \
1571 run_ld_link_tests [list \
1572 [list "Build pr23658.so" \
1573 "-shared" "" "$AFLAGS_PIC" \
1574 {pr23658-1a.s} {} "pr23658.so"] \
1577 "--dynamic-linker tmpdir/pr23658.so --no-as-needed tmpdir/pr23658.so" \
1580 { pr23658-1a.s pr23658-1b.s pr23658-1c.s pr23658-1d.s start.s } \
1581 {{readelf {-lW} pr23658-2.rd}} \