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