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