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