1 # Expect script for various ELF tests.
2 # Copyright (C) 2006-2017 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
37 set old_ASFLAGS $ASFLAGS
39 # This target requires extra GAS options when building code for shared
42 if [istarget "tic6x-*-*"] {
43 append AFLAGS_PIC " -mpic -mpid=near"
45 # This target requires a non-default emulation for successful shared
46 # library/executable builds.
48 if [istarget "tic6x-*-*"] {
49 append LFLAGS " -melf32_tic6x_le"
52 if [is_underscore_target] {
53 set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1"
56 run_ld_link_tests [list \
68 "$LFLAGS -shared --version-script pr22471.t" \
69 "tmpdir/pr22471a.so" \
77 "$LFLAGS -rpath-link ." \
78 "tmpdir/pr22471b.so" \
86 # PR ld/20828 check for correct dynamic symbol table entries where:
87 # - symbols have been defined with a linker script,
88 # - the same symbols have been seen in shared library used in the link,
89 # - the shared library symbols have been swept in section garbage collection.
90 # Verify that the symbols are global rather than local and that a version
91 # script adjusts them accordingly.
92 # Also verify that a version definition supplied by an object rather than
93 # a version script and forcibly exported is unaffected by section GC.
94 if { [check_gc_sections_available] } {
95 run_ld_link_tests [list \
97 "PR ld/20828 dynamic symbols with section GC\
98 (auxiliary shared library)" \
99 "$LFLAGS -shared --gc-sections -T pr20828.ld" "" "$AFLAGS_PIC" \
101 {{readelf --dyn-syms pr20828-a.sd} \
102 {readelf --dyn-syms pr20828-b.sd}} \
105 "PR ld/20828 dynamic symbols with section GC (plain)" \
106 "$LFLAGS -shared --gc-sections -T pr20828.ld" \
107 "tmpdir/libpr20828.so" "$AFLAGS_PIC" \
109 {{readelf --dyn-syms pr20828-a.sd} \
110 {readelf --dyn-syms pr20828-b.sd}} \
113 "PR ld/20828 dynamic symbols with section GC (version script)" \
114 "$LFLAGS -shared --gc-sections -T pr20828.ld\
115 --version-script=pr20828.ver" \
116 "tmpdir/libpr20828.so" \
119 {{readelf --dyn-syms pr20828-b.sd} \
120 {readelf --dyn-syms pr20828-c.sd}} \
123 "PR ld/20828 dynamic symbols with section GC\
124 (versioned shared library)" \
125 "$LFLAGS -shared --gc-sections -T pr20828.ld\
126 --version-script=pr20828-v.ver" \
129 {{readelf --dyn-syms pr20828-c.sd} \
130 {readelf --dyn-syms pr20828-d.sd} \
131 {readelf --dyn-syms pr20828-e.sd}} \
134 "PR ld/20828 dynamic symbols with section GC (versioned)" \
135 "$LFLAGS -shared --gc-sections -T pr20828.ld\
136 --version-script=pr20828-v.ver" \
137 "tmpdir/libpr20828-v.so" \
140 {{readelf --dyn-syms pr20828-c.sd} \
141 {readelf --dyn-syms pr20828-d.sd} \
142 {readelf --dyn-syms pr20828-e.sd}} \
145 "PR ld/20828 forcibly exported symbol version without section GC" \
146 "$LFLAGS --no-dynamic-linker -e foo -E -T pr20828-v.ld" "" "" \
148 {{objdump -p pr20828-v.od}} \
151 "PR ld/20828 forcibly exported symbol version with section GC" \
152 "$LFLAGS --no-dynamic-linker -e foo --gc-sections -E -T pr20828-v.ld" "" "" \
154 {{objdump -p pr20828-v.od}} \
157 # PR ld/21233 check for correct dynamic symbol table entries where:
158 # - a symbol has been defined in a shared library used in the link,
159 # - the symbol has been referenced from a section swept in garbage collection,
160 # - the symbol has also been forced to be entered in the output file as an
161 # undefined symbol, either with a command-line option or a linker script
163 # Verify that the undefined symbol is global rather than local.
164 if { [check_gc_sections_available] } {
165 run_ld_link_tests [list \
167 "PR ld/21233 dynamic symbols with section GC\
168 (auxiliary shared library)" \
169 "$LFLAGS -shared -T pr21233.ld" "" "$AFLAGS_PIC" \
171 {{readelf --dyn-syms pr21233-l.sd}} \
174 run_ld_link_tests [list \
176 "PR ld/21233 dynamic symbols with section GC (--undefined)" \
177 "$LFLAGS --gc-sections -e foo --undefined=bar -T pr21233.ld" \
178 "tmpdir/libpr21233.so" "" \
180 {{readelf --dyn-syms pr21233.sd}} \
183 run_ld_link_tests [list \
185 "PR ld/21233 dynamic symbols with section GC (--require-defined)" \
186 "$LFLAGS --gc-sections -e foo --require-defined=bar\
188 "tmpdir/libpr21233.so" "" \
190 {{readelf --dyn-syms pr21233.sd}} \
193 run_ld_link_tests [list \
195 "PR ld/21233 dynamic symbols with section GC (EXTERN)" \
196 "$LFLAGS --gc-sections -e foo -T pr21233-e.ld" \
197 "tmpdir/libpr21233.so" "" \
199 {{readelf --dyn-syms pr21233.sd}} \
203 if { [check_gc_sections_available] } {
204 run_ld_link_tests [list \
207 "$LFLAGS -shared --version-script pr22150.ver" \
216 "$LFLAGS -e _start --gc-sections" \
217 "tmpdir/pr22150.so" \
220 {{readelf -V pr22150.vd}} \
226 set ASFLAGS $old_ASFLAGS
228 # Check to see if the C compiler works
229 if { [which $CC] == 0 } {
233 # Add -ldl to extralibs if needed
235 if { ![istarget *-*-freebsd*]} {
242 {foo.c} {} "libfoo.so"}
243 {"Build versioned libfoo.so"
244 "-shared -Wl,--version-script=foo.map" "-fPIC"
245 {foo.c} {} "libfoov.so"}
248 {begin.c end.c} {} "libbar.so"}
249 {"Build warn libbar.so"
252 {{readelf {-S --wide} libbarw.rd}
253 {warning "^.*beginwarn.c:7: warning: function foo is deprecated$"}}
255 {"Build hidden libbar.so"
257 {begin.c endhidden.c} {} "libbarh.so"}
258 {"Build protected libbar.so"
260 {begin.c endprotected.c} {} "libbarp.so"}
261 {"Build libbar.so with libfoo.so"
262 "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
263 {end.c} {} "libbarfoo.so"}
264 {"Build libar.so with versioned libfoo.so"
265 "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
266 {end.c} {} "libbarfoov.so"}
267 {"Build hidden libbar.so with libfoo.so"
268 "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
269 {endhidden.c} {} "libbarhfoo.so"}
270 {"Build hidden libar.so with versioned libfoo.so"
271 "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
272 {endhidden.c} {} "libbarhfoov.so"}
273 {"Build protected libbar.so with libfoo.so"
274 "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
275 {endprotected.c} {} "libbarpfoo.so"}
276 {"Build protected libbar.so with versioned libfoo.so"
277 "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
278 {endprotected.c} {} "libbarpfoov.so"}
281 {dl1.c} {} "libdl1.so"}
282 {"Build libdl2a.so with --dynamic-list=dl2.list"
283 "-shared -Wl,--dynamic-list=dl2.list" "-fPIC"
284 {dl2.c dl2xxx.c} {} "libdl2a.so"}
285 {"Build libdl2a.so with --dynamic-list=dl2a.list"
286 "-shared -Wl,--dynamic-list=dl2a.list" "-fPIC"
287 {dl2.c dl2xxx.c} {} "libdl2a.so"}
288 {"Build libdl2a.so with --dynamic-list-data"
289 "-shared -Wl,--dynamic-list-data" "-fPIC"
290 {dl2.c dl2xxx.c} {} "libdl2a.so"}
291 {"Build libdl2b.so with --dynamic-list=dl2.list and dl2xxx.list"
292 "-shared -Wl,--dynamic-list=dl2.list,--dynamic-list=dl2xxx.list" "-fPIC"
293 {dl2.c dl2xxx.c} {} "libdl2b.so"}
294 {"Build libdl2c.so with --dynamic-list-data and dl2xxx.list"
295 "-shared -Wl,--dynamic-list-data,--dynamic-list=dl2xxx.list" "-fPIC"
296 {dl2.c dl2xxx.c} {} "libdl2c.so"}
297 {"Build libdl4a.so with --dynamic-list=dl4.list"
298 "-shared -Wl,--dynamic-list=dl4.list" "-fPIC"
299 {dl4.c dl4xxx.c} {} "libdl4a.so"}
300 {"Build libdl4b.so with --dynamic-list-data"
301 "-shared -Wl,--dynamic-list-data" "-fPIC"
302 {dl4.c dl4xxx.c} {} "libdl4b.so"}
303 {"Build libdl4c.so with --dynamic-list=dl4.list and dl4xxx.list"
304 "-shared -Wl,--dynamic-list=dl4.list,--dynamic-list=dl4xxx.list" "-fPIC"
305 {dl4.c dl4xxx.c} {} "libdl4c.so"}
306 {"Build libdl4d.so with --dynamic-list-data and dl4xxx.list"
307 "-shared -Wl,--dynamic-list-data,--dynamic-list=dl4xxx.list" "-fPIC"
308 {dl4.c dl4xxx.c} {} "libdl4d.so"}
309 {"Build libdl4e.so with -Bsymbolic-functions --dynamic-list-cpp-new"
310 "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC"
311 {dl4.c dl4xxx.c} {} "libdl4e.so"}
312 {"Build libdl4f.so with --dynamic-list-cpp-new -Bsymbolic-functions"
313 "-shared -Wl,--dynamic-list-cpp-new,-Bsymbolic-functions" "-fPIC"
314 {dl4.c dl4xxx.c} {} "libdl4f.so"}
317 {dl6.c} {} "libdl6a.so"}
318 {"Build libdl6b.so with -Bsymbolic --dynamic-list-data"
319 "-shared -Wl,-Bsymbolic,--dynamic-list-data" "-fPIC"
320 {dl6.c} {} "libdl6b.so"}
321 {"Build libdl6c.so with -Bsymbolic"
322 "-shared -Wl,-Bsymbolic" "-fPIC"
323 {dl6.c} {} "libdl6c.so"}
324 {"Build libdl6d.so with --dynamic-list-data -Bsymbolic"
325 "-shared -Wl,--dynamic-list-data,-Bsymbolic" "-fPIC"
326 {dl6.c} {} "libdl6d.so"}
329 {data1.c} {} "libdata1.so"}
332 {data2.c} {} "libdata2.so"}
335 {comm1.c} {} "libcomm1.o"}
338 {func1.c} {} "libfunc1.so"}
339 {"Build libpr9676-1.a"
341 {pr9676-1.c} {} "libpr9676-1.a"}
342 {"Build libpr9676-2.a"
344 {pr9676-2.c} {} "libpr9676-2.a"}
345 {"Build libpr9676-3.so"
347 {pr9676-3.c} {} "libpr9676-3.so"}
348 {"Build libpr9676-4.so"
350 {pr9676-4.c} {} "libpr9676-4.so"}
351 {"Build libpr9676-4a.so"
352 "-shared tmpdir/pr9676-4.o -Ltmpdir -lpr9676-3 -Wl,--start-group -lpr9676-1 -lpr9676-2 -Wl,--end-group"
354 {dummy.c} {{readelf {-s} pr9676.rd}} "libpr9676-4a.so"}
355 {"Build libpr9679.so"
356 "-shared" "-fPIC -O0"
357 {pr9679-1.c pr9679-2.c} {{readelf {-s} pr9679.rd}} "libpr9679.so"}
358 {"Build libpr11138-1.so"
359 "-shared -Wl,--version-script=pr11138-1.map" "-fPIC"
360 {pr11138-1.c} {} "libpr11138-1.so"}
361 {"Build libpr11138-2.o"
363 {pr11138-2.c} {} "libpr11138-2.o"}
364 {"Build pr13250-1.so"
366 {pr13250-1.c} {} "libpr13250-1.so"}
367 {"Build pr13250-2.so with libpr13250-1.so"
368 "-shared -Wl,--no-as-needed tmpdir/libpr13250-1.so" "-fPIC"
369 {pr13250-2.c} {} "libpr13250-2.so"}
370 {"Build libpr13250-3.o"
372 {pr13250-3.c} {} "libpr13250-3.o"}
373 {"Build libpr14323-2.so"
375 {pr14323-2.c} {} "libpr14323-2.so"}
378 {pr14862-1.c} {} "libpr14862-1.o"}
379 {"Build libpr14862.so"
380 "-shared -Wl,--version-script=pr11138-1.map" "-fPIC"
381 {pr14862-2.c} {} "libpr14862.so"}
382 {"Build libneeded1b.so"
384 {needed1b.c} {} "libneeded1b.so"}
385 {"Build libneeded1a.so"
386 "-shared -Wl,--add-needed,--no-as-needed -Ltmpdir -lneeded1b" "-fPIC"
387 {needed1a.c} {} "libneeded1a.so"}
388 {"Build libneeded1c.o"
390 {needed1c.c} {} "libneeded1c.o"}
391 {"Build libneeded1pic.o"
392 "-r -nostdlib" "-fPIC"
393 {needed1c.c} {} "libneeded1pic.o"}
394 {"Build needed1a.so with --add-needed"
395 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--add-needed,-rpath=tmpdir,-rpath-link=tmpdir,-z,defs -Ltmpdir -lneeded1a" ""
396 {dummy.c} {} "needed1a.so"}
397 {"Build needed1b.so with --copy-dt-needed-entries"
398 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--copy-dt-needed-entries,-rpath=tmpdir,-rpath-link=tmpdir,-z,defs -Ltmpdir -lneeded1a" ""
399 {dummy.c} {} "needed1b.so"}
400 {"Build needed1a.so with --no-add-needed"
401 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--no-add-needed -Ltmpdir -lneeded1a" ""
402 {dummy.c} {} "needed1c.so"}
403 {"Build needed1b.so with --no-copy-dt-needed-entries"
404 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--no-copy-dt-needed-entries -Ltmpdir -lneeded1a" ""
405 {dummy.c} {} "needed1d.so"}
408 {rel.c} {} "librel.so"}
409 {"Build libneeded2a.so"
411 {needed2a.c} {} "libneeded2a.so"}
412 {"Build libneeded2b.so"
413 "-shared -Wl,--version-script,needed2.ver" "-fPIC"
414 {needed2b.c} {} "libneeded2b.so"}
415 {"Build libneeded2c.o"
417 {needed2c.c} {} "libneeded2c.o"}
419 "tmpdir/libneeded2c.o -Wl,--as-needed tmpdir/libneeded2a.so tmpdir/libneeded2b.so" ""
420 {dummy.c} {} "needed2"}
421 {"Build libneeded3a.so"
422 "-shared -Wl,--no-add-needed" "-fPIC"
423 {needed1a.c} {} "libneeded3a.so"}
424 {"Build libneeded3b.so"
425 "-shared -Wl,--no-as-needed,--add-needed -Ltmpdir -lneeded1b" "-fPIC"
426 {dummy.c} {} "libneeded3b.so"}
429 {needed3.c} {} "libneeded3.so"}
431 "tmpdir/needed3.o -Wl,--as-needed -Ltmpdir -lneeded3a -lneeded3b -lneeded1b" ""
432 {dummy.c} {} "needed3"}
433 {"Build libpr2404a.so"
435 {pr2404a.c} {} "libpr2404a.so"}
436 {"Build libpr2404n.so"
437 "-shared -Wl,-z,now" "-fPIC"
438 {pr2404a.c} {} "libpr2404n.so"}
439 {"Build libpr2404b.a"
441 {pr2404b.c} {} "libpr2404b.a"}
443 "-Wl,--no-dynamic-linker,-export-dynamic,--gc-sections" "-ffunction-sections"
444 {rdynamic-1.c} {{readelf {-s} rdynamic-1.rd}} "rdynamic-1"}
446 "-Wl,--no-dynamic-linker,--dynamic-list,dynamic-1.syms -Wl,--gc-sections" "-ffunction-sections"
447 {dynamic-1.c} {{readelf {-s} dynamic-1.rd}} "dynamic-1"}
448 {"Build libpr16496a.so"
449 "-shared -Wl,--version-script=pr16496a.map" "-fPIC"
450 {pr16496a.c} {} "libpr16496a.so"}
451 {"Build libpr16496b.a"
453 {pr16496b.c} {} "libpr16496b.a"}
454 {"Build libpr16496b.so"
455 "-shared -Wl,--no-as-needed tmpdir/pr16496b.o tmpdir/libpr16496a.so" ""
456 {dummy.c} {{objdump {-R} pr16496b.od}} "libpr16496b.so"}
457 {"Build libpr16452a.so"
458 "-shared -Wl,-soname,libpr16452a.so,--version-script=pr16452.map" "-fPIC"
459 {pr16452a.c} {} "libpr16452a.so"}
460 {"Build libpr16452b.so"
461 "-shared -Wl,-soname,libpr16452b.so,--no-as-needed tmpdir/libpr16452a.so" "-fPIC"
462 {dummy.c} {} "libpr16452b.so"}
464 "-Wl,--no-as-needed,-rpath=tmpdir,-rpath-link=tmpdir tmpdir/libpr16452b.so" ""
465 {pr16452b.c} {{objdump {-p} pr16452.od}} "pr16452"}
467 "-Wl,--no-as-needed,-rpath=tmpdir,-rpath-link=tmpdir tmpdir/libpr16452b.so" ""
468 {pr16452b.c} {{objdump {-p} pr16457.od}} "pr16457"}
469 {"Build libpr18458a.so"
470 "-shared -Wl,-z,now" "-fPIC"
471 {pr18458a.c} {} "libpr18458a.so"}
472 {"Build libpr18458b.so"
473 "-shared -Wl,-z,now tmpdir/libpr18458a.so" "-fPIC"
474 {pr18458b.c} {} "libpr18458b.so"}
477 {pr19073.s} {} "pr19073a.o"}
478 {"Build libpr19073.so"
479 "-shared -Wl,--version-script=pr19073.map tmpdir/pr19073a.o" "-fPIC"
480 {dummy.c} {{readelf {--dyn-syms --wide} pr19073.rd}} "libpr19073.so"}
481 {"Build pr21964-1a.so"
483 {pr21964-1a.c} {} "pr21964-1a.so"}
484 {"Build pr21964-1b.so"
486 {pr21964-1b.c} {} "pr21964-1b.so"}
487 {"Build pr21964-2a.so"
489 {pr21964-2a.c} {} "pr21964-2a.so"}
490 {"Build pr21964-2b.so"
492 {pr21964-2b.c} {} "pr21964-2b.so"}
494 "-shared" "-fPIC -g -O2"
495 {pr21978a.c pr21978b.c} {{objdump {-Sl} pr21978.od}} "pr21978.so"}
498 run_cc_link_tests $build_tests
500 run_ld_link_tests [list \
503 "-pie -e _start --no-dynamic-linker -z text" \
507 {{readelf -rW pr22269-1.rd}} \
513 set run_tests [list \
514 [list "Run normal with libfoo.so" \
515 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/end.o" "" \
516 {main.c} "normal" "normal.out" ] \
517 [list "Run protected with libfoo.so" \
518 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/endprotected.o" "" \
519 {main.c} "protected" "normal.out" ] \
520 [list "Run hidden with libfoo.so" \
521 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/endhidden.o" "" \
522 {main.c} "hidden" "hidden.out" ] \
523 [list "Run normal with versioned libfoo.so" \
524 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/end.o" "" \
525 {main.c} "normalv" "normal.out" ] \
526 [list "Run warn with versioned libfoo.so" \
527 "-Wl,--no-as-needed tmpdir/beginwarn.o tmpdir/libfoov.so" "" \
528 {main.c} "warn" "warn.out" \
529 "" "c" {^.*beginwarn.c:7: warning: function foo is deprecated$} ] \
530 [list "Run protected with versioned libfoo.so" \
531 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/endprotected.o" "" \
532 {main.c} "protected" "normal.out" ] \
533 [list "Run hidden with versioned libfoo.so" \
534 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/endhidden.o" "" \
535 {main.c} "hiddenv" "hidden.out" ] \
536 [list "Run normal libbar.so with libfoo.so" \
537 "-Wl,--no-as-needed tmpdir/libbarfoo.so tmpdir/libfoo.so" "" \
538 {main.c} "normal" "normal.out" ] \
539 [list "Run protected libbar.so with libfoo.so" \
540 "-Wl,--no-as-needed tmpdir/libbarpfoo.so tmpdir/libfoo.so" "" \
541 {main.c} "protected" "normal.out" ] \
542 [list "Run hidden libbar.so with libfoo.so" \
543 "-Wl,--no-as-needed tmpdir/libbarhfoo.so tmpdir/libfoo.so" "" \
544 {main.c} "hidden" "hidden.out" ] \
545 [list "Run normal libbar.so with versioned libfoo.so" \
546 "-Wl,--no-as-needed tmpdir/libbarfoov.so tmpdir/libfoov.so" "" \
547 {main.c} "normal" "normal.out" ] \
548 [list "Run protected libbar.so with versioned libfoo.so" \
549 "-Wl,--no-as-needed tmpdir/libbarpfoov.so tmpdir/libfoov.so" "" \
550 {main.c} "protected" "normal.out" ] \
551 [list "Run hidden libbar.so with versioned libfoo.so" \
552 "-Wl,--no-as-needed tmpdir/libbarhfoov.so tmpdir/libfoov.so" "" \
553 {main.c} "hidden" "hidden.out" ] \
554 [list "Run with libdl2a.so" \
555 "-Wl,--no-as-needed tmpdir/libdl2a.so" "" \
556 {dl2main.c} "dl2a" "dl2a.out" ] \
557 [list "Run with libdl2b.so" \
558 "-Wl,--no-as-needed tmpdir/libdl2b.so" "" \
559 {dl2main.c} "dl2b" "dl2b.out" ] \
560 [list "Run with libdl2c.so" \
561 "-Wl,--no-as-needed tmpdir/libdl2c.so" "" \
562 {dl2main.c} "dl2c" "dl2b.out" ] \
563 [list "Run with libdl4a.so" \
564 "-Wl,--no-as-needed tmpdir/libdl4a.so" "" \
565 {dl4main.c} "dl4a" "dl4a.out" ] \
566 [list "Run with libdl4b.so" \
567 "-Wl,--no-as-needed tmpdir/libdl4b.so" "" \
568 {dl4main.c} "dl4b" "dl4a.out" ] \
569 [list "Run with libdl4c.so" \
570 "-Wl,--no-as-needed tmpdir/libdl4c.so" "" \
571 {dl4main.c} "dl4c" "dl4b.out" ] \
572 [list "Run with libdl4d.so" \
573 "-Wl,--no-as-needed tmpdir/libdl4d.so" "" \
574 {dl4main.c} "dl4d" "dl4b.out" ] \
575 [list "Run with libdl4e.so" \
576 "-Wl,--no-as-needed tmpdir/libdl4e.so" "" \
577 {dl4main.c} "dl4e" "dl4a.out" ] \
578 [list "Run with libdl4f.so" \
579 "-Wl,--no-as-needed tmpdir/libdl4f.so" "" \
580 {dl4main.c} "dl4f" "dl4a.out" ] \
581 [list "Run with libdata1.so" \
582 "-Wl,--no-as-needed tmpdir/libdata1.so" "" \
583 {dynbss1.c} "dynbss1" "pass.out" ] \
584 [list "Run with libdata2.so" \
585 "-Wl,--no-as-needed tmpdir/libdata2.so" "" \
586 {weakdef1.c} "weakdef1" "pass.out" ] \
587 [list "Run with libfunc1.so comm1.o" \
588 "-Wl,--no-as-needed tmpdir/libfunc1.so tmpdir/comm1.o" "" \
589 {dummy.c} "comm1" "pass.out" ] \
590 [list "Run with comm1.o libfunc1.so" \
591 "-Wl,--no-as-needed tmpdir/comm1.o tmpdir/libfunc1.so" "" \
592 {dummy.c} "comm1" "pass.out" ] \
593 [list "Run with pr11138-2.c libpr11138-1.so" \
594 "-Wl,--no-as-needed,--version-script=pr11138-2.map tmpdir/pr11138-2.o tmpdir/libpr11138-1.so" "" \
595 {dummy.c} "pr11138a" "pr11138.out" ] \
596 [list "Run with libpr11138-1.so pr11138-2.c" \
597 "-Wl,--no-as-needed,--version-script=pr11138-2.map tmpdir/libpr11138-1.so tmpdir/pr11138-2.o" "" \
598 {dummy.c} "pr11138b" "pr11138.out" ] \
599 [list "Run with pr13250-3.c, libpr13250-1.so and libpr13250-2.so" \
600 "-Wl,--as-needed tmpdir/pr13250-3.o tmpdir/libpr13250-1.so tmpdir/libpr13250-2.so" "" \
601 {dummy.c} "pr13250" "pass.out" ] \
602 [list "Run with pr14323-1.c pr14323-2.so" \
603 "-Wl,--no-as-needed tmpdir/libpr14323-2.so" "" \
604 {pr14323-1.c} "pr14323" "pass.out" ] \
605 [list "Run with pr14862-1.c libpr14862.so" \
606 "-Wl,--as-needed tmpdir/libpr14862-1.o tmpdir/libpr14862.so" "" \
607 {dummy.c} "pr14862" "pr14862.out" ] \
608 [list "Link with --add-needed" \
609 "tmpdir/libneeded1c.o -Wl,--no-as-needed,--add-needed,-rpath=tmpdir,-rpath-link=tmpdir -Ltmpdir -lneeded1a" "" \
610 {dummy.c} "needed1a" "needed1.out" ] \
611 [list "Link with --copy-dt-needed-entries" \
612 "tmpdir/libneeded1c.o -Wl,--no-as-needed,--copy-dt-needed-entries,-rpath=tmpdir,-rpath-link=tmpdir -Ltmpdir -lneeded1a" "" \
613 {dummy.c} "needed1b" "needed1.out" ] \
614 [list "Run relmain" \
615 "-Wl,--no-as-needed,-rpath=tmpdir -Ltmpdir -lrel" "" \
616 {relmain.c} "relmain" "relmain.out" ] \
618 "-Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404a.so" "" \
619 {dummy.c} "pr2404" "pr2404.out" ] \
620 [list "Run pr2404n" \
621 "-Wl,-z,now -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404n.so" "" \
622 {dummy.c} "pr2404n" "pr2404.out" ] \
623 [list "Run pr18458" \
624 "-Wl,--no-as-needed,-z,now tmpdir/libpr18458a.so tmpdir/libpr18458b.so" "" \
625 {pr18458c.c} "pr18458" "pass.out" ] \
626 [list "Run pr21964-1" \
627 "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-1a.so tmpdir/pr21964-1b.so" "" \
628 {pr21964-1c.c} "pr21964-1" "pass.out" ] \
631 # NetBSD ELF systems do not currently support the .*_array sections.
632 run_ld_link_exec_tests $run_tests "*-*-netbsdelf*"
634 # These tests require dlopen support.
635 set dlopen_run_tests [list \
636 [list "Run dl1a with --dynamic-list=dl1.list and dlopen on libdl1.so" \
637 "-Wl,--no-as-needed,--dynamic-list=dl1.list $extralibs" "" \
638 {dl1main.c} "dl1a" "dl1.out" ] \
639 [list "Run dl1b with --dynamic-list-data and dlopen on libdl1.so" \
640 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
641 {dl1main.c} "dl1b" "dl1.out" ] \
642 [list "Run dl6a1 with --dynamic-list-data and dlopen on libdl6a.so" \
643 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
644 {dl6amain.c} "dl6a1" "dl6a.out" ] \
645 [list "Run dl6a2 with -Bsymbolic-functions and dlopen on libdl6a.so" \
646 "$NOPIE_LDFLAGS -Wl,--no-as-needed,-Bsymbolic-functions $extralibs" "" \
647 {dl6amain.c} "dl6a2" "dl6b.out" "$NOPIE_CFLAGS" ] \
648 [list "Run dl6a3 with -Bsymbolic and dlopen on libdl6a.so" \
649 "-Wl,--no-as-needed,-Bsymbolic $extralibs" "" \
650 {dl6amain.c} "dl6a3" "dl6b.out" ] \
651 [list "Run dl6a4 with -Bsymbolic --dynamic-list-data and dlopen on libdl6a.so" \
652 "-Wl,--no-as-needed,-Bsymbolic,--dynamic-list-data $extralibs" "" \
653 {dl6amain.c} "dl6a4" "dl6a.out" ] \
654 [list "Run dl6a5 with -Bsymbolic-functions --dynamic-list-cpp-new and dlopen on libdl6a.so" \
655 "$NOPIE_LDFLAGS -Wl,--no-as-needed,-Bsymbolic-functions,--dynamic-list-cpp-new $extralibs" "" \
656 {dl6amain.c} "dl6a5" "dl6b.out" "$NOPIE_CFLAGS" ] \
657 [list "Run dl6a6 with --dynamic-list-cpp-new -Bsymbolic-functions and dlopen on libdl6a.so" \
658 "$NOPIE_LDFLAGS -Wl,--no-as-needed,--dynamic-list-cpp-new,-Bsymbolic-functions $extralibs" "" \
659 {dl6amain.c} "dl6a6" "dl6b.out" "$NOPIE_CFLAGS" ] \
660 [list "Run dl6a7 with --dynamic-list-data -Bsymbolic and dlopen on libdl6a.so" \
661 "$NOPIE_LDFLAGS -Wl,--no-as-needed,--dynamic-list-data,-Bsymbolic $extralibs" "" \
662 {dl6amain.c} "dl6a7" "dl6a.out" "$NOPIE_CFLAGS" ] \
663 [list "Run dl6b1 with --dynamic-list-data and dlopen on libdl6b.so" \
664 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
665 {dl6bmain.c} "dl6b1" "dl6a.out" ] \
666 [list "Run dl6b2 with dlopen on libdl6b.so" \
667 "-Wl,--no-as-needed $extralibs" "" \
668 {dl6bmain.c} "dl6b2" "dl6b.out" ] \
669 [list "Run dl6c1 with --dynamic-list-data and dlopen on libdl6c.so" \
670 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
671 {dl6cmain.c} "dl6c1" "dl6b.out" ] \
672 [list "Run dl6d1 with --dynamic-list-data and dlopen on libdl6d.so" \
673 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
674 {dl6dmain.c} "dl6d1" "dl6b.out" ] \
675 [list "Run pr21964-2" \
676 "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-2a.so $extralibs" "" \
677 {pr21964-2c.c} "pr21964-2" "pass.out" ] \
680 # Only run them when libdl is available.
681 if [check_libdl_available] {
682 # XFAIL on NetBSD ELF systems as they do not currently support the .*_array
684 run_ld_link_exec_tests $dlopen_run_tests "*-*-netbsdelf*"
687 # Check --no-add-needed and --no-copy-dt-needed-entries
688 set testname "--no-add-needed"
689 set exec_output [run_host_cmd "$CC" "tmpdir/libneeded1c.o -Wl,--no-add-needed,-rpath-link=tmpdir -Ltmpdir -lneeded1a"]
690 if { [ regexp "tmpdir/libneeded1b.so: .*: DSO missing" $exec_output ] } {
695 set testname "--no-copy-dt-needed-entries"
696 set exec_output [run_host_cmd "$CC" "tmpdir/libneeded1c.o -Wl,--no-copy-dt-needed-entries,-rpath-link=tmpdir -Ltmpdir -lneeded1a"]
697 if { [ regexp "tmpdir/libneeded1b.so: .*: DSO missing" $exec_output ] } {
702 set testname "--no-add-needed -shared"
703 set exec_output [run_host_cmd "$CC" "-shared tmpdir/libneeded1pic.o -Wl,--no-add-needed,-z,defs -Ltmpdir -lneeded1a"]
704 if { [ regexp "undefined reference to `\.?bar'" $exec_output ] } {
709 set testname "--no-copy-dt-needed-entries -shared"
710 set exec_output [run_host_cmd "$CC" "-shared tmpdir/libneeded1pic.o -Wl,--no-copy-dt-needed-entries,-z,defs -Ltmpdir -lneeded1a"]
711 if { [ regexp "undefined reference to `\.?bar'" $exec_output ] } {
717 # Check to see if the C++ compiler works
718 if { [which $CXX] == 0 } {
722 set build_cxx_tests {
723 {"Build libdl3a.so with --dynamic-list=dl3.list"
724 "-shared -Wl,--dynamic-list=dl3.list" "-fPIC"
725 {dl3.cc} {} "libdl3a.so" "c++"}
726 {"Build libdl3b.so with -Bsymbolic"
727 "-shared -Wl,-Bsymbolic" "-fPIC"
728 {dl3.cc} {} "libdl3b.so" "c++"}
729 {"Build libdl3a.so with --dynamic-list-cpp-typeinfo"
730 "-shared -Wl,--dynamic-list-cpp-typeinfo" "-fPIC"
731 {dl3.cc} {} "libdl3c.so" "c++"}
732 {"Build libdnew1a.so with --Bsymbolic-functions --dynamic-list-cpp-new"
733 "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC -ansi"
734 {del.cc new.cc} {} "libnew1a.so" "c++"}
735 {"Build libdnew1b.so with --dynamic-list-data --dynamic-list-cpp-new"
736 "-shared -Wl,--dynamic-list-data,--dynamic-list-cpp-new" "-fPIC -ansi"
737 {del.cc new.cc} {} "libnew1b.so" "c++"}
740 # "-shared -Bsymbolic" only works with gcc 4.5.0 and newer.
741 # {"Run with libdl3b.so"
742 # "tmpdir/libdl3b.so" ""
743 # {dl3main.cc} "dl3b" "dl3b.out" "" "c++"}
745 {"Run with libdl3a.so"
746 "-Wl,--no-as-needed tmpdir/libdl3a.so" ""
747 {dl3main.cc} "dl3a" "dl3a.out" "" "c++"}
748 {"Run with libdl3c.so"
749 "-Wl,--no-as-needed tmpdir/libdl3c.so" ""
750 {dl3main.cc} "dl3c" "dl3a.out" "" "c++"}
751 {"Run with libnew1a.so"
752 "-Wl,--no-as-needed tmpdir/libnew1a.so" ""
753 {dl5.cc} "dl5a" "dl5.out" "-ansi" "c++"}
754 {"Run with libnew1b.so"
755 "-Wl,--no-as-needed tmpdir/libnew1b.so" ""
756 {dl5.cc} "dl5b" "dl5.out" "-ansi" "c++"}
759 run_cc_link_tests $build_cxx_tests
760 run_ld_link_exec_tests $run_cxx_tests
762 if { [istarget *-*-linux*]
763 || [istarget *-*-nacl*]
764 || [istarget *-*-gnu*] } {
765 run_cc_link_tests [list \
767 "Build libpr2404b.a with PIE" \
782 "Build libpr19579.so" \
790 "Build libpr19579now.so" \
791 "-shared -Wl,-z,now" \
798 run_ld_link_exec_tests [list \
800 "Run pr18458 with PIE" \
801 "-pie -Wl,--no-as-needed,-z,now tmpdir/libpr18458a.so tmpdir/libpr18458b.so" \
809 "Run pr2404 with PIE" \
810 "-pie -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404a.so" \
818 "Run pr2404 with PIE (-z now)" \
819 "-pie -Wl,-z,now -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404n.so" \
830 { pr18718.c check-ptr-eq.c } \
836 "Run pr18718 (-z now)" \
839 { pr18718.c check-ptr-eq.c } \
845 "Run pr18718 with PIE (1)" \
848 { pr18718.c check-ptr-eq.c } \
851 "-O2 -fPIE -I../bfd" \
854 "Run pr18718 with PIE (2)" \
857 { pr18718.c check-ptr-eq.c } \
860 "-O2 -fPIE -I../bfd" \
863 "Run pr18718 with PIE (3)" \
866 { pr18718.c check-ptr-eq.c } \
869 "-O2 -fPIE -I../bfd" \
872 "Run pr18718 with PIE (4)" \
875 { pr18718.c check-ptr-eq.c } \
878 "-O2 -fPIE -I../bfd" \
881 "Run pr18718 with PIC (1)" \
884 { pr18718.c check-ptr-eq.c } \
887 "-O2 -fPIC -I../bfd" \
890 "Run pr18718 with PIC (2)" \
893 { pr18718.c check-ptr-eq.c } \
896 "-O2 -fPIC -I../bfd" \
899 "Run pr18718 with PIC (3)" \
902 { pr18718.c check-ptr-eq.c } \
905 "-O2 -fPIC -I../bfd" \
908 "Run pr18718 with PIC (4)" \
911 { pr18718.c check-ptr-eq.c } \
914 "-O2 -fPIC -I../bfd" \
918 "-pie -Wl,--no-as-needed,-z,text tmpdir/pr19579a.o tmpdir/libpr19579.so" \
926 "Run pr19579 (-z now)" \
927 "-pie -Wl,-z,now -Wl,--no-as-needed,-z,text tmpdir/pr19579a.o tmpdir/libpr19579.so" \
937 proc mix_pic_and_non_pic {xfails cflags ldflags exe} {
938 run_cc_link_tests [list \
940 "Build libpr19719a.so" \
941 "-shared -Wl,-soname,libpr19719.so" \
948 "Build libpr19719b.so" \
949 "-shared -Wl,-soname,libpr19719.so" \
956 "Build libpr19719b.o" \
965 send_log "cp tmpdir/libpr19719b.so tmpdir/libpr19719.so\n"
966 exec cp tmpdir/libpr19719b.so tmpdir/libpr19719.so
968 run_ld_link_exec_tests [list \
970 "Run $exe fun defined" \
971 "-Wl,--no-as-needed,-rpath,tmpdir $ldflags tmpdir/libpr19719b.o tmpdir/libpr19719.so" \
973 { pr19719a.c pr19719c.c } \
980 send_log "cp tmpdir/libpr19719a.so tmpdir/libpr19719.so\n"
981 exec cp tmpdir/libpr19719a.so tmpdir/libpr19719.so
983 foreach targ $xfails {
988 unsupported "Run $exe fun undefined"
992 set exec_output [run_host_cmd "tmpdir/$exe" ""]
993 if {![string match "PASS" $exec_output]} {
994 fail "Run $exe fun undefined"
996 pass "Run $exe fun undefined"
1000 mix_pic_and_non_pic [list "arm*-*-*" "aarch64*-*-*"] "" "" "pr19719"
1001 mix_pic_and_non_pic [] "-fPIE" "-pie" "pr19719pie"