7d35f3f3795436d6df112bc1681697d8cbf1abac
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elf / shared.exp
1 # Expect script for various ELF tests.
2 # Copyright (C) 2006-2020 Free Software Foundation, Inc.
3 #
4 # This file is part of the GNU Binutils.
5 #
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.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20 #
21
22 # Exclude non-ELF targets.
23
24 if ![is_elf_format] {
25 return
26 }
27
28 # Skip targets where -shared is not supported
29
30 if ![check_shared_lib_support] {
31 return
32 }
33
34 # Add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if non-PIE is required.
35 global NOPIE_CFLAGS NOPIE_LDFLAGS
36
37 set old_ASFLAGS $ASFLAGS
38
39 # This target requires extra GAS options when building code for shared
40 # libraries.
41 set AFLAGS_PIC ""
42 if [istarget "nds32*-*"] {
43 append AFLAGS_PIC " -mpic"
44 }
45 if [istarget "tic6x-*-*"] {
46 append AFLAGS_PIC " -mpic -mpid=near"
47 }
48 if [istarget "sparc*-*-*"] {
49 append AFLAGS_PIC " -K PIC -Av9"
50 }
51
52 # GAS options to disable program property note.
53 set AFLAGS_NOTE ""
54 if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
55 append AFLAGS_NOTE "-mx86-used-note=no"
56 }
57
58 # This target requires a non-default emulation for successful shared
59 # library/executable builds.
60 set LFLAGS ""
61 if [istarget "tic6x-*-*"] {
62 append LFLAGS " -melf32_tic6x_le"
63 }
64 # HPUX targets use a different .comm syntax.
65 set hpux ""
66 if [istarget "*-*-hpux*"] {
67 set hpux "--defsym HPUX=1"
68 }
69 # These targets do not default to linking with shared libraries.
70 if { [istarget "mips*vr4100*-*-elf*"] \
71 || [istarget "mips*vr4300*-*-elf*"] \
72 || [istarget "mips*vr5000*-*-elf*"] } {
73 append LFLAGS " -call_shared"
74 }
75
76 if [is_underscore_target] {
77 set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1"
78 }
79
80 run_ld_link_tests [list \
81 [list \
82 "Build pr22471a.so" \
83 "$LFLAGS -shared" \
84 "" \
85 "$AFLAGS_PIC" \
86 {pr22471a.s} \
87 {} \
88 "pr22471a.so" \
89 ] \
90 [list \
91 "Build pr22471b.so" \
92 "$LFLAGS -shared --version-script pr22471.t" \
93 "tmpdir/pr22471a.so" \
94 "$AFLAGS_PIC" \
95 {pr22471a.s} \
96 {} \
97 "pr22471b.so" \
98 ] \
99 [list \
100 "Build pr22471" \
101 "$LFLAGS -rpath-link ." \
102 "tmpdir/pr22471b.so" \
103 "" \
104 {pr22471b.s} \
105 {} \
106 "pr22471" \
107 ] \
108 [list \
109 "Build pr22649-1.so" \
110 "$LFLAGS -shared" \
111 "" \
112 "$AFLAGS_PIC" \
113 {pr22649-1.s} \
114 {} \
115 "pr22649-1.so" \
116 ] \
117 ]
118
119 if { [check_gc_sections_available] } {
120 if [istarget mips*-*-*] {
121 set actions {{ld pr22649-2ab-mips.msg}}
122 } else {
123 set actions {{ld pr22649.msg}}
124 }
125 run_ld_link_tests [list \
126 [list \
127 "Build pr22649-2a.so" \
128 "$LFLAGS -shared -gc-sections -print-gc-sections" \
129 "" \
130 "$AFLAGS_PIC" \
131 {pr22649-2a.s} \
132 $actions \
133 "pr22649-2a.so" \
134 ] \
135 [list \
136 "Build pr22649-2b.so" \
137 "$LFLAGS -shared -gc-sections -print-gc-sections" \
138 "tmpdir/pr22649-1.so" \
139 "$AFLAGS_PIC" \
140 {pr22649-2a.s} \
141 $actions \
142 "pr22649-2b.so" \
143 ] \
144 ]
145 if { [istarget mips*-*-*] && ![istarget *-*-elf*] } {
146 set actions {{ld pr22649-2cd-mips.msg}}
147 } else {
148 set actions {}
149 }
150 run_ld_link_tests [list \
151 [list \
152 "Build pr22649-2c.so" \
153 "$LFLAGS -shared -gc-sections -print-gc-sections" \
154 "" \
155 "$AFLAGS_PIC" \
156 {pr22649-2b.s} \
157 $actions \
158 "pr22649-2b.so" \
159 ] \
160 [list \
161 "Build pr22649-2d.so" \
162 "$LFLAGS -shared -gc-sections -print-gc-sections" \
163 "tmpdir/pr22649-1.so" \
164 "$AFLAGS_PIC" \
165 {pr22649-2b.s} \
166 $actions \
167 "pr22649-2b.so" \
168 ] \
169 ]
170 }
171
172 run_ld_link_tests [list \
173 [list \
174 "DT_TEXTREL in shared lib" \
175 "$LFLAGS -shared --warn-shared-textrel" \
176 "" \
177 "$AFLAGS_PIC" \
178 {textrel.s} \
179 {{ld textrel.warn} \
180 {readelf {-d --wide} textrel.rd}} \
181 "textrel.so" \
182 ] \
183 ] "xtensa-*-*"
184
185 # The MIPS backend sets SHF_WRITE, in `mips_elf_create_dynamic_relocation',
186 # for any section that has a dynamic relocation attached and consequently
187 # this test is irrelevant for MIPS targets. We don't have a clean way to
188 # request UNSUPPORTED result, which would be the most appropriate here,
189 # so we just XFAIL the test instead.
190 run_ld_link_tests [list \
191 [list \
192 "DT_TEXTREL map file warning" \
193 "$LFLAGS -shared -M" \
194 "" \
195 "$AFLAGS_PIC" \
196 {textrel.s} \
197 {{ld textrel.map}} \
198 "textrel.so" \
199 ] \
200 ] "cris*-*-*" "mips*-*-*"
201
202 # PR ld/20828 check for correct dynamic symbol table entries where:
203 # - symbols have been defined with a linker script,
204 # - the same symbols have been seen in shared library used in the link,
205 # - the shared library symbols have been swept in section garbage collection.
206 # Verify that the symbols are global rather than local and that a version
207 # script adjusts them accordingly.
208 # Also verify that a version definition supplied by an object rather than
209 # a version script and forcibly exported is unaffected by section GC.
210 if { [check_gc_sections_available] } {
211 run_ld_link_tests [list \
212 [list \
213 "PR ld/20828 dynamic symbols with section GC\
214 (auxiliary shared library)" \
215 "$LFLAGS -shared --gc-sections -T pr20828.ld" "" "$AFLAGS_PIC" \
216 {pr20828.s} \
217 {{readelf --dyn-syms pr20828-a.sd} \
218 {readelf --dyn-syms pr20828-b.sd}} \
219 "libpr20828.so"] \
220 [list \
221 "PR ld/20828 dynamic symbols with section GC (plain)" \
222 "$LFLAGS -shared --gc-sections -T pr20828.ld" \
223 "tmpdir/libpr20828.so" "$AFLAGS_PIC" \
224 {pr20828.s} \
225 {{readelf --dyn-syms pr20828-a.sd} \
226 {readelf --dyn-syms pr20828-b.sd}} \
227 "pr20828-1.so"] \
228 [list \
229 "PR ld/20828 dynamic symbols with section GC (version script)" \
230 "$LFLAGS -shared --gc-sections -T pr20828.ld\
231 --version-script=pr20828.ver" \
232 "tmpdir/libpr20828.so" \
233 "$AFLAGS_PIC" \
234 {pr20828.s} \
235 {{readelf --dyn-syms pr20828-b.sd} \
236 {readelf --dyn-syms pr20828-c.sd}} \
237 "pr20828-2.so"] \
238 [list \
239 "PR ld/20828 dynamic symbols with section GC\
240 (versioned shared library)" \
241 "$LFLAGS -shared --gc-sections -T pr20828.ld\
242 --version-script=pr20828-v.ver" \
243 "" "$AFLAGS_PIC" \
244 {pr20828.s} \
245 {{readelf --dyn-syms pr20828-c.sd} \
246 {readelf --dyn-syms pr20828-d.sd} \
247 {readelf --dyn-syms pr20828-e.sd}} \
248 "libpr20828-v.so"] \
249 [list \
250 "PR ld/20828 dynamic symbols with section GC (versioned)" \
251 "$LFLAGS -shared --gc-sections -T pr20828.ld\
252 --version-script=pr20828-v.ver" \
253 "tmpdir/libpr20828-v.so" \
254 "$AFLAGS_PIC" \
255 {pr20828.s} \
256 {{readelf --dyn-syms pr20828-c.sd} \
257 {readelf --dyn-syms pr20828-d.sd} \
258 {readelf --dyn-syms pr20828-e.sd}} \
259 "pr20828-v.so"] \
260 [list \
261 "PR ld/20828 forcibly exported symbol version without section GC" \
262 "$LFLAGS --no-dynamic-linker -e foo -E -T pr20828-v.ld" "" "" \
263 {pr20828-v.s} \
264 {{objdump -p pr20828-v.od}} \
265 "pr20828-v-1"] \
266 [list \
267 "PR ld/20828 forcibly exported symbol version with section GC" \
268 "$LFLAGS --no-dynamic-linker -e foo --gc-sections -E -T pr20828-v.ld" "" "" \
269 {pr20828-v.s} \
270 {{objdump -p pr20828-v.od}} \
271 "pr20828-v-2"]]
272 }
273 # PR ld/21233 check for correct dynamic symbol table entries where:
274 # - a symbol has been defined in a shared library used in the link,
275 # - the symbol has been referenced from a section swept in garbage collection,
276 # - the symbol has also been forced to be entered in the output file as an
277 # undefined symbol, either with a command-line option or a linker script
278 # command.
279 # Verify that the undefined symbol is global rather than local.
280 if { [check_gc_sections_available] } {
281 run_ld_link_tests [list \
282 [list \
283 "PR ld/21233 dynamic symbols with section GC\
284 (auxiliary shared library)" \
285 "$LFLAGS -shared -T pr21233.ld" "" "$AFLAGS_PIC" \
286 {pr21233-l.s} \
287 {{readelf --dyn-syms pr21233-l.sd}} \
288 "libpr21233.so"]]
289
290 run_ld_link_tests [list \
291 [list \
292 "PR ld/21233 dynamic symbols with section GC (--undefined)" \
293 "$LFLAGS --gc-sections -e foo --undefined=bar -T pr21233.ld" \
294 "tmpdir/libpr21233.so" "" \
295 {pr21233.s} \
296 {{readelf --dyn-syms pr21233.sd}} \
297 "pr21233-1"]]
298
299 run_ld_link_tests [list \
300 [list \
301 "PR ld/21233 dynamic symbols with section GC (--require-defined)" \
302 "$LFLAGS --gc-sections -e foo --require-defined=bar\
303 -T pr21233.ld" \
304 "tmpdir/libpr21233.so" "" \
305 {pr21233.s} \
306 {{readelf --dyn-syms pr21233.sd}} \
307 "pr21233-2"]]
308
309 run_ld_link_tests [list \
310 [list \
311 "PR ld/21233 dynamic symbols with section GC (EXTERN)" \
312 "$LFLAGS --gc-sections -e foo -T pr21233-e.ld" \
313 "tmpdir/libpr21233.so" "" \
314 {pr21233.s} \
315 {{readelf --dyn-syms pr21233.sd}} \
316 "pr21233-3"]]
317 }
318
319 if { [check_gc_sections_available] } {
320 run_ld_link_tests [list \
321 [list \
322 "Build pr22150.so" \
323 "$LFLAGS -shared --version-script pr22150.ver" \
324 "" \
325 "$AFLAGS_PIC" \
326 {pr22150a.s} \
327 {} \
328 "pr22150.so" \
329 ] \
330 [list \
331 "Build pr22150" \
332 "$LFLAGS -e _start --gc-sections" \
333 "tmpdir/pr22150.so" \
334 "" \
335 {pr22150b.s} \
336 {{readelf -V pr22150.vd}} \
337 "pr22150" \
338 ] \
339 ]
340
341 switch -glob $target_triplet {
342 # exclude targets that don't support copy relocs
343 bfin-*-* { }
344 frv-*-* { }
345 lm32-*-* { }
346 mips*-*-* { }
347 tic6x-*-* { }
348 xtensa-*-* { }
349 default {
350 run_ld_link_tests [list \
351 [list \
352 "Build pr25458.so" \
353 "$LFLAGS -shared --version-script=pr25458.map" \
354 "" \
355 "$AFLAGS_PIC" \
356 {pr25458b.s} \
357 {} \
358 "pr25458.so" \
359 ] \
360 [list \
361 "Build pr25458" \
362 "$LFLAGS -e _start --gc-sections" \
363 "tmpdir/pr25458.so" \
364 "$AFLAGS_PIC" \
365 {pr25458a.s} \
366 {{readelf {--dyn-sym --wide} pr25458.rd}} \
367 "pr25458" \
368 ] \
369 ]
370 }
371 }
372 }
373
374 set ASFLAGS $old_ASFLAGS
375
376 run_ld_link_tests {
377 {"Build pr14170a.o" "" "" "" {pr14170a.s} {} "pr14170.a" }
378 }
379 run_ld_link_tests [list \
380 [list "Build shared library for pr14170" \
381 "-shared" "" "$AFLAGS_PIC" "pr14170b.s" {} "pr14170.so" ] \
382 ]
383
384 # bfin does not currently support copy relocs.
385 run_ld_link_tests [list \
386 [list "PR ld/14170" \
387 "$LFLAGS --no-dynamic-linker tmpdir/pr14170a.o tmpdir/pr14170.so" "" \
388 $hpux \
389 {pr14170c.s} { } "pr14170" ] \
390 ] "bfin-*-*"
391
392 # Targets that use _bfd_generic_link_add_symbols won't pass pr21703 tests
393 # Nor will hppa64 with dot-symbols.
394 run_ld_link_tests [list \
395 [list "PR ld/21703 shared" \
396 "-shared --allow-multiple-definition --version-script pr21703.ver\
397 tmpdir/pr21703-3.o tmpdir/pr21703-4.o" "" "$AFLAGS_PIC" \
398 {pr21703-3.s pr21703-4.s} {{readelf {--dyn-syms} pr21703-shared.sd}} \
399 "pr21703.so" ] \
400 ] \[is_generic\] hppa64-*-*
401
402 # This target requires extra GAS options when building non-PIC code
403 # for linking with shared libraries.
404 set AFLAGS_NONPIC ""
405 if [istarget "mips*-*-*"] {
406 append AFLAGS_NONPIC " -call_nonpic"
407 }
408
409 # Run a test to check linking a shared library with a broken linker
410 # script that accidentally marks dynamic sections as notes. The
411 # resulting executable is not expected to work, but the linker
412 # should not seg-fault whilst creating the binary.
413 run_ld_link_tests [list \
414 [list "Build shared library for broken linker script test" \
415 "-shared --hash-style=sysv" "" "$AFLAGS_PIC" "note-3.s" \
416 {} \
417 "note-3.so" ] \
418 [list "Link using broken linker script" \
419 "$LFLAGS --script note-3.t tmpdir/note-3.so" "" "" "" \
420 { { ld "note-3.l" } } \
421 "a.out" ] \
422 ]
423
424 run_ld_link_tests [list \
425 [list "Build pr17068.so" \
426 "-shared" "" "$AFLAGS_PIC" \
427 {pr17068d.s} {} "pr17068.so"] \
428 [list "Build pr17068a.a" \
429 "" "" "" \
430 {pr17068a.s pr17068c.s pr17068ez.s} {} "pr17068a.a"] \
431 [list "Build pr17068b.a" \
432 "" "" "" \
433 {pr17068b.s pr17068e.s} {} "pr17068b.a"] \
434 ]
435
436 # bfin does not currently support copy relocs.
437 run_ld_link_tests {
438 {"pr17068 link --as-needed lib in group"
439 "$LFLAGS --as-needed --no-dynamic-linker"
440 "--start-group tmpdir/pr17068a.a tmpdir/pr17068.so tmpdir/pr17068b.a\
441 --end-group" ""
442 {start.s pr17068.s} {} "pr17068"}
443 } "bfin-*-*"
444
445 # Fails on MIPS because ABI trickery means that a NULL reloc is emitted.
446 # Fails on bfin because relocations are not created.
447 run_ld_link_tests [list \
448 [list "-Bsymbolic-functions" \
449 "-shared -Bsymbolic-functions" "" "$AFLAGS_PIC" \
450 {symbolic-func.s} {{readelf {-r --wide} symbolic-func.r}} \
451 "symbolic-func.so"] \
452 ] "mips*-*-*" "bfin-*-*"
453
454 run_ld_link_tests [list \
455 [list "Build pr20995.so" \
456 "-shared" "" "$AFLAGS_PIC" \
457 {pr20995b.s} {} "pr20995.so"] \
458 ]
459
460 # xfail on arm*-*-eabi*. The list can be enlarged to those targets that
461 # don't support GNU_RELRO. For more details, please see discussions at:
462 # https://sourceware.org/ml/binutils/2017-01/msg00441.html
463 run_ld_link_tests [list \
464 [list "Build pr20995-2.so" \
465 "-shared -z relro" "" "$AFLAGS_PIC" \
466 {pr20995c.s} {{readelf {-l --wide} pr20995-2so.r}} "pr20995-2.so"] \
467 ] "tic6x-*-*" "arm*-*-eabi*" "hppa*64*-*-hpux*" "aarch64*-*-elf*" \
468 "*-*-lynxos*" "arm*-*-nto*" "i?86-*-nto*" "sh*-*-nto*"
469
470 # These targets don't copy dynamic variables into .bss.
471 setup_xfail "alpha-*-*" "bfin-*-*" "ia64-*-*" "xtensa-*-*"
472 # or don't have .data.rel.ro
473 setup_xfail "hppa*64*-*-hpux*"
474 run_ld_link_tests [list \
475 [list \
476 "pr20995" \
477 "$LFLAGS" "tmpdir/pr20995.so" "$AFLAGS_NONPIC" \
478 {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995"]]
479
480 # xfail on arm*-*-eabi* is particularly because of no support of GNU_RELRO.
481 # Please see the link above for details.
482 setup_xfail "alpha-*-*" "bfin-*-*" "ia64-*-*" "xtensa-*-*" "arm*-*-eabi*"
483 setup_xfail "hppa*64*-*-hpux*" "aarch64*-*-elf*"
484 run_ld_link_tests [list \
485 [list \
486 "pr20995-2" \
487 "$LFLAGS" "tmpdir/pr20995-2.so" "$AFLAGS_NONPIC" \
488 {pr20995a.s} {{readelf {-S --wide} pr20995.r}} "pr20995-2"]
489 ] "*-*-lynxos*" "arm*-*-nto*" "i?86-*-nto*" "sh*-*-nto*"
490
491 run_ld_link_tests [list \
492 [list "Build pr22374 shared library" \
493 "-shared" "" "$AFLAGS_PIC" "pr22374b.s" {} "pr22374.so" ] \
494 ]
495 if { ![istarget "alpha-*-*"]
496 && ![istarget "csky-*-*"]
497 && ![istarget "frv-*-*"]
498 && ![istarget "hppa*-*-*"]
499 && ![istarget "i?86-*-*"]
500 && ![istarget "ia64-*-*"]
501 && ![istarget "microblaze-*-*"]
502 && ![istarget "powerpc*-*-*"]
503 && ![istarget "x86_64-*-*"]
504 && ![istarget "xtensa-*-*"] } {
505 # The next test checks that copy relocs are not used unnecessarily,
506 # but that is just an optimization so don't complain loudly.
507 setup_xfail "*-*-*"
508 }
509 run_ld_link_tests {
510 {"pr22374 function pointer initialization"
511 "" "tmpdir/pr22374.so" "" "pr22374a.s"
512 { {readelf {--wide -r --dyn-syms} "pr22374-1.r"}
513 {readelf {--wide -r} "pr22374-2.r"} }
514 "pr22374" }
515 }
516
517 if { [istarget *-*-linux*]
518 || [istarget *-*-nacl*]
519 || [istarget *-*-gnu*] } {
520 run_ld_link_tests {
521 {"Weak symbols in dynamic objects 1 (support)"
522 "-shared" "" "" {weak-dyn-1a.s}
523 {}
524 "libweakdyn1a.so"}
525 {"Weak symbols in dynamic objects 1 (main test)"
526 "-shared tmpdir/libweakdyn1a.so -Tweak-dyn-1.ld" "" "" {weak-dyn-1b.s}
527 {{readelf {--relocs --wide} weak-dyn-1.rd}}
528 "libweakdyn1b.so"}
529 }
530 }
531
532 # Check to see if the C compiler works
533 if { ![check_compiler_available] } {
534 return
535 }
536
537 # Add -ldl to extralibs if needed
538 set extralibs ""
539 if { ![istarget *-*-freebsd*]} {
540 set extralibs "-ldl"
541 }
542
543 set build_tests {
544 {"Build libfoo.so"
545 "-shared" "-fPIC"
546 {foo.c} {} "libfoo.so"}
547 {"Build versioned libfoo.so"
548 "-shared -Wl,--version-script=foo.map" "-fPIC"
549 {foo.c} {} "libfoov.so"}
550 {"Build libbar.so"
551 "-shared" "-fPIC"
552 {begin.c end.c} {} "libbar.so"}
553 {"Build warn libbar.so"
554 "-shared" "-fPIC"
555 {beginwarn.c end.c}
556 {{readelf {-S --wide} libbarw.rd}
557 {warning "^.*beginwarn.c:7: warning: function foo is deprecated\n?$"}}
558 "libbarw.so" "c"}
559 {"Build hidden libbar.so"
560 "-shared" "-fPIC"
561 {begin.c endhidden.c} {} "libbarh.so"}
562 {"Build protected libbar.so"
563 "-shared" "-fPIC"
564 {begin.c endprotected.c} {} "libbarp.so"}
565 {"Build libbar.so with libfoo.so"
566 "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
567 {end.c} {} "libbarfoo.so"}
568 {"Build libar.so with versioned libfoo.so"
569 "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
570 {end.c} {} "libbarfoov.so"}
571 {"Build hidden libbar.so with libfoo.so"
572 "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
573 {endhidden.c} {} "libbarhfoo.so"}
574 {"Build hidden libar.so with versioned libfoo.so"
575 "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
576 {endhidden.c} {} "libbarhfoov.so"}
577 {"Build protected libbar.so with libfoo.so"
578 "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
579 {endprotected.c} {} "libbarpfoo.so"}
580 {"Build protected libbar.so with versioned libfoo.so"
581 "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
582 {endprotected.c} {} "libbarpfoov.so"}
583 {"Build libdl1.so"
584 "-shared" "-fPIC"
585 {dl1.c} {} "libdl1.so"}
586 {"Build libdl2a.so with --dynamic-list=dl2.list"
587 "-shared -Wl,--dynamic-list=dl2.list" "-fPIC"
588 {dl2.c dl2xxx.c} {} "libdl2a.so"}
589 {"Build libdl2a.so with --dynamic-list=dl2a.list"
590 "-shared -Wl,--dynamic-list=dl2a.list" "-fPIC"
591 {dl2.c dl2xxx.c} {} "libdl2a.so"}
592 {"Build libdl2a.so with --dynamic-list-data"
593 "-shared -Wl,--dynamic-list-data" "-fPIC"
594 {dl2.c dl2xxx.c} {} "libdl2a.so"}
595 {"Build libdl2b.so with --dynamic-list=dl2.list and dl2xxx.list"
596 "-shared -Wl,--dynamic-list=dl2.list,--dynamic-list=dl2xxx.list" "-fPIC"
597 {dl2.c dl2xxx.c} {} "libdl2b.so"}
598 {"Build libdl2c.so with --dynamic-list-data and dl2xxx.list"
599 "-shared -Wl,--dynamic-list-data,--dynamic-list=dl2xxx.list" "-fPIC"
600 {dl2.c dl2xxx.c} {} "libdl2c.so"}
601 {"Build libdl2d.so with --dynamic-list-data -Bsymbolic"
602 "-shared -Wl,-Bsymbolic,--dynamic-list-data" "-fPIC"
603 {dl2.c dl2xxx.c} {} "libdl2d.so"}
604 {"Build libdl4a.so with --dynamic-list=dl4.list"
605 "-shared -Wl,--dynamic-list=dl4.list" "-fPIC"
606 {dl4.c dl4xxx.c} {} "libdl4a.so"}
607 {"Build libdl4b.so with --dynamic-list-data"
608 "-shared -Wl,--dynamic-list-data" "-fPIC"
609 {dl4.c dl4xxx.c} {} "libdl4b.so"}
610 {"Build libdl4c.so with --dynamic-list=dl4.list and dl4xxx.list"
611 "-shared -Wl,--dynamic-list=dl4.list,--dynamic-list=dl4xxx.list" "-fPIC"
612 {dl4.c dl4xxx.c} {} "libdl4c.so"}
613 {"Build libdl4d.so with --dynamic-list-data and dl4xxx.list"
614 "-shared -Wl,--dynamic-list-data,--dynamic-list=dl4xxx.list" "-fPIC"
615 {dl4.c dl4xxx.c} {} "libdl4d.so"}
616 {"Build libdl4e.so with -Bsymbolic-functions --dynamic-list-cpp-new"
617 "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC"
618 {dl4.c dl4xxx.c} {} "libdl4e.so"}
619 {"Build libdl4f.so with --dynamic-list-cpp-new -Bsymbolic-functions"
620 "-shared -Wl,--dynamic-list-cpp-new,-Bsymbolic-functions" "-fPIC"
621 {dl4.c dl4xxx.c} {} "libdl4f.so"}
622 {"Build libdl6a.so"
623 "-shared" "-fPIC"
624 {dl6.c} {} "libdl6a.so"}
625 {"Build libdl6b.so with -Bsymbolic --dynamic-list-data"
626 "-shared -Wl,-Bsymbolic,--dynamic-list-data" "-fPIC"
627 {dl6.c} {} "libdl6b.so"}
628 {"Build libdl6c.so with -Bsymbolic"
629 "-shared -Wl,-Bsymbolic" "-fPIC"
630 {dl6.c} {} "libdl6c.so"}
631 {"Build libdl6d.so with --dynamic-list-data -Bsymbolic"
632 "-shared -Wl,--dynamic-list-data,-Bsymbolic" "-fPIC"
633 {dl6.c} {} "libdl6d.so"}
634 {"Build libdata1.so"
635 "-shared" "-fPIC"
636 {data1.c} {} "libdata1.so"}
637 {"Build libdata2.so"
638 "-shared" "-fPIC"
639 {data2.c} {} "libdata2.so"}
640 {"Build libcomm1.o"
641 "-r -nostdlib" "-fcommon"
642 {comm1.c} {} "libcomm1.o"}
643 {"Build libfunc1.so"
644 "-shared" "-fPIC"
645 {func1.c} {} "libfunc1.so"}
646 {"Build libpr9676-1.a"
647 "" "-fPIC"
648 {pr9676-1.c} {} "libpr9676-1.a"}
649 {"Build libpr9676-2.a"
650 "" "-fPIC"
651 {pr9676-2.c} {} "libpr9676-2.a"}
652 {"Build libpr9676-3.so"
653 "-shared" "-fPIC"
654 {pr9676-3.c} {} "libpr9676-3.so"}
655 {"Build libpr9676-4.so"
656 "-shared" "-fPIC"
657 {pr9676-4.c} {} "libpr9676-4.so"}
658 {"Build libpr9676-4a.so"
659 "-shared tmpdir/pr9676-4.o -Ltmpdir -lpr9676-3 -Wl,--start-group -lpr9676-1 -lpr9676-2 -Wl,--end-group"
660 "-fPIC"
661 {dummy.c} {{readelf {-s} pr9676.rd}} "libpr9676-4a.so"}
662 {"Build libpr9679.so"
663 "-shared" "-fPIC -O0"
664 {pr9679-1.c pr9679-2.c} {{readelf {-s} pr9679.rd}} "libpr9679.so"}
665 {"Build libpr11138-1.so"
666 "-shared -Wl,--version-script=pr11138-1.map" "-fPIC"
667 {pr11138-1.c} {} "libpr11138-1.so"}
668 {"Build libpr11138-2.o"
669 "-r -nostdlib" ""
670 {pr11138-2.c} {} "libpr11138-2.o"}
671 {"Build pr13250-1.so"
672 "-shared" "-fPIC -fcommon"
673 {pr13250-1.c} {} "libpr13250-1.so"}
674 {"Build pr13250-2.so with libpr13250-1.so"
675 "-shared -Wl,--no-as-needed tmpdir/libpr13250-1.so" "-fPIC -fcommon"
676 {pr13250-2.c} {} "libpr13250-2.so"}
677 {"Build libpr13250-3.o"
678 "-r -nostdlib" "-fcommon"
679 {pr13250-3.c} {} "libpr13250-3.o"}
680 {"Build libpr14323-2.so"
681 "-shared" "-fPIC -fcommon"
682 {pr14323-2.c} {} "libpr14323-2.so"}
683 {"Build pr14862-1.o"
684 "-r -nostdlib" ""
685 {pr14862-1.c} {} "libpr14862-1.o"}
686 {"Build libpr14862.so"
687 "-shared -Wl,--version-script=pr11138-1.map" "-fPIC"
688 {pr14862-2.c} {} "libpr14862.so"}
689 {"Build libneeded1b.so"
690 "-shared" "-fPIC"
691 {needed1b.c} {} "libneeded1b.so"}
692 {"Build libneeded1a.so"
693 "-shared -Wl,--add-needed,--no-as-needed -Ltmpdir -lneeded1b" "-fPIC"
694 {needed1a.c} {} "libneeded1a.so"}
695 {"Build libneeded1c.o"
696 "-r -nostdlib" ""
697 {needed1c.c} {} "libneeded1c.o"}
698 {"Build libneeded1pic.o"
699 "-r -nostdlib" "-fPIC"
700 {needed1c.c} {} "libneeded1pic.o"}
701 {"Build needed1a.so with --add-needed"
702 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--add-needed,-rpath=tmpdir,-rpath-link=tmpdir,-z,defs -Ltmpdir -lneeded1a" ""
703 {dummy.c} {} "needed1a.so"}
704 {"Build needed1b.so with --copy-dt-needed-entries"
705 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--copy-dt-needed-entries,-rpath=tmpdir,-rpath-link=tmpdir,-z,defs -Ltmpdir -lneeded1a" ""
706 {dummy.c} {} "needed1b.so"}
707 {"Build needed1a.so with --no-add-needed"
708 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--no-add-needed -Ltmpdir -lneeded1a" ""
709 {dummy.c} {} "needed1c.so"}
710 {"Build needed1b.so with --no-copy-dt-needed-entries"
711 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--no-copy-dt-needed-entries -Ltmpdir -lneeded1a" ""
712 {dummy.c} {} "needed1d.so"}
713 {"Build librel.so"
714 "-shared" "-fPIC"
715 {rel.c} {} "librel.so"}
716 {"Build libneeded2a.so"
717 "-shared" "-fPIC"
718 {needed2a.c} {} "libneeded2a.so"}
719 {"Build libneeded2b.so"
720 "-shared -Wl,--version-script,needed2.ver" "-fPIC"
721 {needed2b.c} {} "libneeded2b.so"}
722 {"Build libneeded2c.o"
723 "-r -nostdlib" ""
724 {needed2c.c} {} "libneeded2c.o"}
725 {"Build needed2"
726 "tmpdir/libneeded2c.o -Wl,--as-needed tmpdir/libneeded2a.so tmpdir/libneeded2b.so" ""
727 {dummy.c} {} "needed2"}
728 {"Build libneeded3a.so"
729 "-shared -Wl,--no-add-needed" "-fPIC"
730 {needed1a.c} {} "libneeded3a.so"}
731 {"Build libneeded3b.so"
732 "-shared -Wl,--no-as-needed,--add-needed -Ltmpdir -lneeded1b" "-fPIC"
733 {dummy.c} {} "libneeded3b.so"}
734 {"Build needed3.o"
735 "-r -nostdlib" ""
736 {needed3.c} {} "libneeded3.so"}
737 {"Build needed3"
738 "tmpdir/needed3.o -Wl,--as-needed -Ltmpdir -lneeded3a -lneeded3b -lneeded1b" ""
739 {dummy.c} {} "needed3"}
740 {"Build libpr2404a.so"
741 "-shared" "-fPIC"
742 {pr2404a.c} {} "libpr2404a.so"}
743 {"Build libpr2404n.so"
744 "-shared -Wl,-z,now" "-fPIC"
745 {pr2404a.c} {} "libpr2404n.so"}
746 {"Build libpr2404b.a"
747 "" ""
748 {pr2404b.c} {} "libpr2404b.a"}
749 {"Build rdynamic-1"
750 "-Wl,--no-dynamic-linker,-export-dynamic,--gc-sections" "-ffunction-sections"
751 {rdynamic-1.c} {{readelf {-s} rdynamic-1.rd}} "rdynamic-1"}
752 {"Build dynamic-1"
753 "-Wl,--no-dynamic-linker,--dynamic-list,dynamic-1.syms -Wl,--gc-sections" "-ffunction-sections"
754 {dynamic-1.c} {{readelf {-s} dynamic-1.rd}} "dynamic-1"}
755 {"Build libpr16496a.so"
756 "-shared -Wl,--version-script=pr16496a.map" "-fPIC"
757 {pr16496a.c} {} "libpr16496a.so"}
758 {"Build libpr16496b.a"
759 "" "-fPIC"
760 {pr16496b.c} {} "libpr16496b.a"}
761 {"Build libpr16496b.so"
762 "-shared -Wl,--no-as-needed tmpdir/pr16496b.o tmpdir/libpr16496a.so" ""
763 {dummy.c} {{objdump {-R} pr16496b.od}} "libpr16496b.so"}
764 {"Build libpr16452a.so"
765 "-shared -Wl,-soname,libpr16452a.so,--version-script=pr16452.map" "-fPIC"
766 {pr16452a.c} {} "libpr16452a.so"}
767 {"Build libpr16452b.so"
768 "-shared -Wl,-soname,libpr16452b.so,--no-as-needed tmpdir/libpr16452a.so" "-fPIC"
769 {dummy.c} {} "libpr16452b.so"}
770 {"Build pr16452"
771 "-Wl,--no-as-needed,-rpath=tmpdir,-rpath-link=tmpdir tmpdir/libpr16452b.so" ""
772 {pr16452b.c} {{objdump {-p} pr16452.od}} "pr16452"}
773 {"Build pr16457"
774 "-Wl,--no-as-needed,-rpath=tmpdir,-rpath-link=tmpdir tmpdir/libpr16452b.so" ""
775 {pr16452b.c} {{objdump {-p} pr16457.od}} "pr16457"}
776 {"Build libpr18458a.so"
777 "-shared -Wl,-z,now" "-fPIC"
778 {pr18458a.c} {} "libpr18458a.so"}
779 {"Build libpr18458b.so"
780 "-shared -Wl,-z,now tmpdir/libpr18458a.so" "-fPIC"
781 {pr18458b.c} {} "libpr18458b.so"}
782 }
783 # pr19073.s uses .set, which has a different meaning on alpha.
784 if { ![istarget alpha-*-*] } {
785 append build_tests {
786 {"Build pr19073a.o"
787 "-r -nostdlib" ""
788 {pr19073.s} {} "pr19073a.o"}
789 {"Build libpr19073.so"
790 "-shared -Wl,--version-script=pr19073.map tmpdir/pr19073a.o" "-fPIC"
791 {dummy.c} {{readelf {--dyn-syms --wide} pr19073.rd}} "libpr19073.so"}
792 }
793 }
794 append build_tests {
795 {"Build pr21964-1a.so"
796 "-shared" "-fPIC"
797 {pr21964-1a.c} {} "pr21964-1a.so"}
798 {"Build pr21964-1b.so"
799 "-shared" "-fPIC"
800 {pr21964-1b.c} {} "pr21964-1b.so"}
801 {"Build pr21964-2a.so"
802 "-shared" "-fPIC"
803 {pr21964-2a.c} {} "pr21964-2a.so"}
804 {"Build pr21964-2b.so"
805 "-shared" "-fPIC"
806 {pr21964-2b.c} {} "pr21964-2b.so"}
807 {"Build pr21964-3a.so"
808 "-shared" "-fPIC"
809 {pr21964-3a.c} {} "pr21964-3a.so"}
810 {"Dump pr21978.so"
811 "-shared" "-fPIC -g -O2"
812 {pr21978a.c pr21978b.c} {{objdump {-Sl} pr21978.od}} "pr21978.so"}
813 }
814
815 run_cc_link_tests $build_tests
816
817 run_ld_link_tests [list \
818 [list \
819 "pr22269-1 (static pie undefined weak)" \
820 "-pie -e _start --no-dynamic-linker -z text -z nocombreloc " \
821 "" \
822 "$AFLAGS_PIC" \
823 { pr22269-1.c } \
824 {{readelf -rW pr22269-1.rd}} \
825 "pr22269-1" \
826 "-fPIE -O2" \
827 ] \
828 ]
829
830 set run_tests [list \
831 [list "Run normal with libfoo.so" \
832 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/end.o" "" \
833 {main.c} "normal" "normal.out" ] \
834 [list "Run protected with libfoo.so" \
835 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/endprotected.o" "" \
836 {main.c} "protected" "normal.out" ] \
837 [list "Run hidden with libfoo.so" \
838 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/endhidden.o" "" \
839 {main.c} "hidden" "hidden.out" ] \
840 [list "Run normal with versioned libfoo.so" \
841 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/end.o" "" \
842 {main.c} "normalv" "normal.out" ] \
843 [list "Run warn with versioned libfoo.so" \
844 "-Wl,--no-as-needed tmpdir/beginwarn.o tmpdir/libfoov.so" "" \
845 {main.c} "warn" "warn.out" \
846 "" "c" {^.*beginwarn.c:7: warning: function foo is deprecated\n?$} ] \
847 [list "Run protected with versioned libfoo.so" \
848 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/endprotected.o" "" \
849 {main.c} "protected" "normal.out" ] \
850 [list "Run hidden with versioned libfoo.so" \
851 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/endhidden.o" "" \
852 {main.c} "hiddenv" "hidden.out" ] \
853 [list "Run normal libbar.so with libfoo.so" \
854 "-Wl,--no-as-needed tmpdir/libbarfoo.so tmpdir/libfoo.so" "" \
855 {main.c} "normal" "normal.out" ] \
856 [list "Run protected libbar.so with libfoo.so" \
857 "-Wl,--no-as-needed tmpdir/libbarpfoo.so tmpdir/libfoo.so" "" \
858 {main.c} "protected" "normal.out" ] \
859 [list "Run hidden libbar.so with libfoo.so" \
860 "-Wl,--no-as-needed tmpdir/libbarhfoo.so tmpdir/libfoo.so" "" \
861 {main.c} "hidden" "hidden.out" ] \
862 [list "Run normal libbar.so with versioned libfoo.so" \
863 "-Wl,--no-as-needed tmpdir/libbarfoov.so tmpdir/libfoov.so" "" \
864 {main.c} "normal" "normal.out" ] \
865 [list "Run protected libbar.so with versioned libfoo.so" \
866 "-Wl,--no-as-needed tmpdir/libbarpfoov.so tmpdir/libfoov.so" "" \
867 {main.c} "protected" "normal.out" ] \
868 [list "Run hidden libbar.so with versioned libfoo.so" \
869 "-Wl,--no-as-needed tmpdir/libbarhfoov.so tmpdir/libfoov.so" "" \
870 {main.c} "hidden" "hidden.out" ] \
871 [list "Run with libdl2a.so" \
872 "-Wl,--no-as-needed tmpdir/libdl2a.so" "" \
873 {dl2main.c} "dl2a" "dl2a.out" ] \
874 [list "Run with libdl2b.so" \
875 "-Wl,--no-as-needed tmpdir/libdl2b.so" "" \
876 {dl2main.c} "dl2b" "dl2b.out" ] \
877 [list "Run with libdl2c.so" \
878 "-Wl,--no-as-needed tmpdir/libdl2c.so" "" \
879 {dl2main.c} "dl2c" "dl2b.out" ] \
880 [list "Run with libdl2d.so" \
881 "-Wl,--no-as-needed tmpdir/libdl2d.so" "" \
882 {dl2main.c} "dl2d" "dl2a.out" ] \
883 [list "Run with libdl4a.so" \
884 "-Wl,--no-as-needed tmpdir/libdl4a.so" "" \
885 {dl4main.c} "dl4a" "dl4a.out" ] \
886 [list "Run with libdl4b.so" \
887 "-Wl,--no-as-needed tmpdir/libdl4b.so" "" \
888 {dl4main.c} "dl4b" "dl4a.out" ] \
889 [list "Run with libdl4c.so" \
890 "-Wl,--no-as-needed tmpdir/libdl4c.so" "" \
891 {dl4main.c} "dl4c" "dl4b.out" ] \
892 [list "Run with libdl4d.so" \
893 "-Wl,--no-as-needed tmpdir/libdl4d.so" "" \
894 {dl4main.c} "dl4d" "dl4b.out" ] \
895 [list "Run with libdl4e.so" \
896 "-Wl,--no-as-needed tmpdir/libdl4e.so" "" \
897 {dl4main.c} "dl4e" "dl4e.out" ] \
898 [list "Run with libdl4f.so" \
899 "-Wl,--no-as-needed tmpdir/libdl4f.so" "" \
900 {dl4main.c} "dl4f" "dl4e.out" ] \
901 [list "Run with libdata1.so" \
902 "-Wl,--no-as-needed tmpdir/libdata1.so" "" \
903 {dynbss1.c} "dynbss1" "pass.out" ] \
904 [list "Run with libdata2.so" \
905 "-Wl,--no-as-needed tmpdir/libdata2.so" "" \
906 {weakdef1.c} "weakdef1" "pass.out" ] \
907 [list "Run with libfunc1.so comm1.o" \
908 "-Wl,--no-as-needed tmpdir/libfunc1.so tmpdir/comm1.o" "" \
909 {dummy.c} "comm1" "pass.out" ] \
910 [list "Run with comm1.o libfunc1.so" \
911 "-Wl,--no-as-needed tmpdir/comm1.o tmpdir/libfunc1.so" "" \
912 {dummy.c} "comm1" "pass.out" ] \
913 [list "Run with pr11138-2.c libpr11138-1.so" \
914 "-Wl,--no-as-needed,--version-script=pr11138-2.map tmpdir/pr11138-2.o tmpdir/libpr11138-1.so" "" \
915 {dummy.c} "pr11138a" "pr11138.out" ] \
916 [list "Run with libpr11138-1.so pr11138-2.c" \
917 "-Wl,--no-as-needed,--version-script=pr11138-2.map tmpdir/libpr11138-1.so tmpdir/pr11138-2.o" "" \
918 {dummy.c} "pr11138b" "pr11138.out" ] \
919 [list "Run with pr13250-3.c, libpr13250-1.so and libpr13250-2.so" \
920 "-Wl,--as-needed tmpdir/pr13250-3.o tmpdir/libpr13250-1.so tmpdir/libpr13250-2.so" "-fcommon" \
921 {dummy.c} "pr13250" "pass.out" ] \
922 [list "Run with pr14323-1.c pr14323-2.so" \
923 "-Wl,--no-as-needed tmpdir/libpr14323-2.so" "" \
924 {pr14323-1.c} "pr14323" "pass.out" ] \
925 [list "Run with pr14862-1.c libpr14862.so" \
926 "-Wl,--as-needed tmpdir/libpr14862-1.o tmpdir/libpr14862.so" "" \
927 {dummy.c} "pr14862" "pr14862.out" ] \
928 [list "Link with --add-needed" \
929 "tmpdir/libneeded1c.o -Wl,--no-as-needed,--add-needed,-rpath=tmpdir,-rpath-link=tmpdir -Ltmpdir -lneeded1a" "" \
930 {dummy.c} "needed1a" "needed1.out" ] \
931 [list "Link with --copy-dt-needed-entries" \
932 "tmpdir/libneeded1c.o -Wl,--no-as-needed,--copy-dt-needed-entries,-rpath=tmpdir,-rpath-link=tmpdir -Ltmpdir -lneeded1a" "" \
933 {dummy.c} "needed1b" "needed1.out" ] \
934 [list "Run relmain" \
935 "-Wl,--no-as-needed,-rpath=tmpdir -Ltmpdir -lrel" "" \
936 {relmain.c} "relmain" "relmain.out" ] \
937 [list "Run pr2404" \
938 "-Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404a.so" "" \
939 {dummy.c} "pr2404" "pr2404.out" ] \
940 [list "Run pr2404n" \
941 "-Wl,-z,now -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404n.so" "" \
942 {dummy.c} "pr2404n" "pr2404.out" ] \
943 [list "Run pr18458" \
944 "-Wl,--no-as-needed,-z,now tmpdir/libpr18458a.so tmpdir/libpr18458b.so" "" \
945 {pr18458c.c} "pr18458" "pass.out" ] \
946 [list "Run pr21964-1" \
947 "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-1a.so tmpdir/pr21964-1b.so" "" \
948 {pr21964-1c.c} "pr21964-1" "pass.out" ] \
949 [list "Run pr21964-3" \
950 "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-1a.so tmpdir/pr21964-1b.so tmpdir/pr21964-3a.so" "" \
951 {pr21964-3c.c} "pr21964-3" "pass.out" ] \
952 ]
953
954 # NetBSD ELF systems do not currently support the .*_array sections.
955 run_ld_link_exec_tests $run_tests "*-*-netbsdelf*"
956
957 # These tests require dlopen support.
958 set dlopen_run_tests [list \
959 [list "Run dl1a with --dynamic-list=dl1.list and dlopen on libdl1.so" \
960 "-Wl,--no-as-needed,--dynamic-list=dl1.list $extralibs" "" \
961 {dl1main.c} "dl1a" "dl1.out" ] \
962 [list "Run dl1b with --dynamic-list-data and dlopen on libdl1.so" \
963 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
964 {dl1main.c} "dl1b" "dl1.out" ] \
965 [list "Run dl6a1 with --dynamic-list-data and dlopen on libdl6a.so" \
966 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
967 {dl6amain.c} "dl6a1" "dl6a.out" ] \
968 [list "Run dl6a2 with -Bsymbolic-functions and dlopen on libdl6a.so" \
969 "$NOPIE_LDFLAGS -Wl,--no-as-needed,-Bsymbolic-functions $extralibs" "" \
970 {dl6amain.c} "dl6a2" "dl6b.out" "$NOPIE_CFLAGS" ] \
971 [list "Run dl6a3 with -Bsymbolic and dlopen on libdl6a.so" \
972 "-Wl,--no-as-needed,-Bsymbolic $extralibs" "" \
973 {dl6amain.c} "dl6a3" "dl6b.out" ] \
974 [list "Run dl6a4 with -Bsymbolic --dynamic-list-data and dlopen on libdl6a.so" \
975 "-Wl,--no-as-needed,-Bsymbolic,--dynamic-list-data $extralibs" "" \
976 {dl6amain.c} "dl6a4" "dl6a.out" ] \
977 [list "Run dl6a5 with -Bsymbolic-functions --dynamic-list-cpp-new and dlopen on libdl6a.so" \
978 "$NOPIE_LDFLAGS -Wl,--no-as-needed,-Bsymbolic-functions,--dynamic-list-cpp-new $extralibs" "" \
979 {dl6amain.c} "dl6a5" "dl6b.out" "$NOPIE_CFLAGS" ] \
980 [list "Run dl6a6 with --dynamic-list-cpp-new -Bsymbolic-functions and dlopen on libdl6a.so" \
981 "$NOPIE_LDFLAGS -Wl,--no-as-needed,--dynamic-list-cpp-new,-Bsymbolic-functions $extralibs" "" \
982 {dl6amain.c} "dl6a6" "dl6b.out" "$NOPIE_CFLAGS" ] \
983 [list "Run dl6a7 with --dynamic-list-data -Bsymbolic and dlopen on libdl6a.so" \
984 "$NOPIE_LDFLAGS -Wl,--no-as-needed,--dynamic-list-data,-Bsymbolic $extralibs" "" \
985 {dl6amain.c} "dl6a7" "dl6a.out" "$NOPIE_CFLAGS" ] \
986 [list "Run dl6b1 with --dynamic-list-data and dlopen on libdl6b.so" \
987 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
988 {dl6bmain.c} "dl6b1" "dl6a.out" ] \
989 [list "Run dl6b2 with dlopen on libdl6b.so" \
990 "-Wl,--no-as-needed $extralibs" "" \
991 {dl6bmain.c} "dl6b2" "dl6b.out" ] \
992 [list "Run dl6c1 with --dynamic-list-data and dlopen on libdl6c.so" \
993 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
994 {dl6cmain.c} "dl6c1" "dl6b.out" ] \
995 [list "Run dl6d1 with --dynamic-list-data and dlopen on libdl6d.so" \
996 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
997 {dl6dmain.c} "dl6d1" "dl6a.out" ] \
998 [list "Run pr21964-2" \
999 "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-2a.so $extralibs" "" \
1000 {pr21964-2c.c} "pr21964-2" "pass.out" ] \
1001 [list "Run pr21964-5" \
1002 "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-1a.so $extralibs" "" \
1003 {pr21964-5.c} "pr21964-5" "pass.out" ] \
1004 ]
1005
1006 # Only run them when libdl is available.
1007 if [check_libdl_available] {
1008 # XFAIL on NetBSD ELF systems as they do not currently support the .*_array
1009 # sections.
1010 run_ld_link_exec_tests $dlopen_run_tests "*-*-netbsdelf*"
1011 }
1012
1013 # Check --no-add-needed and --no-copy-dt-needed-entries
1014 set testname "--no-add-needed"
1015 set exec_output [run_host_cmd "$CC" "tmpdir/libneeded1c.o -Wl,--no-add-needed,-rpath-link=tmpdir -Ltmpdir -lneeded1a"]
1016 if { [ regexp "tmpdir/libneeded1b.so: .*: DSO missing" $exec_output ] } {
1017 pass $testname
1018 } {
1019 fail $testname
1020 }
1021 set testname "--no-copy-dt-needed-entries"
1022 set exec_output [run_host_cmd "$CC" "tmpdir/libneeded1c.o -Wl,--no-copy-dt-needed-entries,-rpath-link=tmpdir -Ltmpdir -lneeded1a"]
1023 if { [ regexp "tmpdir/libneeded1b.so: .*: DSO missing" $exec_output ] } {
1024 pass $testname
1025 } {
1026 fail $testname
1027 }
1028 set testname "--no-add-needed -shared"
1029 set exec_output [run_host_cmd "$CC" "-shared tmpdir/libneeded1pic.o -Wl,--no-add-needed,-z,defs -Ltmpdir -lneeded1a"]
1030 if { [ regexp "undefined reference to `\.?bar'" $exec_output ] } {
1031 pass $testname
1032 } {
1033 fail $testname
1034 }
1035 set testname "--no-copy-dt-needed-entries -shared"
1036 set exec_output [run_host_cmd "$CC" "-shared tmpdir/libneeded1pic.o -Wl,--no-copy-dt-needed-entries,-z,defs -Ltmpdir -lneeded1a"]
1037 if { [ regexp "undefined reference to `\.?bar'" $exec_output ] } {
1038 pass $testname
1039 } {
1040 fail $testname
1041 }
1042
1043 # Check to see if the C++ compiler works
1044 if { [which $CXX] == 0 } {
1045 return
1046 }
1047
1048 set build_cxx_tests {
1049 {"Build libdl3a.so with --dynamic-list=dl3.list"
1050 "-shared -Wl,--dynamic-list=dl3.list" "-fPIC"
1051 {dl3.cc} {} "libdl3a.so" "c++"}
1052 {"Build libdl3b.so with -Bsymbolic"
1053 "-shared -Wl,-Bsymbolic" "-fPIC"
1054 {dl3.cc} {} "libdl3b.so" "c++"}
1055 {"Build libdl3a.so with --dynamic-list-cpp-typeinfo"
1056 "-shared -Wl,--dynamic-list-cpp-typeinfo" "-fPIC"
1057 {dl3.cc} {} "libdl3c.so" "c++"}
1058 {"Build libdnew1a.so with --Bsymbolic-functions --dynamic-list-cpp-new"
1059 "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC -ansi"
1060 {del.cc new.cc} {} "libnew1a.so" "c++"}
1061 {"Build libdnew1b.so with --dynamic-list-data --dynamic-list-cpp-new"
1062 "-shared -Wl,--dynamic-list-data,--dynamic-list-cpp-new" "-fPIC -ansi"
1063 {del.cc new.cc} {} "libnew1b.so" "c++"}
1064 }
1065
1066 # "-shared -Bsymbolic" only works with gcc 4.5.0 and newer.
1067 # {"Run with libdl3b.so"
1068 # "tmpdir/libdl3b.so" ""
1069 # {dl3main.cc} "dl3b" "dl3b.out" "" "c++"}
1070 set run_cxx_tests {
1071 {"Run with libdl3a.so"
1072 "-Wl,--no-as-needed tmpdir/libdl3a.so" ""
1073 {dl3main.cc} "dl3a" "dl3a.out" "" "c++"}
1074 {"Run with libdl3c.so"
1075 "-Wl,--no-as-needed tmpdir/libdl3c.so" ""
1076 {dl3main.cc} "dl3c" "dl3a.out" "" "c++"}
1077 {"Run with libnew1a.so"
1078 "-Wl,--no-as-needed tmpdir/libnew1a.so" ""
1079 {dl5.cc} "dl5a" "dl5.out" "-ansi" "c++"}
1080 {"Run with libnew1b.so"
1081 "-Wl,--no-as-needed tmpdir/libnew1b.so" ""
1082 {dl5.cc} "dl5b" "dl5.out" "-ansi" "c++"}
1083 }
1084
1085 run_cc_link_tests $build_cxx_tests
1086 run_ld_link_exec_tests $run_cxx_tests
1087
1088 if { [istarget *-*-linux*]
1089 || [istarget *-*-nacl*]
1090 || [istarget *-*-gnu*] } {
1091 run_cc_link_tests [list \
1092 [list \
1093 "Build libpr2404b.a with PIE" \
1094 "" \
1095 "-fPIE" \
1096 { pr2404b.c } \
1097 {} \
1098 "libpr2404b.a" \
1099 ] \
1100 [list \
1101 "Build pr19579a.o" \
1102 "" "-fPIE -fcommon" \
1103 {pr19579a.c} \
1104 {} \
1105 "libpr19579a.a" \
1106 ] \
1107 [list \
1108 "Build libpr19579.so" \
1109 "-shared" \
1110 "-fPIC -fcommon" \
1111 {pr19579b.c} \
1112 {} \
1113 "libpr19579.so" \
1114 ] \
1115 [list \
1116 "Build libpr19579now.so" \
1117 "-shared -Wl,-z,now" \
1118 "-fPIC -fcommon" \
1119 {pr19579b.c} \
1120 {} \
1121 "libpr19579.so" \
1122 ] \
1123 [list \
1124 "Build pr22393-2a.so" \
1125 "-shared -Wl,-z,separate-code" \
1126 "-fPIC" \
1127 {pr22393-2a.c} \
1128 {{readelf -lW pr22393-2a.rd} \
1129 {readelf -lW pr22393-2b.rd}} \
1130 "pr22393-2a.so" \
1131 ] \
1132 [list \
1133 "Build pr22393-2a-now.so" \
1134 "-shared -Wl,-z,separate-code,-z,now" \
1135 "-fPIC" \
1136 {pr22393-2a.c} \
1137 {{readelf -lW pr22393-2a.rd} \
1138 {readelf -lW pr22393-2b.rd}} \
1139 "pr22393-2a-now.so" \
1140 ] \
1141 [list \
1142 "Build pr22393-2" \
1143 "$NOPIE_LDFLAGS -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a.so" \
1144 "$NOPIE_CFLAGS" \
1145 {pr22393-2b.c} \
1146 {{readelf -lW pr22393-2a.rd} \
1147 {readelf -lW pr22393-2b.rd}} \
1148 "pr22393-2" \
1149 ] \
1150 [list \
1151 "Build pr22393-2 (PIE)" \
1152 "-pie -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a-now.so" \
1153 "-fPIE" \
1154 {pr22393-2b.c} \
1155 {{readelf -lW pr22393-2a.rd} \
1156 {readelf -lW pr22393-2b.rd}} \
1157 "pr22393-2-pie" \
1158 ] \
1159 [list \
1160 "Build pr22393-2 (static)" \
1161 "-static -Wl,-z,separate-code" \
1162 "" \
1163 {pr22393-2a.c pr22393-2b.c} \
1164 {{readelf -lW pr22393-2a.rd} \
1165 {readelf -lW pr22393-2b.rd}} \
1166 "pr22393-2-static" \
1167 ] \
1168 ]
1169 run_ld_link_exec_tests [list \
1170 [list \
1171 "Run pr18458 with PIE" \
1172 "-pie -Wl,--no-as-needed,-z,now tmpdir/libpr18458a.so tmpdir/libpr18458b.so" \
1173 "" \
1174 {pr18458c.c} \
1175 "pr18458p" \
1176 "pass.out" \
1177 "-fPIE" \
1178 ] \
1179 [list \
1180 "Run pr2404 with PIE" \
1181 "-pie -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404a.so" \
1182 "" \
1183 { dummy.c } \
1184 "pr2404pie" \
1185 "pr2404.out" \
1186 "-fPIE" \
1187 ] \
1188 [list \
1189 "Run pr2404 with PIE (-z now)" \
1190 "-pie -Wl,-z,now -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404n.so" \
1191 "" \
1192 { dummy.c } \
1193 "pr2404pien" \
1194 "pr2404.out" \
1195 "-fPIE" \
1196 ] \
1197 [list \
1198 "Run pr18718" \
1199 "" \
1200 "" \
1201 { pr18718.c check-ptr-eq.c } \
1202 "pr18718" \
1203 "pass.out" \
1204 "-O2 -I../bfd" \
1205 ] \
1206 [list \
1207 "Run pr18718 (-z now)" \
1208 "-Wl,-z,now" \
1209 "" \
1210 { pr18718.c check-ptr-eq.c } \
1211 "pr18718" \
1212 "pass.out" \
1213 "-O2 -I../bfd" \
1214 ] \
1215 [list \
1216 "Run pr18718 with PIE (1)" \
1217 "-pie" \
1218 "" \
1219 { pr18718.c check-ptr-eq.c } \
1220 "pr18718pie1" \
1221 "pass.out" \
1222 "-O2 -fPIE -I../bfd" \
1223 ] \
1224 [list \
1225 "Run pr18718 with PIE (2)" \
1226 "" \
1227 "" \
1228 { pr18718.c check-ptr-eq.c } \
1229 "pr18718pie2" \
1230 "pass.out" \
1231 "-O2 -fPIE -I../bfd" \
1232 ] \
1233 [list \
1234 "Run pr18718 with PIE (3)" \
1235 "-pie -Wl,-z,now" \
1236 "" \
1237 { pr18718.c check-ptr-eq.c } \
1238 "pr18718pie3" \
1239 "pass.out" \
1240 "-O2 -fPIE -I../bfd" \
1241 ] \
1242 [list \
1243 "Run pr18718 with PIE (4)" \
1244 "-Wl,-z,now" \
1245 "" \
1246 { pr18718.c check-ptr-eq.c } \
1247 "pr18718pie4" \
1248 "pass.out" \
1249 "-O2 -fPIE -I../bfd" \
1250 ] \
1251 [list \
1252 "Run pr18718 with PIC (1)" \
1253 "" \
1254 "" \
1255 { pr18718.c check-ptr-eq.c } \
1256 "pr18718pic1" \
1257 "pass.out" \
1258 "-O2 -fPIC -I../bfd" \
1259 ] \
1260 [list \
1261 "Run pr18718 with PIC (2)" \
1262 "-pie" \
1263 "" \
1264 { pr18718.c check-ptr-eq.c } \
1265 "pr18718pic2" \
1266 "pass.out" \
1267 "-O2 -fPIC -I../bfd" \
1268 ] \
1269 [list \
1270 "Run pr18718 with PIC (3)" \
1271 "-Wl,-z,now" \
1272 "" \
1273 { pr18718.c check-ptr-eq.c } \
1274 "pr18718pic3" \
1275 "pass.out" \
1276 "-O2 -fPIC -I../bfd" \
1277 ] \
1278 [list \
1279 "Run pr18718 with PIC (4)" \
1280 "-pie -Wl,-z,now" \
1281 "" \
1282 { pr18718.c check-ptr-eq.c } \
1283 "pr18718pic4" \
1284 "pass.out" \
1285 "-O2 -fPIC -I../bfd" \
1286 ] \
1287 [list \
1288 "Run pr19579" \
1289 "-pie -Wl,--no-as-needed,-z,text tmpdir/pr19579a.o tmpdir/libpr19579.so" \
1290 "" \
1291 {dummy.c} \
1292 "pr19579" \
1293 "pass.out" \
1294 "-fPIE" \
1295 ] \
1296 [list \
1297 "Run pr19579 (-z now)" \
1298 "-pie -Wl,-z,now -Wl,--no-as-needed,-z,text tmpdir/pr19579a.o tmpdir/libpr19579.so" \
1299 "" \
1300 {dummy.c} \
1301 "pr19579n" \
1302 "pass.out" \
1303 "-fPIE" \
1304 ] \
1305 [list \
1306 "Run pr22393-2" \
1307 "$NOPIE_LDFLAGS -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a.so" \
1308 "" \
1309 {pr22393-2b.c} \
1310 "pr22393-2" \
1311 "pass.out" \
1312 "$NOPIE_CFLAGS" \
1313 ] \
1314 [list \
1315 "Run pr22393-2 (PIE)" \
1316 "-pie -Wl,-z,separate-code,--no-as-needed tmpdir/pr22393-2a-now.so" \
1317 "" \
1318 {pr22393-2b.c} \
1319 "pr22393-2-pie" \
1320 "pass.out" \
1321 "-fPIE" \
1322 ] \
1323 [list \
1324 "Run pr22393-2 (static)" \
1325 "-static -Wl,-z,separate-code" \
1326 "" \
1327 {pr22393-2a.c pr22393-2b.c} \
1328 "pr22393-2-static" \
1329 "pass.out" \
1330 ] \
1331 [list \
1332 "Run pr21964-4" \
1333 "" \
1334 "" \
1335 {pr21964-4.c} \
1336 "pr21964-4" \
1337 "pass.out" \
1338 "" \
1339 "" \
1340 "" \
1341 "-ldl" \
1342 ] \
1343 ]
1344 }
1345
1346 proc mix_pic_and_non_pic {xfails cflags ldflags exe} {
1347 run_cc_link_tests [list \
1348 [list \
1349 "Build libpr19719a.so" \
1350 "-shared -Wl,-soname,libpr19719.so" \
1351 "-fPIC" \
1352 { pr19719d.c } \
1353 {} \
1354 "libpr19719a.so" \
1355 ] \
1356 [list \
1357 "Build libpr19719b.so" \
1358 "-shared -Wl,-soname,libpr19719.so" \
1359 "-fPIC" \
1360 { dummy.c } \
1361 {} \
1362 "libpr19719b.so" \
1363 ] \
1364 [list \
1365 "Build libpr19719b.o" \
1366 "-r -nostdlib" \
1367 "-fPIC" \
1368 { pr19719b.c } \
1369 {} \
1370 "libpr19719b.o" \
1371 ] \
1372 ]
1373
1374 send_log "cp tmpdir/libpr19719b.so tmpdir/libpr19719.so\n"
1375 exec cp tmpdir/libpr19719b.so tmpdir/libpr19719.so
1376
1377 run_ld_link_exec_tests [list \
1378 [list \
1379 "Run $exe fun defined" \
1380 "-Wl,--no-as-needed,-rpath,tmpdir $ldflags tmpdir/libpr19719b.o tmpdir/libpr19719.so" \
1381 "" \
1382 { pr19719a.c pr19719c.c } \
1383 $exe \
1384 "pass.out" \
1385 "$cflags" \
1386 ] \
1387 ]
1388
1389 send_log "cp tmpdir/libpr19719a.so tmpdir/libpr19719.so\n"
1390 exec cp tmpdir/libpr19719a.so tmpdir/libpr19719.so
1391
1392 foreach targ $xfails {
1393 setup_xfail $targ
1394 }
1395
1396 if ![isnative] {
1397 unsupported "Run $exe fun undefined"
1398 return
1399 }
1400
1401 set exec_output [run_host_cmd "tmpdir/$exe" ""]
1402 if {![string match "PASS" $exec_output]} {
1403 fail "Run $exe fun undefined"
1404 } else {
1405 pass "Run $exe fun undefined"
1406 }
1407 }
1408
1409 mix_pic_and_non_pic [list "arm*-*-*" "aarch64*-*-*"] "" "" "pr19719"
1410 mix_pic_and_non_pic [] "-fPIE" "-pie" "pr19719pie"
1411
1412 set AFLAGS_PIE ""
1413 if { [istarget "i?86-*-*"]
1414 || [istarget "x86_64-*-*"] } {
1415 set AFLAGS_PIE "-mrelax-relocations=yes"
1416 }
1417
1418 if { ([istarget "*-*-linux*"]
1419 || [istarget "*-*-nacl*"]
1420 || [istarget "*-*-gnu*"])
1421 && ![istarget "mips*-*-*"] } {
1422 run_ld_link_tests [list \
1423 [list \
1424 "Build libpr23162a.so" \
1425 "-shared" \
1426 "" \
1427 "$AFLAGS_PIC" \
1428 { pr23162a.c } \
1429 "" \
1430 "libpr23162a.so" \
1431 "-fPIC -O2" \
1432 ] \
1433 [list \
1434 "Build pr23162a" \
1435 "-pie --no-as-needed tmpdir/libpr23162a.so" \
1436 "" \
1437 $AFLAGS_PIE \
1438 { pr23162b.c } \
1439 {{readelf {-rW} pr23162.rd}} \
1440 "pr23162a" \
1441 "-fPIC -O0" \
1442 ] \
1443 [list \
1444 "Build libpr23162b.so" \
1445 "-shared --version-script=pr23162.map" \
1446 "" \
1447 "$AFLAGS_PIC" \
1448 { pr23162a.c } \
1449 "" \
1450 "libpr23162b.so" \
1451 "-fPIC -O2" \
1452 ] \
1453 [list \
1454 "Build pr23162b" \
1455 "-pie --no-as-needed tmpdir/libpr23162b.so" \
1456 "" \
1457 $AFLAGS_PIE \
1458 { pr23162b.c } \
1459 {{readelf {-rW} pr23162.rd}} \
1460 "pr23162b" \
1461 "-fPIC -O0" \
1462 ] \
1463 [list \
1464 "Build libpr23161a.so" \
1465 "-shared" \
1466 "" \
1467 "$AFLAGS_PIC" \
1468 { pr23161a.c } \
1469 {{readelf {--dyn-syms -rW} pr23161a.rd}} \
1470 "libpr23161a.so" \
1471 "-fPIC -O2" \
1472 ] \
1473 [list \
1474 "Build pr23161a" \
1475 "-pie --no-as-needed tmpdir/libpr23161a.so" \
1476 "" \
1477 $AFLAGS_PIE \
1478 { pr23161b.c } \
1479 {{readelf {--dyn-syms -rW} pr23161b.rd}} \
1480 "pr23161a" \
1481 "-fPIC -O0" \
1482 ] \
1483 [list \
1484 "Build libpr23161b.so" \
1485 "-shared --version-script=pr23161.map" \
1486 "" \
1487 "$AFLAGS_PIC" \
1488 { pr23161a.c } \
1489 {{readelf {--dyn-syms -rW} pr23161a.rd}} \
1490 "libpr23161b.so" \
1491 "-fPIC -O2" \
1492 ] \
1493 [list \
1494 "Build pr23161b" \
1495 "-pie --no-as-needed tmpdir/libpr23161b.so" \
1496 "" \
1497 $AFLAGS_PIE \
1498 { pr23161b.c } \
1499 {{readelf {--dyn-syms -rW} pr23161b.rd}} \
1500 "pr23161b" \
1501 "-fPIC -O0" \
1502 ] \
1503 ]
1504 }
1505
1506 if { [istarget "i?86-*-*"]
1507 || [istarget "x86_64-*-*"] } {
1508 run_ld_link_tests [list \
1509 [list \
1510 "Build libpr23161c.so" \
1511 "-shared" \
1512 "" \
1513 "$AFLAGS_PIC" \
1514 { pr23161c.c } \
1515 {{readelf {--dyn-syms -rW} pr23161c.rd}} \
1516 "libpr23161c.so" \
1517 "-fPIC -O2" \
1518 ] \
1519 [list \
1520 "Build pr23161c" \
1521 "-pie --no-as-needed tmpdir/libpr23161c.so" \
1522 "" \
1523 $AFLAGS_PIE \
1524 { pr23161b.c } \
1525 {{readelf {--dyn-syms -rW} pr23161d.rd}} \
1526 "pr23161c" \
1527 "-fPIC -O0" \
1528 ] \
1529 ]
1530 }
1531
1532 run_ld_link_tests [list \
1533 [list "Build pr23658.so" \
1534 "-shared" "" "$AFLAGS_PIC" \
1535 {pr23658-1a.s} {} "pr23658.so"] \
1536 [list \
1537 "Build pr23658-2" \
1538 "--dynamic-linker tmpdir/pr23658.so --no-as-needed tmpdir/pr23658.so" \
1539 "" \
1540 $AFLAGS_NOTE \
1541 { pr23658-1a.s pr23658-1b.s pr23658-1c.s pr23658-1d.s start.s } \
1542 {{readelf {-lW} pr23658-2.rd}} \
1543 "pr23658-2" \
1544 ] \
1545 ]
This page took 0.082809 seconds and 3 git commands to generate.