Commit | Line | Data |
---|---|---|
d8045f23 NC |
1 | # Expect script for linker support of IFUNC symbols and relocations. |
2 | # | |
b3adc24a | 3 | # Copyright (C) 2009-2020 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 | ||
bb4e012c AM |
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-*-*] } { | |
d8045f23 NC |
47 | verbose "IFUNC tests not run - target does not support IFUNC" |
48 | return | |
49 | } | |
50 | ||
47523653 AM |
51 | # Skip targets where -shared is not supported |
52 | ||
53 | if ![check_shared_lib_support] { | |
54 | return | |
55 | } | |
56 | ||
e9d644e8 L |
57 | set saved_ASFLAGS "$ASFLAGS" |
58 | if { [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] } { | |
59 | set ASFLAGS "$ASFLAGS -mx86-used-note=no" | |
60 | } | |
61 | ||
f657f8c4 NC |
62 | # This test does not need a compiler... |
63 | run_dump_test "ifuncmod5" | |
64 | ||
ac98f9e2 L |
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 | ||
d8045f23 NC |
72 | # We need a working compiler. (Strictly speaking this is |
73 | # not true, we could use target specific assembler files). | |
44ed8092 | 74 | if { ![check_compiler_available] } { |
d8045f23 NC |
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" | |
5a68afcf | 102 | |
d8045f23 NC |
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 | |
4115bfc6 | 121 | # with perhaps some other info between the visibility and section |
d8045f23 | 122 | |
4115bfc6 | 123 | if { ![regexp ".*\[ \]*IFUNC\[ \]+GLOBAL\[ \]+DEFAULT .* \[UND0-9\]+\[ \]+library_func2\n" [file_contents readelf.out]] } { |
d8045f23 NC |
124 | return 0 |
125 | } | |
126 | ||
127 | return 1 | |
128 | } | |
129 | ||
cbe950e9 L |
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 | ||
bb4e012c | 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]] } { |
cbe950e9 L |
151 | return 0 |
152 | } | |
153 | ||
154 | return 1 | |
155 | } | |
156 | ||
d8045f23 NC |
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. | |
be19bd51 L |
185 | if ![ld_compile "$CC -c -fPIC" "$srcdir/$subdir/prog.c" "tmpdir/shared_prog.o"] { |
186 | fail "Could not create a PIC object file" | |
d8045f23 NC |
187 | set fails [expr $fails + 1] |
188 | } | |
640d0ed8 | 189 | if ![ld_compile "$CC -c $NOPIE_CFLAGS" "$srcdir/$subdir/prog.c" "tmpdir/static_prog.o"] { |
be19bd51 | 190 | fail "Could not create a non-PIC object file" |
d8045f23 NC |
191 | set fails [expr $fails + 1] |
192 | } | |
be19bd51 L |
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" | |
d8045f23 NC |
195 | set fails [expr $fails + 1] |
196 | } | |
640d0ed8 | 197 | if ![ld_compile "$CC -c $NOPIE_CFLAGS -DWITH_IFUNC" "$srcdir/$subdir/lib.c" "tmpdir/static_ifunc.o"] { |
be19bd51 | 198 | fail "Could not create a non-PIC object file containing an IFUNC symbol" |
d8045f23 NC |
199 | set fails [expr $fails + 1] |
200 | } | |
be19bd51 L |
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" | |
d8045f23 NC |
207 | set fails [expr $fails + 1] |
208 | } | |
2955ec4c L |
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 | } | |
d8045f23 NC |
217 | |
218 | if { $fails != 0 } { | |
219 | return | |
220 | } | |
221 | ||
d9816402 | 222 | if ![ld_link $ld "tmpdir/libshared_ifunc.so" "-shared tmpdir/shared_ifunc.o"] { |
d8045f23 NC |
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 | ||
d9816402 | 235 | if ![ld_link $CC "tmpdir/dynamic_prog" "-Wl,--no-as-needed,-rpath=./tmpdir,-Bdynamic -Ltmpdir tmpdir/shared_prog.o -lshared_ifunc"] { |
d8045f23 NC |
236 | fail "Could not link a dynamic executable" |
237 | set fails [expr $fails + 1] | |
238 | } | |
640d0ed8 | 239 | if ![ld_link $CC "tmpdir/local_prog" "$NOPIE_LDFLAGS -Wl,--no-as-needed,-rpath=./tmpdir -Ltmpdir tmpdir/static_prog.o -lifunc"] { |
e054468f AM |
240 | fail "Could not link a dynamic executable using local ifunc" |
241 | set fails [expr $fails + 1] | |
242 | } | |
98d72909 L |
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 | } | |
d0042c6e L |
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] | |
d8045f23 | 252 | } |
d9816402 | 253 | if ![ld_link $CC "tmpdir/test-1" "-Wl,--no-as-needed,-rpath=./tmpdir tmpdir/test-1.o tmpdir/libshared_ifunc.so"] { |
2955ec4c L |
254 | fail "Could not link test-1" |
255 | set fails [expr $fails + 1] | |
256 | } | |
d9816402 | 257 | if ![ld_link $ld "tmpdir/libtest-2.so" "-shared tmpdir/test-2.o"] { |
2955ec4c L |
258 | fail "Could not link libtest-2.so" |
259 | set fails [expr $fails + 1] | |
260 | } | |
e492d2f8 L |
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 | } | |
d8045f23 NC |
265 | |
266 | if { $fails == 0 } { | |
267 | pass "Building ifunc binaries" | |
268 | set fails 0 | |
269 | } else { | |
270 | return | |
271 | } | |
272 | ||
cbe950e9 | 273 | # Check the executables and shared libraries |
d8045f23 | 274 | # |
cbe950e9 | 275 | # The linked ifunc using executables and the shared library containing |
9c55345c | 276 | # ifunc should have an OSABI field of GNU. The linked non-ifunc using |
cbe950e9 | 277 | # executable should have an OSABI field of NONE (aka System V). |
d8045f23 | 278 | |
e3696f67 AM |
279 | switch -glob $target_triplet { |
280 | hppa*-*-linux* { set expected_none {UNIX - GNU} } | |
d9816402 AM |
281 | default { set expected_none {UNIX - System V} } |
282 | } | |
283 | ||
9c55345c TS |
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" | |
cbe950e9 L |
286 | set fails [expr $fails + 1] |
287 | } | |
9c55345c TS |
288 | if {! [check_osabi tmpdir/local_prog {UNIX - GNU}]} { |
289 | fail "Local ifunc-using executable does not have an OS/ABI field of GNU" | |
e054468f AM |
290 | set fails [expr $fails + 1] |
291 | } | |
98d72909 L |
292 | if { ![string match "" $STATIC_LDFLAGS] \ |
293 | && ![check_osabi tmpdir/static_prog {UNIX - GNU}]} { | |
9c55345c | 294 | fail "Static ifunc-using executable does not have an OS/ABI field of GNU" |
d8045f23 NC |
295 | set fails [expr $fails + 1] |
296 | } | |
d9816402 AM |
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" | |
d8045f23 NC |
299 | set fails [expr $fails + 1] |
300 | } | |
d9816402 AM |
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" | |
be19bd51 L |
303 | set fails [expr $fails + 1] |
304 | } | |
d8045f23 | 305 | |
cbe950e9 L |
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. | |
d8045f23 | 309 | |
cbe950e9 L |
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 | } | |
e054468f AM |
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 | } | |
98d72909 L |
318 | if { ![string match "" $STATIC_LDFLAGS] \ |
319 | && [contains_ifunc_symbol tmpdir/static_prog] != 1} { | |
d8045f23 NC |
320 | fail "Static ifunc-using executable does not contain an IFUNC symbol" |
321 | set fails [expr $fails + 1] | |
322 | } | |
2955ec4c L |
323 | if {[contains_ifunc_symbol tmpdir/dynamic_prog] != 0} { |
324 | fail "Dynamic ifunc-using executable contains an IFUNC symbol" | |
d8045f23 NC |
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 | } | |
2955ec4c L |
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 | } | |
e492d2f8 L |
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 | } | |
d8045f23 | 343 | |
cbe950e9 L |
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. | |
d8045f23 | 348 | |
cbe950e9 L |
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 | } | |
e054468f AM |
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 | } | |
98d72909 L |
357 | if { ![string match "" $STATIC_LDFLAGS] \ |
358 | && [contains_irelative_reloc tmpdir/static_prog] != 1} { | |
cbe950e9 | 359 | fail "Static ifunc-using executable does not contain R_*_IRELATIVE relocation" |
d8045f23 NC |
360 | set fails [expr $fails + 1] |
361 | } | |
2955ec4c L |
362 | if {[contains_ifunc_reloc tmpdir/dynamic_prog] != 0} { |
363 | fail "Dynamic ifunc-using executable contains a reloc against an IFUNC symbol" | |
d8045f23 NC |
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 | ||
4584ec12 L |
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 | ] \ | |
d6f48aed L |
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 | ] \ | |
4584ec12 L |
426 | ] |
427 | ||
982c6f26 | 428 | run_ld_link_exec_tests [list \ |
37a9e49a L |
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 | ] \ | |
c22ee0ad L |
447 | ] |
448 | ||
c22ee0ad L |
449 | # Run-time tests which require working IFUNC support. |
450 | if { ![check_ifunc_available] } { | |
451 | return | |
452 | } | |
453 | ||
5f7cbeec L |
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 | ] \ | |
d6f48aed L |
463 | [list \ |
464 | "Build ifunc-libn.so" \ | |
465 | "-shared -Wl,-z,now" \ | |
466 | "-fPIC" \ | |
467 | { ifunc-lib.c } \ | |
468 | {} \ | |
469 | "libifunc-libn.so" \ | |
470 | ] \ | |
5f7cbeec L |
471 | ] |
472 | ||
982c6f26 | 473 | run_ld_link_exec_tests [list \ |
4584ec12 L |
474 | [list \ |
475 | "Run pr16467" \ | |
d9816402 | 476 | "-Wl,--no-as-needed tmpdir/pr16467c.o tmpdir/libpr16467b.so tmpdir/libpr16467a.so" \ |
4584ec12 L |
477 | "" \ |
478 | { dummy.c } \ | |
479 | "pr16467" \ | |
480 | "pr16467.out" \ | |
481 | "" \ | |
482 | ] \ | |
d6f48aed L |
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 | ] \ | |
5f7cbeec L |
492 | [list \ |
493 | "Run ifunc-main" \ | |
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 | ] \ | |
500 | [list \ | |
501 | "Run ifunc-main with -fpic" \ | |
d9816402 | 502 | "-Wl,--no-as-needed tmpdir/libifunc-lib.so" \ |
5f7cbeec L |
503 | "" \ |
504 | { ifunc-main.c } \ | |
505 | "ifunc-main" \ | |
506 | "ifunc-main.out" \ | |
507 | "-fpic" \ | |
508 | ] \ | |
d6f48aed L |
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 | ] \ | |
37a9e49a | 526 | ] |
97dc35c8 L |
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 \ | |
205ac185 L |
534 | [list \ |
535 | "Build pr18808a.o" \ | |
536 | "" \ | |
537 | "" \ | |
538 | { pr18808a.c } \ | |
539 | "" \ | |
540 | "" \ | |
541 | ] \ | |
97dc35c8 L |
542 | [list \ |
543 | "Build libpr18808.so" \ | |
544 | "-shared" \ | |
545 | "-fPIC -O2 -g" \ | |
546 | { pr18808b.c } \ | |
547 | {} \ | |
548 | "libpr18808.so" \ | |
549 | ] \ | |
d6f48aed L |
550 | [list \ |
551 | "Build libpr18808n.so" \ | |
552 | "-shared -Wl,-z,now" \ | |
553 | "-fPIC -O2 -g" \ | |
554 | { pr18808b.c } \ | |
555 | {} \ | |
556 | "libpr18808n.so" \ | |
557 | ] \ | |
205ac185 L |
558 | [list \ |
559 | "Build pr18841a.o" \ | |
560 | "" \ | |
561 | "" \ | |
562 | { pr18841a.c } \ | |
563 | "" \ | |
564 | "" \ | |
565 | ] \ | |
cae1fbbb | 566 | [list \ |
4e1626f5 | 567 | "Build libpr18841b.so" \ |
cae1fbbb L |
568 | "-shared" \ |
569 | "-fPIC -O0 -g" \ | |
570 | { pr18841b.c } \ | |
571 | {} \ | |
4e1626f5 L |
572 | "libpr18841b.so" \ |
573 | ] \ | |
574 | [list \ | |
575 | "Build libpr18841c.so" \ | |
576 | "-shared" \ | |
577 | "-fPIC -O0 -g" \ | |
578 | { pr18841c.c } \ | |
579 | {} \ | |
580 | "libpr18841c.so" \ | |
cae1fbbb | 581 | ] \ |
d6f48aed L |
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 | ] \ | |
4ec09950 L |
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 | ] \ | |
97dc35c8 L |
668 | ] |
669 | ||
982c6f26 | 670 | run_ld_link_exec_tests [list \ |
97dc35c8 L |
671 | [list \ |
672 | "Run pr18808" \ | |
d9816402 | 673 | "-Wl,--no-as-needed tmpdir/pr18808a.o tmpdir/libpr18808.so" \ |
97dc35c8 | 674 | "" \ |
205ac185 | 675 | { dummy.c } \ |
97dc35c8 L |
676 | "pr18808" \ |
677 | "pr18808.out" \ | |
678 | ] \ | |
d6f48aed L |
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 | ] \ | |
cae1fbbb | 687 | [list \ |
4e1626f5 | 688 | "Run pr18841 with libpr18841b.so" \ |
d9816402 | 689 | "-Wl,--no-as-needed tmpdir/pr18841a.o tmpdir/libpr18841b.so" \ |
4e1626f5 | 690 | "" \ |
205ac185 | 691 | { dummy.c } \ |
4e1626f5 L |
692 | "pr18841b" \ |
693 | "pr18841.out" \ | |
694 | ] \ | |
695 | [list \ | |
696 | "Run pr18841 with libpr18841c.so" \ | |
d9816402 | 697 | "-Wl,--as-needed tmpdir/pr18841a.o tmpdir/libpr18841c.so" \ |
cae1fbbb | 698 | "" \ |
205ac185 | 699 | { dummy.c } \ |
4e1626f5 | 700 | "pr18841c" \ |
cae1fbbb L |
701 | "pr18841.out" \ |
702 | ] \ | |
d6f48aed L |
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 | ] \ | |
2822b09f AM |
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] | |
c49829c3 EB |
730 | && !([istarget "powerpc-*-*"] |
731 | || [istarget "aarch64*-*-*"] | |
732 | || [istarget "sparc*-*-*"]) } { | |
2822b09f | 733 | run_ld_link_exec_tests [list \ |
4ec09950 L |
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 | ] \ | |
b3d7a867 L |
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 | } | |
e9d644e8 L |
803 | |
804 | set ASFLAGS "$saved_ASFLAGS" |