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