Commit | Line | Data |
---|---|---|
d8045f23 NC |
1 | # Expect script for linker support of IFUNC symbols and relocations. |
2 | # | |
250d07de | 3 | # Copyright (C) 2009-2021 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 | 26 | if { ![is_elf_format] || ![supports_gnu_osabi] |
2d0a923c | 27 | || [istarget alpha-*-*] |
bb4e012c AM |
28 | || [istarget arc*-*-*] |
29 | || [istarget am33*-*-*] | |
30 | || [istarget bfin-*-*] | |
31 | || [istarget cris*-*-*] | |
32 | || [istarget frv-*-*] | |
33 | || [istarget lm32-*-*] | |
34 | || [istarget m32r-*-*] | |
35 | || [istarget m68k-*-*] | |
36 | || [istarget microblaze-*-*] | |
37 | || [istarget mips*-*-*] | |
38 | || [istarget mn10300-*-*] | |
39 | || [istarget nds32*-*-*] | |
40 | || [istarget nios2-*-*] | |
41 | || [istarget or1k-*-*] | |
bb4e012c AM |
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 | ||
e6a6c767 L |
184 | # Disable LTO for these tests. |
185 | set cc_cmd "$CC" | |
186 | if {[check_lto_available]} { | |
187 | append cc_cmd " -fno-lto" | |
188 | } | |
189 | ||
d8045f23 | 190 | # Create the object files, libraries and executables. |
e6a6c767 | 191 | if ![ld_compile "$cc_cmd -c -fPIC" "$srcdir/$subdir/prog.c" "tmpdir/shared_prog.o"] { |
be19bd51 | 192 | fail "Could not create a PIC object file" |
d8045f23 NC |
193 | set fails [expr $fails + 1] |
194 | } | |
e6a6c767 | 195 | if ![ld_compile "$cc_cmd -c $NOPIE_CFLAGS" "$srcdir/$subdir/prog.c" "tmpdir/static_prog.o"] { |
be19bd51 | 196 | fail "Could not create a non-PIC object file" |
d8045f23 NC |
197 | set fails [expr $fails + 1] |
198 | } | |
e6a6c767 | 199 | if ![ld_compile "$cc_cmd -c -fPIC -DWITH_IFUNC" "$srcdir/$subdir/lib.c" "tmpdir/shared_ifunc.o"] { |
be19bd51 | 200 | fail "Could not create a PIC object file containing an IFUNC symbol" |
d8045f23 NC |
201 | set fails [expr $fails + 1] |
202 | } | |
e6a6c767 | 203 | if ![ld_compile "$cc_cmd -c $NOPIE_CFLAGS -DWITH_IFUNC" "$srcdir/$subdir/lib.c" "tmpdir/static_ifunc.o"] { |
be19bd51 | 204 | fail "Could not create a non-PIC object file containing an IFUNC symbol" |
d8045f23 NC |
205 | set fails [expr $fails + 1] |
206 | } | |
e6a6c767 | 207 | if ![ld_compile "$cc_cmd -c -DWITHOUT_IFUNC" "$srcdir/$subdir/lib.c" "tmpdir/static_noifunc.o"] { |
be19bd51 L |
208 | fail "Could not create an ordinary non-PIC object file" |
209 | set fails [expr $fails + 1] | |
210 | } | |
211 | if ![ld_assemble $as "$srcdir/ld-elf/empty.s" "tmpdir/empty.o"] { | |
212 | fail "Could not create an empty object file" | |
d8045f23 NC |
213 | set fails [expr $fails + 1] |
214 | } | |
e6a6c767 | 215 | if ![ld_compile "$cc_cmd -c" "$srcdir/$subdir/test-1.c" "tmpdir/test-1.o"] { |
2955ec4c L |
216 | fail "Could not create test-1.o" |
217 | set fails [expr $fails + 1] | |
218 | } | |
e6a6c767 | 219 | if ![ld_compile "$cc_cmd -fPIC -c" "$srcdir/$subdir/test-2.c" "tmpdir/test-2.o"] { |
2955ec4c L |
220 | fail "Could not create test-2.o" |
221 | set fails [expr $fails + 1] | |
222 | } | |
d8045f23 NC |
223 | |
224 | if { $fails != 0 } { | |
225 | return | |
226 | } | |
227 | ||
d9816402 | 228 | if ![ld_link $ld "tmpdir/libshared_ifunc.so" "-shared tmpdir/shared_ifunc.o"] { |
d8045f23 NC |
229 | fail "Could not create a shared library containing an IFUNC symbol" |
230 | set fails [expr $fails + 1] | |
231 | } | |
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] | |
235 | } | |
236 | ||
237 | if { $fails != 0 } { | |
238 | return | |
239 | } | |
240 | ||
d9816402 | 241 | if ![ld_link $CC "tmpdir/dynamic_prog" "-Wl,--no-as-needed,-rpath=./tmpdir,-Bdynamic -Ltmpdir tmpdir/shared_prog.o -lshared_ifunc"] { |
d8045f23 NC |
242 | fail "Could not link a dynamic executable" |
243 | set fails [expr $fails + 1] | |
244 | } | |
640d0ed8 | 245 | if ![ld_link $CC "tmpdir/local_prog" "$NOPIE_LDFLAGS -Wl,--no-as-needed,-rpath=./tmpdir -Ltmpdir tmpdir/static_prog.o -lifunc"] { |
e054468f AM |
246 | fail "Could not link a dynamic executable using local ifunc" |
247 | set fails [expr $fails + 1] | |
248 | } | |
98d72909 L |
249 | if ![string match "" $STATIC_LDFLAGS] { |
250 | if ![ld_link $CC "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 | } | |
d0042c6e L |
254 | } |
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] | |
d8045f23 | 258 | } |
d9816402 | 259 | if ![ld_link $CC "tmpdir/test-1" "-Wl,--no-as-needed,-rpath=./tmpdir tmpdir/test-1.o tmpdir/libshared_ifunc.so"] { |
2955ec4c L |
260 | fail "Could not link test-1" |
261 | set fails [expr $fails + 1] | |
262 | } | |
d9816402 | 263 | if ![ld_link $ld "tmpdir/libtest-2.so" "-shared tmpdir/test-2.o"] { |
2955ec4c L |
264 | fail "Could not link libtest-2.so" |
265 | set fails [expr $fails + 1] | |
266 | } | |
e492d2f8 L |
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] | |
270 | } | |
d8045f23 NC |
271 | |
272 | if { $fails == 0 } { | |
273 | pass "Building ifunc binaries" | |
274 | set fails 0 | |
275 | } else { | |
276 | return | |
277 | } | |
278 | ||
cbe950e9 | 279 | # Check the executables and shared libraries |
d8045f23 | 280 | # |
cbe950e9 | 281 | # The linked ifunc using executables and the shared library containing |
9c55345c | 282 | # ifunc should have an OSABI field of GNU. The linked non-ifunc using |
cbe950e9 | 283 | # executable should have an OSABI field of NONE (aka System V). |
d8045f23 | 284 | |
e3696f67 AM |
285 | switch -glob $target_triplet { |
286 | hppa*-*-linux* { set expected_none {UNIX - GNU} } | |
d9816402 AM |
287 | default { set expected_none {UNIX - System V} } |
288 | } | |
289 | ||
9c55345c TS |
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" | |
cbe950e9 L |
292 | set fails [expr $fails + 1] |
293 | } | |
9c55345c TS |
294 | if {! [check_osabi tmpdir/local_prog {UNIX - GNU}]} { |
295 | fail "Local ifunc-using executable does not have an OS/ABI field of GNU" | |
e054468f AM |
296 | set fails [expr $fails + 1] |
297 | } | |
98d72909 L |
298 | if { ![string match "" $STATIC_LDFLAGS] \ |
299 | && ![check_osabi tmpdir/static_prog {UNIX - GNU}]} { | |
9c55345c | 300 | fail "Static ifunc-using executable does not have an OS/ABI field of GNU" |
d8045f23 NC |
301 | set fails [expr $fails + 1] |
302 | } | |
d9816402 AM |
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" | |
d8045f23 NC |
305 | set fails [expr $fails + 1] |
306 | } | |
d9816402 AM |
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" | |
be19bd51 L |
309 | set fails [expr $fails + 1] |
310 | } | |
d8045f23 | 311 | |
cbe950e9 L |
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. | |
d8045f23 | 315 | |
cbe950e9 L |
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] | |
319 | } | |
e054468f AM |
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] | |
323 | } | |
98d72909 L |
324 | if { ![string match "" $STATIC_LDFLAGS] \ |
325 | && [contains_ifunc_symbol tmpdir/static_prog] != 1} { | |
d8045f23 NC |
326 | fail "Static ifunc-using executable does not contain an IFUNC symbol" |
327 | set fails [expr $fails + 1] | |
328 | } | |
2955ec4c L |
329 | if {[contains_ifunc_symbol tmpdir/dynamic_prog] != 0} { |
330 | fail "Dynamic ifunc-using executable contains an IFUNC symbol" | |
d8045f23 NC |
331 | set fails [expr $fails + 1] |
332 | } | |
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] | |
336 | } | |
2955ec4c L |
337 | if {[contains_ifunc_symbol tmpdir/test-1] != 0} { |
338 | fail "test-1 contains IFUNC symbols" | |
339 | set fails [expr $fails + 1] | |
340 | } | |
341 | if {[contains_ifunc_symbol tmpdir/libtest-2.so] != 0} { | |
342 | fail "libtest-2.so contains IFUNC symbols" | |
343 | set fails [expr $fails + 1] | |
344 | } | |
e492d2f8 L |
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] | |
348 | } | |
d8045f23 | 349 | |
cbe950e9 L |
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. | |
d8045f23 | 354 | |
cbe950e9 L |
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] | |
358 | } | |
e054468f AM |
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] | |
362 | } | |
98d72909 L |
363 | if { ![string match "" $STATIC_LDFLAGS] \ |
364 | && [contains_irelative_reloc tmpdir/static_prog] != 1} { | |
cbe950e9 | 365 | fail "Static ifunc-using executable does not contain R_*_IRELATIVE relocation" |
d8045f23 NC |
366 | set fails [expr $fails + 1] |
367 | } | |
2955ec4c L |
368 | if {[contains_ifunc_reloc tmpdir/dynamic_prog] != 0} { |
369 | fail "Dynamic ifunc-using executable contains a reloc against an IFUNC symbol" | |
d8045f23 NC |
370 | set fails [expr $fails + 1] |
371 | } | |
372 | if {[contains_ifunc_reloc tmpdir/static_nonifunc_prog] == 1} { | |
373 | fail "Static non-ifunc-using executable contains a reloc against an IFUNC symbol!" | |
374 | set fails [expr $fails + 1] | |
375 | } | |
376 | ||
377 | if { $fails == 0 } { | |
378 | pass "Checking ifunc binaries" | |
379 | } | |
380 | ||
4584ec12 L |
381 | run_cc_link_tests [list \ |
382 | [list \ | |
383 | "Build libpr16467a.so" \ | |
384 | "-shared -Wl,--version-script=pr16467a.map" \ | |
385 | "-fPIC" \ | |
386 | { pr16467a.c } \ | |
387 | {} \ | |
388 | "libpr16467a.so" \ | |
389 | ] \ | |
390 | [list \ | |
391 | "Build libpr16467b.a" \ | |
392 | "" \ | |
393 | "-fPIC" \ | |
394 | { pr16467b.c } \ | |
395 | {} \ | |
396 | "libpr16467b.a" \ | |
397 | ] \ | |
398 | [list \ | |
399 | "Build libpr16467b.so" \ | |
69551367 | 400 | "-shared -Wl,--as-needed tmpdir/pr16467b.o tmpdir/libpr16467a.so \ |
4584ec12 L |
401 | -Wl,--version-script=pr16467b.map" \ |
402 | "-fPIC" \ | |
403 | { dummy.c } \ | |
404 | {} \ | |
405 | "libpr16467b.so" \ | |
406 | ] \ | |
407 | [list \ | |
408 | "Build libpr16467c.a" \ | |
409 | "" \ | |
410 | "" \ | |
411 | { pr16467c.c } \ | |
412 | {} \ | |
413 | "libpr16467c.a" \ | |
414 | ] \ | |
d6f48aed L |
415 | [list \ |
416 | "Build libpr16467an.so" \ | |
417 | "-shared -Wl,-z,now -Wl,--version-script=pr16467a.map" \ | |
418 | "-fPIC" \ | |
419 | { pr16467a.c } \ | |
420 | {} \ | |
421 | "libpr16467an.so" \ | |
422 | ] \ | |
423 | [list \ | |
424 | "Build libpr16467bn.so" \ | |
69551367 | 425 | "-shared -Wl,--as-needed tmpdir/pr16467b.o tmpdir/libpr16467an.so \ |
d6f48aed L |
426 | -Wl,--version-script=pr16467b.map" \ |
427 | "-fPIC" \ | |
428 | { dummy.c } \ | |
429 | {} \ | |
430 | "libpr16467bn.so" \ | |
431 | ] \ | |
4584ec12 L |
432 | ] |
433 | ||
982c6f26 | 434 | run_ld_link_exec_tests [list \ |
37a9e49a L |
435 | [list \ |
436 | "Common symbol override ifunc test 1a" \ | |
437 | "-static" \ | |
438 | "" \ | |
439 | { ifunc-common-1a.c ifunc-common-1b.c } \ | |
440 | "ifunc-common-1a" \ | |
441 | "ifunc-common-1.out" \ | |
442 | "-g" \ | |
443 | ] \ | |
444 | [list \ | |
445 | "Common symbol override ifunc test 1b" \ | |
446 | "-static" \ | |
447 | "" \ | |
448 | { ifunc-common-1b.c ifunc-common-1a.c } \ | |
449 | "ifunc-common-1b" \ | |
450 | "ifunc-common-1.out" \ | |
451 | "-g" \ | |
452 | ] \ | |
c22ee0ad L |
453 | ] |
454 | ||
c22ee0ad L |
455 | # Run-time tests which require working IFUNC support. |
456 | if { ![check_ifunc_available] } { | |
457 | return | |
458 | } | |
459 | ||
5f7cbeec L |
460 | run_cc_link_tests [list \ |
461 | [list \ | |
462 | "Build ifunc-lib.so" \ | |
463 | "-shared" \ | |
464 | "-fPIC" \ | |
465 | { ifunc-lib.c } \ | |
466 | {} \ | |
467 | "libifunc-lib.so" \ | |
468 | ] \ | |
d6f48aed L |
469 | [list \ |
470 | "Build ifunc-libn.so" \ | |
471 | "-shared -Wl,-z,now" \ | |
472 | "-fPIC" \ | |
473 | { ifunc-lib.c } \ | |
474 | {} \ | |
475 | "libifunc-libn.so" \ | |
476 | ] \ | |
5f7cbeec L |
477 | ] |
478 | ||
982c6f26 | 479 | run_ld_link_exec_tests [list \ |
4584ec12 L |
480 | [list \ |
481 | "Run pr16467" \ | |
d9816402 | 482 | "-Wl,--no-as-needed tmpdir/pr16467c.o tmpdir/libpr16467b.so tmpdir/libpr16467a.so" \ |
4584ec12 L |
483 | "" \ |
484 | { dummy.c } \ | |
485 | "pr16467" \ | |
486 | "pr16467.out" \ | |
487 | "" \ | |
488 | ] \ | |
d6f48aed L |
489 | [list \ |
490 | "Run pr16467 (-z now)" \ | |
491 | "-Wl,-z,now -Wl,--no-as-needed tmpdir/pr16467c.o tmpdir/libpr16467bn.so tmpdir/libpr16467an.so" \ | |
492 | "" \ | |
493 | { dummy.c } \ | |
494 | "pr16467n" \ | |
495 | "pr16467.out" \ | |
496 | "" \ | |
497 | ] \ | |
5f7cbeec L |
498 | [list \ |
499 | "Run ifunc-main" \ | |
d9816402 | 500 | "-Wl,--no-as-needed tmpdir/libifunc-lib.so" \ |
5f7cbeec L |
501 | "" \ |
502 | { ifunc-main.c } \ | |
503 | "ifunc-main" \ | |
504 | "ifunc-main.out" \ | |
505 | ] \ | |
506 | [list \ | |
507 | "Run ifunc-main with -fpic" \ | |
d9816402 | 508 | "-Wl,--no-as-needed tmpdir/libifunc-lib.so" \ |
5f7cbeec L |
509 | "" \ |
510 | { ifunc-main.c } \ | |
511 | "ifunc-main" \ | |
512 | "ifunc-main.out" \ | |
513 | "-fpic" \ | |
514 | ] \ | |
d6f48aed L |
515 | [list \ |
516 | "Run ifunc-main (-z now)" \ | |
517 | "-Wl,-z,now -Wl,--no-as-needed tmpdir/libifunc-libn.so" \ | |
518 | "" \ | |
519 | { ifunc-main.c } \ | |
520 | "ifunc-mainn" \ | |
521 | "ifunc-main.out" \ | |
522 | ] \ | |
523 | [list \ | |
524 | "Run ifunc-main with PIE (-z now)" \ | |
525 | "-pie -Wl,-z,now -Wl,--no-as-needed tmpdir/libifunc-libn.so" \ | |
526 | "" \ | |
527 | { ifunc-main.c } \ | |
528 | "ifunc-mainpn" \ | |
529 | "ifunc-main.out" \ | |
530 | "-fpie" \ | |
531 | ] \ | |
37a9e49a | 532 | ] |
97dc35c8 L |
533 | |
534 | # Run-time tests which require working ifunc attribute support. | |
535 | if { ![check_ifunc_attribute_available] } { | |
536 | return | |
537 | } | |
538 | ||
539 | run_cc_link_tests [list \ | |
205ac185 L |
540 | [list \ |
541 | "Build pr18808a.o" \ | |
542 | "" \ | |
543 | "" \ | |
544 | { pr18808a.c } \ | |
545 | "" \ | |
546 | "" \ | |
547 | ] \ | |
97dc35c8 L |
548 | [list \ |
549 | "Build libpr18808.so" \ | |
550 | "-shared" \ | |
551 | "-fPIC -O2 -g" \ | |
552 | { pr18808b.c } \ | |
553 | {} \ | |
554 | "libpr18808.so" \ | |
555 | ] \ | |
d6f48aed L |
556 | [list \ |
557 | "Build libpr18808n.so" \ | |
558 | "-shared -Wl,-z,now" \ | |
559 | "-fPIC -O2 -g" \ | |
560 | { pr18808b.c } \ | |
561 | {} \ | |
562 | "libpr18808n.so" \ | |
563 | ] \ | |
205ac185 L |
564 | [list \ |
565 | "Build pr18841a.o" \ | |
566 | "" \ | |
470cd0fa | 567 | "$NOPIE_CFLAGS" \ |
205ac185 L |
568 | { pr18841a.c } \ |
569 | "" \ | |
570 | "" \ | |
571 | ] \ | |
cae1fbbb | 572 | [list \ |
4e1626f5 | 573 | "Build libpr18841b.so" \ |
cae1fbbb L |
574 | "-shared" \ |
575 | "-fPIC -O0 -g" \ | |
576 | { pr18841b.c } \ | |
577 | {} \ | |
4e1626f5 L |
578 | "libpr18841b.so" \ |
579 | ] \ | |
580 | [list \ | |
581 | "Build libpr18841c.so" \ | |
582 | "-shared" \ | |
583 | "-fPIC -O0 -g" \ | |
584 | { pr18841c.c } \ | |
585 | {} \ | |
586 | "libpr18841c.so" \ | |
cae1fbbb | 587 | ] \ |
d6f48aed L |
588 | [list \ |
589 | "Build libpr18841bn.so" \ | |
590 | "-Wl,-z,now -shared" \ | |
591 | "-fPIC -O0 -g" \ | |
592 | { pr18841b.c } \ | |
593 | {} \ | |
594 | "libpr18841bn.so" \ | |
595 | ] \ | |
596 | [list \ | |
597 | "Build libpr18841cn.so" \ | |
598 | "-shared" \ | |
599 | "-Wl,-z,now -fPIC -O0 -g" \ | |
600 | { pr18841c.c } \ | |
601 | {} \ | |
602 | "libpr18841cn.so" \ | |
603 | ] \ | |
4ec09950 L |
604 | [list \ |
605 | "Build libpr23169a.so" \ | |
606 | "-shared" \ | |
607 | "-fPIC -O2 -g" \ | |
608 | { pr23169a.c } \ | |
609 | {} \ | |
610 | "libpr23169a.so" \ | |
611 | ] \ | |
612 | [list \ | |
613 | "Build libpr23169b.so" \ | |
614 | "-shared -Wl,-z,now" \ | |
615 | "-fPIC -O2 -g" \ | |
616 | { pr23169a.c } \ | |
617 | {} \ | |
618 | "libpr23169b.so" \ | |
619 | ] \ | |
620 | [list \ | |
621 | "Build pr23169a" \ | |
622 | "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libpr23169a.so" \ | |
623 | "$NOPIE_CFLAGS -O2 -g" \ | |
624 | { pr23169b.c pr23169c.c } \ | |
625 | {{readelf {--dyn-syms} pr23169a.rd} \ | |
626 | {readelf {-r -W} pr23169b.rd}} \ | |
627 | "pr23169a" \ | |
628 | ] \ | |
629 | [list \ | |
630 | "Build pr23169b" \ | |
631 | "-pie -Wl,--no-as-needed tmpdir/libpr23169a.so" \ | |
632 | "-fPIE -O2 -g" \ | |
633 | { pr23169b.c pr23169c.c } \ | |
634 | {{readelf {--dyn-syms} pr23169c.rd} \ | |
635 | {readelf {-r -W} pr23169b.rd}} \ | |
636 | "pr23169b" \ | |
637 | ] \ | |
638 | [list \ | |
639 | "Build pr23169c" \ | |
640 | "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libpr23169a.so" \ | |
641 | "-fPIE -O2 -g" \ | |
642 | { pr23169b.c pr23169c.c } \ | |
75a933f3 | 643 | {{readelf {--dyn-syms} pr23169a.rd} \ |
4ec09950 L |
644 | {readelf {-r -W} pr23169b.rd}} \ |
645 | "pr23169c" \ | |
646 | ] \ | |
647 | [list \ | |
648 | "Build pr23169d" \ | |
649 | "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,now tmpdir/libpr23169b.so" \ | |
650 | "$NOPIE_CFLAGS -O2 -g" \ | |
651 | { pr23169b.c pr23169c.c } \ | |
652 | {{readelf {--dyn-syms} pr23169a.rd} \ | |
653 | {readelf {-r -W} pr23169b.rd}} \ | |
654 | "pr23169d" \ | |
655 | ] \ | |
4ec09950 L |
656 | [list \ |
657 | "Build pr23169f" \ | |
658 | "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,now tmpdir/libpr23169b.so" \ | |
659 | "-fPIE -O2 -g" \ | |
660 | { pr23169b.c pr23169c.c } \ | |
75a933f3 | 661 | {{readelf {--dyn-syms} pr23169a.rd} \ |
4ec09950 L |
662 | {readelf {-r -W} pr23169b.rd}} \ |
663 | "pr23169f" \ | |
664 | ] \ | |
97dc35c8 L |
665 | ] |
666 | ||
982c6f26 | 667 | run_ld_link_exec_tests [list \ |
97dc35c8 L |
668 | [list \ |
669 | "Run pr18808" \ | |
d9816402 | 670 | "-Wl,--no-as-needed tmpdir/pr18808a.o tmpdir/libpr18808.so" \ |
97dc35c8 | 671 | "" \ |
205ac185 | 672 | { dummy.c } \ |
97dc35c8 L |
673 | "pr18808" \ |
674 | "pr18808.out" \ | |
675 | ] \ | |
d6f48aed L |
676 | [list \ |
677 | "Run pr18808 (-z now)" \ | |
678 | "-Wl,-z,now -Wl,--no-as-needed tmpdir/pr18808a.o tmpdir/libpr18808n.so" \ | |
679 | "" \ | |
680 | { dummy.c } \ | |
681 | "pr18808n" \ | |
682 | "pr18808.out" \ | |
683 | ] \ | |
cae1fbbb | 684 | [list \ |
4e1626f5 | 685 | "Run pr18841 with libpr18841b.so" \ |
470cd0fa AM |
686 | "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/pr18841a.o tmpdir/libpr18841b.so" \ |
687 | "$NOPIE_CFLAGS" \ | |
205ac185 | 688 | { dummy.c } \ |
4e1626f5 L |
689 | "pr18841b" \ |
690 | "pr18841.out" \ | |
691 | ] \ | |
692 | [list \ | |
693 | "Run pr18841 with libpr18841c.so" \ | |
470cd0fa AM |
694 | "$NOPIE_LDFLAGS -Wl,--as-needed tmpdir/pr18841a.o tmpdir/libpr18841c.so" \ |
695 | "$NOPIE_CFLAGS" \ | |
205ac185 | 696 | { dummy.c } \ |
4e1626f5 | 697 | "pr18841c" \ |
cae1fbbb L |
698 | "pr18841.out" \ |
699 | ] \ | |
d6f48aed L |
700 | [list \ |
701 | "Run pr18841 with libpr18841bn.so (-z now)" \ | |
470cd0fa AM |
702 | "$NOPIE_LDFLAGS -Wl,-z,now -Wl,--no-as-needed tmpdir/pr18841a.o tmpdir/libpr18841bn.so" \ |
703 | "$NOPIE_CFLAGS" \ | |
d6f48aed L |
704 | { dummy.c } \ |
705 | "pr18841bn" \ | |
706 | "pr18841.out" \ | |
707 | ] \ | |
708 | [list \ | |
709 | "Run pr18841 with libpr18841cn.so (-z now)" \ | |
470cd0fa AM |
710 | "$NOPIE_LDFLAGS -Wl,-z,now -Wl,--as-needed tmpdir/pr18841a.o tmpdir/libpr18841cn.so" \ |
711 | "$NOPIE_CFLAGS" \ | |
d6f48aed L |
712 | { dummy.c } \ |
713 | "pr18841cn" \ | |
714 | "pr18841.out" \ | |
715 | ] \ | |
2822b09f AM |
716 | ] |
717 | ||
718 | # The pr23169 testcase is not valid. In general, you can't call ifunc | |
719 | # resolvers in another binary unless you know what you're doing. In | |
720 | # particular you must ensure that the binary containing the resolver | |
721 | # is relocated before the resolver is called (for example, the | |
722 | # function addresses returned by the resolver may be loaded from the | |
723 | # GOT). | |
724 | # That does not happen for the pr23169 testcase where the resolver is | |
725 | # in the executable (which is relocated last by ld.so). | |
726 | if { [isnative] | |
c49829c3 EB |
727 | && !([istarget "powerpc-*-*"] |
728 | || [istarget "aarch64*-*-*"] | |
02dd9d25 NC |
729 | || [istarget "sparc*-*-*"] |
730 | || [istarget "riscv*-*-*"]) } { | |
2822b09f | 731 | run_ld_link_exec_tests [list \ |
4ec09950 L |
732 | [list \ |
733 | "Run pr23169a" \ | |
734 | "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libpr23169a.so" \ | |
735 | "" \ | |
736 | { pr23169b.c pr23169c.c } \ | |
737 | "pr23169a" \ | |
738 | "pass.out" \ | |
739 | "$NOPIE_CFLAGS -O2 -g" \ | |
740 | ] \ | |
741 | [list \ | |
742 | "Run pr23169b" \ | |
743 | "-pie -Wl,--no-as-needed tmpdir/libpr23169a.so" \ | |
744 | "" \ | |
745 | { pr23169b.c pr23169c.c } \ | |
746 | "pr23169b" \ | |
747 | "pass.out" \ | |
748 | "-fPIE -O2 -g" \ | |
749 | ] \ | |
750 | [list \ | |
751 | "Run pr23169c" \ | |
752 | "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libpr23169a.so" \ | |
753 | "" \ | |
754 | { pr23169b.c pr23169c.c } \ | |
755 | "pr23169c" \ | |
756 | "pass.out" \ | |
757 | "-fPIE -O2 -g" \ | |
758 | ] \ | |
759 | [list \ | |
760 | "Run pr23169d" \ | |
761 | "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,now tmpdir/libpr23169b.so" \ | |
762 | "" \ | |
763 | { pr23169b.c pr23169c.c } \ | |
764 | "pr23169d" \ | |
765 | "pass.out" \ | |
766 | "$NOPIE_CFLAGS -O2 -g" \ | |
767 | ] \ | |
4ec09950 L |
768 | [list \ |
769 | "Run pr23169f" \ | |
770 | "$NOPIE_LDFLAGS -Wl,--no-as-needed,-z,now tmpdir/libpr23169b.so" \ | |
771 | "" \ | |
772 | { pr23169b.c pr23169c.c } \ | |
773 | "pr23169f" \ | |
774 | "pass.out" \ | |
775 | "-fPIE -O2 -g" \ | |
776 | ] \ | |
b3d7a867 L |
777 | ] |
778 | if { $STATIC_PIE_LDFLAGS != "" } then { | |
779 | run_ld_link_exec_tests [list \ | |
780 | [list \ | |
781 | "Run pr23169g" \ | |
782 | "$STATIC_PIE_LDFLAGS" \ | |
783 | "" \ | |
784 | { pr23169a.c pr23169b.c pr23169c.c } \ | |
785 | "pr23169g" \ | |
786 | "pass.out" \ | |
787 | "-fPIE -O2 -g" \ | |
788 | ] \ | |
789 | ] | |
790 | } | |
791 | } | |
e9d644e8 L |
792 | |
793 | set ASFLAGS "$saved_ASFLAGS" |