ce3434b30fa33350682053b6800aec6c91276520
[deliverable/binutils-gdb.git] / ld / testsuite / ld-ifunc / ifunc.exp
1 # Expect script for linker support of IFUNC symbols and relocations.
2 #
3 # Copyright (C) 2009-2020 Free Software Foundation, Inc.
4 # Contributed by Red Hat.
5 #
6 # This file is part of the GNU Binutils.
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 # MA 02110-1301, USA.
22 #
23 # Written by Nick Clifton <nickc@redhat.com>
24
25
26 if { ![is_elf_format] || ![supports_gnu_osabi]
27 || [istarget arc*-*-*]
28 || [istarget am33*-*-*]
29 || [istarget bfin-*-*]
30 || [istarget cris*-*-*]
31 || [istarget frv-*-*]
32 || [istarget lm32-*-*]
33 || [istarget m32r-*-*]
34 || [istarget m68k-*-*]
35 || [istarget microblaze-*-*]
36 || [istarget mips*-*-*]
37 || [istarget mn10300-*-*]
38 || [istarget nds32*-*-*]
39 || [istarget nios2-*-*]
40 || [istarget or1k-*-*]
41 || [istarget riscv*-*-*]
42 || [istarget score*-*-*]
43 || [istarget sh*-*-*]
44 || [istarget tic6x-*-*]
45 || [istarget tile*-*-*]
46 || [istarget vax-*-*] } {
47 verbose "IFUNC tests not run - target does not support IFUNC"
48 return
49 }
50
51 # Skip targets where -shared is not supported
52
53 if ![check_shared_lib_support] {
54 return
55 }
56
57 set saved_ASFLAGS "$ASFLAGS"
58 if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
59 set ASFLAGS "$ASFLAGS -mx86-used-note=no"
60 }
61
62 # This test does not need a compiler...
63 run_dump_test "ifuncmod5"
64
65 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
66 foreach t $test_list {
67 # We need to strip the ".d", but can leave the dirname.
68 verbose [file rootname $t]
69 run_dump_test [file rootname $t]
70 }
71
72 # We need a working compiler. (Strictly speaking this is
73 # not true, we could use target specific assembler files).
74 if { ![check_compiler_available] } {
75 verbose "IFUNC tests not run - no compiler available"
76 return
77 }
78
79 # A procedure to check the OS/ABI field in the ELF header of a binary file.
80 proc check_osabi { binary_file expected_osabi } {
81 global READELF
82 global READELFFLAGS
83
84 catch "exec $READELF $READELFFLAGS --file-header $binary_file > readelf.out" got
85
86 if ![string match "" $got] then {
87 verbose "proc check_osabi: Readelf produced unexpected out processing $binary_file: $got"
88 return 0
89 }
90
91 if { ![regexp "\n\[ \]*OS/ABI:\[ \]*(.+)\n\[ \]*ABI" \
92 [file_contents readelf.out] nil osabi] } {
93 verbose "proc check_osabi: Readelf failed to extract an ELF header from $binary_file"
94 return 0
95 }
96
97 if { $osabi == $expected_osabi } {
98 return 1
99 }
100
101 verbose "Expected OSABI: $expected_osabi, Obtained osabi: $osabi"
102
103 return 0
104 }
105
106 # A procedure to confirm that a file contains the IFUNC symbol.
107 # Returns -1 upon error, 0 if the symbol was not found and 1 if it was found.
108 proc contains_ifunc_symbol { binary_file } {
109 global READELF
110 global READELFFLAGS
111
112 catch "exec $READELF $READELFFLAGS --symbols $binary_file > readelf.out" got
113
114 if ![string match "" $got] then {
115 verbose "proc contains_ifunc_symbol: Readelf produced unexpected out processing $binary_file: $got"
116 return -1
117 }
118
119 # Look for a line like this:
120 # 58: 0000000000400600 30 IFUNC GLOBAL DEFAULT 12 library_func2
121 # with perhaps some other info between the visibility and section
122
123 if { ![regexp ".*\[ \]*IFUNC\[ \]+GLOBAL\[ \]+DEFAULT .* \[UND0-9\]+\[ \]+library_func2\n" [file_contents readelf.out]] } {
124 return 0
125 }
126
127 return 1
128 }
129
130 # A procedure to confirm that a file contains the R_*_IRELATIVE
131 # relocation.
132 # Returns -1 upon error, 0 if the relocation was not found and 1 if
133 # it was found.
134 proc contains_irelative_reloc { binary_file } {
135 global READELF
136 global READELFFLAGS
137
138 catch "exec $READELF $READELFFLAGS --relocs --wide $binary_file > readelf.out" got
139
140 if ![string match "" $got] then {
141 verbose "proc contains_irelative_reloc: Readelf produced unexpected out processing $binary_file: $got"
142 return -1
143 }
144
145 # Look for a line like this:
146 # 0000000000600ab0 0000000000000025 R_X86_64_IRELATIVE 000000000040061c
147 # 080496f4 0000002a R_386_IRELATIVE
148
149
150 if { ![regexp "\[0-9a-f\]+\[ \]+\[0-9a-f\]+\[ \]+R_(\[_0-9A-Z\]+_IREL(|ATIVE)|PARISC_IPLT)\[ \]*\[0-9a-f\]*\n" [file_contents readelf.out]] } {
151 return 0
152 }
153
154 return 1
155 }
156
157 # A procedure to confirm that a file contains a relocation that references an IFUNC symbol.
158 # Returns -1 upon error, 0 if the reloc was not found and 1 if it was found.
159 proc contains_ifunc_reloc { binary_file } {
160 global READELF
161 global READELFFLAGS
162
163 catch "exec $READELF $READELFFLAGS --relocs $binary_file > readelf.out" got
164
165 if ![string match "" $got] then {
166 verbose "proc contains_ifunc_reloc: Readelf produced unexpected out processing $binary_file: $got"
167 return -1
168 }
169
170 if [string match "" [file_contents readelf.out]] then {
171 verbose "No relocs found in $binary_file"
172 return 0
173 }
174
175 if { ![regexp "\\(\\)" [file_contents readelf.out]] } {
176 return 0
177 }
178
179 return 1
180 }
181
182 set fails 0
183
184 # Create the object files, libraries and executables.
185 if ![ld_compile "$CC -c -fPIC" "$srcdir/$subdir/prog.c" "tmpdir/shared_prog.o"] {
186 fail "Could not create a PIC object file"
187 set fails [expr $fails + 1]
188 }
189 if ![ld_compile "$CC -c $NOPIE_CFLAGS" "$srcdir/$subdir/prog.c" "tmpdir/static_prog.o"] {
190 fail "Could not create a non-PIC object file"
191 set fails [expr $fails + 1]
192 }
193 if ![ld_compile "$CC -c -fPIC -DWITH_IFUNC" "$srcdir/$subdir/lib.c" "tmpdir/shared_ifunc.o"] {
194 fail "Could not create a PIC object file containing an IFUNC symbol"
195 set fails [expr $fails + 1]
196 }
197 if ![ld_compile "$CC -c $NOPIE_CFLAGS -DWITH_IFUNC" "$srcdir/$subdir/lib.c" "tmpdir/static_ifunc.o"] {
198 fail "Could not create a non-PIC object file containing an IFUNC symbol"
199 set fails [expr $fails + 1]
200 }
201 if ![ld_compile "$CC -c -DWITHOUT_IFUNC" "$srcdir/$subdir/lib.c" "tmpdir/static_noifunc.o"] {
202 fail "Could not create an ordinary non-PIC object file"
203 set fails [expr $fails + 1]
204 }
205 if ![ld_assemble $as "$srcdir/ld-elf/empty.s" "tmpdir/empty.o"] {
206 fail "Could not create an empty object file"
207 set fails [expr $fails + 1]
208 }
209 if ![ld_compile "$CC -c" "$srcdir/$subdir/test-1.c" "tmpdir/test-1.o"] {
210 fail "Could not create test-1.o"
211 set fails [expr $fails + 1]
212 }
213 if ![ld_compile "$CC -fPIC -c" "$srcdir/$subdir/test-2.c" "tmpdir/test-2.o"] {
214 fail "Could not create test-2.o"
215 set fails [expr $fails + 1]
216 }
217
218 if { $fails != 0 } {
219 return
220 }
221
222 if ![ld_link $ld "tmpdir/libshared_ifunc.so" "-shared tmpdir/shared_ifunc.o"] {
223 fail "Could not create a shared library containing an IFUNC symbol"
224 set fails [expr $fails + 1]
225 }
226 if ![ar_simple_create $ar "" "tmpdir/libifunc.a" "tmpdir/static_ifunc.o"] {
227 fail "Could not create a static library containing an IFUNC symbol"
228 set fails [expr $fails + 1]
229 }
230
231 if { $fails != 0 } {
232 return
233 }
234
235 if ![ld_link $CC "tmpdir/dynamic_prog" "-Wl,--no-as-needed,-rpath=./tmpdir,-Bdynamic -Ltmpdir tmpdir/shared_prog.o -lshared_ifunc"] {
236 fail "Could not link a dynamic executable"
237 set fails [expr $fails + 1]
238 }
239 if ![ld_link $CC "tmpdir/local_prog" "$NOPIE_LDFLAGS -Wl,--no-as-needed,-rpath=./tmpdir -Ltmpdir tmpdir/static_prog.o -lifunc"] {
240 fail "Could not link a dynamic executable using local ifunc"
241 set fails [expr $fails + 1]
242 }
243 if ![string match "" $STATIC_LDFLAGS] {
244 if ![ld_link $CC "tmpdir/static_prog" "-static -Ltmpdir tmpdir/static_prog.o -lifunc"] {
245 fail "Could not link a static executable"
246 set fails [expr $fails + 1]
247 }
248 }
249 if ![ld_link $ld "tmpdir/static_nonifunc_prog" "-static tmpdir/empty.o"] {
250 fail "Could not link a non-ifunc using static executable"
251 set fails [expr $fails + 1]
252 }
253 if ![ld_link $CC "tmpdir/test-1" "-Wl,--no-as-needed,-rpath=./tmpdir tmpdir/test-1.o tmpdir/libshared_ifunc.so"] {
254 fail "Could not link test-1"
255 set fails [expr $fails + 1]
256 }
257 if ![ld_link $ld "tmpdir/libtest-2.so" "-shared tmpdir/test-2.o"] {
258 fail "Could not link libtest-2.so"
259 set fails [expr $fails + 1]
260 }
261 if ![ld_link $ld "tmpdir/libtest-2-now.so" "-shared -z now tmpdir/test-2.o"] {
262 fail "Could not link libtest-2-now.so"
263 set fails [expr $fails + 1]
264 }
265
266 if { $fails == 0 } {
267 pass "Building ifunc binaries"
268 set fails 0
269 } else {
270 return
271 }
272
273 # Check the executables and shared libraries
274 #
275 # The linked ifunc using executables and the shared library containing
276 # ifunc should have an OSABI field of GNU. The linked non-ifunc using
277 # executable should have an OSABI field of NONE (aka System V).
278
279 switch -glob $target_triplet {
280 hppa*-*-linux* { set expected_none {UNIX - GNU} }
281 default { set expected_none {UNIX - System V} }
282 }
283
284 if {! [check_osabi tmpdir/libshared_ifunc.so {UNIX - GNU}]} {
285 fail "Shared libraries containing ifunc does not have an OS/ABI field of GNU"
286 set fails [expr $fails + 1]
287 }
288 if {! [check_osabi tmpdir/local_prog {UNIX - GNU}]} {
289 fail "Local ifunc-using executable does not have an OS/ABI field of GNU"
290 set fails [expr $fails + 1]
291 }
292 if { ![string match "" $STATIC_LDFLAGS] \
293 && ![check_osabi tmpdir/static_prog {UNIX - GNU}]} {
294 fail "Static ifunc-using executable does not have an OS/ABI field of GNU"
295 set fails [expr $fails + 1]
296 }
297 if {! [check_osabi tmpdir/dynamic_prog $expected_none]} {
298 fail "Dynamic ifunc-using executable does not have an OS/ABI field of $expected_none"
299 set fails [expr $fails + 1]
300 }
301 if {! [check_osabi tmpdir/static_nonifunc_prog $expected_none]} {
302 fail "Static non-ifunc-using executable does not have an OS/ABI field of $expected_none"
303 set fails [expr $fails + 1]
304 }
305
306 # The linked ifunc using executables and the shared library containing
307 # ifunc should contain an IFUNC symbol. The non-ifunc using executable
308 # should not.
309
310 if {[contains_ifunc_symbol tmpdir/libshared_ifunc.so] != 1} {
311 fail "Shared libraries containing ifunc does not contain an IFUNC symbol"
312 set fails [expr $fails + 1]
313 }
314 if {[contains_ifunc_symbol tmpdir/local_prog] != 1} {
315 fail "Local ifunc-using executable does not contain an IFUNC symbol"
316 set fails [expr $fails + 1]
317 }
318 if { ![string match "" $STATIC_LDFLAGS] \
319 && [contains_ifunc_symbol tmpdir/static_prog] != 1} {
320 fail "Static ifunc-using executable does not contain an IFUNC symbol"
321 set fails [expr $fails + 1]
322 }
323 if {[contains_ifunc_symbol tmpdir/dynamic_prog] != 0} {
324 fail "Dynamic ifunc-using executable contains an IFUNC symbol"
325 set fails [expr $fails + 1]
326 }
327 if {[contains_ifunc_symbol tmpdir/static_nonifunc_prog] != 0} {
328 fail "Static non-ifunc-using executable contains an IFUNC symbol"
329 set fails [expr $fails + 1]
330 }
331 if {[contains_ifunc_symbol tmpdir/test-1] != 0} {
332 fail "test-1 contains IFUNC symbols"
333 set fails [expr $fails + 1]
334 }
335 if {[contains_ifunc_symbol tmpdir/libtest-2.so] != 0} {
336 fail "libtest-2.so contains IFUNC symbols"
337 set fails [expr $fails + 1]
338 }
339 if {[contains_ifunc_symbol tmpdir/libtest-2-now.so] != 0} {
340 fail "libtest-2-now.so contains IFUNC symbols"
341 set fails [expr $fails + 1]
342 }
343
344 # The linked ifunc using executables and shared libraries should contain
345 # a dynamic reloc referencing the IFUNC symbol. (Even the static
346 # executable which should have a dynamic section created for it). The
347 # non-ifunc using executable should not.
348
349 if {[contains_irelative_reloc tmpdir/libshared_ifunc.so] != 1} {
350 fail "ifunc-using shared library does not contain R_*_IRELATIVE relocation"
351 set fails [expr $fails + 1]
352 }
353 if {[contains_irelative_reloc tmpdir/local_prog] != 1} {
354 fail "Local ifunc-using executable does not contain R_*_IRELATIVE relocation"
355 set fails [expr $fails + 1]
356 }
357 if { ![string match "" $STATIC_LDFLAGS] \
358 && [contains_irelative_reloc tmpdir/static_prog] != 1} {
359 fail "Static ifunc-using executable does not contain R_*_IRELATIVE relocation"
360 set fails [expr $fails + 1]
361 }
362 if {[contains_ifunc_reloc tmpdir/dynamic_prog] != 0} {
363 fail "Dynamic ifunc-using executable contains a reloc against an IFUNC symbol"
364 set fails [expr $fails + 1]
365 }
366 if {[contains_ifunc_reloc tmpdir/static_nonifunc_prog] == 1} {
367 fail "Static non-ifunc-using executable contains a reloc against an IFUNC symbol!"
368 set fails [expr $fails + 1]
369 }
370
371 if { $fails == 0 } {
372 pass "Checking ifunc binaries"
373 }
374
375 run_cc_link_tests [list \
376 [list \
377 "Build libpr16467a.so" \
378 "-shared -Wl,--version-script=pr16467a.map" \
379 "-fPIC" \
380 { pr16467a.c } \
381 {} \
382 "libpr16467a.so" \
383 ] \
384 [list \
385 "Build libpr16467b.a" \
386 "" \
387 "-fPIC" \
388 { pr16467b.c } \
389 {} \
390 "libpr16467b.a" \
391 ] \
392 [list \
393 "Build libpr16467b.so" \
394 "-shared tmpdir/pr16467b.o tmpdir/libpr16467a.so \
395 -Wl,--version-script=pr16467b.map" \
396 "-fPIC" \
397 { dummy.c } \
398 {} \
399 "libpr16467b.so" \
400 ] \
401 [list \
402 "Build libpr16467c.a" \
403 "" \
404 "" \
405 { pr16467c.c } \
406 {} \
407 "libpr16467c.a" \
408 ] \
409 [list \
410 "Build libpr16467an.so" \
411 "-shared -Wl,-z,now -Wl,--version-script=pr16467a.map" \
412 "-fPIC" \
413 { pr16467a.c } \
414 {} \
415 "libpr16467an.so" \
416 ] \
417 [list \
418 "Build libpr16467bn.so" \
419 "-shared tmpdir/pr16467b.o tmpdir/libpr16467an.so \
420 -Wl,--version-script=pr16467b.map" \
421 "-fPIC" \
422 { dummy.c } \
423 {} \
424 "libpr16467bn.so" \
425 ] \
426 ]
427
428 run_ld_link_exec_tests [list \
429 [list \
430 "Common symbol override ifunc test 1a" \
431 "-static" \
432 "" \
433 { ifunc-common-1a.c ifunc-common-1b.c } \
434 "ifunc-common-1a" \
435 "ifunc-common-1.out" \
436 "-g" \
437 ] \
438 [list \
439 "Common symbol override ifunc test 1b" \
440 "-static" \
441 "" \
442 { ifunc-common-1b.c ifunc-common-1a.c } \
443 "ifunc-common-1b" \
444 "ifunc-common-1.out" \
445 "-g" \
446 ] \
447 ]
448
449 # Run-time tests which require working IFUNC support.
450 if { ![check_ifunc_available] } {
451 return
452 }
453
454 run_cc_link_tests [list \
455 [list \
456 "Build ifunc-lib.so" \
457 "-shared" \
458 "-fPIC" \
459 { ifunc-lib.c } \
460 {} \
461 "libifunc-lib.so" \
462 ] \
463 [list \
464 "Build ifunc-libn.so" \
465 "-shared -Wl,-z,now" \
466 "-fPIC" \
467 { ifunc-lib.c } \
468 {} \
469 "libifunc-libn.so" \
470 ] \
471 ]
472
473 run_ld_link_exec_tests [list \
474 [list \
475 "Run pr16467" \
476 "-Wl,--no-as-needed tmpdir/pr16467c.o tmpdir/libpr16467b.so tmpdir/libpr16467a.so" \
477 "" \
478 { dummy.c } \
479 "pr16467" \
480 "pr16467.out" \
481 "" \
482 ] \
483 [list \
484 "Run pr16467 (-z now)" \
485 "-Wl,-z,now -Wl,--no-as-needed tmpdir/pr16467c.o tmpdir/libpr16467bn.so tmpdir/libpr16467an.so" \
486 "" \
487 { dummy.c } \
488 "pr16467n" \
489 "pr16467.out" \
490 "" \
491 ] \
492 [list \
493 "Run ifunc-main" \
494 "-Wl,--no-as-needed tmpdir/libifunc-lib.so" \
495 "" \
496 { ifunc-main.c } \
497 "ifunc-main" \
498 "ifunc-main.out" \
499 ] \
500 [list \
501 "Run ifunc-main with -fpic" \
502 "-Wl,--no-as-needed tmpdir/libifunc-lib.so" \
503 "" \
504 { ifunc-main.c } \
505 "ifunc-main" \
506 "ifunc-main.out" \
507 "-fpic" \
508 ] \
509 [list \
510 "Run ifunc-main (-z now)" \
511 "-Wl,-z,now -Wl,--no-as-needed tmpdir/libifunc-libn.so" \
512 "" \
513 { ifunc-main.c } \
514 "ifunc-mainn" \
515 "ifunc-main.out" \
516 ] \
517 [list \
518 "Run ifunc-main with PIE (-z now)" \
519 "-pie -Wl,-z,now -Wl,--no-as-needed tmpdir/libifunc-libn.so" \
520 "" \
521 { ifunc-main.c } \
522 "ifunc-mainpn" \
523 "ifunc-main.out" \
524 "-fpie" \
525 ] \
526 ]
527
528 # Run-time tests which require working ifunc attribute support.
529 if { ![check_ifunc_attribute_available] } {
530 return
531 }
532
533 run_cc_link_tests [list \
534 [list \
535 "Build pr18808a.o" \
536 "" \
537 "" \
538 { pr18808a.c } \
539 "" \
540 "" \
541 ] \
542 [list \
543 "Build libpr18808.so" \
544 "-shared" \
545 "-fPIC -O2 -g" \
546 { pr18808b.c } \
547 {} \
548 "libpr18808.so" \
549 ] \
550 [list \
551 "Build libpr18808n.so" \
552 "-shared -Wl,-z,now" \
553 "-fPIC -O2 -g" \
554 { pr18808b.c } \
555 {} \
556 "libpr18808n.so" \
557 ] \
558 [list \
559 "Build pr18841a.o" \
560 "" \
561 "" \
562 { pr18841a.c } \
563 "" \
564 "" \
565 ] \
566 [list \
567 "Build libpr18841b.so" \
568 "-shared" \
569 "-fPIC -O0 -g" \
570 { pr18841b.c } \
571 {} \
572 "libpr18841b.so" \
573 ] \
574 [list \
575 "Build libpr18841c.so" \
576 "-shared" \
577 "-fPIC -O0 -g" \
578 { pr18841c.c } \
579 {} \
580 "libpr18841c.so" \
581 ] \
582 [list \
583 "Build libpr18841bn.so" \
584 "-Wl,-z,now -shared" \
585 "-fPIC -O0 -g" \
586 { pr18841b.c } \
587 {} \
588 "libpr18841bn.so" \
589 ] \
590 [list \
591 "Build libpr18841cn.so" \
592 "-shared" \
593 "-Wl,-z,now -fPIC -O0 -g" \
594 { pr18841c.c } \
595 {} \
596 "libpr18841cn.so" \
597 ] \
598 [list \
599 "Build libpr23169a.so" \
600 "-shared" \
601 "-fPIC -O2 -g" \
602 { pr23169a.c } \
603 {} \
604 "libpr23169a.so" \
605 ] \
606 [list \
607 "Build libpr23169b.so" \
608 "-shared -Wl,-z,now" \
609 "-fPIC -O2 -g" \
610 { pr23169a.c } \
611 {} \
612 "libpr23169b.so" \
613 ] \
614 [list \
615 "Build pr23169a" \
616 "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libpr23169a.so" \
617 "$NOPIE_CFLAGS -O2 -g" \
618 { pr23169b.c pr23169c.c } \
619 {{readelf {--dyn-syms} pr23169a.rd} \
620 {readelf {-r -W} pr23169b.rd}} \
621 "pr23169a" \
622 ] \
623 [list \
624 "Build pr23169b" \
625 "-pie -Wl,--no-as-needed tmpdir/libpr23169a.so" \
626 "-fPIE -O2 -g" \
627 { pr23169b.c pr23169c.c } \
628 {{readelf {--dyn-syms} pr23169c.rd} \
629 {readelf {-r -W} pr23169b.rd}} \
630 "pr23169b" \
631 ] \
632 [list \
633 "Build pr23169c" \
634 "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libpr23169a.so" \
635 "-fPIE -O2 -g" \
636 { pr23169b.c pr23169c.c } \
637 {{readelf {--dyn-syms} pr23169c.rd} \
638 {readelf {-r -W} pr23169b.rd}} \
639 "pr23169c" \
640 ] \
641 [list \
642 "Build pr23169d" \
643 "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,now tmpdir/libpr23169b.so" \
644 "$NOPIE_CFLAGS -O2 -g" \
645 { pr23169b.c pr23169c.c } \
646 {{readelf {--dyn-syms} pr23169a.rd} \
647 {readelf {-r -W} pr23169b.rd}} \
648 "pr23169d" \
649 ] \
650 [list \
651 "Build pr23169e" \
652 "-pie -Wl,--no-as-needed,-z,now tmpdir/libpr23169b.so" \
653 "-fPIE -O2 -g" \
654 { pr23169b.c pr23169c.c } \
655 {{readelf {--dyn-syms} pr23169c.rd} \
656 {readelf {-r -W} pr23169b.rd}} \
657 "pr23169e" \
658 ] \
659 [list \
660 "Build pr23169f" \
661 "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,now tmpdir/libpr23169b.so" \
662 "-fPIE -O2 -g" \
663 { pr23169b.c pr23169c.c } \
664 {{readelf {--dyn-syms} pr23169c.rd} \
665 {readelf {-r -W} pr23169b.rd}} \
666 "pr23169f" \
667 ] \
668 ]
669
670 run_ld_link_exec_tests [list \
671 [list \
672 "Run pr18808" \
673 "-Wl,--no-as-needed tmpdir/pr18808a.o tmpdir/libpr18808.so" \
674 "" \
675 { dummy.c } \
676 "pr18808" \
677 "pr18808.out" \
678 ] \
679 [list \
680 "Run pr18808 (-z now)" \
681 "-Wl,-z,now -Wl,--no-as-needed tmpdir/pr18808a.o tmpdir/libpr18808n.so" \
682 "" \
683 { dummy.c } \
684 "pr18808n" \
685 "pr18808.out" \
686 ] \
687 [list \
688 "Run pr18841 with libpr18841b.so" \
689 "-Wl,--no-as-needed tmpdir/pr18841a.o tmpdir/libpr18841b.so" \
690 "" \
691 { dummy.c } \
692 "pr18841b" \
693 "pr18841.out" \
694 ] \
695 [list \
696 "Run pr18841 with libpr18841c.so" \
697 "-Wl,--as-needed tmpdir/pr18841a.o tmpdir/libpr18841c.so" \
698 "" \
699 { dummy.c } \
700 "pr18841c" \
701 "pr18841.out" \
702 ] \
703 [list \
704 "Run pr18841 with libpr18841bn.so (-z now)" \
705 "-Wl,-z,now -Wl,--no-as-needed tmpdir/pr18841a.o tmpdir/libpr18841bn.so" \
706 "" \
707 { dummy.c } \
708 "pr18841bn" \
709 "pr18841.out" \
710 ] \
711 [list \
712 "Run pr18841 with libpr18841cn.so (-z now)" \
713 "-Wl,-z,now -Wl,--as-needed tmpdir/pr18841a.o tmpdir/libpr18841cn.so" \
714 "" \
715 { dummy.c } \
716 "pr18841cn" \
717 "pr18841.out" \
718 ] \
719 ]
720
721 # The pr23169 testcase is not valid. In general, you can't call ifunc
722 # resolvers in another binary unless you know what you're doing. In
723 # particular you must ensure that the binary containing the resolver
724 # is relocated before the resolver is called (for example, the
725 # function addresses returned by the resolver may be loaded from the
726 # GOT).
727 # That does not happen for the pr23169 testcase where the resolver is
728 # in the executable (which is relocated last by ld.so).
729 if { [isnative]
730 && !([istarget "powerpc-*-*"]
731 || [istarget "aarch64*-*-*"]
732 || [istarget "sparc*-*-*"]) } {
733 run_ld_link_exec_tests [list \
734 [list \
735 "Run pr23169a" \
736 "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libpr23169a.so" \
737 "" \
738 { pr23169b.c pr23169c.c } \
739 "pr23169a" \
740 "pass.out" \
741 "$NOPIE_CFLAGS -O2 -g" \
742 ] \
743 [list \
744 "Run pr23169b" \
745 "-pie -Wl,--no-as-needed tmpdir/libpr23169a.so" \
746 "" \
747 { pr23169b.c pr23169c.c } \
748 "pr23169b" \
749 "pass.out" \
750 "-fPIE -O2 -g" \
751 ] \
752 [list \
753 "Run pr23169c" \
754 "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libpr23169a.so" \
755 "" \
756 { pr23169b.c pr23169c.c } \
757 "pr23169c" \
758 "pass.out" \
759 "-fPIE -O2 -g" \
760 ] \
761 [list \
762 "Run pr23169d" \
763 "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,now tmpdir/libpr23169b.so" \
764 "" \
765 { pr23169b.c pr23169c.c } \
766 "pr23169d" \
767 "pass.out" \
768 "$NOPIE_CFLAGS -O2 -g" \
769 ] \
770 [list \
771 "Run pr23169e" \
772 "-pie -Wl,--no-as-needed,-z,now tmpdir/libpr23169b.so" \
773 "" \
774 { pr23169b.c pr23169c.c } \
775 "pr23169e" \
776 "pass.out" \
777 "-fPIE -O2 -g" \
778 ] \
779 [list \
780 "Run pr23169f" \
781 "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,now tmpdir/libpr23169b.so" \
782 "" \
783 { pr23169b.c pr23169c.c } \
784 "pr23169f" \
785 "pass.out" \
786 "-fPIE -O2 -g" \
787 ] \
788 ]
789 if { $STATIC_PIE_LDFLAGS != "" } then {
790 run_ld_link_exec_tests [list \
791 [list \
792 "Run pr23169g" \
793 "$STATIC_PIE_LDFLAGS" \
794 "" \
795 { pr23169a.c pr23169b.c pr23169c.c } \
796 "pr23169g" \
797 "pass.out" \
798 "-fPIE -O2 -g" \
799 ] \
800 ]
801 }
802 }
803
804 set ASFLAGS "$saved_ASFLAGS"
This page took 0.045866 seconds and 3 git commands to generate.