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