Updated Malay translation for the bfd sub-directory
[binutils-gdb.git] / ld / testsuite / ld-ifunc / ifunc.exp
blobea444da0b63ae0a044ae87df942487a5fb172423
1 # Expect script for linker support of IFUNC symbols and relocations.
3 #   Copyright (C) 2009-2025 Free Software Foundation, Inc.
4 #   Contributed by Red Hat.
6 # This file is part of the GNU Binutils.
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.
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.
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.
23 # Written by Nick Clifton <nickc@redhat.com>
26 if { ![is_elf_format] || ![supports_gnu_osabi]
27      || [istarget alpha-*-*]
28      || [istarget arc*-*-*]
29      || [istarget am33*-*-*]
30      || [istarget bfin-*-*]
31      || [istarget cris*-*-*]
32      || [istarget frv-*-*]
33      || [istarget kvx*-*-*]
34      || [istarget lm32-*-*]
35      || [istarget m32r-*-*]
36      || [istarget m68k-*-*]
37      || [istarget microblaze-*-*]
38      || [istarget mips*-*-*]
39      || [istarget mn10300-*-*]
40      || [istarget nds32*-*-*]
41      || [istarget or1k-*-*]
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
51 # Skip targets where -shared is not supported
53 if ![check_shared_lib_support] {
54     return
57 set saved_ASFLAGS "$ASFLAGS"
58 if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } {
59     set ASFLAGS "$ASFLAGS -mx86-used-note=no"
62 # This test does not need a compiler...
63 run_dump_test "ifuncmod5"
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]
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
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
84     catch "exec $READELF $READELFFLAGS --file-header $binary_file > readelf.out" got
86     if ![string match "" $got] then {
87         verbose "proc check_osabi: Readelf produced unexpected out processing $binary_file: $got"
88         return 0
89     }
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     }
97     if { $osabi == $expected_osabi } {
98         return 1
99     }
101     verbose "Expected OSABI: $expected_osabi, Obtained osabi: $osabi"
103     return 0
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
112     catch "exec $READELF $READELFFLAGS --symbols $binary_file > readelf.out" got
114     if ![string match "" $got] then {
115         verbose "proc contains_ifunc_symbol: Readelf produced unexpected out processing $binary_file: $got"
116         return -1
117     }
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
123     if { ![regexp ".*\[ \]*IFUNC\[ \]+GLOBAL\[ \]+DEFAULT .* \[UND0-9\]+\[ \]+library_func2\n" [file_contents readelf.out]] } {
124         return 0
125     }
127     return 1
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
138     catch "exec $READELF $READELFFLAGS --relocs --wide $binary_file > readelf.out" got
140     if ![string match "" $got] then {
141         verbose "proc contains_irelative_reloc: Readelf produced unexpected out processing $binary_file: $got"
142         return -1
143     }
145     # Look for a line like this:
146     #    0000000000600ab0  0000000000000025 R_X86_64_IRELATIVE      000000000040061c
147     #    080496f4  0000002a R_386_IRELATIVE
150     if { ![regexp "\[0-9a-f\]+\[ \]+\[0-9a-f\]+\[ \]+R_(\[_0-9A-Z\]+_IREL(|ATIVE)|PARISC_IPLT).*\n" [file_contents readelf.out]] } {
151         return 0
152     }
154     return 1
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
163     catch "exec $READELF $READELFFLAGS --relocs $binary_file > readelf.out" got
165     if ![string match "" $got] then {
166         verbose "proc contains_ifunc_reloc: Readelf produced unexpected out processing $binary_file: $got"
167         return -1
168     }
170     if [string match "" [file_contents readelf.out]] then {
171         verbose "No relocs found in $binary_file"
172         return 0
173     }
175     if { ![regexp "\\(\\)" [file_contents readelf.out]] } {
176         return 0
177     }
179     return 1
182 set fails 0
184 # Disable LTO for these tests.
185 set cc_cmd "$CC_FOR_TARGET"
186 if {[check_lto_available]} {
187    append cc_cmd " -fno-lto"
190 # Create the object files, libraries and executables.
191 if ![ld_compile "$cc_cmd -c -fPIC" "$srcdir/$subdir/prog.c" "tmpdir/shared_prog.o"] {
192     fail "Could not create a PIC object file"
193     set fails [expr $fails + 1]
195 if ![ld_compile "$cc_cmd -c $NOPIE_CFLAGS" "$srcdir/$subdir/prog.c" "tmpdir/static_prog.o"] {
196     fail "Could not create a non-PIC object file"
197     set fails [expr $fails + 1]
199 if ![ld_compile "$cc_cmd -c -fPIC -DWITH_IFUNC" "$srcdir/$subdir/lib.c" "tmpdir/shared_ifunc.o"] {
200     fail "Could not create a PIC object file containing an IFUNC symbol"
201     set fails [expr $fails + 1]
203 if ![ld_compile "$cc_cmd -c $NOPIE_CFLAGS -DWITH_IFUNC" "$srcdir/$subdir/lib.c" "tmpdir/static_ifunc.o"] {
204     fail "Could not create a non-PIC object file containing an IFUNC symbol"
205     set fails [expr $fails + 1]
207 if ![ld_compile "$cc_cmd -c -DWITHOUT_IFUNC" "$srcdir/$subdir/lib.c" "tmpdir/static_noifunc.o"] {
208     fail "Could not create an ordinary non-PIC object file"
209     set fails [expr $fails + 1]
211 if ![ld_assemble $as "$srcdir/ld-elf/empty.s" "tmpdir/empty.o"] {
212     fail "Could not create an empty object file"
213     set fails [expr $fails + 1]
215 if ![ld_compile "$cc_cmd -c" "$srcdir/$subdir/test-1.c" "tmpdir/test-1.o"] {
216     fail "Could not create test-1.o"
217     set fails [expr $fails + 1]
219 if ![ld_compile "$cc_cmd -fPIC -c" "$srcdir/$subdir/test-2.c" "tmpdir/test-2.o"] {
220     fail "Could not create test-2.o"
221     set fails [expr $fails + 1]
224 if { $fails != 0 } {
225     return
228 if ![ld_link $ld "tmpdir/libshared_ifunc.so" "-shared tmpdir/shared_ifunc.o"] {
229     fail "Could not create a shared library containing an IFUNC symbol"
230     set fails [expr $fails + 1]
232 if ![ar_simple_create $ar "" "tmpdir/libifunc.a" "tmpdir/static_ifunc.o"] {
233     fail "Could not create a static library containing an IFUNC symbol"
234     set fails [expr $fails + 1]
237 if { $fails != 0 } {
238     return
241 if ![ld_link $CC_FOR_TARGET "tmpdir/dynamic_prog" "-Wl,--no-as-needed,-rpath=./tmpdir,-Bdynamic -Ltmpdir tmpdir/shared_prog.o -lshared_ifunc"] {
242     fail "Could not link a dynamic executable"
243     set fails [expr $fails + 1]
245 if ![ld_link $CC_FOR_TARGET "tmpdir/local_prog" "$NOPIE_LDFLAGS -Wl,--no-as-needed,-rpath=./tmpdir -Ltmpdir tmpdir/static_prog.o -lifunc"] {
246     fail "Could not link a dynamic executable using local ifunc"
247     set fails [expr $fails + 1]
249 if ![string match "" $STATIC_LDFLAGS] {
250     if ![ld_link $CC_FOR_TARGET "tmpdir/static_prog" "-static -Ltmpdir tmpdir/static_prog.o -lifunc"] {
251         fail "Could not link a static executable"
252         set fails [expr $fails + 1]
253     }
255 if ![ld_link $ld "tmpdir/static_nonifunc_prog" "-static tmpdir/empty.o"] {
256     fail "Could not link a non-ifunc using static executable"
257     set fails [expr $fails + 1]
259 if ![ld_link $CC_FOR_TARGET "tmpdir/test-1" "-Wl,--no-as-needed,-rpath=./tmpdir tmpdir/test-1.o tmpdir/libshared_ifunc.so"] {
260     fail "Could not link test-1"
261     set fails [expr $fails + 1]
263 if ![ld_link $ld "tmpdir/libtest-2.so" "-shared tmpdir/test-2.o"] {
264     fail "Could not link libtest-2.so"
265     set fails [expr $fails + 1]
267 if ![ld_link $ld "tmpdir/libtest-2-now.so" "-shared -z now tmpdir/test-2.o"] {
268     fail "Could not link libtest-2-now.so"
269     set fails [expr $fails + 1]
272 if { $fails == 0 } {
273   pass "Building ifunc binaries"
274   set fails 0
275 } else {
276     return
279 # Check the executables and shared libraries
281 # The linked ifunc using executables and the shared library containing
282 # ifunc should have an OSABI field of GNU.  The linked non-ifunc using
283 # executable should have an OSABI field of NONE (aka System V).
285 switch -glob $target_triplet {
286     hppa*-*-linux* { set expected_none {UNIX - GNU} }
287     default { set expected_none {UNIX - System V} }
290 if {! [check_osabi tmpdir/libshared_ifunc.so {UNIX - GNU}]} {
291     fail "Shared libraries containing ifunc does not have an OS/ABI field of GNU"
292     set fails [expr $fails + 1]
294 if {! [check_osabi tmpdir/local_prog {UNIX - GNU}]} {
295     fail "Local ifunc-using executable does not have an OS/ABI field of GNU"
296     set fails [expr $fails + 1]
298 if { ![string match "" $STATIC_LDFLAGS] \
299      && ![check_osabi tmpdir/static_prog {UNIX - GNU}]} {
300     fail "Static ifunc-using executable does not have an OS/ABI field of GNU"
301     set fails [expr $fails + 1]
303 if {! [check_osabi tmpdir/dynamic_prog $expected_none]} {
304     fail "Dynamic ifunc-using executable does not have an OS/ABI field of $expected_none"
305     set fails [expr $fails + 1]
307 if {! [check_osabi tmpdir/static_nonifunc_prog $expected_none]} {
308     fail "Static non-ifunc-using executable does not have an OS/ABI field of $expected_none"
309     set fails [expr $fails + 1]
312 # The linked ifunc using executables and the shared library containing
313 # ifunc should contain an IFUNC symbol.  The non-ifunc using executable
314 # should not.
316 if {[contains_ifunc_symbol tmpdir/libshared_ifunc.so] != 1} {
317     fail "Shared libraries containing ifunc does not contain an IFUNC symbol"
318     set fails [expr $fails + 1]
320 if {[contains_ifunc_symbol tmpdir/local_prog] != 1} {
321     fail "Local ifunc-using executable does not contain an IFUNC symbol"
322     set fails [expr $fails + 1]
324 if { ![string match "" $STATIC_LDFLAGS] \
325      && [contains_ifunc_symbol tmpdir/static_prog] != 1} {
326     fail "Static ifunc-using executable does not contain an IFUNC symbol"
327     set fails [expr $fails + 1]
329 if {[contains_ifunc_symbol tmpdir/dynamic_prog] != 0} {
330     fail "Dynamic ifunc-using executable contains an IFUNC symbol"
331     set fails [expr $fails + 1]
333 if {[contains_ifunc_symbol tmpdir/static_nonifunc_prog] != 0} {
334     fail "Static non-ifunc-using executable contains an IFUNC symbol"
335     set fails [expr $fails + 1]
337 if {[contains_ifunc_symbol tmpdir/test-1] != 0} {
338     fail "test-1 contains IFUNC symbols"
339     set fails [expr $fails + 1]
341 if {[contains_ifunc_symbol tmpdir/libtest-2.so] != 0} {
342     fail "libtest-2.so contains IFUNC symbols"
343     set fails [expr $fails + 1]
345 if {[contains_ifunc_symbol tmpdir/libtest-2-now.so] != 0} {
346     fail "libtest-2-now.so contains IFUNC symbols"
347     set fails [expr $fails + 1]
350 # The linked ifunc using executables and shared libraries should contain
351 # a dynamic reloc referencing the IFUNC symbol.  (Even the static
352 # executable which should have a dynamic section created for it).  The
353 # non-ifunc using executable should not.
355 if {[contains_irelative_reloc tmpdir/libshared_ifunc.so] != 1} {
356     fail "ifunc-using shared library does not contain R_*_IRELATIVE relocation"
357     set fails [expr $fails + 1]
359 if {[contains_irelative_reloc tmpdir/local_prog] != 1} {
360     fail "Local ifunc-using executable does not contain R_*_IRELATIVE relocation"
361     set fails [expr $fails + 1]
363 if { ![string match "" $STATIC_LDFLAGS] \
364     && ![istarget hppa*-*-*] \
365     && [contains_irelative_reloc tmpdir/static_prog] != 1} {
366     fail "Static ifunc-using executable does not contain R_*_IRELATIVE relocation"
367     set fails [expr $fails + 1]
369 if {[contains_ifunc_reloc tmpdir/dynamic_prog] != 0} {
370     fail "Dynamic ifunc-using executable contains a reloc against an IFUNC symbol"
371     set fails [expr $fails + 1]
373 if {[contains_ifunc_reloc tmpdir/static_nonifunc_prog] == 1} {
374     fail "Static non-ifunc-using executable contains a reloc against an IFUNC symbol!"
375     set fails [expr $fails + 1]
378 if { $fails == 0 } {
379   pass "Checking ifunc binaries"
382 run_cc_link_tests [list \
383     [list \
384         "Build libpr16467a.so" \
385         "-shared -Wl,--version-script=pr16467a.map" \
386         "-fPIC" \
387         { pr16467a.c } \
388         {} \
389         "libpr16467a.so" \
390     ] \
391     [list \
392         "Build libpr16467b.a" \
393         "" \
394         "-fPIC" \
395         { pr16467b.c } \
396         {} \
397         "libpr16467b.a" \
398     ] \
399     [list \
400         "Build libpr16467b.so" \
401         "-shared -Wl,--as-needed tmpdir/pr16467b.o tmpdir/libpr16467a.so \
402          -Wl,--version-script=pr16467b.map" \
403         "-fPIC" \
404         { dummy.c } \
405         {} \
406         "libpr16467b.so" \
407     ] \
408     [list \
409         "Build libpr16467c.a" \
410         "" \
411         "" \
412         { pr16467c.c } \
413         {} \
414         "libpr16467c.a" \
415     ] \
416     [list \
417         "Build libpr16467an.so" \
418         "-shared -Wl,-z,now -Wl,--version-script=pr16467a.map" \
419         "-fPIC" \
420         { pr16467a.c } \
421         {} \
422         "libpr16467an.so" \
423     ] \
424     [list \
425         "Build libpr16467bn.so" \
426         "-shared -Wl,--as-needed tmpdir/pr16467b.o tmpdir/libpr16467an.so \
427          -Wl,--version-script=pr16467b.map" \
428         "-fPIC" \
429         { dummy.c } \
430         {} \
431         "libpr16467bn.so" \
432     ] \
435 run_ld_link_exec_tests [list \
436     [list \
437         "Common symbol override ifunc test 1a" \
438         "-static" \
439         "" \
440         { ifunc-common-1a.c ifunc-common-1b.c } \
441         "ifunc-common-1a" \
442         "ifunc-common-1.out" \
443         "-g" \
444     ] \
445     [list \
446         "Common symbol override ifunc test 1b" \
447         "-static" \
448         "" \
449         { ifunc-common-1b.c ifunc-common-1a.c } \
450         "ifunc-common-1b" \
451         "ifunc-common-1.out" \
452         "-g" \
453     ] \
456 # Run-time tests which require working IFUNC support.
457 if { ![check_ifunc_available] } {
458     return
461 run_cc_link_tests [list \
462     [list \
463         "Build ifunc-lib.so" \
464         "-shared" \
465         "-fPIC" \
466         { ifunc-lib.c } \
467         {} \
468         "libifunc-lib.so" \
469     ] \
470     [list \
471         "Build ifunc-libn.so" \
472         "-shared -Wl,-z,now" \
473         "-fPIC" \
474         { ifunc-lib.c } \
475         {} \
476         "libifunc-libn.so" \
477     ] \
480 run_ld_link_exec_tests [list \
481     [list \
482         "Run pr16467" \
483         "-Wl,--no-as-needed tmpdir/pr16467c.o tmpdir/libpr16467b.so tmpdir/libpr16467a.so" \
484         "" \
485         { dummy.c } \
486         "pr16467" \
487         "pr16467.out" \
488         "" \
489     ] \
490     [list \
491         "Run pr16467 (-z now)" \
492         "-Wl,-z,now -Wl,--no-as-needed tmpdir/pr16467c.o tmpdir/libpr16467bn.so tmpdir/libpr16467an.so" \
493         "" \
494         { dummy.c } \
495         "pr16467n" \
496         "pr16467.out" \
497         "" \
498     ] \
499     [list \
500         "Run ifunc-main" \
501         "-Wl,--no-as-needed tmpdir/libifunc-lib.so" \
502         "" \
503         { ifunc-main.c } \
504         "ifunc-main" \
505         "ifunc-main.out" \
506     ] \
507     [list \
508         "Run ifunc-main with -fpic" \
509         "-Wl,--no-as-needed tmpdir/libifunc-lib.so" \
510         "" \
511         { ifunc-main.c } \
512         "ifunc-main" \
513         "ifunc-main.out" \
514         "-fpic" \
515     ] \
516     [list \
517         "Run ifunc-main (-z now)" \
518         "-Wl,-z,now -Wl,--no-as-needed tmpdir/libifunc-libn.so" \
519         "" \
520         { ifunc-main.c } \
521         "ifunc-mainn" \
522         "ifunc-main.out" \
523     ] \
524     [list \
525         "Run ifunc-main with PIE (-z now)" \
526         "-pie -Wl,-z,now -Wl,--no-as-needed tmpdir/libifunc-libn.so" \
527         "" \
528         { ifunc-main.c } \
529         "ifunc-mainpn" \
530         "ifunc-main.out" \
531         "-fpie" \
532     ] \
535 # Run-time tests which require working ifunc attribute support.
536 if { ![check_ifunc_attribute_available] } {
537     return
540 run_cc_link_tests [list \
541     [list \
542         "Build pr18808a.o" \
543         "" \
544         "" \
545         { pr18808a.c } \
546         "" \
547         "" \
548     ] \
549     [list \
550         "Build libpr18808.so" \
551         "-shared" \
552         "-fPIC -O2 -g" \
553         { pr18808b.c } \
554         {} \
555         "libpr18808.so" \
556     ] \
557     [list \
558         "Build libpr18808n.so" \
559         "-shared -Wl,-z,now" \
560         "-fPIC -O2 -g" \
561         { pr18808b.c } \
562         {} \
563         "libpr18808n.so" \
564     ] \
565     [list \
566         "Build pr18841a.o" \
567         "" \
568         "$NOPIE_CFLAGS" \
569         { pr18841a.c } \
570         "" \
571         "" \
572     ] \
573     [list \
574         "Build libpr18841b.so" \
575         "-shared" \
576         "-fPIC -O0 -g" \
577         { pr18841b.c } \
578         {} \
579         "libpr18841b.so" \
580     ] \
581     [list \
582         "Build libpr18841c.so" \
583         "-shared" \
584         "-fPIC -O0 -g" \
585         { pr18841c.c } \
586         {} \
587         "libpr18841c.so" \
588     ] \
589     [list \
590         "Build libpr18841bn.so" \
591         "-Wl,-z,now -shared" \
592         "-fPIC -O0 -g" \
593         { pr18841b.c } \
594         {} \
595         "libpr18841bn.so" \
596     ] \
597     [list \
598         "Build libpr18841cn.so" \
599         "-shared" \
600         "-Wl,-z,now -fPIC -O0 -g" \
601         { pr18841c.c } \
602         {} \
603         "libpr18841cn.so" \
604     ] \
605     [list \
606         "Build libpr23169a.so" \
607         "-shared -Wl,-z,lazy" \
608         "-fPIC -O2 -g" \
609         { pr23169a.c } \
610         {} \
611         "libpr23169a.so" \
612     ] \
613     [list \
614         "Build libpr23169b.so" \
615         "-shared -Wl,-z,now" \
616         "-fPIC -O2 -g" \
617         { pr23169a.c } \
618         {} \
619         "libpr23169b.so" \
620     ] \
621     [list \
622         "Build pr23169a" \
623         "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libpr23169a.so" \
624         "$NOPIE_CFLAGS -O2 -g" \
625         { pr23169b.c pr23169c.c } \
626         {{readelf {--dyn-syms} pr23169a.rd} \
627          {readelf {-r -W} pr23169b.rd}} \
628         "pr23169a" \
629     ] \
630     [list \
631         "Build pr23169b" \
632         "-pie -Wl,--no-as-needed tmpdir/libpr23169a.so" \
633         "-fPIE -O2 -g" \
634         { pr23169b.c pr23169c.c } \
635         {{readelf {--dyn-syms} pr23169c.rd} \
636          {readelf {-r -W} pr23169b.rd}} \
637         "pr23169b" \
638     ] \
639     [list \
640         "Build pr23169c" \
641         "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libpr23169a.so" \
642         "-fPIE -O2 -g" \
643         { pr23169b.c pr23169c.c } \
644         {{readelf {--dyn-syms} pr23169a.rd} \
645          {readelf {-r -W} pr23169b.rd}} \
646         "pr23169c" \
647     ] \
648     [list \
649         "Build pr23169d" \
650         "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,now tmpdir/libpr23169b.so" \
651         "$NOPIE_CFLAGS -O2 -g" \
652         { pr23169b.c pr23169c.c } \
653         {{readelf {--dyn-syms} pr23169a.rd} \
654          {readelf {-r -W} pr23169b.rd}} \
655         "pr23169d" \
656     ] \
657     [list \
658         "Build pr23169f" \
659         "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,now tmpdir/libpr23169b.so" \
660         "-fPIE -O2 -g" \
661         { pr23169b.c pr23169c.c } \
662         {{readelf {--dyn-syms} pr23169a.rd} \
663          {readelf {-r -W} pr23169b.rd}} \
664         "pr23169f" \
665     ] \
668 run_ld_link_exec_tests [list \
669     [list \
670         "Run pr18808" \
671         "-Wl,--no-as-needed tmpdir/pr18808a.o tmpdir/libpr18808.so" \
672         "" \
673         { dummy.c } \
674         "pr18808" \
675         "pr18808.out" \
676     ] \
677     [list \
678         "Run pr18808 (-z now)" \
679         "-Wl,-z,now -Wl,--no-as-needed tmpdir/pr18808a.o tmpdir/libpr18808n.so" \
680         "" \
681         { dummy.c } \
682         "pr18808n" \
683         "pr18808.out" \
684     ] \
685     [list \
686         "Run pr18841 with libpr18841b.so" \
687         "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/pr18841a.o tmpdir/libpr18841b.so" \
688         "$NOPIE_CFLAGS" \
689         { dummy.c } \
690         "pr18841b" \
691         "pr18841.out" \
692     ] \
693     [list \
694         "Run pr18841 with libpr18841c.so" \
695         "$NOPIE_LDFLAGS -Wl,--as-needed tmpdir/pr18841a.o tmpdir/libpr18841c.so" \
696         "$NOPIE_CFLAGS" \
697         { dummy.c } \
698         "pr18841c" \
699         "pr18841.out" \
700     ] \
701     [list \
702         "Run pr18841 with libpr18841bn.so (-z now)" \
703         "$NOPIE_LDFLAGS -Wl,-z,now -Wl,--no-as-needed tmpdir/pr18841a.o tmpdir/libpr18841bn.so" \
704         "$NOPIE_CFLAGS" \
705         { dummy.c } \
706         "pr18841bn" \
707         "pr18841.out" \
708     ] \
709     [list \
710         "Run pr18841 with libpr18841cn.so (-z now)" \
711         "$NOPIE_LDFLAGS -Wl,-z,now -Wl,--as-needed tmpdir/pr18841a.o tmpdir/libpr18841cn.so" \
712         "$NOPIE_CFLAGS" \
713         { dummy.c } \
714         "pr18841cn" \
715         "pr18841.out" \
716     ] \
717     [list \
718         "Run pr29216" \
719         "$NOPIE_LDFLAGS" \
720         "" \
721         { pr29216.c } \
722         "pr29216" \
723         "pass.out" \
724         "-fPIC" \
725     ] \
728 # The pr23169 testcase is not valid.  In general, you can't call ifunc
729 # resolvers in another binary unless you know what you're doing.  In
730 # particular you must ensure that the binary containing the resolver
731 # is relocated before the resolver is called (for example, the
732 # function addresses returned by the resolver may be loaded from the
733 # GOT).
734 # That does not happen for the pr23169 testcase where the resolver is
735 # in the executable (which is relocated last by ld.so).
736 if { [isnative]
737      && !([istarget "powerpc-*-*"]
738           || [istarget "aarch64*-*-*"]
739           || [istarget "arm*-*-*"]
740           || [istarget "sparc*-*-*"]
741           || [istarget "riscv*-*-*"]) } {
742 run_ld_link_exec_tests [list \
743     [list \
744         "Run pr23169a" \
745         "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libpr23169a.so" \
746         "" \
747         { pr23169b.c pr23169c.c } \
748         "pr23169a" \
749         "pass.out" \
750         "$NOPIE_CFLAGS -O2 -g" \
751     ] \
752     [list \
753         "Run pr23169b" \
754         "-pie -Wl,--no-as-needed,-z,lazy tmpdir/libpr23169a.so" \
755         "" \
756         { pr23169b.c pr23169c.c } \
757         "pr23169b" \
758         "pass.out" \
759         "-fPIE -O2 -g" \
760     ] \
761     [list \
762         "Run pr23169c" \
763         "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libpr23169a.so" \
764         "" \
765         { pr23169b.c pr23169c.c } \
766         "pr23169c" \
767         "pass.out" \
768         "-fPIE -O2 -g" \
769     ] \
770     [list \
771         "Run pr23169d" \
772         "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,now tmpdir/libpr23169b.so" \
773         "" \
774         { pr23169b.c pr23169c.c } \
775         "pr23169d" \
776         "pass.out" \
777         "$NOPIE_CFLAGS -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     ] \
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         ] \
804 set ASFLAGS "$saved_ASFLAGS"