]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - ld/testsuite/ld-elf/shared.exp
Remove support for using the bsd-uthread target on FreeBSD.
[thirdparty/binutils-gdb.git] / ld / testsuite / ld-elf / shared.exp
CommitLineData
d2dee3b2 1# Expect script for various ELF tests.
2571583a 2# Copyright (C) 2006-2017 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
81ff47b3
MR
34# This target requires extra GAS options when building code for shared
35# libraries.
36set AFLAGS_PIC ""
37if [istarget "tic6x-*-*"] {
38 append AFLAGS_PIC " -mpic -mpid=near"
39}
40# This target requires a non-default emulation for successful shared
41# library/executable builds.
42set LFLAGS ""
43if [istarget "tic6x-*-*"] {
44 append LFLAGS " -melf32_tic6x_le"
45}
46
47# PR ld/20828 check for correct dynamic symbol table entries where:
48# - symbols have been defined with a linker script,
49# - the same symbols have been seen in shared library used in the link,
50# - the shared library symbols have been swept in section garbage collection.
51# Verify that the symbols are global rather than local and that a version
52# script adjusts them accordingly.
902e9fc7
MR
53# Also verify that a version definition supplied by an object rather than
54# a version script and forcibly exported is unaffected by section GC.
81ff47b3
MR
55if { [check_gc_sections_available] } {
56 run_ld_link_tests [list \
57 [list \
58 "PR ld/20828 dynamic symbols with section GC\
15a00b13
MR
59 (auxiliary shared library)" \
60 "$LFLAGS -shared --gc-sections -T pr20828.ld" "" "$AFLAGS_PIC" \
61 {pr20828.s} \
62 {{readelf --dyn-syms pr20828-a.sd} \
63 {readelf --dyn-syms pr20828-b.sd}} \
64 "libpr20828.so"] \
81ff47b3
MR
65 [list \
66 "PR ld/20828 dynamic symbols with section GC (plain)" \
15a00b13
MR
67 "$LFLAGS -shared --gc-sections -T pr20828.ld" \
68 "tmpdir/libpr20828.so" "$AFLAGS_PIC" \
69 {pr20828.s} \
70 {{readelf --dyn-syms pr20828-a.sd} \
71 {readelf --dyn-syms pr20828-b.sd}} \
72 "pr20828-1.so"] \
81ff47b3
MR
73 [list \
74 "PR ld/20828 dynamic symbols with section GC (version script)" \
15a00b13
MR
75 "$LFLAGS -shared --gc-sections -T pr20828.ld\
76 --version-script=pr20828.ver" \
77 "tmpdir/libpr20828.so" \
78 "$AFLAGS_PIC" \
79 {pr20828.s} \
80 {{readelf --dyn-syms pr20828-b.sd} \
81 {readelf --dyn-syms pr20828-c.sd}} \
902e9fc7
MR
82 "pr20828-2.so"] \
83 [list \
84 "PR ld/20828 dynamic symbols with section GC\
85 (versioned shared library)" \
86 "$LFLAGS -shared --gc-sections -T pr20828.ld\
87 --version-script=pr20828-v.ver" \
88 "" "$AFLAGS_PIC" \
89 {pr20828.s} \
90 {{readelf --dyn-syms pr20828-c.sd} \
91 {readelf --dyn-syms pr20828-d.sd} \
92 {readelf --dyn-syms pr20828-e.sd}} \
93 "libpr20828-v.so"] \
94 [list \
95 "PR ld/20828 dynamic symbols with section GC (versioned)" \
96 "$LFLAGS -shared --gc-sections -T pr20828.ld\
97 --version-script=pr20828-v.ver" \
98 "tmpdir/libpr20828-v.so" \
99 "$AFLAGS_PIC" \
100 {pr20828.s} \
101 {{readelf --dyn-syms pr20828-c.sd} \
102 {readelf --dyn-syms pr20828-d.sd} \
103 {readelf --dyn-syms pr20828-e.sd}} \
104 "pr20828-v.so"] \
105 [list \
106 "PR ld/20828 forcibly exported symbol version without section GC" \
107 "$LFLAGS -e foo -E -T pr20828-v.ld" "" "" \
108 {pr20828-v.s} \
109 {{objdump -p pr20828-v.od}} \
110 "pr20828-v-1"] \
111 [list \
112 "PR ld/20828 forcibly exported symbol version with section GC" \
113 "$LFLAGS -e foo --gc-sections -E -T pr20828-v.ld" "" "" \
114 {pr20828-v.s} \
115 {{objdump -p pr20828-v.od}} \
116 "pr20828-v-2"]]
81ff47b3
MR
117}
118
dd98f8d2 119# Check to see if the C compiler works
d2dee3b2
L
120if { [which $CC] == 0 } {
121 return
122}
123
fb2c6e43 124# Add -ldl to extralibs if needed
d9816402 125set extralibs ""
fb2c6e43
AT
126if { ![istarget *-*-freebsd*]} {
127 set extralibs "-ldl"
128}
129
d2dee3b2
L
130set build_tests {
131 {"Build libfoo.so"
132 "-shared" "-fPIC"
133 {foo.c} {} "libfoo.so"}
134 {"Build versioned libfoo.so"
135 "-shared -Wl,--version-script=foo.map" "-fPIC"
55255dae 136 {foo.c} {} "libfoov.so"}
d2dee3b2
L
137 {"Build libbar.so"
138 "-shared" "-fPIC"
139 {begin.c end.c} {} "libbar.so"}
fab4a87f
L
140 {"Build warn libbar.so"
141 "-shared" "-fPIC"
2bd7f877
AB
142 {beginwarn.c end.c}
143 {{readelf {-S --wide} libbarw.rd}
3239a423 144 {warning "^.*beginwarn.c:7: warning: function foo is deprecated$"}}
2bd7f877 145 "libbarw.so" "c"}
d2dee3b2
L
146 {"Build hidden libbar.so"
147 "-shared" "-fPIC"
148 {begin.c endhidden.c} {} "libbarh.so"}
149 {"Build protected libbar.so"
150 "-shared" "-fPIC"
151 {begin.c endprotected.c} {} "libbarp.so"}
152 {"Build libbar.so with libfoo.so"
153 "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
154 {end.c} {} "libbarfoo.so"}
155 {"Build libar.so with versioned libfoo.so"
156 "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
157 {end.c} {} "libbarfoov.so"}
158 {"Build hidden libbar.so with libfoo.so"
159 "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
160 {endhidden.c} {} "libbarhfoo.so"}
161 {"Build hidden libar.so with versioned libfoo.so"
162 "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
163 {endhidden.c} {} "libbarhfoov.so"}
164 {"Build protected libbar.so with libfoo.so"
165 "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
166 {endprotected.c} {} "libbarpfoo.so"}
167 {"Build protected libbar.so with versioned libfoo.so"
168 "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
169 {endprotected.c} {} "libbarpfoov.so"}
55255dae
L
170 {"Build libdl1.so"
171 "-shared" "-fPIC"
172 {dl1.c} {} "libdl1.so"}
173 {"Build libdl2a.so with --dynamic-list=dl2.list"
174 "-shared -Wl,--dynamic-list=dl2.list" "-fPIC"
175 {dl2.c dl2xxx.c} {} "libdl2a.so"}
b7b7fe3f
AS
176 {"Build libdl2a.so with --dynamic-list=dl2a.list"
177 "-shared -Wl,--dynamic-list=dl2a.list" "-fPIC"
178 {dl2.c dl2xxx.c} {} "libdl2a.so"}
40b36307
L
179 {"Build libdl2a.so with --dynamic-list-data"
180 "-shared -Wl,--dynamic-list-data" "-fPIC"
181 {dl2.c dl2xxx.c} {} "libdl2a.so"}
55255dae
L
182 {"Build libdl2b.so with --dynamic-list=dl2.list and dl2xxx.list"
183 "-shared -Wl,--dynamic-list=dl2.list,--dynamic-list=dl2xxx.list" "-fPIC"
184 {dl2.c dl2xxx.c} {} "libdl2b.so"}
d8cf8b51 185 {"Build libdl2c.so with --dynamic-list-data and dl2xxx.list"
40b36307 186 "-shared -Wl,--dynamic-list-data,--dynamic-list=dl2xxx.list" "-fPIC"
d8cf8b51 187 {dl2.c dl2xxx.c} {} "libdl2c.so"}
c555238b
L
188 {"Build libdl4a.so with --dynamic-list=dl4.list"
189 "-shared -Wl,--dynamic-list=dl4.list" "-fPIC"
190 {dl4.c dl4xxx.c} {} "libdl4a.so"}
d8cf8b51 191 {"Build libdl4b.so with --dynamic-list-data"
40b36307 192 "-shared -Wl,--dynamic-list-data" "-fPIC"
c555238b 193 {dl4.c dl4xxx.c} {} "libdl4b.so"}
d8cf8b51
L
194 {"Build libdl4c.so with --dynamic-list=dl4.list and dl4xxx.list"
195 "-shared -Wl,--dynamic-list=dl4.list,--dynamic-list=dl4xxx.list" "-fPIC"
196 {dl4.c dl4xxx.c} {} "libdl4c.so"}
197 {"Build libdl4d.so with --dynamic-list-data and dl4xxx.list"
40b36307 198 "-shared -Wl,--dynamic-list-data,--dynamic-list=dl4xxx.list" "-fPIC"
d8cf8b51
L
199 {dl4.c dl4xxx.c} {} "libdl4d.so"}
200 {"Build libdl4e.so with -Bsymbolic-functions --dynamic-list-cpp-new"
201 "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC"
202 {dl4.c dl4xxx.c} {} "libdl4e.so"}
203 {"Build libdl4f.so with --dynamic-list-cpp-new -Bsymbolic-functions"
204 "-shared -Wl,--dynamic-list-cpp-new,-Bsymbolic-functions" "-fPIC"
205 {dl4.c dl4xxx.c} {} "libdl4f.so"}
206 {"Build libdl6a.so"
207 "-shared" "-fPIC"
208 {dl6.c} {} "libdl6a.so"}
209 {"Build libdl6b.so with -Bsymbolic --dynamic-list-data"
210 "-shared -Wl,-Bsymbolic,--dynamic-list-data" "-fPIC"
211 {dl6.c} {} "libdl6b.so"}
212 {"Build libdl6c.so with -Bsymbolic"
213 "-shared -Wl,-Bsymbolic" "-fPIC"
214 {dl6.c} {} "libdl6c.so"}
215 {"Build libdl6d.so with --dynamic-list-data -Bsymbolic"
216 "-shared -Wl,--dynamic-list-data,-Bsymbolic" "-fPIC"
217 {dl6.c} {} "libdl6d.so"}
43edfb7f
L
218 {"Build libdata1.so"
219 "-shared" "-fPIC"
220 {data1.c} {} "libdata1.so"}
a47edf27
L
221 {"Build libdata2.so"
222 "-shared" "-fPIC"
223 {data2.c} {} "libdata2.so"}
0a36a439
L
224 {"Build libcomm1.o"
225 "-r -nostdlib" ""
226 {comm1.c} {} "libcomm1.o"}
227 {"Build libfunc1.so"
228 "-shared" "-fPIC"
229 {func1.c} {} "libfunc1.so"}
d8880531
L
230 {"Build libpr9676-1.a"
231 "" "-fPIC"
232 {pr9676-1.c} {} "libpr9676-1.a"}
233 {"Build libpr9676-2.a"
234 "" "-fPIC"
235 {pr9676-2.c} {} "libpr9676-2.a"}
236 {"Build libpr9676-3.so"
237 "-shared" "-fPIC"
238 {pr9676-3.c} {} "libpr9676-3.so"}
239 {"Build libpr9676-4.so"
240 "-shared" "-fPIC"
241 {pr9676-4.c} {} "libpr9676-4.so"}
242 {"Build libpr9676-4a.so"
243 "-shared tmpdir/pr9676-4.o -Ltmpdir -lpr9676-3 -Wl,--start-group -lpr9676-1 -lpr9676-2 -Wl,--end-group"
244 "-fPIC"
245 {dummy.c} {{readelf {-s} pr9676.rd}} "libpr9676-4a.so"}
54ac0771
L
246 {"Build libpr9679.so"
247 "-shared" "-fPIC -O0"
248 {pr9679-1.c pr9679-2.c} {{readelf {-s} pr9679.rd}} "libpr9679.so"}
d023c380
L
249 {"Build libpr11138-1.so"
250 "-shared -Wl,--version-script=pr11138-1.map" "-fPIC"
251 {pr11138-1.c} {} "libpr11138-1.so"}
252 {"Build libpr11138-2.o"
253 "-r -nostdlib" ""
254 {pr11138-2.c} {} "libpr11138-2.o"}
3e0882af
L
255 {"Build pr13250-1.so"
256 "-shared" "-fPIC"
257 {pr13250-1.c} {} "libpr13250-1.so"}
258 {"Build pr13250-2.so with libpr13250-1.so"
5cb49709 259 "-shared -Wl,--no-as-needed tmpdir/libpr13250-1.so" "-fPIC"
3e0882af
L
260 {pr13250-2.c} {} "libpr13250-2.so"}
261 {"Build libpr13250-3.o"
262 "-r -nostdlib" ""
263 {pr13250-3.c} {} "libpr13250-3.o"}
bc9ad2e4
L
264 {"Build libpr14323-2.so"
265 "-shared" "-fPIC"
266 {pr14323-2.c} {} "libpr14323-2.so"}
dda8ddc5
L
267 {"Build pr14862-1.o"
268 "-r -nostdlib" ""
269 {pr14862-1.c} {} "libpr14862-1.o"}
270 {"Build libpr14862.so"
271 "-shared -Wl,--version-script=pr11138-1.map" "-fPIC"
272 {pr14862-2.c} {} "libpr14862.so"}
63406f0a
L
273 {"Build libneeded1b.so"
274 "-shared" "-fPIC"
275 {needed1b.c} {} "libneeded1b.so"}
276 {"Build libneeded1a.so"
2eb64a9f 277 "-shared -Wl,--add-needed,--no-as-needed -Ltmpdir -lneeded1b" "-fPIC"
63406f0a
L
278 {needed1a.c} {} "libneeded1a.so"}
279 {"Build libneeded1c.o"
280 "-r -nostdlib" ""
281 {needed1c.c} {} "libneeded1c.o"}
8fbb09e8
L
282 {"Build libneeded1pic.o"
283 "-r -nostdlib" "-fPIC"
284 {needed1c.c} {} "libneeded1pic.o"}
285 {"Build needed1a.so with --add-needed"
8cfc7cf8 286 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--add-needed,-rpath=tmpdir,-rpath-link=tmpdir,-z,defs -Ltmpdir -lneeded1a" ""
8fbb09e8
L
287 {dummy.c} {} "needed1a.so"}
288 {"Build needed1b.so with --copy-dt-needed-entries"
8cfc7cf8 289 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--copy-dt-needed-entries,-rpath=tmpdir,-rpath-link=tmpdir,-z,defs -Ltmpdir -lneeded1a" ""
8fbb09e8
L
290 {dummy.c} {} "needed1b.so"}
291 {"Build needed1a.so with --no-add-needed"
8cfc7cf8 292 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--no-add-needed -Ltmpdir -lneeded1a" ""
8fbb09e8
L
293 {dummy.c} {} "needed1c.so"}
294 {"Build needed1b.so with --no-copy-dt-needed-entries"
8cfc7cf8 295 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--no-copy-dt-needed-entries -Ltmpdir -lneeded1a" ""
8fbb09e8 296 {dummy.c} {} "needed1d.so"}
8877b5e5
AM
297 {"Build librel.so"
298 "-shared" "-fPIC"
299 {rel.c} {} "librel.so"}
5e319dd3
L
300 {"Build libneeded2a.so"
301 "-shared" "-fPIC"
302 {needed2a.c} {} "libneeded2a.so"}
303 {"Build libneeded2b.so"
304 "-shared -Wl,--version-script,needed2.ver" "-fPIC"
305 {needed2b.c} {} "libneeded2b.so"}
306 {"Build libneeded2c.o"
307 "-r -nostdlib" ""
308 {needed2c.c} {} "libneeded2c.o"}
309 {"Build needed2"
310 "tmpdir/libneeded2c.o -Wl,--as-needed tmpdir/libneeded2a.so tmpdir/libneeded2b.so" ""
311 {dummy.c} {} "needed2"}
1240be6b
AM
312 {"Build libneeded3a.so"
313 "-shared -Wl,--no-add-needed" "-fPIC"
314 {needed1a.c} {} "libneeded3a.so"}
315 {"Build libneeded3b.so"
316 "-shared -Wl,--no-as-needed,--add-needed -Ltmpdir -lneeded1b" "-fPIC"
317 {dummy.c} {} "libneeded3b.so"}
318 {"Build needed3.o"
319 "-r -nostdlib" ""
320 {needed3.c} {} "libneeded3.so"}
321 {"Build needed3"
322 "tmpdir/needed3.o -Wl,--as-needed -Ltmpdir -lneeded3a -lneeded3b -lneeded1b" ""
323 {dummy.c} {} "needed3"}
cec2c50d
L
324 {"Build libpr2404a.so"
325 "-shared" "-fPIC"
326 {pr2404a.c} {} "libpr2404a.so"}
327 {"Build libpr2404b.a"
328 "" ""
329 {pr2404b.c} {} "libpr2404b.a"}
50a53d3f 330 {"Build rdynamic-1"
bb4287c5 331 "-Wl,-export-dynamic,--gc-sections" "-ffunction-sections"
50a53d3f 332 {rdynamic-1.c} {{readelf {-s} rdynamic-1.rd}} "rdynamic-1"}
d6f6f455
L
333 {"Build dynamic-1"
334 "-Wl,--dynamic-list,dynamic-1.syms -Wl,--gc-sections" "-ffunction-sections"
335 {dynamic-1.c} {{readelf {-s} dynamic-1.rd}} "dynamic-1"}
bb4d2ac2
L
336 {"Build libpr16496a.so"
337 "-shared -Wl,--version-script=pr16496a.map" "-fPIC"
338 {pr16496a.c} {} "libpr16496a.so"}
339 {"Build libpr16496b.a"
340 "" "-fPIC"
341 {pr16496b.c} {} "libpr16496b.a"}
342 {"Build libpr16496b.so"
8cfc7cf8 343 "-shared -Wl,--no-as-needed tmpdir/pr16496b.o tmpdir/libpr16496a.so" ""
bb4d2ac2 344 {dummy.c} {{objdump {-R} pr16496b.od}} "libpr16496b.so"}
fb389763
L
345 {"Build libpr16452a.so"
346 "-shared -Wl,-soname,libpr16452a.so,--version-script=pr16452.map" "-fPIC"
347 {pr16452a.c} {} "libpr16452a.so"}
348 {"Build libpr16452b.so"
349 "-shared -Wl,-soname,libpr16452b.so,--no-as-needed tmpdir/libpr16452a.so" "-fPIC"
350 {dummy.c} {} "libpr16452b.so"}
351 {"Build pr16452"
8cfc7cf8 352 "-Wl,--no-as-needed,-rpath=tmpdir,-rpath-link=tmpdir tmpdir/libpr16452b.so" ""
fb389763
L
353 {pr16452b.c} {{objdump {-p} pr16452.od}} "pr16452"}
354 {"Build pr16457"
8cfc7cf8 355 "-Wl,--no-as-needed,-rpath=tmpdir,-rpath-link=tmpdir tmpdir/libpr16452b.so" ""
fb389763 356 {pr16452b.c} {{objdump {-p} pr16457.od}} "pr16457"}
8ded2ddc
L
357 {"Build libpr18458a.so"
358 "-shared -Wl,-z,now" "-fPIC"
359 {pr18458a.c} {} "libpr18458a.so"}
360 {"Build libpr18458b.so"
361 "-shared -Wl,-z,now tmpdir/libpr18458a.so" "-fPIC"
362 {pr18458b.c} {} "libpr18458b.so"}
4373f8af
L
363 {"Build pr19073a.o"
364 "-r -nostdlib" ""
365 {pr19073.s} {} "pr19073a.o"}
366 {"Build libpr19073.so"
367 "-shared -Wl,--version-script=pr19073.map tmpdir/pr19073a.o" "-fPIC"
368 {dummy.c} {{readelf {--dyn-syms --wide} pr19073.rd}} "libpr19073.so"}
d2dee3b2
L
369}
370
dd98f8d2
NC
371run_cc_link_tests $build_tests
372
d9816402
AM
373set run_tests [list \
374 [list "Run normal with libfoo.so" \
375 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/end.o" "" \
376 {main.c} "normal" "normal.out" ] \
377 [list "Run protected with libfoo.so" \
378 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/endprotected.o" "" \
379 {main.c} "protected" "normal.out" ] \
380 [list "Run hidden with libfoo.so" \
381 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/endhidden.o" "" \
382 {main.c} "hidden" "hidden.out" ] \
383 [list "Run normal with versioned libfoo.so" \
384 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/end.o" "" \
385 {main.c} "normalv" "normal.out" ] \
386 [list "Run warn with versioned libfoo.so" \
387 "-Wl,--no-as-needed tmpdir/beginwarn.o tmpdir/libfoov.so" "" \
388 {main.c} "warn" "warn.out" \
3239a423 389 "" "c" {^.*beginwarn.c:7: warning: function foo is deprecated$} ] \
d9816402
AM
390 [list "Run protected with versioned libfoo.so" \
391 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/endprotected.o" "" \
392 {main.c} "protected" "normal.out" ] \
393 [list "Run hidden with versioned libfoo.so" \
394 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/endhidden.o" "" \
395 {main.c} "hiddenv" "hidden.out" ] \
396 [list "Run normal libbar.so with libfoo.so" \
397 "-Wl,--no-as-needed tmpdir/libbarfoo.so tmpdir/libfoo.so" "" \
398 {main.c} "normal" "normal.out" ] \
399 [list "Run protected libbar.so with libfoo.so" \
400 "-Wl,--no-as-needed tmpdir/libbarpfoo.so tmpdir/libfoo.so" "" \
401 {main.c} "protected" "normal.out" ] \
402 [list "Run hidden libbar.so with libfoo.so" \
403 "-Wl,--no-as-needed tmpdir/libbarhfoo.so tmpdir/libfoo.so" "" \
404 {main.c} "hidden" "hidden.out" ] \
405 [list "Run normal libbar.so with versioned libfoo.so" \
406 "-Wl,--no-as-needed tmpdir/libbarfoov.so tmpdir/libfoov.so" "" \
407 {main.c} "normal" "normal.out" ] \
408 [list "Run protected libbar.so with versioned libfoo.so" \
409 "-Wl,--no-as-needed tmpdir/libbarpfoov.so tmpdir/libfoov.so" "" \
410 {main.c} "protected" "normal.out" ] \
411 [list "Run hidden libbar.so with versioned libfoo.so" \
412 "-Wl,--no-as-needed tmpdir/libbarhfoov.so tmpdir/libfoov.so" "" \
413 {main.c} "hidden" "hidden.out" ] \
d9816402
AM
414 [list "Run with libdl2a.so" \
415 "-Wl,--no-as-needed tmpdir/libdl2a.so" "" \
416 {dl2main.c} "dl2a" "dl2a.out" ] \
417 [list "Run with libdl2b.so" \
418 "-Wl,--no-as-needed tmpdir/libdl2b.so" "" \
419 {dl2main.c} "dl2b" "dl2b.out" ] \
420 [list "Run with libdl2c.so" \
421 "-Wl,--no-as-needed tmpdir/libdl2c.so" "" \
422 {dl2main.c} "dl2c" "dl2b.out" ] \
423 [list "Run with libdl4a.so" \
424 "-Wl,--no-as-needed tmpdir/libdl4a.so" "" \
425 {dl4main.c} "dl4a" "dl4a.out" ] \
426 [list "Run with libdl4b.so" \
427 "-Wl,--no-as-needed tmpdir/libdl4b.so" "" \
428 {dl4main.c} "dl4b" "dl4a.out" ] \
429 [list "Run with libdl4c.so" \
430 "-Wl,--no-as-needed tmpdir/libdl4c.so" "" \
431 {dl4main.c} "dl4c" "dl4b.out" ] \
432 [list "Run with libdl4d.so" \
433 "-Wl,--no-as-needed tmpdir/libdl4d.so" "" \
434 {dl4main.c} "dl4d" "dl4b.out" ] \
435 [list "Run with libdl4e.so" \
436 "-Wl,--no-as-needed tmpdir/libdl4e.so" "" \
437 {dl4main.c} "dl4e" "dl4a.out" ] \
438 [list "Run with libdl4f.so" \
439 "-Wl,--no-as-needed tmpdir/libdl4f.so" "" \
440 {dl4main.c} "dl4f" "dl4a.out" ] \
d9816402
AM
441 [list "Run with libdata1.so" \
442 "-Wl,--no-as-needed tmpdir/libdata1.so" "" \
443 {dynbss1.c} "dynbss1" "pass.out" ] \
444 [list "Run with libdata2.so" \
445 "-Wl,--no-as-needed tmpdir/libdata2.so" "" \
446 {weakdef1.c} "weakdef1" "pass.out" ] \
447 [list "Run with libfunc1.so comm1.o" \
448 "-Wl,--no-as-needed tmpdir/libfunc1.so tmpdir/comm1.o" "" \
449 {dummy.c} "comm1" "pass.out" ] \
450 [list "Run with comm1.o libfunc1.so" \
451 "-Wl,--no-as-needed tmpdir/comm1.o tmpdir/libfunc1.so" "" \
452 {dummy.c} "comm1" "pass.out" ] \
453 [list "Run with pr11138-2.c libpr11138-1.so" \
454 "-Wl,--no-as-needed,--version-script=pr11138-2.map tmpdir/pr11138-2.o tmpdir/libpr11138-1.so" "" \
455 {dummy.c} "pr11138a" "pr11138.out" ] \
456 [list "Run with libpr11138-1.so pr11138-2.c" \
457 "-Wl,--no-as-needed,--version-script=pr11138-2.map tmpdir/libpr11138-1.so tmpdir/pr11138-2.o" "" \
458 {dummy.c} "pr11138b" "pr11138.out" ] \
459 [list "Run with pr13250-3.c, libpr13250-1.so and libpr13250-2.so" \
460 "-Wl,--as-needed tmpdir/pr13250-3.o tmpdir/libpr13250-1.so tmpdir/libpr13250-2.so" "" \
461 {dummy.c} "pr13250" "pass.out" ] \
462 [list "Run with pr14323-1.c pr14323-2.so" \
463 "-Wl,--no-as-needed tmpdir/libpr14323-2.so" "" \
464 {pr14323-1.c} "pr14323" "pass.out" ] \
465 [list "Run with pr14862-1.c libpr14862.so" \
466 "-Wl,--as-needed tmpdir/libpr14862-1.o tmpdir/libpr14862.so" "" \
467 {dummy.c} "pr14862" "pr14862.out" ] \
468 [list "Link with --add-needed" \
8cfc7cf8 469 "tmpdir/libneeded1c.o -Wl,--no-as-needed,--add-needed,-rpath=tmpdir,-rpath-link=tmpdir -Ltmpdir -lneeded1a" "" \
d9816402
AM
470 {dummy.c} "needed1a" "needed1.out" ] \
471 [list "Link with --copy-dt-needed-entries" \
8cfc7cf8 472 "tmpdir/libneeded1c.o -Wl,--no-as-needed,--copy-dt-needed-entries,-rpath=tmpdir,-rpath-link=tmpdir -Ltmpdir -lneeded1a" "" \
d9816402
AM
473 {dummy.c} "needed1b" "needed1.out" ] \
474 [list "Run relmain" \
475 "-Wl,--no-as-needed,-rpath=tmpdir -Ltmpdir -lrel" "" \
476 {relmain.c} "relmain" "relmain.out" ] \
477 [list "Run pr2404" \
478 "-Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404a.so" "" \
479 {dummy.c} "pr2404" "pr2404.out" ] \
480 [list "Run pr18458" \
481 "-Wl,--no-as-needed,-z,now tmpdir/libpr18458a.so tmpdir/libpr18458b.so" "" \
482 {pr18458c.c} "pr18458" "pass.out" ] \
483]
d2dee3b2 484
d2dee3b2 485# NetBSD ELF systems do not currently support the .*_array sections.
982c6f26 486run_ld_link_exec_tests $run_tests "*-*-netbsdelf*"
55255dae 487
fd121c5c
JW
488# These tests require dlopen support.
489set dlopen_run_tests [list \
490 [list "Run dl1a with --dynamic-list=dl1.list and dlopen on libdl1.so" \
491 "-Wl,--no-as-needed,--dynamic-list=dl1.list $extralibs" "" \
492 {dl1main.c} "dl1a" "dl1.out" ] \
493 [list "Run dl1b with --dynamic-list-data and dlopen on libdl1.so" \
494 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
495 {dl1main.c} "dl1b" "dl1.out" ] \
496 [list "Run dl6a1 with --dynamic-list-data and dlopen on libdl6a.so" \
497 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
498 {dl6amain.c} "dl6a1" "dl6a.out" ] \
499 [list "Run dl6a2 with -Bsymbolic-functions and dlopen on libdl6a.so" \
500 "-Wl,--no-as-needed,-Bsymbolic-functions $extralibs" "" \
501 {dl6amain.c} "dl6a2" "dl6b.out" ] \
502 [list "Run dl6a3 with -Bsymbolic and dlopen on libdl6a.so" \
503 "-Wl,--no-as-needed,-Bsymbolic $extralibs" "" \
504 {dl6amain.c} "dl6a3" "dl6b.out" ] \
505 [list "Run dl6a4 with -Bsymbolic --dynamic-list-data and dlopen on libdl6a.so" \
506 "-Wl,--no-as-needed,-Bsymbolic,--dynamic-list-data $extralibs" "" \
507 {dl6amain.c} "dl6a4" "dl6a.out" ] \
508 [list "Run dl6a5 with -Bsymbolic-functions --dynamic-list-cpp-new and dlopen on libdl6a.so" \
509 "-Wl,--no-as-needed,-Bsymbolic-functions,--dynamic-list-cpp-new $extralibs" "" \
510 {dl6amain.c} "dl6a5" "dl6b.out" ] \
511 [list "Run dl6a6 with --dynamic-list-cpp-new -Bsymbolic-functions and dlopen on libdl6a.so" \
512 "-Wl,--no-as-needed,--dynamic-list-cpp-new,-Bsymbolic-functions $extralibs" "" \
513 {dl6amain.c} "dl6a6" "dl6b.out" ] \
514 [list "Run dl6a7 with --dynamic-list-data -Bsymbolic and dlopen on libdl6a.so" \
515 "-Wl,--no-as-needed,--dynamic-list-data,-Bsymbolic $extralibs" "" \
516 {dl6amain.c} "dl6a7" "dl6a.out" ] \
517 [list "Run dl6b1 with --dynamic-list-data and dlopen on libdl6b.so" \
518 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
519 {dl6bmain.c} "dl6b1" "dl6a.out" ] \
520 [list "Run dl6b2 with dlopen on libdl6b.so" \
521 "-Wl,--no-as-needed $extralibs" "" \
522 {dl6bmain.c} "dl6b2" "dl6b.out" ] \
523 [list "Run dl6c1 with --dynamic-list-data and dlopen on libdl6c.so" \
524 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
525 {dl6cmain.c} "dl6c1" "dl6b.out" ] \
526 [list "Run dl6d1 with --dynamic-list-data and dlopen on libdl6d.so" \
527 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
528 {dl6dmain.c} "dl6d1" "dl6b.out" ] \
529]
530
531# Only run them when libdl is available.
532if [check_libdl_available] {
533 # XFAIL on NetBSD ELF systems as they do not currently support the .*_array
534 # sections.
535 run_ld_link_exec_tests $dlopen_run_tests "*-*-netbsdelf*"
536}
537
63406f0a
L
538# Check --no-add-needed and --no-copy-dt-needed-entries
539set testname "--no-add-needed"
f1d7f4a6 540set exec_output [run_host_cmd "$CC" "tmpdir/libneeded1c.o -Wl,--no-add-needed,-rpath-link=tmpdir -Ltmpdir -lneeded1a"]
e65cb106 541if { [ regexp "tmpdir/libneeded1b.so: .*: DSO missing" $exec_output ] } {
63406f0a
L
542 pass $testname
543} {
544 fail $testname
545}
546set testname "--no-copy-dt-needed-entries"
f1d7f4a6 547set exec_output [run_host_cmd "$CC" "tmpdir/libneeded1c.o -Wl,--no-copy-dt-needed-entries,-rpath-link=tmpdir -Ltmpdir -lneeded1a"]
e65cb106 548if { [ regexp "tmpdir/libneeded1b.so: .*: DSO missing" $exec_output ] } {
63406f0a
L
549 pass $testname
550} {
551 fail $testname
552}
8fbb09e8 553set testname "--no-add-needed -shared"
f1d7f4a6 554set exec_output [run_host_cmd "$CC" "-shared tmpdir/libneeded1pic.o -Wl,--no-add-needed,-z,defs -Ltmpdir -lneeded1a"]
4e95fbcd 555if { [ regexp "undefined reference to `\.?bar'" $exec_output ] } {
8fbb09e8
L
556 pass $testname
557} {
558 fail $testname
559}
560set testname "--no-copy-dt-needed-entries -shared"
f1d7f4a6 561set exec_output [run_host_cmd "$CC" "-shared tmpdir/libneeded1pic.o -Wl,--no-copy-dt-needed-entries,-z,defs -Ltmpdir -lneeded1a"]
4e95fbcd 562if { [ regexp "undefined reference to `\.?bar'" $exec_output ] } {
8fbb09e8
L
563 pass $testname
564} {
565 fail $testname
566}
63406f0a 567
dd98f8d2 568# Check to see if the C++ compiler works
55255dae
L
569if { [which $CXX] == 0 } {
570 return
571}
572
573set build_cxx_tests {
574 {"Build libdl3a.so with --dynamic-list=dl3.list"
575 "-shared -Wl,--dynamic-list=dl3.list" "-fPIC"
576 {dl3.cc} {} "libdl3a.so" "c++"}
577 {"Build libdl3b.so with -Bsymbolic"
578 "-shared -Wl,-Bsymbolic" "-fPIC"
579 {dl3.cc} {} "libdl3b.so" "c++"}
580 {"Build libdl3a.so with --dynamic-list-cpp-typeinfo"
581 "-shared -Wl,--dynamic-list-cpp-typeinfo" "-fPIC"
582 {dl3.cc} {} "libdl3c.so" "c++"}
d8cf8b51 583 {"Build libdnew1a.so with --Bsymbolic-functions --dynamic-list-cpp-new"
199add01 584 "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC -ansi"
d8cf8b51
L
585 {del.cc new.cc} {} "libnew1a.so" "c++"}
586 {"Build libdnew1b.so with --dynamic-list-data --dynamic-list-cpp-new"
199add01 587 "-shared -Wl,--dynamic-list-data,--dynamic-list-cpp-new" "-fPIC -ansi"
d8cf8b51 588 {del.cc new.cc} {} "libnew1b.so" "c++"}
55255dae
L
589}
590
b37470e4
L
591# "-shared -Bsymbolic" only works with gcc 4.5.0 and newer.
592# {"Run with libdl3b.so"
593# "tmpdir/libdl3b.so" ""
594# {dl3main.cc} "dl3b" "dl3b.out" "" "c++"}
cb5ab6c8
L
595set run_cxx_tests {
596 {"Run with libdl3a.so"
597 "-Wl,--no-as-needed tmpdir/libdl3a.so" ""
598 {dl3main.cc} "dl3a" "dl3a.out" "" "c++"}
55255dae 599 {"Run with libdl3c.so"
5cb49709 600 "-Wl,--no-as-needed tmpdir/libdl3c.so" ""
55255dae 601 {dl3main.cc} "dl3c" "dl3a.out" "" "c++"}
d8cf8b51 602 {"Run with libnew1a.so"
d9816402 603 "-Wl,--no-as-needed tmpdir/libnew1a.so" ""
199add01 604 {dl5.cc} "dl5a" "dl5.out" "-ansi" "c++"}
d8cf8b51 605 {"Run with libnew1b.so"
d9816402 606 "-Wl,--no-as-needed tmpdir/libnew1b.so" ""
199add01 607 {dl5.cc} "dl5b" "dl5.out" "-ansi" "c++"}
55255dae
L
608}
609
610run_cc_link_tests $build_cxx_tests
982c6f26 611run_ld_link_exec_tests $run_cxx_tests
22ef172a
L
612
613if { [istarget *-*-linux*]
614 || [istarget *-*-nacl*]
615 || [istarget *-*-gnu*] } {
616 run_cc_link_tests [list \
617 [list \
618 "Build libpr2404b.a with PIE" \
619 "" \
620 "-fPIE" \
621 { pr2404b.c } \
622 {} \
623 "libpr2404b.a" \
624 ] \
07492f66
L
625 [list \
626 "Build pr19579a.o" \
627 "" "-fPIE" \
628 {pr19579a.c} \
629 {} \
630 "libpr19579a.a" \
631 ] \
632 [list \
633 "Build libpr19579.so" \
634 "-shared" \
635 "-fPIC" \
636 {pr19579b.c} \
637 {} \
638 "libpr19579.so" \
639 ] \
22ef172a 640 ]
982c6f26 641 run_ld_link_exec_tests [list \
22ef172a
L
642 [list \
643 "Run pr2404 with PIE" \
d9816402 644 "-pie -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404a.so" \
22ef172a
L
645 "" \
646 { dummy.c } \
647 "pr2404pie" \
648 "pr2404.out" \
649 "-fPIE" \
650 ] \
1659f720
L
651 [list \
652 "Run pr18718" \
653 "" \
654 "" \
c45bd4fd 655 { pr18718.c check-ptr-eq.c } \
1659f720
L
656 "pr18718" \
657 "pass.out" \
edcab5e8 658 "-O2 -I../bfd" \
1659f720
L
659 ] \
660 [list \
661 "Run pr18718 with PIE (1)" \
662 "-pie" \
663 "" \
c45bd4fd 664 { pr18718.c check-ptr-eq.c } \
1659f720
L
665 "pr18718pie1" \
666 "pass.out" \
edcab5e8 667 "-O2 -fPIE -I../bfd" \
1659f720
L
668 ] \
669 [list \
670 "Run pr18718 with PIE (2)" \
671 "" \
672 "" \
c45bd4fd 673 { pr18718.c check-ptr-eq.c } \
1659f720
L
674 "pr18718pie2" \
675 "pass.out" \
edcab5e8 676 "-O2 -fPIE -I../bfd" \
1659f720
L
677 ] \
678 [list \
679 "Run pr18718 with PIC (1)" \
680 "" \
681 "" \
c45bd4fd 682 { pr18718.c check-ptr-eq.c } \
1659f720
L
683 "pr18718pic1" \
684 "pass.out" \
edcab5e8 685 "-O2 -fPIC -I../bfd" \
1659f720
L
686 ] \
687 [list \
688 "Run pr18718 with PIC (2)" \
689 "-pie" \
690 "" \
c45bd4fd 691 { pr18718.c check-ptr-eq.c } \
1659f720
L
692 "pr18718pic2" \
693 "pass.out" \
edcab5e8 694 "-O2 -fPIC -I../bfd" \
1659f720 695 ] \
07492f66
L
696 [list \
697 "Run pr19579" \
d9816402 698 "-pie -Wl,--no-as-needed,-z,text tmpdir/pr19579a.o tmpdir/libpr19579.so" \
07492f66
L
699 "" \
700 {dummy.c} \
701 "pr19579" \
702 "pass.out" \
703 "-fPIE" \
704 ] \
22ef172a
L
705 ]
706}
aec6b87e 707
f1b2ca70 708proc mix_pic_and_non_pic {xfails cflags ldflags exe} {
aec6b87e
L
709 run_cc_link_tests [list \
710 [list \
711 "Build libpr19719a.so" \
712 "-shared -Wl,-soname,libpr19719.so" \
713 "-fPIC" \
714 { pr19719d.c } \
715 {} \
716 "libpr19719a.so" \
717 ] \
718 [list \
719 "Build libpr19719b.so" \
720 "-shared -Wl,-soname,libpr19719.so" \
721 "-fPIC" \
722 { dummy.c } \
723 {} \
724 "libpr19719b.so" \
725 ] \
726 [list \
f1b2ca70 727 "Build libpr19719b.o" \
aec6b87e
L
728 "-r -nostdlib" \
729 "-fPIC" \
730 { pr19719b.c } \
731 {} \
732 "libpr19719b.o" \
733 ] \
734 ]
735
f1b2ca70 736 send_log "cp tmpdir/libpr19719b.so tmpdir/libpr19719.so\n"
aec6b87e
L
737 exec cp tmpdir/libpr19719b.so tmpdir/libpr19719.so
738
982c6f26 739 run_ld_link_exec_tests [list \
aec6b87e 740 [list \
f1b2ca70 741 "Run $exe fun defined" \
d9816402 742 "-Wl,--no-as-needed,-rpath,tmpdir $ldflags tmpdir/libpr19719b.o tmpdir/libpr19719.so" \
aec6b87e
L
743 "" \
744 { pr19719a.c pr19719c.c } \
f1b2ca70 745 $exe \
aec6b87e
L
746 "pass.out" \
747 "$cflags" \
748 ] \
749 ]
750
f1b2ca70 751 send_log "cp tmpdir/libpr19719a.so tmpdir/libpr19719.so\n"
aec6b87e
L
752 exec cp tmpdir/libpr19719a.so tmpdir/libpr19719.so
753
7494161b
L
754 foreach targ $xfails {
755 setup_xfail $targ
756 }
757
d9816402
AM
758 if ![isnative] {
759 unsupported "Run $exe fun undefined"
760 return
761 }
762
f1b2ca70 763 set exec_output [run_host_cmd "tmpdir/$exe" ""]
aec6b87e 764 if {![string match "PASS" $exec_output]} {
f1b2ca70 765 fail "Run $exe fun undefined"
aec6b87e 766 } else {
f1b2ca70 767 pass "Run $exe fun undefined"
aec6b87e
L
768 }
769}
770
f1b2ca70
AM
771mix_pic_and_non_pic [list "arm*-*-*" "aarch64*-*-*"] "" "" "pr19719"
772mix_pic_and_non_pic [] "-fPIE" "-pie" "pr19719pie"