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