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 # Add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if non-PIE is required.
35 global NOPIE_CFLAGS NOPIE_LDFLAGS
36 global NOSANTIZE_CFLAGS
38 set old_ASFLAGS $ASFLAGS
40 # This target requires extra GAS options when building code for shared
43 if [istarget "nds32*-*"] {
44 append AFLAGS_PIC " -mpic"
46 if [istarget "tic6x-*-*"] {
47 append AFLAGS_PIC " -mpic -mpid=near"
49 if [istarget "sparc*-*-*"] {
50 append AFLAGS_PIC " -K PIC -Av9"
53 # GAS options to disable program property note.
55 if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
56 append AFLAGS_NOTE "-mx86-used-note=no"
59 # This target requires a non-default emulation for successful shared
60 # library/executable builds.
62 if [istarget "tic6x-*-*"] {
63 append LFLAGS " -melf32_tic6x_le"
65 # HPUX targets use a different .comm syntax.
67 if [istarget "*-*-hpux*"] {
68 set hpux "--defsym HPUX=1"
70 # These targets do not default to linking with shared libraries.
71 if { [istarget "mips*vr4100*-*-elf*"] \
72 || [istarget "mips*vr4300*-*-elf*"] \
73 || [istarget "mips*vr5000*-*-elf*"] } {
74 append LFLAGS " -call_shared"
77 if [is_underscore_target] {
78 set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1"
81 run_ld_link_tests [list \
93 "$LFLAGS -shared --version-script pr22471.t" \
94 "tmpdir/pr22471a.so" \
102 "$LFLAGS -rpath-link ." \
103 "tmpdir/pr22471b.so" \
110 "Build pr22649-1.so" \
120 if { [check_gc_sections_available] } {
121 if [istarget mips*-*-*] {
122 set actions {{ld pr22649-2ab-mips.msg}}
124 set actions {{ld pr22649.msg}}
126 run_ld_link_tests [list \
128 "Build pr22649-2a.so" \
129 "$LFLAGS -shared -gc-sections -print-gc-sections" \
137 "Build pr22649-2b.so" \
138 "$LFLAGS -shared -gc-sections -print-gc-sections" \
139 "tmpdir/pr22649-1.so" \
146 if { [istarget mips*-*-*] && ![istarget *-*-elf*] } {
147 set actions {{ld pr22649-2cd-mips.msg}}
151 run_ld_link_tests [list \
153 "Build pr22649-2c.so" \
154 "$LFLAGS -shared -gc-sections -print-gc-sections" \
162 "Build pr22649-2d.so" \
163 "$LFLAGS -shared -gc-sections -print-gc-sections" \
164 "tmpdir/pr22649-1.so" \
173 run_ld_link_tests [list \
175 "DT_TEXTREL in shared lib" \
176 "$LFLAGS -shared --warn-shared-textrel" \
181 {readelf {-d --wide} textrel.rd}} \
186 # The MIPS backend sets SHF_WRITE, in `mips_elf_create_dynamic_relocation',
187 # for any section that has a dynamic relocation attached and consequently
188 # this test is irrelevant for MIPS targets. We don't have a clean way to
189 # request UNSUPPORTED result, which would be the most appropriate here,
190 # so we just XFAIL the test instead.
191 run_ld_link_tests [list \
193 "DT_TEXTREL map file warning" \
194 "$LFLAGS -shared -M" \
201 ] "cris*-*-*" "mips*-*-*"
203 # PR ld/20828 check for correct dynamic symbol table entries where:
204 # - symbols have been defined with a linker script,
205 # - the same symbols have been seen in shared library used in the link,
206 # - the shared library symbols have been swept in section garbage collection.
207 # Verify that the symbols are global rather than local and that a version
208 # script adjusts them accordingly.
209 # Also verify that a version definition supplied by an object rather than
210 # a version script and forcibly exported is unaffected by section GC.
211 if { [check_gc_sections_available] } {
212 run_ld_link_tests [list \
214 "PR ld/20828 dynamic symbols with section GC\
215 (auxiliary shared library)" \
216 "$LFLAGS -shared --gc-sections -T pr20828.ld" "" "$AFLAGS_PIC" \
218 {{readelf --dyn-syms pr20828-a.sd} \
219 {readelf --dyn-syms pr20828-b.sd}} \
222 "PR ld/20828 dynamic symbols with section GC (plain)" \
223 "$LFLAGS -shared --gc-sections -T pr20828.ld" \
224 "tmpdir/libpr20828.so" "$AFLAGS_PIC" \
226 {{readelf --dyn-syms pr20828-a.sd} \
227 {readelf --dyn-syms pr20828-b.sd}} \
230 "PR ld/20828 dynamic symbols with section GC (version script)" \
231 "$LFLAGS -shared --gc-sections -T pr20828.ld\
232 --version-script=pr20828.ver" \
233 "tmpdir/libpr20828.so" \
236 {{readelf --dyn-syms pr20828-b.sd} \
237 {readelf --dyn-syms pr20828-c.sd}} \
240 "PR ld/20828 dynamic symbols with section GC\
241 (versioned shared library)" \
242 "$LFLAGS -shared --gc-sections -T pr20828.ld\
243 --version-script=pr20828-v.ver" \
246 {{readelf --dyn-syms pr20828-c.sd} \
247 {readelf --dyn-syms pr20828-d.sd} \
248 {readelf --dyn-syms pr20828-e.sd}} \
251 "PR ld/20828 dynamic symbols with section GC (versioned)" \
252 "$LFLAGS -shared --gc-sections -T pr20828.ld\
253 --version-script=pr20828-v.ver" \
254 "tmpdir/libpr20828-v.so" \
257 {{readelf --dyn-syms pr20828-c.sd} \
258 {readelf --dyn-syms pr20828-d.sd} \
259 {readelf --dyn-syms pr20828-e.sd}} \
262 "PR ld/20828 forcibly exported symbol version without section GC" \
263 "$LFLAGS --no-dynamic-linker -e foo -E -T pr20828-v.ld" "" "" \
265 {{objdump -p pr20828-v.od}} \
268 "PR ld/20828 forcibly exported symbol version with section GC" \
269 "$LFLAGS --no-dynamic-linker -e foo --gc-sections -E -T pr20828-v.ld" "" "" \
271 {{objdump -p pr20828-v.od}} \
274 # PR ld/21233 check for correct dynamic symbol table entries where:
275 # - a symbol has been defined in a shared library used in the link,
276 # - the symbol has been referenced from a section swept in garbage collection,
277 # - the symbol has also been forced to be entered in the output file as an
278 # undefined symbol, either with a command-line option or a linker script
280 # Verify that the undefined symbol is global rather than local.
281 if { [check_gc_sections_available] } {
282 run_ld_link_tests [list \
284 "PR ld/21233 dynamic symbols with section GC\
285 (auxiliary shared library)" \
286 "$LFLAGS -shared -T pr21233.ld" "" "$AFLAGS_PIC" \
288 {{readelf --dyn-syms pr21233-l.sd}} \
291 run_ld_link_tests [list \
293 "PR ld/21233 dynamic symbols with section GC (--undefined)" \
294 "$LFLAGS --gc-sections -e foo --undefined=bar -T pr21233.ld" \
295 "tmpdir/libpr21233.so" "" \
297 {{readelf --dyn-syms pr21233.sd}} \
300 run_ld_link_tests [list \
302 "PR ld/21233 dynamic symbols with section GC (--require-defined)" \
303 "$LFLAGS --gc-sections -e foo --require-defined=bar\
305 "tmpdir/libpr21233.so" "" \
307 {{readelf --dyn-syms pr21233.sd}} \
310 run_ld_link_tests [list \
312 "PR ld/21233 dynamic symbols with section GC (EXTERN)" \
313 "$LFLAGS --gc-sections -e foo -T pr21233-e.ld" \
314 "tmpdir/libpr21233.so" "" \
316 {{readelf --dyn-syms pr21233.sd}} \
320 if { [check_gc_sections_available] } {
321 run_ld_link_tests [list \
324 "$LFLAGS -shared --version-script pr22150.ver" \
333 "$LFLAGS -e _start --gc-sections" \
334 "tmpdir/pr22150.so" \
337 {{readelf -V pr22150.vd}} \
342 switch -glob $target_triplet {
343 # exclude targets that don't support copy relocs
351 run_ld_link_tests [list \
354 "$LFLAGS -shared --version-script=pr25458.map" \
363 "$LFLAGS -e _start --gc-sections" \
364 "tmpdir/pr25458.so" \
367 {{readelf {--dyn-sym --wide} pr25458.rd}} \
375 set ASFLAGS $old_ASFLAGS
378 {"Build pr14170a.o" "" "" "" {pr14170a.s} {} "pr14170.a" }
380 run_ld_link_tests [list \
381 [list "Build shared library for pr14170" \
382 "-shared" "" "$AFLAGS_PIC" "pr14170b.s" {} "pr14170.so" ] \
385 # bfin does not currently support copy relocs.
386 run_ld_link_tests [list \
387 [list "PR ld/14170" \
388 "$LFLAGS --no-dynamic-linker tmpdir/pr14170a.o tmpdir/pr14170.so" "" \
390 {pr14170c.s} { } "pr14170" ] \
393 # Targets that use _bfd_generic_link_add_symbols won't pass pr21703 tests
394 # Nor will hppa64 with dot-symbols.
395 run_ld_link_tests [list \
396 [list "PR ld/21703 shared" \
397 "-shared --allow-multiple-definition --version-script pr21703.ver\
398 tmpdir/pr21703-3.o tmpdir/pr21703-4.o" "" "$AFLAGS_PIC" \
399 {pr21703-3.s pr21703-4.s} {{readelf {--dyn-syms} pr21703-shared.sd}} \
401 ] \[is_generic\] hppa64-*-*
403 # This target requires extra GAS options when building non-PIC code
404 # for linking with shared libraries.
406 if [istarget "mips*-*-*"] {
407 append AFLAGS_NONPIC " -call_nonpic"
410 # Run a test to check linking a shared library with a broken linker
411 # script that accidentally marks dynamic sections as notes. The
412 # resulting executable is not expected to work, but the linker
413 # should not seg-fault whilst creating the binary.
414 run_ld_link_tests [list \
415 [list "Build shared library for broken linker script test" \
416 "-shared --hash-style=sysv" "" "$AFLAGS_PIC" "note-3.s" \
419 [list "Link using broken linker script" \
420 "$LFLAGS --script note-3.t tmpdir/note-3.so" "" "" "" \
421 { { ld "note-3.l" } } \
425 run_ld_link_tests [list \
426 [list "Build pr17068.so" \
427 "-shared" "" "$AFLAGS_PIC" \
428 {pr17068d.s} {} "pr17068.so"] \
429 [list "Build pr17068a.a" \
431 {pr17068a.s pr17068c.s pr17068ez.s} {} "pr17068a.a"] \
432 [list "Build pr17068b.a" \
434 {pr17068b.s pr17068e.s} {} "pr17068b.a"] \
437 # bfin does not currently support copy relocs.
439 {"pr17068 link --as-needed lib in group"
440 "$LFLAGS --as-needed --no-dynamic-linker"
441 "--start-group tmpdir/pr17068a.a tmpdir/pr17068.so tmpdir/pr17068b.a\
443 {start.s pr17068.s} {} "pr17068"}
446 # Fails on MIPS because ABI trickery means that a NULL reloc is emitted.
447 # Fails on bfin because relocations are not created.
448 run_ld_link_tests [list \
449 [list "-Bsymbolic-functions" \
450 "-shared -Bsymbolic-functions" "" "$AFLAGS_PIC" \
451 {symbolic-func.s} {{readelf {-r --wide} symbolic-func.r}} \
452 "symbolic-func.so"] \
453 ] "mips*-*-*" "bfin-*-*"
455 run_ld_link_tests [list \
456 [list "Build pr20995.so" \
457 "-shared" "" "$AFLAGS_PIC" \
458 {pr20995b.s} {} "pr20995.so"] \
461 # xfail on arm*-*-eabi*. The list can be enlarged to those targets that
462 # don't support GNU_RELRO. For more details, please see discussions at:
463 # https://sourceware.org/ml/binutils/2017-01/msg00441.html
464 run_ld_link_tests [list \
465 [list "Build pr20995-2.so" \
466 "-shared -z relro" "" "$AFLAGS_PIC" \
467 {pr20995c.s} {{readelf {-l --wide} pr20995-2so.r}} "pr20995-2.so"] \
468 ] "tic6x-*-*" "arm*-*-eabi*" "hppa*64*-*-hpux*" "aarch64*-*-elf*" \
469 "*-*-lynxos*" "arm*-*-nto*" "i?86-*-nto*" "sh*-*-nto*"
471 # These targets don't copy dynamic variables into .bss.
472 setup_xfail "alpha-*-*" "bfin-*-*" "ia64-*-*" "xtensa-*-*"
473 # or don't have .data.rel.ro
474 setup_xfail "hppa*64*-*-hpux*"
475 run_ld_link_tests [list \
478 "$LFLAGS" "tmpdir/pr20995.so" "$AFLAGS_NONPIC" \
479 {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995"]]
481 # xfail on arm*-*-eabi* is particularly because of no support of GNU_RELRO.
482 # Please see the link above for details.
483 setup_xfail "alpha-*-*" "bfin-*-*" "ia64-*-*" "xtensa-*-*" "arm*-*-eabi*"
484 setup_xfail "hppa*64*-*-hpux*" "aarch64*-*-elf*"
485 run_ld_link_tests [list \
488 "$LFLAGS" "tmpdir/pr20995-2.so" "$AFLAGS_NONPIC" \
489 {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995-2"]
490 ] "*-*-lynxos*" "arm*-*-nto*" "i?86-*-nto*" "sh*-*-nto*"
492 run_ld_link_tests [list \
493 [list "Build pr22374 shared library" \
494 "-shared" "" "$AFLAGS_PIC" "pr22374b.s" {} "pr22374.so" ] \
496 if { ![istarget "alpha-*-*"]
497 && ![istarget "csky-*-*"]
498 && ![istarget "frv-*-*"]
499 && ![istarget "hppa*-*-*"]
500 && ![istarget "i?86-*-*"]
501 && ![istarget "ia64-*-*"]
502 && ![istarget "microblaze-*-*"]
503 && ![istarget "powerpc*-*-*"]
504 && ![istarget "x86_64-*-*"]
505 && ![istarget "xtensa-*-*"] } {
506 # The next test checks that copy relocs are not used unnecessarily,
507 # but that is just an optimization so don't complain loudly.
511 {"pr22374 function pointer initialization"
512 "" "tmpdir/pr22374.so" "" "pr22374a.s"
513 { {readelf {--wide -r --dyn-syms} "pr22374-1.r"}
514 {readelf {--wide -r} "pr22374-2.r"} }
518 if { [istarget *-*-linux*]
519 || [istarget *-*-nacl*]
520 || [istarget *-*-gnu*] } {
522 {"Weak symbols in dynamic objects 1 (support)"
523 "-shared" "" "" {weak-dyn-1a.s}
526 {"Weak symbols in dynamic objects 1 (main test)"
527 "-shared tmpdir/libweakdyn1a.so -Tweak-dyn-1.ld" "" "" {weak-dyn-1b.s}
528 {{readelf {--relocs --wide} weak-dyn-1.rd}}
533 # Check to see if the C compiler works
534 if { ![check_compiler_available] } {
538 # Add -ldl to extralibs if needed
540 if { ![istarget *-*-freebsd*]} {
547 {foo.c} {} "libfoo.so"}
548 {"Build versioned libfoo.so"
549 "-shared -Wl,--version-script=foo.map" "-fPIC"
550 {foo.c} {} "libfoov.so"}
553 {begin.c end.c} {} "libbar.so"}
554 {"Build warn libbar.so"
557 {{readelf {-S --wide} libbarw.rd}
558 {warning "^.*beginwarn.c:7: warning: function foo is deprecated\n?$"}}
560 {"Build hidden libbar.so"
562 {begin.c endhidden.c} {} "libbarh.so"}
563 {"Build protected libbar.so"
565 {begin.c endprotected.c} {} "libbarp.so"}
566 {"Build libbar.so with libfoo.so"
567 "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
568 {end.c} {} "libbarfoo.so"}
569 {"Build libar.so with versioned libfoo.so"
570 "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
571 {end.c} {} "libbarfoov.so"}
572 {"Build hidden libbar.so with libfoo.so"
573 "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
574 {endhidden.c} {} "libbarhfoo.so"}
575 {"Build hidden libar.so with versioned libfoo.so"
576 "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
577 {endhidden.c} {} "libbarhfoov.so"}
578 {"Build protected libbar.so with libfoo.so"
579 "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
580 {endprotected.c} {} "libbarpfoo.so"}
581 {"Build protected libbar.so with versioned libfoo.so"
582 "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
583 {endprotected.c} {} "libbarpfoov.so"}
586 {dl1.c} {} "libdl1.so"}
587 {"Build libdl2a.so with --dynamic-list=dl2.list"
588 "-shared -Wl,--dynamic-list=dl2.list" "-fPIC"
589 {dl2.c dl2xxx.c} {} "libdl2a.so"}
590 {"Build libdl2a.so with --dynamic-list=dl2a.list"
591 "-shared -Wl,--dynamic-list=dl2a.list" "-fPIC"
592 {dl2.c dl2xxx.c} {} "libdl2a.so"}
593 {"Build libdl2a.so with --dynamic-list-data"
594 "-shared -Wl,--dynamic-list-data" "-fPIC"
595 {dl2.c dl2xxx.c} {} "libdl2a.so"}
596 {"Build libdl2b.so with --dynamic-list=dl2.list and dl2xxx.list"
597 "-shared -Wl,--dynamic-list=dl2.list,--dynamic-list=dl2xxx.list" "-fPIC"
598 {dl2.c dl2xxx.c} {} "libdl2b.so"}
599 {"Build libdl2c.so with --dynamic-list-data and dl2xxx.list"
600 "-shared -Wl,--dynamic-list-data,--dynamic-list=dl2xxx.list" "-fPIC"
601 {dl2.c dl2xxx.c} {} "libdl2c.so"}
602 {"Build libdl2d.so with --dynamic-list-data -Bsymbolic"
603 "-shared -Wl,-Bsymbolic,--dynamic-list-data" "-fPIC"
604 {dl2.c dl2xxx.c} {} "libdl2d.so"}
605 {"Build libdl2e.so with --export-dynamic-symbol=foo"
606 "-shared -Wl,--export-dynamic-symbol=foo" "-fPIC"
607 {dl2.c dl2xxx.c} {} "libdl2e.so"}
608 {"Build libdl2f.so with --dynamic-list=dlempty.list and --export-dynamic-symbol=foo"
609 "-shared -Wl,--dynamic-list=dlempty.list,--export-dynamic-symbol=foo" "-fPIC"
610 {dl2.c dl2xxx.c} {} "libdl2f.so"}
611 {"Build libdl2g.so with --export-dynamic-symbol-list=dl2.list"
612 "-shared -Wl,--export-dynamic-symbol-list=dl2.list" "-fPIC"
613 {dl2.c dl2xxx.c} {} "libdl2g.so"}
614 {"Build libdl2h.so with --dynamic-list=dlempty.list and --export-dynamic-symbol-list=dl2.list"
615 "-shared -Wl,--dynamic-list=dlempty.list,--export-dynamic-symbol-list=dl2.list" "-fPIC"
616 {dl2.c dl2xxx.c} {} "libdl2h.so"}
617 {"Build libdl2i.so with -Bsymbolic and --export-dynamic-symbol=foo"
618 "-shared -Wl,-Bsymbolic,--export-dynamic-symbol=foo" "-fPIC"
619 {dl2.c dl2xxx.c} {} "libdl2i.so"}
620 {"Build libdl2j.so with -Bsymbolic and --export-dynamic-symbol-list=dl2.list"
621 "-shared -Wl,-Bsymbolic,--export-dynamic-symbol-list=dl2.list" "-fPIC"
622 {dl2.c dl2xxx.c} {} "libdl2j.so"}
623 {"Build libdl2k.so with --export-dynamic-symbol-list=dl2.list and -Bsymbolic"
624 "-shared -Wl,--export-dynamic-symbol-list=dl2.list,-Bsymbolic" "-fPIC"
625 {dl2.c dl2xxx.c} {} "libdl2k.so"}
626 {"Build libdl4a.so with --dynamic-list=dl4.list"
627 "-shared -Wl,--dynamic-list=dl4.list" "-fPIC"
628 {dl4.c dl4xxx.c} {} "libdl4a.so"}
629 {"Build libdl4b.so with --dynamic-list-data"
630 "-shared -Wl,--dynamic-list-data" "-fPIC"
631 {dl4.c dl4xxx.c} {} "libdl4b.so"}
632 {"Build libdl4c.so with --dynamic-list=dl4.list and dl4xxx.list"
633 "-shared -Wl,--dynamic-list=dl4.list,--dynamic-list=dl4xxx.list" "-fPIC"
634 {dl4.c dl4xxx.c} {} "libdl4c.so"}
635 {"Build libdl4d.so with --dynamic-list-data and dl4xxx.list"
636 "-shared -Wl,--dynamic-list-data,--dynamic-list=dl4xxx.list" "-fPIC"
637 {dl4.c dl4xxx.c} {} "libdl4d.so"}
638 {"Build libdl4e.so with -Bsymbolic-functions --dynamic-list-cpp-new"
639 "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC"
640 {dl4.c dl4xxx.c} {} "libdl4e.so"}
641 {"Build libdl4f.so with --dynamic-list-cpp-new -Bsymbolic-functions"
642 "-shared -Wl,--dynamic-list-cpp-new,-Bsymbolic-functions" "-fPIC"
643 {dl4.c dl4xxx.c} {} "libdl4f.so"}
646 {dl6.c} {} "libdl6a.so"}
647 {"Build libdl6b.so with -Bsymbolic --dynamic-list-data"
648 "-shared -Wl,-Bsymbolic,--dynamic-list-data" "-fPIC"
649 {dl6.c} {} "libdl6b.so"}
650 {"Build libdl6c.so with -Bsymbolic"
651 "-shared -Wl,-Bsymbolic" "-fPIC"
652 {dl6.c} {} "libdl6c.so"}
653 {"Build libdl6d.so with --dynamic-list-data -Bsymbolic"
654 "-shared -Wl,--dynamic-list-data,-Bsymbolic" "-fPIC"
655 {dl6.c} {} "libdl6d.so"}
658 {data1.c} {} "libdata1.so"}
661 {data2.c} {} "libdata2.so"}
663 "-r -nostdlib" "-fcommon"
664 {comm1.c} {} "libcomm1.o"}
667 {func1.c} {} "libfunc1.so"}
668 {"Build libpr9676-1.a"
670 {pr9676-1.c} {} "libpr9676-1.a"}
671 {"Build libpr9676-2.a"
673 {pr9676-2.c} {} "libpr9676-2.a"}
674 {"Build libpr9676-3.so"
676 {pr9676-3.c} {} "libpr9676-3.so"}
677 {"Build libpr9676-4.so"
679 {pr9676-4.c} {} "libpr9676-4.so"}
680 {"Build libpr9676-4a.so"
681 "-shared tmpdir/pr9676-4.o -Ltmpdir -lpr9676-3 -Wl,--start-group -lpr9676-1 -lpr9676-2 -Wl,--end-group"
683 {dummy.c} {{readelf {-s} pr9676.rd}} "libpr9676-4a.so"}
684 {"Build libpr9679.so"
685 "-shared" "-fPIC -O0"
686 {pr9679-1.c pr9679-2.c} {{readelf {-s} pr9679.rd}} "libpr9679.so"}
687 {"Build libpr11138-1.so"
688 "-shared -Wl,--version-script=pr11138-1.map" "-fPIC"
689 {pr11138-1.c} {} "libpr11138-1.so"}
690 {"Build libpr11138-2.o"
692 {pr11138-2.c} {} "libpr11138-2.o"}
693 {"Build pr13250-1.so"
694 "-shared" "-fPIC -fcommon"
695 {pr13250-1.c} {} "libpr13250-1.so"}
696 {"Build pr13250-2.so with libpr13250-1.so"
697 "-shared -Wl,--no-as-needed tmpdir/libpr13250-1.so" "-fPIC -fcommon"
698 {pr13250-2.c} {} "libpr13250-2.so"}
699 {"Build libpr13250-3.o"
700 "-r -nostdlib" "-fcommon"
701 {pr13250-3.c} {} "libpr13250-3.o"}
702 {"Build libpr14323-2.so"
703 "-shared" "-fPIC -fcommon"
704 {pr14323-2.c} {} "libpr14323-2.so"}
707 {pr14862-1.c} {} "libpr14862-1.o"}
708 {"Build libpr14862.so"
709 "-shared -Wl,--version-script=pr11138-1.map" "-fPIC"
710 {pr14862-2.c} {} "libpr14862.so"}
711 {"Build libneeded1b.so"
713 {needed1b.c} {} "libneeded1b.so"}
714 {"Build libneeded1a.so"
715 "-shared -Wl,--add-needed,--no-as-needed -Ltmpdir -lneeded1b" "-fPIC"
716 {needed1a.c} {} "libneeded1a.so"}
717 {"Build libneeded1c.o"
719 {needed1c.c} {} "libneeded1c.o"}
720 {"Build libneeded1pic.o"
721 "-r -nostdlib" "-fPIC"
722 {needed1c.c} {} "libneeded1pic.o"}
723 {"Build needed1a.so with --add-needed"
724 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--add-needed,-rpath=tmpdir,-rpath-link=tmpdir,-z,defs -Ltmpdir -lneeded1a" ""
725 {dummy.c} {} "needed1a.so"}
726 {"Build needed1b.so with --copy-dt-needed-entries"
727 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--copy-dt-needed-entries,-rpath=tmpdir,-rpath-link=tmpdir,-z,defs -Ltmpdir -lneeded1a" ""
728 {dummy.c} {} "needed1b.so"}
729 {"Build needed1a.so with --no-add-needed"
730 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--no-add-needed -Ltmpdir -lneeded1a" ""
731 {dummy.c} {} "needed1c.so"}
732 {"Build needed1b.so with --no-copy-dt-needed-entries"
733 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--no-copy-dt-needed-entries -Ltmpdir -lneeded1a" ""
734 {dummy.c} {} "needed1d.so"}
737 {rel.c} {} "librel.so"}
738 {"Build libneeded2a.so"
740 {needed2a.c} {} "libneeded2a.so"}
741 {"Build libneeded2b.so"
742 "-shared -Wl,--version-script,needed2.ver" "-fPIC"
743 {needed2b.c} {} "libneeded2b.so"}
744 {"Build libneeded2c.o"
746 {needed2c.c} {} "libneeded2c.o"}
748 "tmpdir/libneeded2c.o -Wl,--as-needed tmpdir/libneeded2a.so tmpdir/libneeded2b.so" ""
749 {dummy.c} {} "needed2"}
750 {"Build libneeded3a.so"
751 "-shared -Wl,--no-add-needed" "-fPIC"
752 {needed1a.c} {} "libneeded3a.so"}
753 {"Build libneeded3b.so"
754 "-shared -Wl,--no-as-needed,--add-needed -Ltmpdir -lneeded1b" "-fPIC"
755 {dummy.c} {} "libneeded3b.so"}
758 {needed3.c} {} "libneeded3.so"}
760 "tmpdir/needed3.o -Wl,--as-needed -Ltmpdir -lneeded3a -lneeded3b -lneeded1b" ""
761 {dummy.c} {} "needed3"}
762 {"Build libpr2404a.so"
764 {pr2404a.c} {} "libpr2404a.so"}
765 {"Build libpr2404n.so"
766 "-shared -Wl,-z,now" "-fPIC"
767 {pr2404a.c} {} "libpr2404n.so"}
768 {"Build libpr2404b.a"
770 {pr2404b.c} {} "libpr2404b.a"}
772 "-Wl,--no-dynamic-linker,-export-dynamic,--gc-sections" "-ffunction-sections"
773 {rdynamic-1.c} {{readelf {-s} rdynamic-1.rd}} "rdynamic-1"}
775 "-Wl,--no-dynamic-linker,--dynamic-list,dynamic-1.syms -Wl,--gc-sections" "-ffunction-sections"
776 {dynamic-1.c} {{readelf {-s} dynamic-1.rd}} "dynamic-1"}
777 {"Build libpr16496a.so"
778 "-shared -Wl,--version-script=pr16496a.map" "-fPIC"
779 {pr16496a.c} {} "libpr16496a.so"}
780 {"Build libpr16496b.a"
782 {pr16496b.c} {} "libpr16496b.a"}
783 {"Build libpr16496b.so"
784 "-shared -Wl,--no-as-needed tmpdir/pr16496b.o tmpdir/libpr16496a.so" ""
785 {dummy.c} {{objdump {-R} pr16496b.od}} "libpr16496b.so"}
786 {"Build libpr16452a.so"
787 "-shared -Wl,-soname,libpr16452a.so,--version-script=pr16452.map" "-fPIC"
788 {pr16452a.c} {} "libpr16452a.so"}
789 {"Build libpr16452b.so"
790 "-shared -Wl,-soname,libpr16452b.so,--no-as-needed tmpdir/libpr16452a.so" "-fPIC"
791 {dummy.c} {} "libpr16452b.so"}
793 "-Wl,--no-as-needed,-rpath=tmpdir,-rpath-link=tmpdir tmpdir/libpr16452b.so" ""
794 {pr16452b.c} {{objdump {-p} pr16452.od}} "pr16452"}
796 "-Wl,--no-as-needed,-rpath=tmpdir,-rpath-link=tmpdir tmpdir/libpr16452b.so" ""
797 {pr16452b.c} {{objdump {-p} pr16457.od}} "pr16457"}
798 {"Build libpr18458a.so"
799 "-shared -Wl,-z,now" "-fPIC"
800 {pr18458a.c} {} "libpr18458a.so"}
801 {"Build libpr18458b.so"
802 "-shared -Wl,-z,now tmpdir/libpr18458a.so" "-fPIC"
803 {pr18458b.c} {} "libpr18458b.so"}
805 # pr19073.s uses .set, which has a different meaning on alpha.
806 if { ![istarget alpha-*-*] } {
810 {pr19073.s} {} "pr19073a.o"}
811 {"Build libpr19073.so"
812 "-shared -Wl,--version-script=pr19073.map tmpdir/pr19073a.o" "-fPIC"
813 {dummy.c} {{readelf {--dyn-syms --wide} pr19073.rd}} "libpr19073.so"}
817 {"Build pr21964-1a.so"
819 {pr21964-1a.c} {} "pr21964-1a.so"}
820 {"Build pr21964-1b.so"
822 {pr21964-1b.c} {} "pr21964-1b.so"}
823 {"Build pr21964-2a.so"
825 {pr21964-2a.c} {} "pr21964-2a.so"}
826 {"Build pr21964-2b.so"
828 {pr21964-2b.c} {} "pr21964-2b.so"}
829 {"Build pr21964-3a.so"
831 {pr21964-3a.c} {} "pr21964-3a.so"}
833 "-shared" "-fPIC -g -O2"
834 {pr21978a.c pr21978b.c} {{objdump {-Sl} pr21978.od}} "pr21978.so"}
837 run_cc_link_tests $build_tests
839 run_ld_link_tests [list \
841 "pr22269-1 (static pie undefined weak)" \
842 "-pie -e _start --no-dynamic-linker -z text -z nocombreloc " \
846 {{readelf -rW pr22269-1.rd}} \
852 set run_tests [list \
853 [list "Run normal with libfoo.so" \
854 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/end.o" "" \
855 {main.c} "normal" "normal.out" ] \
856 [list "Run protected with libfoo.so" \
857 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/endprotected.o" "" \
858 {main.c} "protected" "normal.out" ] \
859 [list "Run hidden with libfoo.so" \
860 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/endhidden.o" "" \
861 {main.c} "hidden" "hidden.out" ] \
862 [list "Run normal with versioned libfoo.so" \
863 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/end.o" "" \
864 {main.c} "normalv" "normal.out" ] \
865 [list "Run warn with versioned libfoo.so" \
866 "-Wl,--no-as-needed tmpdir/beginwarn.o tmpdir/libfoov.so" "" \
867 {main.c} "warn" "warn.out" \
868 "" "c" {^.*beginwarn.c:7: warning: function foo is deprecated\n?$} ] \
869 [list "Run protected with versioned libfoo.so" \
870 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/endprotected.o" "" \
871 {main.c} "protected" "normal.out" ] \
872 [list "Run hidden with versioned libfoo.so" \
873 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/endhidden.o" "" \
874 {main.c} "hiddenv" "hidden.out" ] \
875 [list "Run normal libbar.so with libfoo.so" \
876 "-Wl,--no-as-needed tmpdir/libbarfoo.so tmpdir/libfoo.so" "" \
877 {main.c} "normal" "normal.out" ] \
878 [list "Run protected libbar.so with libfoo.so" \
879 "-Wl,--no-as-needed tmpdir/libbarpfoo.so tmpdir/libfoo.so" "" \
880 {main.c} "protected" "normal.out" ] \
881 [list "Run hidden libbar.so with libfoo.so" \
882 "-Wl,--no-as-needed tmpdir/libbarhfoo.so tmpdir/libfoo.so" "" \
883 {main.c} "hidden" "hidden.out" ] \
884 [list "Run normal libbar.so with versioned libfoo.so" \
885 "-Wl,--no-as-needed tmpdir/libbarfoov.so tmpdir/libfoov.so" "" \
886 {main.c} "normal" "normal.out" ] \
887 [list "Run protected libbar.so with versioned libfoo.so" \
888 "-Wl,--no-as-needed tmpdir/libbarpfoov.so tmpdir/libfoov.so" "" \
889 {main.c} "protected" "normal.out" ] \
890 [list "Run hidden libbar.so with versioned libfoo.so" \
891 "-Wl,--no-as-needed tmpdir/libbarhfoov.so tmpdir/libfoov.so" "" \
892 {main.c} "hidden" "hidden.out" ] \
893 [list "Run with libdl2a.so" \
894 "-Wl,--no-as-needed tmpdir/libdl2a.so" "" \
895 {dl2main.c} "dl2a" "dl2a.out" ] \
896 [list "Run with libdl2b.so" \
897 "-Wl,--no-as-needed tmpdir/libdl2b.so" "" \
898 {dl2main.c} "dl2b" "dl2b.out" ] \
899 [list "Run with libdl2c.so" \
900 "-Wl,--no-as-needed tmpdir/libdl2c.so" "" \
901 {dl2main.c} "dl2c" "dl2b.out" ] \
902 [list "Run with libdl2d.so" \
903 "-Wl,--no-as-needed tmpdir/libdl2d.so" "" \
904 {dl2main.c} "dl2d" "dl2a.out" ] \
905 [list "Run with libdl2e.so" \
906 "-Wl,--no-as-needed tmpdir/libdl2e.so" "" \
907 {dl2main.c} "dl2e" "dl2b.out" ] \
908 [list "Run with libdl2f.so" \
909 "-Wl,--no-as-needed tmpdir/libdl2f.so" "" \
910 {dl2main.c} "dl2f" "dl2a.out" ] \
911 [list "Run with libdl2g.so" \
912 "-Wl,--no-as-needed tmpdir/libdl2g.so" "" \
913 {dl2main.c} "dl2g" "dl2b.out" ] \
914 [list "Run with libdl2h.so" \
915 "-Wl,--no-as-needed tmpdir/libdl2h.so" "" \
916 {dl2main.c} "dl2h" "dl2a.out" ] \
917 [list "Run with libdl2i.so" \
918 "-Wl,--no-as-needed tmpdir/libdl2i.so" "" \
919 {dl2main.c} "dl2i" "dl2a.out" ] \
920 [list "Run with libdl2j.so" \
921 "-Wl,--no-as-needed tmpdir/libdl2j.so" "" \
922 {dl2main.c} "dl2j" "dl2a.out" ] \
923 [list "Run with libdl2k.so" \
924 "-Wl,--no-as-needed tmpdir/libdl2k.so" "" \
925 {dl2main.c} "dl2k" "dl2a.out" ] \
926 [list "Run with libdl4a.so" \
927 "-Wl,--no-as-needed tmpdir/libdl4a.so" "" \
928 {dl4main.c} "dl4a" "dl4a.out" ] \
929 [list "Run with libdl4b.so" \
930 "-Wl,--no-as-needed tmpdir/libdl4b.so" "" \
931 {dl4main.c} "dl4b" "dl4a.out" ] \
932 [list "Run with libdl4c.so" \
933 "-Wl,--no-as-needed tmpdir/libdl4c.so" "" \
934 {dl4main.c} "dl4c" "dl4b.out" ] \
935 [list "Run with libdl4d.so" \
936 "-Wl,--no-as-needed tmpdir/libdl4d.so" "" \
937 {dl4main.c} "dl4d" "dl4b.out" ] \
938 [list "Run with libdl4e.so" \
939 "-Wl,--no-as-needed tmpdir/libdl4e.so" "" \
940 {dl4main.c} "dl4e" "dl4e.out" ] \
941 [list "Run with libdl4f.so" \
942 "-Wl,--no-as-needed tmpdir/libdl4f.so" "" \
943 {dl4main.c} "dl4f" "dl4e.out" ] \
944 [list "Run with libdata1.so" \
945 "-Wl,--no-as-needed tmpdir/libdata1.so" "" \
946 {dynbss1.c} "dynbss1" "pass.out" ] \
947 [list "Run with libdata2.so" \
948 "-Wl,--no-as-needed tmpdir/libdata2.so" "" \
949 {weakdef1.c} "weakdef1" "pass.out" ] \
950 [list "Run with libfunc1.so comm1.o" \
951 "-Wl,--no-as-needed tmpdir/libfunc1.so tmpdir/comm1.o" "" \
952 {dummy.c} "comm1" "pass.out" ] \
953 [list "Run with comm1.o libfunc1.so" \
954 "-Wl,--no-as-needed tmpdir/comm1.o tmpdir/libfunc1.so" "" \
955 {dummy.c} "comm1" "pass.out" ] \
956 [list "Run with pr11138-2.c libpr11138-1.so" \
957 "-Wl,--no-as-needed,--version-script=pr11138-2.map tmpdir/pr11138-2.o tmpdir/libpr11138-1.so" "" \
958 {dummy.c} "pr11138a" "pr11138.out" ] \
959 [list "Run with libpr11138-1.so pr11138-2.c" \
960 "-Wl,--no-as-needed,--version-script=pr11138-2.map tmpdir/libpr11138-1.so tmpdir/pr11138-2.o" "" \
961 {dummy.c} "pr11138b" "pr11138.out" ] \
962 [list "Run with pr13250-3.c, libpr13250-1.so and libpr13250-2.so" \
963 "-Wl,--as-needed tmpdir/pr13250-3.o tmpdir/libpr13250-1.so tmpdir/libpr13250-2.so" "-fcommon" \
964 {dummy.c} "pr13250" "pass.out" ] \
965 [list "Run with pr14323-1.c pr14323-2.so" \
966 "-Wl,--no-as-needed tmpdir/libpr14323-2.so" "" \
967 {pr14323-1.c} "pr14323" "pass.out" ] \
968 [list "Run with pr14862-1.c libpr14862.so" \
969 "-Wl,--as-needed tmpdir/libpr14862-1.o tmpdir/libpr14862.so" "" \
970 {dummy.c} "pr14862" "pr14862.out" ] \
971 [list "Link with --add-needed" \
972 "tmpdir/libneeded1c.o -Wl,--no-as-needed,--add-needed,-rpath=tmpdir,-rpath-link=tmpdir -Ltmpdir -lneeded1a" "" \
973 {dummy.c} "needed1a" "needed1.out" ] \
974 [list "Link with --copy-dt-needed-entries" \
975 "tmpdir/libneeded1c.o -Wl,--no-as-needed,--copy-dt-needed-entries,-rpath=tmpdir,-rpath-link=tmpdir -Ltmpdir -lneeded1a" "" \
976 {dummy.c} "needed1b" "needed1.out" ] \
977 [list "Run relmain" \
978 "-Wl,--no-as-needed,-rpath=tmpdir -Ltmpdir -lrel" "" \
979 {relmain.c} "relmain" "relmain.out" ] \
981 "-Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404a.so" "" \
982 {dummy.c} "pr2404" "pr2404.out" ] \
983 [list "Run pr2404n" \
984 "-Wl,-z,now -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404n.so" "" \
985 {dummy.c} "pr2404n" "pr2404.out" ] \
986 [list "Run pr18458" \
987 "-Wl,--no-as-needed,-z,now tmpdir/libpr18458a.so tmpdir/libpr18458b.so" "" \
988 {pr18458c.c} "pr18458" "pass.out" ] \
989 [list "Run pr21964-1" \
990 "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-1a.so tmpdir/pr21964-1b.so" "" \
991 {pr21964-1c.c} "pr21964-1" "pass.out" ] \
992 [list "Run pr21964-3" \
993 "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-1a.so tmpdir/pr21964-1b.so tmpdir/pr21964-3a.so" "" \
994 {pr21964-3c.c} "pr21964-3" "pass.out" ] \
997 # NetBSD ELF systems do not currently support the .*_array sections.
998 run_ld_link_exec_tests $run_tests "*-*-netbsdelf*"
1000 # These tests require dlopen support.
1001 set dlopen_run_tests [list \
1002 [list "Run dl1a with --dynamic-list=dl1.list and dlopen on libdl1.so" \
1003 "-Wl,--no-as-needed,--dynamic-list=dl1.list $extralibs" "" \
1004 {dl1main.c} "dl1a" "dl1.out" ] \
1005 [list "Run dl1b with --dynamic-list-data and dlopen on libdl1.so" \
1006 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
1007 {dl1main.c} "dl1b" "dl1.out" ] \
1008 [list "Run dl6a1 with --dynamic-list-data and dlopen on libdl6a.so" \
1009 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
1010 {dl6amain.c} "dl6a1" "dl6a.out" ] \
1011 [list "Run dl6a2 with -Bsymbolic-functions and dlopen on libdl6a.so" \
1012 "$NOPIE_LDFLAGS -Wl,--no-as-needed,-Bsymbolic-functions $extralibs" "" \
1013 {dl6amain.c} "dl6a2" "dl6b.out" "$NOPIE_CFLAGS" ] \
1014 [list "Run dl6a3 with -Bsymbolic and dlopen on libdl6a.so" \
1015 "-Wl,--no-as-needed,-Bsymbolic $extralibs" "" \
1016 {dl6amain.c} "dl6a3" "dl6b.out" ] \
1017 [list "Run dl6a4 with -Bsymbolic --dynamic-list-data and dlopen on libdl6a.so" \
1018 "-Wl,--no-as-needed,-Bsymbolic,--dynamic-list-data $extralibs" "" \
1019 {dl6amain.c} "dl6a4" "dl6a.out" ] \
1020 [list "Run dl6a5 with -Bsymbolic-functions --dynamic-list-cpp-new and dlopen on libdl6a.so" \
1021 "$NOPIE_LDFLAGS -Wl,--no-as-needed,-Bsymbolic-functions,--dynamic-list-cpp-new $extralibs" "" \
1022 {dl6amain.c} "dl6a5" "dl6b.out" "$NOPIE_CFLAGS" ] \
1023 [list "Run dl6a6 with --dynamic-list-cpp-new -Bsymbolic-functions and dlopen on libdl6a.so" \
1024 "$NOPIE_LDFLAGS -Wl,--no-as-needed,--dynamic-list-cpp-new,-Bsymbolic-functions $extralibs" "" \
1025 {dl6amain.c} "dl6a6" "dl6b.out" "$NOPIE_CFLAGS" ] \
1026 [list "Run dl6a7 with --dynamic-list-data -Bsymbolic and dlopen on libdl6a.so" \
1027 "$NOPIE_LDFLAGS -Wl,--no-as-needed,--dynamic-list-data,-Bsymbolic $extralibs" "" \
1028 {dl6amain.c} "dl6a7" "dl6a.out" "$NOPIE_CFLAGS" ] \
1029 [list "Run dl6b1 with --dynamic-list-data and dlopen on libdl6b.so" \
1030 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
1031 {dl6bmain.c} "dl6b1" "dl6a.out" ] \
1032 [list "Run dl6b2 with dlopen on libdl6b.so" \
1033 "-Wl,--no-as-needed $extralibs" "" \
1034 {dl6bmain.c} "dl6b2" "dl6b.out" ] \
1035 [list "Run dl6c1 with --dynamic-list-data and dlopen on libdl6c.so" \
1036 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
1037 {dl6cmain.c} "dl6c1" "dl6b.out" ] \
1038 [list "Run dl6d1 with --dynamic-list-data and dlopen on libdl6d.so" \
1039 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
1040 {dl6dmain.c} "dl6d1" "dl6a.out" ] \
1041 [list "Run pr21964-2" \
1042 "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-2a.so $extralibs" "" \
1043 {pr21964-2c.c} "pr21964-2" "pass.out" ] \
1044 [list "Run pr21964-5" \
1045 "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-1a.so $extralibs" "" \
1046 {pr21964-5.c} "pr21964-5" "pass.out" ] \
1049 # Only run them when libdl is available.
1050 if [check_libdl_available] {
1051 # XFAIL on NetBSD ELF systems as they do not currently support the .*_array
1053 run_ld_link_exec_tests $dlopen_run_tests "*-*-netbsdelf*"
1056 # Check --no-add-needed and --no-copy-dt-needed-entries
1057 set testname "--no-add-needed"
1058 set exec_output [run_host_cmd "$CC" "tmpdir/libneeded1c.o -Wl,--no-add-needed,-rpath-link=tmpdir -Ltmpdir -lneeded1a"]
1059 if { [ regexp "tmpdir/libneeded1b.so: .*: DSO missing" $exec_output ] } {
1064 set testname "--no-copy-dt-needed-entries"
1065 set exec_output [run_host_cmd "$CC" "tmpdir/libneeded1c.o -Wl,--no-copy-dt-needed-entries,-rpath-link=tmpdir -Ltmpdir -lneeded1a"]
1066 if { [ regexp "tmpdir/libneeded1b.so: .*: DSO missing" $exec_output ] } {
1071 set testname "--no-add-needed -shared"
1072 set exec_output [run_host_cmd "$CC" "-shared tmpdir/libneeded1pic.o -Wl,--no-add-needed,-z,defs -Ltmpdir -lneeded1a"]
1073 if { [ regexp "undefined reference to `\.?bar'" $exec_output ] } {
1078 set testname "--no-copy-dt-needed-entries -shared"
1079 set exec_output [run_host_cmd "$CC" "-shared tmpdir/libneeded1pic.o -Wl,--no-copy-dt-needed-entries,-z,defs -Ltmpdir -lneeded1a"]
1080 if { [ regexp "undefined reference to `\.?bar'" $exec_output ] } {
1086 # Check to see if the C++ compiler works
1087 if { [which $CXX] == 0 } {
1091 set build_cxx_tests {
1092 {"Build libdl3a.so with --dynamic-list=dl3.list"
1093 "-shared -Wl,--dynamic-list=dl3.list" "-fPIC"
1094 {dl3.cc} {} "libdl3a.so" "c++"}
1095 {"Build libdl3b.so with -Bsymbolic"
1096 "-shared -Wl,-Bsymbolic" "-fPIC"
1097 {dl3.cc} {} "libdl3b.so" "c++"}
1098 {"Build libdl3a.so with --dynamic-list-cpp-typeinfo"
1099 "-shared -Wl,--dynamic-list-cpp-typeinfo" "-fPIC"
1100 {dl3.cc} {} "libdl3c.so" "c++"}
1101 {"Build libdnew1a.so with --Bsymbolic-functions --dynamic-list-cpp-new"
1102 "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC -ansi"
1103 {del.cc new.cc} {} "libnew1a.so" "c++"}
1104 {"Build libdnew1b.so with --dynamic-list-data --dynamic-list-cpp-new"
1105 "-shared -Wl,--dynamic-list-data,--dynamic-list-cpp-new" "-fPIC -ansi"
1106 {del.cc new.cc} {} "libnew1b.so" "c++"}
1109 # "-shared -Bsymbolic" only works with gcc 4.5.0 and newer.
1110 # {"Run with libdl3b.so"
1111 # "tmpdir/libdl3b.so" ""
1112 # {dl3main.cc} "dl3b" "dl3b.out" "" "c++"}
1114 {"Run with libdl3a.so"
1115 "-Wl,--no-as-needed tmpdir/libdl3a.so" ""
1116 {dl3main.cc} "dl3a" "dl3a.out" "" "c++"}
1117 {"Run with libdl3c.so"
1118 "-Wl,--no-as-needed tmpdir/libdl3c.so" ""
1119 {dl3main.cc} "dl3c" "dl3a.out" "" "c++"}
1120 {"Run with libnew1a.so"
1121 "-Wl,--no-as-needed tmpdir/libnew1a.so" ""
1122 {dl5.cc} "dl5a" "dl5.out" "-ansi" "c++"}
1123 {"Run with libnew1b.so"
1124 "-Wl,--no-as-needed tmpdir/libnew1b.so" ""
1125 {dl5.cc} "dl5b" "dl5.out" "-ansi" "c++"}
1128 run_cc_link_tests $build_cxx_tests
1129 run_ld_link_exec_tests $run_cxx_tests
1131 if { [istarget *-*-linux*]
1132 || [istarget *-*-nacl*]
1133 || [istarget *-*-gnu*] } {
1134 run_cc_link_tests [list \
1136 "Build libpr2404b.a with PIE" \
1144 "Build pr19579a.o" \
1145 "" "-fPIE -fcommon" \
1151 "Build libpr19579.so" \
1159 "Build libpr19579now.so" \
1160 "-shared -Wl,-z,now" \
1167 "Build pr22393-2a.so" \
1168 "-shared -Wl,-z,separate-code" \
1171 {{readelf -lW pr22393-2a.rd} \
1172 {readelf -lW pr22393-2b.rd}} \
1176 "Build pr22393-2a-now.so" \
1177 "-shared -Wl,-z,separate-code,-z,now" \
1180 {{readelf -lW pr22393-2a.rd} \
1181 {readelf -lW pr22393-2b.rd}} \
1182 "pr22393-2a-now.so" \
1186 "$NOPIE_LDFLAGS -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a.so" \
1189 {{readelf -lW pr22393-2a.rd} \
1190 {readelf -lW pr22393-2b.rd}} \
1194 "Build pr22393-2 (PIE)" \
1195 "-pie -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a-now.so" \
1198 {{readelf -lW pr22393-2a.rd} \
1199 {readelf -lW pr22393-2b.rd}} \
1203 "Build pr22393-2 (static)" \
1204 "-static -Wl,-z,separate-code" \
1206 {pr22393-2a.c pr22393-2b.c} \
1207 {{readelf -lW pr22393-2a.rd} \
1208 {readelf -lW pr22393-2b.rd}} \
1209 "pr22393-2-static" \
1212 run_ld_link_exec_tests [list \
1214 "Run pr18458 with PIE" \
1215 "-pie -Wl,--no-as-needed,-z,now tmpdir/libpr18458a.so tmpdir/libpr18458b.so" \
1223 "Run pr2404 with PIE" \
1224 "-pie -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404a.so" \
1232 "Run pr2404 with PIE (-z now)" \
1233 "-pie -Wl,-z,now -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404n.so" \
1244 { pr18718.c check-ptr-eq.c } \
1250 "Run pr18718 (-z now)" \
1253 { pr18718.c check-ptr-eq.c } \
1259 "Run pr18718 with PIE (1)" \
1262 { pr18718.c check-ptr-eq.c } \
1265 "-O2 -fPIE -I../bfd" \
1268 "Run pr18718 with PIE (2)" \
1271 { pr18718.c check-ptr-eq.c } \
1274 "-O2 -fPIE -I../bfd" \
1277 "Run pr18718 with PIE (3)" \
1280 { pr18718.c check-ptr-eq.c } \
1283 "-O2 -fPIE -I../bfd" \
1286 "Run pr18718 with PIE (4)" \
1289 { pr18718.c check-ptr-eq.c } \
1292 "-O2 -fPIE -I../bfd" \
1295 "Run pr18718 with PIC (1)" \
1298 { pr18718.c check-ptr-eq.c } \
1301 "-O2 -fPIC -I../bfd" \
1304 "Run pr18718 with PIC (2)" \
1307 { pr18718.c check-ptr-eq.c } \
1310 "-O2 -fPIC -I../bfd" \
1313 "Run pr18718 with PIC (3)" \
1316 { pr18718.c check-ptr-eq.c } \
1319 "-O2 -fPIC -I../bfd" \
1322 "Run pr18718 with PIC (4)" \
1325 { pr18718.c check-ptr-eq.c } \
1328 "-O2 -fPIC -I../bfd" \
1332 "-pie -Wl,--no-as-needed,-z,text tmpdir/pr19579a.o tmpdir/libpr19579.so" \
1340 "Run pr19579 (-z now)" \
1341 "-pie -Wl,-z,now -Wl,--no-as-needed,-z,text tmpdir/pr19579a.o tmpdir/libpr19579.so" \
1350 "$NOPIE_LDFLAGS -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a.so" \
1358 "Run pr22393-2 (PIE)" \
1359 "-pie -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a-now.so" \
1367 "Run pr22393-2 (static)" \
1368 "-static -Wl,-z,separate-code" \
1370 {pr22393-2a.c pr22393-2b.c} \
1371 "pr22393-2-static" \
1389 proc mix_pic_and_non_pic {xfails cflags ldflags exe} {
1390 run_cc_link_tests [list \
1392 "Build libpr19719a.so" \
1393 "-shared -Wl,-soname,libpr19719.so" \
1400 "Build libpr19719b.so" \
1401 "-shared -Wl,-soname,libpr19719.so" \
1408 "Build libpr19719b.o" \
1417 send_log "cp tmpdir/libpr19719b.so tmpdir/libpr19719.so\n"
1418 exec cp tmpdir/libpr19719b.so tmpdir/libpr19719.so
1420 run_ld_link_exec_tests [list \
1422 "Run $exe fun defined" \
1423 "-Wl,--no-as-needed,-rpath,tmpdir $ldflags tmpdir/libpr19719b.o tmpdir/libpr19719.so" \
1425 { pr19719a.c pr19719c.c } \
1432 send_log "cp tmpdir/libpr19719a.so tmpdir/libpr19719.so\n"
1433 exec cp tmpdir/libpr19719a.so tmpdir/libpr19719.so
1435 foreach targ $xfails {
1440 unsupported "Run $exe fun undefined"
1444 set exec_output [run_host_cmd "tmpdir/$exe" ""]
1445 if {![string match "PASS" $exec_output]} {
1446 fail "Run $exe fun undefined"
1448 pass "Run $exe fun undefined"
1452 mix_pic_and_non_pic [list "arm*-*-*" "aarch64*-*-*"] "" "" "pr19719"
1453 mix_pic_and_non_pic [] "-fPIE" "-pie" "pr19719pie"
1456 if { [istarget "i?86-*-*"]
1457 || [istarget "x86_64-*-*"] } {
1458 set AFLAGS_PIE "-mrelax-relocations=yes"
1461 if { ([istarget "*-*-linux*"]
1462 || [istarget "*-*-nacl*"]
1463 || [istarget "*-*-gnu*"])
1464 && ![istarget "mips*-*-*"] } {
1465 run_ld_link_tests [list \
1467 "Build libpr23162a.so" \
1478 "-pie --no-as-needed tmpdir/libpr23162a.so" \
1482 {{readelf {-rW} pr23162.rd}} \
1487 "Build libpr23162b.so" \
1488 "-shared --version-script=pr23162.map" \
1498 "-pie --no-as-needed tmpdir/libpr23162b.so" \
1502 {{readelf {-rW} pr23162.rd}} \
1507 "Build libpr23161a.so" \
1512 {{readelf {--dyn-syms -rW} pr23161a.rd}} \
1514 "-fPIC -O2 $NOSANTIZE_CFLAGS" \
1518 "-pie --no-as-needed tmpdir/libpr23161a.so" \
1522 {{readelf {--dyn-syms -rW} pr23161b.rd}} \
1524 "-fPIC -O0 $NOSANTIZE_CFLAGS" \
1527 "Build libpr23161b.so" \
1528 "-shared --version-script=pr23161.map" \
1532 {{readelf {--dyn-syms -rW} pr23161a.rd}} \
1534 "-fPIC -O2 $NOSANTIZE_CFLAGS" \
1538 "-pie --no-as-needed tmpdir/libpr23161b.so" \
1542 {{readelf {--dyn-syms -rW} pr23161b.rd}} \
1544 "-fPIC -O0 $NOSANTIZE_CFLAGS" \
1549 if { [istarget "i?86-*-*"]
1550 || [istarget "x86_64-*-*"] } {
1551 run_ld_link_tests [list \
1553 "Build libpr23161c.so" \
1558 {{readelf {--dyn-syms -rW} pr23161c.rd}} \
1560 "-fPIC -O2 $NOSANTIZE_CFLAGS" \
1564 "-pie --no-as-needed tmpdir/libpr23161c.so" \
1568 {{readelf {--dyn-syms -rW} pr23161d.rd}} \
1570 "-fPIC -O0 $NOSANTIZE_CFLAGS" \
1575 run_ld_link_tests [list \
1576 [list "Build pr23658.so" \
1577 "-shared" "" "$AFLAGS_PIC" \
1578 {pr23658-1a.s} {} "pr23658.so"] \
1581 "--dynamic-linker tmpdir/pr23658.so --no-as-needed tmpdir/pr23658.so" \
1584 { pr23658-1a.s pr23658-1b.s pr23658-1c.s pr23658-1d.s start.s } \
1585 {{readelf {-lW} pr23658-2.rd}} \