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