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