]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/testsuite/ld-elf/shared.exp
Ignore dynamic references on forced local symbols
[thirdparty/binutils-gdb.git] / ld / testsuite / ld-elf / shared.exp
1 # Expect script for various ELF tests.
2 # Copyright (C) 2006-2018 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 # Add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if non-PIE is required.
35 global NOPIE_CFLAGS NOPIE_LDFLAGS
36
37 set old_ASFLAGS $ASFLAGS
38
39 # This target requires extra GAS options when building code for shared
40 # libraries.
41 set AFLAGS_PIC ""
42 if [istarget "tic6x-*-*"] {
43 append AFLAGS_PIC " -mpic -mpid=near"
44 }
45 # This target requires a non-default emulation for successful shared
46 # library/executable builds.
47 set LFLAGS ""
48 if [istarget "tic6x-*-*"] {
49 append LFLAGS " -melf32_tic6x_le"
50 }
51
52 if [is_underscore_target] {
53 set ASFLAGS "$ASFLAGS --defsym UNDERSCORE=1"
54 }
55
56 run_ld_link_tests [list \
57 [list \
58 "Build pr22471a.so" \
59 "$LFLAGS -shared" \
60 "" \
61 "$AFLAGS_PIC" \
62 {pr22471a.s} \
63 {} \
64 "pr22471a.so" \
65 ] \
66 [list \
67 "Build pr22471b.so" \
68 "$LFLAGS -shared --version-script pr22471.t" \
69 "tmpdir/pr22471a.so" \
70 "$AFLAGS_PIC" \
71 {pr22471a.s} \
72 {} \
73 "pr22471b.so" \
74 ] \
75 [list \
76 "Build pr22471" \
77 "$LFLAGS -rpath-link ." \
78 "tmpdir/pr22471b.so" \
79 "" \
80 {pr22471b.s} \
81 {} \
82 "pr22471" \
83 ] \
84 [list \
85 "Build pr22649-1.so" \
86 "$LFLAGS -shared" \
87 "" \
88 "$AFLAGS_PIC" \
89 {pr22649-1.s} \
90 {} \
91 "pr22649-1.so" \
92 ] \
93 [list \
94 "Build pr22649-2a.so" \
95 "$LFLAGS -shared -gc-sections -print-gc-sections" \
96 "" \
97 "$AFLAGS_PIC" \
98 {pr22649-2a.s} \
99 {{ld pr22649.msg}} \
100 "pr22649-2a.so" \
101 ] \
102 [list \
103 "Build pr22649-2b.so" \
104 "$LFLAGS -shared -gc-sections -print-gc-sections" \
105 "tmpdir/pr22649-1.so" \
106 "$AFLAGS_PIC" \
107 {pr22649-2a.s} \
108 {{ld pr22649.msg}} \
109 "pr22649-2b.so" \
110 ] \
111 [list \
112 "Build pr22649-2c.so" \
113 "$LFLAGS -shared -gc-sections -print-gc-sections" \
114 "" \
115 "$AFLAGS_PIC" \
116 {pr22649-2b.s} \
117 {} \
118 "pr22649-2b.so" \
119 ] \
120 [list \
121 "Build pr22649-2d.so" \
122 "$LFLAGS -shared -gc-sections -print-gc-sections" \
123 "tmpdir/pr22649-1.so" \
124 "$AFLAGS_PIC" \
125 {pr22649-2b.s} \
126 {} \
127 "pr22649-2b.so" \
128 ] \
129 ]
130
131 run_ld_link_tests [list \
132 [list \
133 "DT_TEXTREL in shared lib" \
134 "$LFLAGS -shared --warn-shared-textrel" \
135 "" \
136 "$AFLAGS_PIC" \
137 {textrel.s} \
138 {{ld textrel.warn} \
139 {readelf {-d --wide} textrel.rd}} \
140 "textrel.so" \
141 ] \
142 ] "xtensa-*-*"
143
144 run_ld_link_tests [list \
145 [list \
146 "DT_TEXTREL map file warning" \
147 "$LFLAGS -shared -M" \
148 "" \
149 "$AFLAGS_PIC" \
150 {textrel.s} \
151 {{ld textrel.map}} \
152 "textrel.so" \
153 ] \
154 ] "cris*-*-*"
155
156 # PR ld/20828 check for correct dynamic symbol table entries where:
157 # - symbols have been defined with a linker script,
158 # - the same symbols have been seen in shared library used in the link,
159 # - the shared library symbols have been swept in section garbage collection.
160 # Verify that the symbols are global rather than local and that a version
161 # script adjusts them accordingly.
162 # Also verify that a version definition supplied by an object rather than
163 # a version script and forcibly exported is unaffected by section GC.
164 if { [check_gc_sections_available] } {
165 run_ld_link_tests [list \
166 [list \
167 "PR ld/20828 dynamic symbols with section GC\
168 (auxiliary shared library)" \
169 "$LFLAGS -shared --gc-sections -T pr20828.ld" "" "$AFLAGS_PIC" \
170 {pr20828.s} \
171 {{readelf --dyn-syms pr20828-a.sd} \
172 {readelf --dyn-syms pr20828-b.sd}} \
173 "libpr20828.so"] \
174 [list \
175 "PR ld/20828 dynamic symbols with section GC (plain)" \
176 "$LFLAGS -shared --gc-sections -T pr20828.ld" \
177 "tmpdir/libpr20828.so" "$AFLAGS_PIC" \
178 {pr20828.s} \
179 {{readelf --dyn-syms pr20828-a.sd} \
180 {readelf --dyn-syms pr20828-b.sd}} \
181 "pr20828-1.so"] \
182 [list \
183 "PR ld/20828 dynamic symbols with section GC (version script)" \
184 "$LFLAGS -shared --gc-sections -T pr20828.ld\
185 --version-script=pr20828.ver" \
186 "tmpdir/libpr20828.so" \
187 "$AFLAGS_PIC" \
188 {pr20828.s} \
189 {{readelf --dyn-syms pr20828-b.sd} \
190 {readelf --dyn-syms pr20828-c.sd}} \
191 "pr20828-2.so"] \
192 [list \
193 "PR ld/20828 dynamic symbols with section GC\
194 (versioned shared library)" \
195 "$LFLAGS -shared --gc-sections -T pr20828.ld\
196 --version-script=pr20828-v.ver" \
197 "" "$AFLAGS_PIC" \
198 {pr20828.s} \
199 {{readelf --dyn-syms pr20828-c.sd} \
200 {readelf --dyn-syms pr20828-d.sd} \
201 {readelf --dyn-syms pr20828-e.sd}} \
202 "libpr20828-v.so"] \
203 [list \
204 "PR ld/20828 dynamic symbols with section GC (versioned)" \
205 "$LFLAGS -shared --gc-sections -T pr20828.ld\
206 --version-script=pr20828-v.ver" \
207 "tmpdir/libpr20828-v.so" \
208 "$AFLAGS_PIC" \
209 {pr20828.s} \
210 {{readelf --dyn-syms pr20828-c.sd} \
211 {readelf --dyn-syms pr20828-d.sd} \
212 {readelf --dyn-syms pr20828-e.sd}} \
213 "pr20828-v.so"] \
214 [list \
215 "PR ld/20828 forcibly exported symbol version without section GC" \
216 "$LFLAGS --no-dynamic-linker -e foo -E -T pr20828-v.ld" "" "" \
217 {pr20828-v.s} \
218 {{objdump -p pr20828-v.od}} \
219 "pr20828-v-1"] \
220 [list \
221 "PR ld/20828 forcibly exported symbol version with section GC" \
222 "$LFLAGS --no-dynamic-linker -e foo --gc-sections -E -T pr20828-v.ld" "" "" \
223 {pr20828-v.s} \
224 {{objdump -p pr20828-v.od}} \
225 "pr20828-v-2"]]
226 }
227 # PR ld/21233 check for correct dynamic symbol table entries where:
228 # - a symbol has been defined in a shared library used in the link,
229 # - the symbol has been referenced from a section swept in garbage collection,
230 # - the symbol has also been forced to be entered in the output file as an
231 # undefined symbol, either with a command-line option or a linker script
232 # command.
233 # Verify that the undefined symbol is global rather than local.
234 if { [check_gc_sections_available] } {
235 run_ld_link_tests [list \
236 [list \
237 "PR ld/21233 dynamic symbols with section GC\
238 (auxiliary shared library)" \
239 "$LFLAGS -shared -T pr21233.ld" "" "$AFLAGS_PIC" \
240 {pr21233-l.s} \
241 {{readelf --dyn-syms pr21233-l.sd}} \
242 "libpr21233.so"]]
243
244 run_ld_link_tests [list \
245 [list \
246 "PR ld/21233 dynamic symbols with section GC (--undefined)" \
247 "$LFLAGS --gc-sections -e foo --undefined=bar -T pr21233.ld" \
248 "tmpdir/libpr21233.so" "" \
249 {pr21233.s} \
250 {{readelf --dyn-syms pr21233.sd}} \
251 "pr21233-1"]]
252
253 run_ld_link_tests [list \
254 [list \
255 "PR ld/21233 dynamic symbols with section GC (--require-defined)" \
256 "$LFLAGS --gc-sections -e foo --require-defined=bar\
257 -T pr21233.ld" \
258 "tmpdir/libpr21233.so" "" \
259 {pr21233.s} \
260 {{readelf --dyn-syms pr21233.sd}} \
261 "pr21233-2"]]
262
263 run_ld_link_tests [list \
264 [list \
265 "PR ld/21233 dynamic symbols with section GC (EXTERN)" \
266 "$LFLAGS --gc-sections -e foo -T pr21233-e.ld" \
267 "tmpdir/libpr21233.so" "" \
268 {pr21233.s} \
269 {{readelf --dyn-syms pr21233.sd}} \
270 "pr21233-3"]]
271 }
272
273 if { [check_gc_sections_available] } {
274 run_ld_link_tests [list \
275 [list \
276 "Build pr22150.so" \
277 "$LFLAGS -shared --version-script pr22150.ver" \
278 "" \
279 "$AFLAGS_PIC" \
280 {pr22150a.s} \
281 {} \
282 "pr22150.so" \
283 ] \
284 [list \
285 "Build pr22150" \
286 "$LFLAGS -e _start --gc-sections" \
287 "tmpdir/pr22150.so" \
288 "" \
289 {pr22150b.s} \
290 {{readelf -V pr22150.vd}} \
291 "pr22150" \
292 ] \
293 ]
294 }
295
296 set ASFLAGS $old_ASFLAGS
297
298 # Check to see if the C compiler works
299 if { [which $CC] == 0 } {
300 return
301 }
302
303 # Add -ldl to extralibs if needed
304 set extralibs ""
305 if { ![istarget *-*-freebsd*]} {
306 set extralibs "-ldl"
307 }
308
309 set build_tests {
310 {"Build libfoo.so"
311 "-shared" "-fPIC"
312 {foo.c} {} "libfoo.so"}
313 {"Build versioned libfoo.so"
314 "-shared -Wl,--version-script=foo.map" "-fPIC"
315 {foo.c} {} "libfoov.so"}
316 {"Build libbar.so"
317 "-shared" "-fPIC"
318 {begin.c end.c} {} "libbar.so"}
319 {"Build warn libbar.so"
320 "-shared" "-fPIC"
321 {beginwarn.c end.c}
322 {{readelf {-S --wide} libbarw.rd}
323 {warning "^.*beginwarn.c:7: warning: function foo is deprecated$"}}
324 "libbarw.so" "c"}
325 {"Build hidden libbar.so"
326 "-shared" "-fPIC"
327 {begin.c endhidden.c} {} "libbarh.so"}
328 {"Build protected libbar.so"
329 "-shared" "-fPIC"
330 {begin.c endprotected.c} {} "libbarp.so"}
331 {"Build libbar.so with libfoo.so"
332 "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
333 {end.c} {} "libbarfoo.so"}
334 {"Build libar.so with versioned libfoo.so"
335 "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
336 {end.c} {} "libbarfoov.so"}
337 {"Build hidden libbar.so with libfoo.so"
338 "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
339 {endhidden.c} {} "libbarhfoo.so"}
340 {"Build hidden libar.so with versioned libfoo.so"
341 "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
342 {endhidden.c} {} "libbarhfoov.so"}
343 {"Build protected libbar.so with libfoo.so"
344 "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
345 {endprotected.c} {} "libbarpfoo.so"}
346 {"Build protected libbar.so with versioned libfoo.so"
347 "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
348 {endprotected.c} {} "libbarpfoov.so"}
349 {"Build libdl1.so"
350 "-shared" "-fPIC"
351 {dl1.c} {} "libdl1.so"}
352 {"Build libdl2a.so with --dynamic-list=dl2.list"
353 "-shared -Wl,--dynamic-list=dl2.list" "-fPIC"
354 {dl2.c dl2xxx.c} {} "libdl2a.so"}
355 {"Build libdl2a.so with --dynamic-list=dl2a.list"
356 "-shared -Wl,--dynamic-list=dl2a.list" "-fPIC"
357 {dl2.c dl2xxx.c} {} "libdl2a.so"}
358 {"Build libdl2a.so with --dynamic-list-data"
359 "-shared -Wl,--dynamic-list-data" "-fPIC"
360 {dl2.c dl2xxx.c} {} "libdl2a.so"}
361 {"Build libdl2b.so with --dynamic-list=dl2.list and dl2xxx.list"
362 "-shared -Wl,--dynamic-list=dl2.list,--dynamic-list=dl2xxx.list" "-fPIC"
363 {dl2.c dl2xxx.c} {} "libdl2b.so"}
364 {"Build libdl2c.so with --dynamic-list-data and dl2xxx.list"
365 "-shared -Wl,--dynamic-list-data,--dynamic-list=dl2xxx.list" "-fPIC"
366 {dl2.c dl2xxx.c} {} "libdl2c.so"}
367 {"Build libdl4a.so with --dynamic-list=dl4.list"
368 "-shared -Wl,--dynamic-list=dl4.list" "-fPIC"
369 {dl4.c dl4xxx.c} {} "libdl4a.so"}
370 {"Build libdl4b.so with --dynamic-list-data"
371 "-shared -Wl,--dynamic-list-data" "-fPIC"
372 {dl4.c dl4xxx.c} {} "libdl4b.so"}
373 {"Build libdl4c.so with --dynamic-list=dl4.list and dl4xxx.list"
374 "-shared -Wl,--dynamic-list=dl4.list,--dynamic-list=dl4xxx.list" "-fPIC"
375 {dl4.c dl4xxx.c} {} "libdl4c.so"}
376 {"Build libdl4d.so with --dynamic-list-data and dl4xxx.list"
377 "-shared -Wl,--dynamic-list-data,--dynamic-list=dl4xxx.list" "-fPIC"
378 {dl4.c dl4xxx.c} {} "libdl4d.so"}
379 {"Build libdl4e.so with -Bsymbolic-functions --dynamic-list-cpp-new"
380 "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC"
381 {dl4.c dl4xxx.c} {} "libdl4e.so"}
382 {"Build libdl4f.so with --dynamic-list-cpp-new -Bsymbolic-functions"
383 "-shared -Wl,--dynamic-list-cpp-new,-Bsymbolic-functions" "-fPIC"
384 {dl4.c dl4xxx.c} {} "libdl4f.so"}
385 {"Build libdl6a.so"
386 "-shared" "-fPIC"
387 {dl6.c} {} "libdl6a.so"}
388 {"Build libdl6b.so with -Bsymbolic --dynamic-list-data"
389 "-shared -Wl,-Bsymbolic,--dynamic-list-data" "-fPIC"
390 {dl6.c} {} "libdl6b.so"}
391 {"Build libdl6c.so with -Bsymbolic"
392 "-shared -Wl,-Bsymbolic" "-fPIC"
393 {dl6.c} {} "libdl6c.so"}
394 {"Build libdl6d.so with --dynamic-list-data -Bsymbolic"
395 "-shared -Wl,--dynamic-list-data,-Bsymbolic" "-fPIC"
396 {dl6.c} {} "libdl6d.so"}
397 {"Build libdata1.so"
398 "-shared" "-fPIC"
399 {data1.c} {} "libdata1.so"}
400 {"Build libdata2.so"
401 "-shared" "-fPIC"
402 {data2.c} {} "libdata2.so"}
403 {"Build libcomm1.o"
404 "-r -nostdlib" ""
405 {comm1.c} {} "libcomm1.o"}
406 {"Build libfunc1.so"
407 "-shared" "-fPIC"
408 {func1.c} {} "libfunc1.so"}
409 {"Build libpr9676-1.a"
410 "" "-fPIC"
411 {pr9676-1.c} {} "libpr9676-1.a"}
412 {"Build libpr9676-2.a"
413 "" "-fPIC"
414 {pr9676-2.c} {} "libpr9676-2.a"}
415 {"Build libpr9676-3.so"
416 "-shared" "-fPIC"
417 {pr9676-3.c} {} "libpr9676-3.so"}
418 {"Build libpr9676-4.so"
419 "-shared" "-fPIC"
420 {pr9676-4.c} {} "libpr9676-4.so"}
421 {"Build libpr9676-4a.so"
422 "-shared tmpdir/pr9676-4.o -Ltmpdir -lpr9676-3 -Wl,--start-group -lpr9676-1 -lpr9676-2 -Wl,--end-group"
423 "-fPIC"
424 {dummy.c} {{readelf {-s} pr9676.rd}} "libpr9676-4a.so"}
425 {"Build libpr9679.so"
426 "-shared" "-fPIC -O0"
427 {pr9679-1.c pr9679-2.c} {{readelf {-s} pr9679.rd}} "libpr9679.so"}
428 {"Build libpr11138-1.so"
429 "-shared -Wl,--version-script=pr11138-1.map" "-fPIC"
430 {pr11138-1.c} {} "libpr11138-1.so"}
431 {"Build libpr11138-2.o"
432 "-r -nostdlib" ""
433 {pr11138-2.c} {} "libpr11138-2.o"}
434 {"Build pr13250-1.so"
435 "-shared" "-fPIC"
436 {pr13250-1.c} {} "libpr13250-1.so"}
437 {"Build pr13250-2.so with libpr13250-1.so"
438 "-shared -Wl,--no-as-needed tmpdir/libpr13250-1.so" "-fPIC"
439 {pr13250-2.c} {} "libpr13250-2.so"}
440 {"Build libpr13250-3.o"
441 "-r -nostdlib" ""
442 {pr13250-3.c} {} "libpr13250-3.o"}
443 {"Build libpr14323-2.so"
444 "-shared" "-fPIC"
445 {pr14323-2.c} {} "libpr14323-2.so"}
446 {"Build pr14862-1.o"
447 "-r -nostdlib" ""
448 {pr14862-1.c} {} "libpr14862-1.o"}
449 {"Build libpr14862.so"
450 "-shared -Wl,--version-script=pr11138-1.map" "-fPIC"
451 {pr14862-2.c} {} "libpr14862.so"}
452 {"Build libneeded1b.so"
453 "-shared" "-fPIC"
454 {needed1b.c} {} "libneeded1b.so"}
455 {"Build libneeded1a.so"
456 "-shared -Wl,--add-needed,--no-as-needed -Ltmpdir -lneeded1b" "-fPIC"
457 {needed1a.c} {} "libneeded1a.so"}
458 {"Build libneeded1c.o"
459 "-r -nostdlib" ""
460 {needed1c.c} {} "libneeded1c.o"}
461 {"Build libneeded1pic.o"
462 "-r -nostdlib" "-fPIC"
463 {needed1c.c} {} "libneeded1pic.o"}
464 {"Build needed1a.so with --add-needed"
465 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--add-needed,-rpath=tmpdir,-rpath-link=tmpdir,-z,defs -Ltmpdir -lneeded1a" ""
466 {dummy.c} {} "needed1a.so"}
467 {"Build needed1b.so with --copy-dt-needed-entries"
468 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--copy-dt-needed-entries,-rpath=tmpdir,-rpath-link=tmpdir,-z,defs -Ltmpdir -lneeded1a" ""
469 {dummy.c} {} "needed1b.so"}
470 {"Build needed1a.so with --no-add-needed"
471 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--no-add-needed -Ltmpdir -lneeded1a" ""
472 {dummy.c} {} "needed1c.so"}
473 {"Build needed1b.so with --no-copy-dt-needed-entries"
474 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--no-copy-dt-needed-entries -Ltmpdir -lneeded1a" ""
475 {dummy.c} {} "needed1d.so"}
476 {"Build librel.so"
477 "-shared" "-fPIC"
478 {rel.c} {} "librel.so"}
479 {"Build libneeded2a.so"
480 "-shared" "-fPIC"
481 {needed2a.c} {} "libneeded2a.so"}
482 {"Build libneeded2b.so"
483 "-shared -Wl,--version-script,needed2.ver" "-fPIC"
484 {needed2b.c} {} "libneeded2b.so"}
485 {"Build libneeded2c.o"
486 "-r -nostdlib" ""
487 {needed2c.c} {} "libneeded2c.o"}
488 {"Build needed2"
489 "tmpdir/libneeded2c.o -Wl,--as-needed tmpdir/libneeded2a.so tmpdir/libneeded2b.so" ""
490 {dummy.c} {} "needed2"}
491 {"Build libneeded3a.so"
492 "-shared -Wl,--no-add-needed" "-fPIC"
493 {needed1a.c} {} "libneeded3a.so"}
494 {"Build libneeded3b.so"
495 "-shared -Wl,--no-as-needed,--add-needed -Ltmpdir -lneeded1b" "-fPIC"
496 {dummy.c} {} "libneeded3b.so"}
497 {"Build needed3.o"
498 "-r -nostdlib" ""
499 {needed3.c} {} "libneeded3.so"}
500 {"Build needed3"
501 "tmpdir/needed3.o -Wl,--as-needed -Ltmpdir -lneeded3a -lneeded3b -lneeded1b" ""
502 {dummy.c} {} "needed3"}
503 {"Build libpr2404a.so"
504 "-shared" "-fPIC"
505 {pr2404a.c} {} "libpr2404a.so"}
506 {"Build libpr2404n.so"
507 "-shared -Wl,-z,now" "-fPIC"
508 {pr2404a.c} {} "libpr2404n.so"}
509 {"Build libpr2404b.a"
510 "" ""
511 {pr2404b.c} {} "libpr2404b.a"}
512 {"Build rdynamic-1"
513 "-Wl,--no-dynamic-linker,-export-dynamic,--gc-sections" "-ffunction-sections"
514 {rdynamic-1.c} {{readelf {-s} rdynamic-1.rd}} "rdynamic-1"}
515 {"Build dynamic-1"
516 "-Wl,--no-dynamic-linker,--dynamic-list,dynamic-1.syms -Wl,--gc-sections" "-ffunction-sections"
517 {dynamic-1.c} {{readelf {-s} dynamic-1.rd}} "dynamic-1"}
518 {"Build libpr16496a.so"
519 "-shared -Wl,--version-script=pr16496a.map" "-fPIC"
520 {pr16496a.c} {} "libpr16496a.so"}
521 {"Build libpr16496b.a"
522 "" "-fPIC"
523 {pr16496b.c} {} "libpr16496b.a"}
524 {"Build libpr16496b.so"
525 "-shared -Wl,--no-as-needed tmpdir/pr16496b.o tmpdir/libpr16496a.so" ""
526 {dummy.c} {{objdump {-R} pr16496b.od}} "libpr16496b.so"}
527 {"Build libpr16452a.so"
528 "-shared -Wl,-soname,libpr16452a.so,--version-script=pr16452.map" "-fPIC"
529 {pr16452a.c} {} "libpr16452a.so"}
530 {"Build libpr16452b.so"
531 "-shared -Wl,-soname,libpr16452b.so,--no-as-needed tmpdir/libpr16452a.so" "-fPIC"
532 {dummy.c} {} "libpr16452b.so"}
533 {"Build pr16452"
534 "-Wl,--no-as-needed,-rpath=tmpdir,-rpath-link=tmpdir tmpdir/libpr16452b.so" ""
535 {pr16452b.c} {{objdump {-p} pr16452.od}} "pr16452"}
536 {"Build pr16457"
537 "-Wl,--no-as-needed,-rpath=tmpdir,-rpath-link=tmpdir tmpdir/libpr16452b.so" ""
538 {pr16452b.c} {{objdump {-p} pr16457.od}} "pr16457"}
539 {"Build libpr18458a.so"
540 "-shared -Wl,-z,now" "-fPIC"
541 {pr18458a.c} {} "libpr18458a.so"}
542 {"Build libpr18458b.so"
543 "-shared -Wl,-z,now tmpdir/libpr18458a.so" "-fPIC"
544 {pr18458b.c} {} "libpr18458b.so"}
545 {"Build pr19073a.o"
546 "-r -nostdlib" ""
547 {pr19073.s} {} "pr19073a.o"}
548 {"Build libpr19073.so"
549 "-shared -Wl,--version-script=pr19073.map tmpdir/pr19073a.o" "-fPIC"
550 {dummy.c} {{readelf {--dyn-syms --wide} pr19073.rd}} "libpr19073.so"}
551 {"Build pr21964-1a.so"
552 "-shared" "-fPIC"
553 {pr21964-1a.c} {} "pr21964-1a.so"}
554 {"Build pr21964-1b.so"
555 "-shared" "-fPIC"
556 {pr21964-1b.c} {} "pr21964-1b.so"}
557 {"Build pr21964-2a.so"
558 "-shared" "-fPIC"
559 {pr21964-2a.c} {} "pr21964-2a.so"}
560 {"Build pr21964-2b.so"
561 "-shared" "-fPIC"
562 {pr21964-2b.c} {} "pr21964-2b.so"}
563 {"Dump pr21978.so"
564 "-shared" "-fPIC -g -O2"
565 {pr21978a.c pr21978b.c} {{objdump {-Sl} pr21978.od}} "pr21978.so"}
566 }
567
568 run_cc_link_tests $build_tests
569
570 run_ld_link_tests [list \
571 [list \
572 "Build pr22269-1" \
573 "-pie -e _start --no-dynamic-linker -z text" \
574 "" \
575 "" \
576 { pr22269-1.c } \
577 {{readelf -rW pr22269-1.rd}} \
578 "pr22269-1" \
579 "-fPIE -O2" \
580 ] \
581 ]
582
583 set run_tests [list \
584 [list "Run normal with libfoo.so" \
585 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/end.o" "" \
586 {main.c} "normal" "normal.out" ] \
587 [list "Run protected with libfoo.so" \
588 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/endprotected.o" "" \
589 {main.c} "protected" "normal.out" ] \
590 [list "Run hidden with libfoo.so" \
591 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/endhidden.o" "" \
592 {main.c} "hidden" "hidden.out" ] \
593 [list "Run normal with versioned libfoo.so" \
594 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/end.o" "" \
595 {main.c} "normalv" "normal.out" ] \
596 [list "Run warn with versioned libfoo.so" \
597 "-Wl,--no-as-needed tmpdir/beginwarn.o tmpdir/libfoov.so" "" \
598 {main.c} "warn" "warn.out" \
599 "" "c" {^.*beginwarn.c:7: warning: function foo is deprecated$} ] \
600 [list "Run protected with versioned libfoo.so" \
601 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/endprotected.o" "" \
602 {main.c} "protected" "normal.out" ] \
603 [list "Run hidden with versioned libfoo.so" \
604 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/endhidden.o" "" \
605 {main.c} "hiddenv" "hidden.out" ] \
606 [list "Run normal libbar.so with libfoo.so" \
607 "-Wl,--no-as-needed tmpdir/libbarfoo.so tmpdir/libfoo.so" "" \
608 {main.c} "normal" "normal.out" ] \
609 [list "Run protected libbar.so with libfoo.so" \
610 "-Wl,--no-as-needed tmpdir/libbarpfoo.so tmpdir/libfoo.so" "" \
611 {main.c} "protected" "normal.out" ] \
612 [list "Run hidden libbar.so with libfoo.so" \
613 "-Wl,--no-as-needed tmpdir/libbarhfoo.so tmpdir/libfoo.so" "" \
614 {main.c} "hidden" "hidden.out" ] \
615 [list "Run normal libbar.so with versioned libfoo.so" \
616 "-Wl,--no-as-needed tmpdir/libbarfoov.so tmpdir/libfoov.so" "" \
617 {main.c} "normal" "normal.out" ] \
618 [list "Run protected libbar.so with versioned libfoo.so" \
619 "-Wl,--no-as-needed tmpdir/libbarpfoov.so tmpdir/libfoov.so" "" \
620 {main.c} "protected" "normal.out" ] \
621 [list "Run hidden libbar.so with versioned libfoo.so" \
622 "-Wl,--no-as-needed tmpdir/libbarhfoov.so tmpdir/libfoov.so" "" \
623 {main.c} "hidden" "hidden.out" ] \
624 [list "Run with libdl2a.so" \
625 "-Wl,--no-as-needed tmpdir/libdl2a.so" "" \
626 {dl2main.c} "dl2a" "dl2a.out" ] \
627 [list "Run with libdl2b.so" \
628 "-Wl,--no-as-needed tmpdir/libdl2b.so" "" \
629 {dl2main.c} "dl2b" "dl2b.out" ] \
630 [list "Run with libdl2c.so" \
631 "-Wl,--no-as-needed tmpdir/libdl2c.so" "" \
632 {dl2main.c} "dl2c" "dl2b.out" ] \
633 [list "Run with libdl4a.so" \
634 "-Wl,--no-as-needed tmpdir/libdl4a.so" "" \
635 {dl4main.c} "dl4a" "dl4a.out" ] \
636 [list "Run with libdl4b.so" \
637 "-Wl,--no-as-needed tmpdir/libdl4b.so" "" \
638 {dl4main.c} "dl4b" "dl4a.out" ] \
639 [list "Run with libdl4c.so" \
640 "-Wl,--no-as-needed tmpdir/libdl4c.so" "" \
641 {dl4main.c} "dl4c" "dl4b.out" ] \
642 [list "Run with libdl4d.so" \
643 "-Wl,--no-as-needed tmpdir/libdl4d.so" "" \
644 {dl4main.c} "dl4d" "dl4b.out" ] \
645 [list "Run with libdl4e.so" \
646 "-Wl,--no-as-needed tmpdir/libdl4e.so" "" \
647 {dl4main.c} "dl4e" "dl4a.out" ] \
648 [list "Run with libdl4f.so" \
649 "-Wl,--no-as-needed tmpdir/libdl4f.so" "" \
650 {dl4main.c} "dl4f" "dl4a.out" ] \
651 [list "Run with libdata1.so" \
652 "-Wl,--no-as-needed tmpdir/libdata1.so" "" \
653 {dynbss1.c} "dynbss1" "pass.out" ] \
654 [list "Run with libdata2.so" \
655 "-Wl,--no-as-needed tmpdir/libdata2.so" "" \
656 {weakdef1.c} "weakdef1" "pass.out" ] \
657 [list "Run with libfunc1.so comm1.o" \
658 "-Wl,--no-as-needed tmpdir/libfunc1.so tmpdir/comm1.o" "" \
659 {dummy.c} "comm1" "pass.out" ] \
660 [list "Run with comm1.o libfunc1.so" \
661 "-Wl,--no-as-needed tmpdir/comm1.o tmpdir/libfunc1.so" "" \
662 {dummy.c} "comm1" "pass.out" ] \
663 [list "Run with pr11138-2.c libpr11138-1.so" \
664 "-Wl,--no-as-needed,--version-script=pr11138-2.map tmpdir/pr11138-2.o tmpdir/libpr11138-1.so" "" \
665 {dummy.c} "pr11138a" "pr11138.out" ] \
666 [list "Run with libpr11138-1.so pr11138-2.c" \
667 "-Wl,--no-as-needed,--version-script=pr11138-2.map tmpdir/libpr11138-1.so tmpdir/pr11138-2.o" "" \
668 {dummy.c} "pr11138b" "pr11138.out" ] \
669 [list "Run with pr13250-3.c, libpr13250-1.so and libpr13250-2.so" \
670 "-Wl,--as-needed tmpdir/pr13250-3.o tmpdir/libpr13250-1.so tmpdir/libpr13250-2.so" "" \
671 {dummy.c} "pr13250" "pass.out" ] \
672 [list "Run with pr14323-1.c pr14323-2.so" \
673 "-Wl,--no-as-needed tmpdir/libpr14323-2.so" "" \
674 {pr14323-1.c} "pr14323" "pass.out" ] \
675 [list "Run with pr14862-1.c libpr14862.so" \
676 "-Wl,--as-needed tmpdir/libpr14862-1.o tmpdir/libpr14862.so" "" \
677 {dummy.c} "pr14862" "pr14862.out" ] \
678 [list "Link with --add-needed" \
679 "tmpdir/libneeded1c.o -Wl,--no-as-needed,--add-needed,-rpath=tmpdir,-rpath-link=tmpdir -Ltmpdir -lneeded1a" "" \
680 {dummy.c} "needed1a" "needed1.out" ] \
681 [list "Link with --copy-dt-needed-entries" \
682 "tmpdir/libneeded1c.o -Wl,--no-as-needed,--copy-dt-needed-entries,-rpath=tmpdir,-rpath-link=tmpdir -Ltmpdir -lneeded1a" "" \
683 {dummy.c} "needed1b" "needed1.out" ] \
684 [list "Run relmain" \
685 "-Wl,--no-as-needed,-rpath=tmpdir -Ltmpdir -lrel" "" \
686 {relmain.c} "relmain" "relmain.out" ] \
687 [list "Run pr2404" \
688 "-Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404a.so" "" \
689 {dummy.c} "pr2404" "pr2404.out" ] \
690 [list "Run pr2404n" \
691 "-Wl,-z,now -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404n.so" "" \
692 {dummy.c} "pr2404n" "pr2404.out" ] \
693 [list "Run pr18458" \
694 "-Wl,--no-as-needed,-z,now tmpdir/libpr18458a.so tmpdir/libpr18458b.so" "" \
695 {pr18458c.c} "pr18458" "pass.out" ] \
696 [list "Run pr21964-1" \
697 "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-1a.so tmpdir/pr21964-1b.so" "" \
698 {pr21964-1c.c} "pr21964-1" "pass.out" ] \
699 ]
700
701 # NetBSD ELF systems do not currently support the .*_array sections.
702 run_ld_link_exec_tests $run_tests "*-*-netbsdelf*"
703
704 # These tests require dlopen support.
705 set dlopen_run_tests [list \
706 [list "Run dl1a with --dynamic-list=dl1.list and dlopen on libdl1.so" \
707 "-Wl,--no-as-needed,--dynamic-list=dl1.list $extralibs" "" \
708 {dl1main.c} "dl1a" "dl1.out" ] \
709 [list "Run dl1b with --dynamic-list-data and dlopen on libdl1.so" \
710 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
711 {dl1main.c} "dl1b" "dl1.out" ] \
712 [list "Run dl6a1 with --dynamic-list-data and dlopen on libdl6a.so" \
713 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
714 {dl6amain.c} "dl6a1" "dl6a.out" ] \
715 [list "Run dl6a2 with -Bsymbolic-functions and dlopen on libdl6a.so" \
716 "$NOPIE_LDFLAGS -Wl,--no-as-needed,-Bsymbolic-functions $extralibs" "" \
717 {dl6amain.c} "dl6a2" "dl6b.out" "$NOPIE_CFLAGS" ] \
718 [list "Run dl6a3 with -Bsymbolic and dlopen on libdl6a.so" \
719 "-Wl,--no-as-needed,-Bsymbolic $extralibs" "" \
720 {dl6amain.c} "dl6a3" "dl6b.out" ] \
721 [list "Run dl6a4 with -Bsymbolic --dynamic-list-data and dlopen on libdl6a.so" \
722 "-Wl,--no-as-needed,-Bsymbolic,--dynamic-list-data $extralibs" "" \
723 {dl6amain.c} "dl6a4" "dl6a.out" ] \
724 [list "Run dl6a5 with -Bsymbolic-functions --dynamic-list-cpp-new and dlopen on libdl6a.so" \
725 "$NOPIE_LDFLAGS -Wl,--no-as-needed,-Bsymbolic-functions,--dynamic-list-cpp-new $extralibs" "" \
726 {dl6amain.c} "dl6a5" "dl6b.out" "$NOPIE_CFLAGS" ] \
727 [list "Run dl6a6 with --dynamic-list-cpp-new -Bsymbolic-functions and dlopen on libdl6a.so" \
728 "$NOPIE_LDFLAGS -Wl,--no-as-needed,--dynamic-list-cpp-new,-Bsymbolic-functions $extralibs" "" \
729 {dl6amain.c} "dl6a6" "dl6b.out" "$NOPIE_CFLAGS" ] \
730 [list "Run dl6a7 with --dynamic-list-data -Bsymbolic and dlopen on libdl6a.so" \
731 "$NOPIE_LDFLAGS -Wl,--no-as-needed,--dynamic-list-data,-Bsymbolic $extralibs" "" \
732 {dl6amain.c} "dl6a7" "dl6a.out" "$NOPIE_CFLAGS" ] \
733 [list "Run dl6b1 with --dynamic-list-data and dlopen on libdl6b.so" \
734 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
735 {dl6bmain.c} "dl6b1" "dl6a.out" ] \
736 [list "Run dl6b2 with dlopen on libdl6b.so" \
737 "-Wl,--no-as-needed $extralibs" "" \
738 {dl6bmain.c} "dl6b2" "dl6b.out" ] \
739 [list "Run dl6c1 with --dynamic-list-data and dlopen on libdl6c.so" \
740 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
741 {dl6cmain.c} "dl6c1" "dl6b.out" ] \
742 [list "Run dl6d1 with --dynamic-list-data and dlopen on libdl6d.so" \
743 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
744 {dl6dmain.c} "dl6d1" "dl6b.out" ] \
745 [list "Run pr21964-2" \
746 "-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-2a.so $extralibs" "" \
747 {pr21964-2c.c} "pr21964-2" "pass.out" ] \
748 ]
749
750 # Only run them when libdl is available.
751 if [check_libdl_available] {
752 # XFAIL on NetBSD ELF systems as they do not currently support the .*_array
753 # sections.
754 run_ld_link_exec_tests $dlopen_run_tests "*-*-netbsdelf*"
755 }
756
757 # Check --no-add-needed and --no-copy-dt-needed-entries
758 set testname "--no-add-needed"
759 set exec_output [run_host_cmd "$CC" "tmpdir/libneeded1c.o -Wl,--no-add-needed,-rpath-link=tmpdir -Ltmpdir -lneeded1a"]
760 if { [ regexp "tmpdir/libneeded1b.so: .*: DSO missing" $exec_output ] } {
761 pass $testname
762 } {
763 fail $testname
764 }
765 set testname "--no-copy-dt-needed-entries"
766 set exec_output [run_host_cmd "$CC" "tmpdir/libneeded1c.o -Wl,--no-copy-dt-needed-entries,-rpath-link=tmpdir -Ltmpdir -lneeded1a"]
767 if { [ regexp "tmpdir/libneeded1b.so: .*: DSO missing" $exec_output ] } {
768 pass $testname
769 } {
770 fail $testname
771 }
772 set testname "--no-add-needed -shared"
773 set exec_output [run_host_cmd "$CC" "-shared tmpdir/libneeded1pic.o -Wl,--no-add-needed,-z,defs -Ltmpdir -lneeded1a"]
774 if { [ regexp "undefined reference to `\.?bar'" $exec_output ] } {
775 pass $testname
776 } {
777 fail $testname
778 }
779 set testname "--no-copy-dt-needed-entries -shared"
780 set exec_output [run_host_cmd "$CC" "-shared tmpdir/libneeded1pic.o -Wl,--no-copy-dt-needed-entries,-z,defs -Ltmpdir -lneeded1a"]
781 if { [ regexp "undefined reference to `\.?bar'" $exec_output ] } {
782 pass $testname
783 } {
784 fail $testname
785 }
786
787 # Check to see if the C++ compiler works
788 if { [which $CXX] == 0 } {
789 return
790 }
791
792 set build_cxx_tests {
793 {"Build libdl3a.so with --dynamic-list=dl3.list"
794 "-shared -Wl,--dynamic-list=dl3.list" "-fPIC"
795 {dl3.cc} {} "libdl3a.so" "c++"}
796 {"Build libdl3b.so with -Bsymbolic"
797 "-shared -Wl,-Bsymbolic" "-fPIC"
798 {dl3.cc} {} "libdl3b.so" "c++"}
799 {"Build libdl3a.so with --dynamic-list-cpp-typeinfo"
800 "-shared -Wl,--dynamic-list-cpp-typeinfo" "-fPIC"
801 {dl3.cc} {} "libdl3c.so" "c++"}
802 {"Build libdnew1a.so with --Bsymbolic-functions --dynamic-list-cpp-new"
803 "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC -ansi"
804 {del.cc new.cc} {} "libnew1a.so" "c++"}
805 {"Build libdnew1b.so with --dynamic-list-data --dynamic-list-cpp-new"
806 "-shared -Wl,--dynamic-list-data,--dynamic-list-cpp-new" "-fPIC -ansi"
807 {del.cc new.cc} {} "libnew1b.so" "c++"}
808 }
809
810 # "-shared -Bsymbolic" only works with gcc 4.5.0 and newer.
811 # {"Run with libdl3b.so"
812 # "tmpdir/libdl3b.so" ""
813 # {dl3main.cc} "dl3b" "dl3b.out" "" "c++"}
814 set run_cxx_tests {
815 {"Run with libdl3a.so"
816 "-Wl,--no-as-needed tmpdir/libdl3a.so" ""
817 {dl3main.cc} "dl3a" "dl3a.out" "" "c++"}
818 {"Run with libdl3c.so"
819 "-Wl,--no-as-needed tmpdir/libdl3c.so" ""
820 {dl3main.cc} "dl3c" "dl3a.out" "" "c++"}
821 {"Run with libnew1a.so"
822 "-Wl,--no-as-needed tmpdir/libnew1a.so" ""
823 {dl5.cc} "dl5a" "dl5.out" "-ansi" "c++"}
824 {"Run with libnew1b.so"
825 "-Wl,--no-as-needed tmpdir/libnew1b.so" ""
826 {dl5.cc} "dl5b" "dl5.out" "-ansi" "c++"}
827 }
828
829 run_cc_link_tests $build_cxx_tests
830 run_ld_link_exec_tests $run_cxx_tests
831
832 if { [istarget *-*-linux*]
833 || [istarget *-*-nacl*]
834 || [istarget *-*-gnu*] } {
835 run_cc_link_tests [list \
836 [list \
837 "Build libpr2404b.a with PIE" \
838 "" \
839 "-fPIE" \
840 { pr2404b.c } \
841 {} \
842 "libpr2404b.a" \
843 ] \
844 [list \
845 "Build pr19579a.o" \
846 "" "-fPIE" \
847 {pr19579a.c} \
848 {} \
849 "libpr19579a.a" \
850 ] \
851 [list \
852 "Build libpr19579.so" \
853 "-shared" \
854 "-fPIC" \
855 {pr19579b.c} \
856 {} \
857 "libpr19579.so" \
858 ] \
859 [list \
860 "Build libpr19579now.so" \
861 "-shared -Wl,-z,now" \
862 "-fPIC" \
863 {pr19579b.c} \
864 {} \
865 "libpr19579.so" \
866 ] \
867 ]
868 run_ld_link_exec_tests [list \
869 [list \
870 "Run pr18458 with PIE" \
871 "-pie -Wl,--no-as-needed,-z,now tmpdir/libpr18458a.so tmpdir/libpr18458b.so" \
872 "" \
873 {pr18458c.c} \
874 "pr18458p" \
875 "pass.out" \
876 "-fPIE" \
877 ] \
878 [list \
879 "Run pr2404 with PIE" \
880 "-pie -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404a.so" \
881 "" \
882 { dummy.c } \
883 "pr2404pie" \
884 "pr2404.out" \
885 "-fPIE" \
886 ] \
887 [list \
888 "Run pr2404 with PIE (-z now)" \
889 "-pie -Wl,-z,now -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404n.so" \
890 "" \
891 { dummy.c } \
892 "pr2404pien" \
893 "pr2404.out" \
894 "-fPIE" \
895 ] \
896 [list \
897 "Run pr18718" \
898 "" \
899 "" \
900 { pr18718.c check-ptr-eq.c } \
901 "pr18718" \
902 "pass.out" \
903 "-O2 -I../bfd" \
904 ] \
905 [list \
906 "Run pr18718 (-z now)" \
907 "-Wl,-z,now" \
908 "" \
909 { pr18718.c check-ptr-eq.c } \
910 "pr18718" \
911 "pass.out" \
912 "-O2 -I../bfd" \
913 ] \
914 [list \
915 "Run pr18718 with PIE (1)" \
916 "-pie" \
917 "" \
918 { pr18718.c check-ptr-eq.c } \
919 "pr18718pie1" \
920 "pass.out" \
921 "-O2 -fPIE -I../bfd" \
922 ] \
923 [list \
924 "Run pr18718 with PIE (2)" \
925 "" \
926 "" \
927 { pr18718.c check-ptr-eq.c } \
928 "pr18718pie2" \
929 "pass.out" \
930 "-O2 -fPIE -I../bfd" \
931 ] \
932 [list \
933 "Run pr18718 with PIE (3)" \
934 "-pie -Wl,-z,now" \
935 "" \
936 { pr18718.c check-ptr-eq.c } \
937 "pr18718pie3" \
938 "pass.out" \
939 "-O2 -fPIE -I../bfd" \
940 ] \
941 [list \
942 "Run pr18718 with PIE (4)" \
943 "-Wl,-z,now" \
944 "" \
945 { pr18718.c check-ptr-eq.c } \
946 "pr18718pie4" \
947 "pass.out" \
948 "-O2 -fPIE -I../bfd" \
949 ] \
950 [list \
951 "Run pr18718 with PIC (1)" \
952 "" \
953 "" \
954 { pr18718.c check-ptr-eq.c } \
955 "pr18718pic1" \
956 "pass.out" \
957 "-O2 -fPIC -I../bfd" \
958 ] \
959 [list \
960 "Run pr18718 with PIC (2)" \
961 "-pie" \
962 "" \
963 { pr18718.c check-ptr-eq.c } \
964 "pr18718pic2" \
965 "pass.out" \
966 "-O2 -fPIC -I../bfd" \
967 ] \
968 [list \
969 "Run pr18718 with PIC (3)" \
970 "-Wl,-z,now" \
971 "" \
972 { pr18718.c check-ptr-eq.c } \
973 "pr18718pic3" \
974 "pass.out" \
975 "-O2 -fPIC -I../bfd" \
976 ] \
977 [list \
978 "Run pr18718 with PIC (4)" \
979 "-pie -Wl,-z,now" \
980 "" \
981 { pr18718.c check-ptr-eq.c } \
982 "pr18718pic4" \
983 "pass.out" \
984 "-O2 -fPIC -I../bfd" \
985 ] \
986 [list \
987 "Run pr19579" \
988 "-pie -Wl,--no-as-needed,-z,text tmpdir/pr19579a.o tmpdir/libpr19579.so" \
989 "" \
990 {dummy.c} \
991 "pr19579" \
992 "pass.out" \
993 "-fPIE" \
994 ] \
995 [list \
996 "Run pr19579 (-z now)" \
997 "-pie -Wl,-z,now -Wl,--no-as-needed,-z,text tmpdir/pr19579a.o tmpdir/libpr19579.so" \
998 "" \
999 {dummy.c} \
1000 "pr19579n" \
1001 "pass.out" \
1002 "-fPIE" \
1003 ] \
1004 ]
1005 }
1006
1007 proc mix_pic_and_non_pic {xfails cflags ldflags exe} {
1008 run_cc_link_tests [list \
1009 [list \
1010 "Build libpr19719a.so" \
1011 "-shared -Wl,-soname,libpr19719.so" \
1012 "-fPIC" \
1013 { pr19719d.c } \
1014 {} \
1015 "libpr19719a.so" \
1016 ] \
1017 [list \
1018 "Build libpr19719b.so" \
1019 "-shared -Wl,-soname,libpr19719.so" \
1020 "-fPIC" \
1021 { dummy.c } \
1022 {} \
1023 "libpr19719b.so" \
1024 ] \
1025 [list \
1026 "Build libpr19719b.o" \
1027 "-r -nostdlib" \
1028 "-fPIC" \
1029 { pr19719b.c } \
1030 {} \
1031 "libpr19719b.o" \
1032 ] \
1033 ]
1034
1035 send_log "cp tmpdir/libpr19719b.so tmpdir/libpr19719.so\n"
1036 exec cp tmpdir/libpr19719b.so tmpdir/libpr19719.so
1037
1038 run_ld_link_exec_tests [list \
1039 [list \
1040 "Run $exe fun defined" \
1041 "-Wl,--no-as-needed,-rpath,tmpdir $ldflags tmpdir/libpr19719b.o tmpdir/libpr19719.so" \
1042 "" \
1043 { pr19719a.c pr19719c.c } \
1044 $exe \
1045 "pass.out" \
1046 "$cflags" \
1047 ] \
1048 ]
1049
1050 send_log "cp tmpdir/libpr19719a.so tmpdir/libpr19719.so\n"
1051 exec cp tmpdir/libpr19719a.so tmpdir/libpr19719.so
1052
1053 foreach targ $xfails {
1054 setup_xfail $targ
1055 }
1056
1057 if ![isnative] {
1058 unsupported "Run $exe fun undefined"
1059 return
1060 }
1061
1062 set exec_output [run_host_cmd "tmpdir/$exe" ""]
1063 if {![string match "PASS" $exec_output]} {
1064 fail "Run $exe fun undefined"
1065 } else {
1066 pass "Run $exe fun undefined"
1067 }
1068 }
1069
1070 mix_pic_and_non_pic [list "arm*-*-*" "aarch64*-*-*"] "" "" "pr19719"
1071 mix_pic_and_non_pic [] "-fPIE" "-pie" "pr19719pie"