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