ld: Update function prototypes for compilers defaulting to -std=gnu23
[binutils-gdb.git] / ld / testsuite / ld-elf / linux-x86.exp
blob27173b916dac810acdbe42e72ced696da7075250
1 # Expect script for simple native Linux/x86 tests.
2 # Copyright (C) 2018-2025 Free Software Foundation, Inc.
4 # This file is part of the GNU Binutils.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 # MA 02110-1301, USA.
22 # Linux/x86 tests.
23 if { ![istarget "i?86-*-linux*"] \
24 && ![istarget "x86_64-*-linux*"] \
25 && ![istarget "amd64-*-linux*"] } {
26 return
29 run_ld_link_tests [list \
30 [list \
31 "Build pr24920.so" \
32 "-shared" \
33 "" \
34 "" \
35 {dummy.s} \
36 {} \
37 "pr24920.so" \
38 ] \
39 [list \
40 "Build pr24920" \
41 "-static " \
42 "-Bdynamic tmpdir/pr24920.so" \
43 "" \
44 {start.s} \
45 {{ld pr24920.err}} \
46 "pr24920" \
47 ] \
50 # Test very simple native Linux/x86 programs with linux-x86.S.
51 run_ld_link_exec_tests [list \
52 [list \
53 "Run PR ld/23428 test" \
54 "--no-dynamic-linker -z separate-code -z noexecstack" \
55 "" \
56 { linux-x86.S pr23428.c dummy.s } \
57 "pr23428" \
58 "pass.out" \
59 "$NOPIE_CFLAGS $NOSANITIZE_CFLAGS -fno-asynchronous-unwind-tables" \
60 "asm" \
61 ] \
64 run_ld_link_tests [list \
65 [list \
66 "Build x86-feature-1" \
67 "-z separate-code -z shstk" \
68 "" \
69 "-mx86-used-note=yes" \
70 { start.s } \
71 {{readelf -n x86-feature-1a.rd}} \
72 "x86-feature-1" \
73 ] \
76 run_cc_link_tests [list \
77 [list \
78 "Build indirect-extern-access-1.so" \
79 "-shared -z noexecstack" \
80 "-fPIC" \
81 { indirect-extern-access-1a.c } \
82 {} \
83 "indirect-extern-access-1.so" \
84 ] \
85 [list \
86 "Build indirect-extern-access-1a without PIE" \
87 "$NOPIE_LDFLAGS -Wl,--no-as-needed -z noexecstack \
88 tmpdir/indirect-extern-access-1.so" \
89 "$NOPIE_CFLAGS" \
90 { indirect-extern-access.S indirect-extern-access-1b.c } \
91 {{readelf -rn indirect-extern-access-1.rd}} \
92 "indirect-extern-access-1a" \
93 ] \
94 [list \
95 "Build indirect-extern-access-2.so" \
96 "-shared" \
97 "-fPIC" \
98 { indirect-extern-access-2a.c } \
99 {} \
100 "indirect-extern-access-2.so" \
102 [list \
103 "Build indirect-extern-access-2a without PIE" \
104 "$NOPIE_LDFLAGS -Wl,--no-as-needed -z noexecstack \
105 tmpdir/indirect-extern-access-2.so" \
106 "$NOPIE_CFLAGS" \
107 { indirect-extern-access.S indirect-extern-access-1b.c } \
108 {{readelf -rn indirect-extern-access-2.rd}} \
109 "indirect-extern-access-2a" \
111 [list \
112 "Build indirect-extern-access-2b with PIE" \
113 "-pie -Wl,--no-as-needed -z noexecstack \
114 tmpdir/indirect-extern-access-2.so" \
115 "-fpie" \
116 { indirect-extern-access.S indirect-extern-access-2b.c } \
117 {{readelf -rn indirect-extern-access-3.rd}} \
118 "indirect-extern-access-2b" \
120 [list \
121 "Build pr28158.so" \
122 "-shared -Wl,-version-script,pr27128.t" \
123 "-fPIC" \
124 { pr28158-1.c } \
125 {} \
126 "pr28158.so" \
128 [list \
129 "Build pr28158" \
130 "$NOPIE_LDFLAGS -Wl,--no-as-needed \
131 tmpdir/pr28158.so" \
132 "" \
133 { pr28158-2.S } \
134 {{readelf {--dyn-syms -W} pr28158.rd} {nm -D pr28158.nd}} \
135 "pr28158" \
137 [list \
138 "Build pr29377.o" \
139 "-r -nostdlib -Wl,-z,noexecstack" \
140 "" \
141 {pr29377a.c indirect-extern-access.S} \
142 {} \
143 "pr29377.o" \
145 [list \
146 "Build pr29377" \
147 "$NOPIE_LDFLAGS tmpdir/pr29377.o" \
148 "-fPIC" \
149 {pr29377b.c} \
150 {} \
151 "pr29377" \
155 run_ld_link_exec_tests [list \
156 [list \
157 "Run indirect-extern-access-1a without PIE" \
158 "$NOPIE_LDFLAGS -z noexecstack" \
159 "" \
160 { indirect-extern-access.S indirect-extern-access-1b.c } \
161 "indirect-extern-access-1a" \
162 "pass.out" \
163 "$NOPIE_CFLAGS" \
164 "" \
165 "" \
166 "tmpdir/indirect-extern-access-1.so" \
168 [list \
169 "Run indirect-extern-access-1b with PIE" \
170 "-pie -z noexecstack" \
171 "" \
172 { indirect-extern-access.S indirect-extern-access-1b.c } \
173 "indirect-extern-access-1b" \
174 "pass.out" \
175 "-fpie" \
176 "" \
177 "" \
178 "tmpdir/indirect-extern-access-1.so" \
180 [list \
181 "Run indirect-extern-access-2a without PIE" \
182 "$NOPIE_LDFLAGS -z noexecstack" \
183 "" \
184 { indirect-extern-access.S indirect-extern-access-2b.c } \
185 "indirect-extern-access-2a" \
186 "pass.out" \
187 "$NOPIE_CFLAGS" \
188 "" \
189 "" \
190 "tmpdir/indirect-extern-access-2.so" \
192 [list \
193 "Run indirect-extern-access-2b with PIE" \
194 "-pie -z noexecstack" \
195 "" \
196 { indirect-extern-access.S indirect-extern-access-2b.c } \
197 "indirect-extern-access-2b" \
198 "pass.out" \
199 "-fpie" \
200 "" \
201 "" \
202 "tmpdir/indirect-extern-access-2.so" \
206 # Run-time tests which require working ifunc attribute support.
207 if { [check_ifunc_attribute_available] } {
208 run_ld_link_exec_tests [list \
209 [list \
210 "Run pr29797" \
211 "-s" \
212 "" \
213 { pr29797.c } \
214 "pr29797" \
215 "pass.out" \
216 "-O0" \
221 # Old gcc silently ignores __attribute__ ((aligned())) with too big alignment.
222 proc compiler_honours_aligned { } {
223 global CC_FOR_TARGET READELF srcdir subdir
224 ld_compile $CC_FOR_TARGET $srcdir/$subdir/p_align-1.c tmpdir/p_align-1.o
225 set output [run_host_cmd "$READELF" "-SW tmpdir/p_align-1.o"]
226 if { [regexp { [.]data *PROGBITS .* 8388608[\n]} $output] } {
227 return 1
229 return 0
232 if { [check_compiler_available] && [compiler_honours_aligned] } {
233 run_ld_link_exec_tests [list \
234 [list \
235 "Run p_align-1a without PIE" \
236 "$NOPIE_LDFLAGS" \
237 "" \
238 { p_align-1.c } \
239 "p_align-1a" \
240 "pass.out" \
241 "$NOPIE_CFLAGS" \
243 [list \
244 "Run p_align-1b with PIE" \
245 "-pie" \
246 "" \
247 { p_align-1.c } \
248 "p_align-1b" \
249 "pass.out" \
250 "-fpie" \
252 [list \
253 "Run p_align-1c with -Wl,-z,max-page-size=0x1000 without PIE" \
254 "$NOPIE_LDFLAGS -Wl,-z,max-page-size=0x1000" \
255 "" \
256 { p_align-1.c } \
257 "p_align-1c" \
258 "pass.out" \
259 "$NOPIE_CFLAGS" \
261 [list \
262 "Run p_align-1d with -Wl,-z,max-page-size=0x1000 with PIE" \
263 "-pie -Wl,-z,max-page-size=0x1000" \
264 "" \
265 { p_align-1.c } \
266 "p_align-1d" \
267 "pass.out" \
268 "-fpie" \
271 } else {
272 unsupported "p_align-1"
275 proc elfedit_test { options test output } {
276 global ELFEDIT
277 global READELF
278 global srcdir
279 global subdir
281 set test_name "elfedit $options"
282 send_log "$ELFEDIT $options tmpdir/$test\n"
283 set got [remote_exec host "$ELFEDIT $options tmpdir/$test" "" "/dev/null"]
284 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
285 send_log "$got\n"
286 fail "$test_name"
288 send_log "$READELF -n $options tmpdir/$test > tmpdir/$output.out\n"
289 set got [remote_exec host "$READELF -n tmpdir/$test" "" "/dev/null" "tmpdir/$output.out"]
290 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
291 send_log "$got\n"
292 fail "$test_name"
294 if { [regexp_diff tmpdir/$output.out $srcdir/$subdir/$output.rd] } then {
295 fail "$test_name"
296 } else {
297 pass "$test_name"
301 elfedit_test "--enable-x86-feature ibt --disable-x86-feature shstk" \
302 x86-feature-1 x86-feature-1b
303 elfedit_test "--enable-x86-feature ibt" x86-feature-1 x86-feature-1b
304 elfedit_test "--disable-x86-feature shstk" x86-feature-1 x86-feature-1c
305 elfedit_test "--disable-x86-feature ibt" x86-feature-1 x86-feature-1d
306 elfedit_test "--enable-x86-feature ibt --enable-x86-feature shstk" \
307 x86-feature-1 x86-feature-1e
309 proc check_pr25749a {testname srcfilea srcfileb cflags ldflags lderror} {
310 global objcopy
311 global srcdir
312 global subdir
314 if { [istarget "i?86-*-linux*"] } {
315 set output_arch "i386:i386"
316 set output_target "elf32-i386"
317 } else {
318 set output_arch "i386:x86-64"
319 if {[istarget "x86_64-*-linux*-gnux32"]} {
320 set output_target "elf32-x86-64"
321 } else {
322 set output_target "elf64-x86-64"
326 # Suppress warning for unsupported attribute from older GCC.
327 append cflags " -w"
329 exec cp $srcdir/$subdir/$srcfilea $srcfilea
330 exec chmod +w $srcfilea
331 set pr25749_bin "$objcopy -B $output_arch -I binary -O $output_target $srcfilea tmpdir/pr25749-bin.o"
332 send_log "$pr25749_bin\n"
333 set got [remote_exec host "$pr25749_bin"]
334 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
335 send_log "$got\n"
336 fail "Convert $srcfilea to $output_target"
337 return
340 if {"$lderror" == ""} {
341 run_cc_link_tests [list \
342 [list \
343 "Build $testname ($ldflags $cflags)" \
344 "$ldflags tmpdir/pr25749-bin.o -z noexecstack" \
345 "$cflags -I../bfd" \
346 [list $srcfilea $srcfileb]\
347 {{readelf {-Wr} pr25749.rd}} \
348 "${testname}a" \
351 run_ld_link_exec_tests [list \
352 [list \
353 "Run ${testname}a ($ldflags $cflags)" \
354 "$ldflags tmpdir/pr25749-bin.o -z noexecstack" \
355 "" \
356 [list $srcfilea $srcfileb]\
357 "${testname}a" \
358 "pass.out" \
359 "$cflags -I../bfd" \
362 } else {
363 run_cc_link_tests [list \
364 [list \
365 "Build $testname ($ldflags $cflags)" \
366 "$ldflags tmpdir/pr25749-bin.o -z noexecstack" \
367 "$cflags -I../bfd" \
368 [list $srcfilea $srcfileb]\
369 [list [list error_output $lderror]] \
370 "$testname" \
376 check_pr25749a "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
377 check_pr25749a "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "-fPIE" "-pie" ""
378 check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
379 if { [istarget "i?86-*-linux*"] || ![at_least_gcc_version 5 1] } {
380 check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" ""
381 } else {
382 check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" "pr25749-1b.err"
384 check_pr25749a "pr25749-1c" "pr25749-1.c" "pr25749-1c.c" "-fPIC" "-shared" "pr25749-1b.err"
385 check_pr25749a "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
386 check_pr25749a "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "-fPIE" "-pie" ""
387 check_pr25749a "pr25749-2b" "pr25749-2.c" "pr25749-2b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
388 check_pr25749a "pr25749-2b" "pr25749-2.c" "pr25749-2b.s" "-fPIE" "-pie" ""
389 check_pr25749a "pr25754-1a" "pr25754-1a.c" "pr25754-1b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
390 check_pr25749a "pr25754-1b" "pr25754-1a.c" "pr25754-1b.s" "-fPIE" "$NOPIE_LDFLAGS" ""
391 check_pr25749a "pr25754-1c" "pr25754-1a.c" "pr25754-1b.s" "-fPIC" "$NOPIE_LDFLAGS" ""
392 check_pr25749a "pr25754-1d" "pr25754-1a.c" "pr25754-1b.s" "-fPIC" "-pie" ""
393 if { [istarget "i?86-*-linux*"] || [istarget "x86_64-*-linux*-gnux32"]} {
394 check_pr25749a "pr25754-2a" "pr25754-2a.c" "pr25754-2b.s" "-fPIC" "$NOPIE_LDFLAGS" ""
395 check_pr25749a "pr25754-2b" "pr25754-2a.c" "pr25754-2b.s" "-fPIC" "-pie" ""
396 } else {
397 check_pr25749a "pr25754-3a" "pr25754-3a.c" "pr25754-3b.s" "-fPIC" "$NOPIE_LDFLAGS" ""
398 check_pr25749a "pr25754-3b" "pr25754-3a.c" "pr25754-3b.s" "-fPIC" "-pie" ""
400 if { [istarget "i?86-*-linux*"] } {
401 check_pr25749a "pr25754-4a" "pr25754-4a.c" "pr25754-4b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
402 check_pr25749a "pr25754-4b" "pr25754-4a.c" "pr25754-4b.s" "-fpie" "-pie" ""
403 check_pr25749a "pr25754-5a" "pr25754-5a.c" "pr25754-5b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
404 check_pr25749a "pr25754-5b" "pr25754-5a.c" "pr25754-5b.s" "-fpie" "-pie" ""
405 } else {
406 check_pr25749a "pr25754-4a" "pr25754-4a.c" "pr25754-4c.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
407 check_pr25749a "pr25754-4b" "pr25754-4a.c" "pr25754-4c.s" "-fpie" "-pie" ""
408 check_pr25749a "pr25754-5a" "pr25754-5a.c" "pr25754-5c.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
409 check_pr25749a "pr25754-5b" "pr25754-5a.c" "pr25754-5c.s" "-fpie" "-pie" ""
410 if { ![istarget "x86_64-*-linux*-gnux32"]} {
411 check_pr25749a "pr25754-6a" "pr25754-6a.c" "pr25754-6b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
412 check_pr25749a "pr25754-6b" "pr25754-6a.c" "pr25754-6b.s" "-fpie" "-pie" ""
416 proc check_pr25749b {testname srcfilea srcfileb cflags ldflags dsoldflags args} {
417 global objcopy
418 global srcdir
419 global subdir
421 if { [istarget "i?86-*-linux*"] } {
422 set output_arch "i386:i386"
423 set output_target "elf32-i386"
424 } else {
425 set output_arch "i386:x86-64"
426 if {[istarget "x86_64-*-linux*-gnux32"]} {
427 set output_target "elf32-x86-64"
428 } else {
429 set output_target "elf64-x86-64"
433 exec cp $srcdir/$subdir/$srcfilea $srcfilea
434 exec chmod +w $srcfilea
435 set pr25749_bin "$objcopy -B $output_arch -I binary -O $output_target $srcfilea tmpdir/pr25749-bin.o"
436 send_log "$pr25749_bin\n"
437 set got [remote_exec host "$pr25749_bin"]
438 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
439 send_log "$got\n"
440 fail "Convert $srcfilea to $output_target"
441 return
444 run_cc_link_tests [list \
445 [list \
446 "Build lib${testname}.so ($dsoldflags)" \
447 "-shared $dsoldflags tmpdir/pr25749-bin.o -z noexecstack" \
448 "-fPIC -I../bfd" \
449 [list $srcfileb] \
450 {{readelf {-Wr} pr25749.rd}} \
451 "lib${testname}.so" \
455 set pass "pass.out"
456 if { [llength $args] > 0 } {
457 set pass [lindex $args 0]
460 run_ld_link_exec_tests [list \
461 [list \
462 "Run ${testname}b ($ldflags $cflags)" \
463 "$ldflags -Wl,--no-as-needed tmpdir/lib${testname}.so -z noexecstack" \
464 "" \
465 [list $srcfilea]\
466 "${testname}b" \
467 "$pass" \
468 "$cflags -I../bfd" \
473 check_pr25749b "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
474 check_pr25749b "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "-fPIE" "-pie" ""
475 check_pr25749b "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "-fPIE" "-pie" "-Wl,-Bsymbolic"
476 check_pr25749b "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" "" "passall.out"
477 check_pr25749b "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" "" "passall.out"
478 check_pr25749b "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" "-Wl,-Bsymbolic"
479 check_pr25749b "pr25749-1d" "pr25749-1.c" "pr25749-1d.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" "-Wl,-defsym=_begin=0"
480 check_pr25749b "pr25749-1d" "pr25749-1.c" "pr25749-1d.c" "-fPIE" "-pie" "-Wl,-defsym=_begin=0"
481 check_pr25749b "pr25749-1d" "pr25749-1.c" "pr25749-1d.c" "-fPIE" "-pie" "-Wl,-Bsymbolic -Wl,-defsym=_begin=0"
482 check_pr25749b "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" "" "passall.out"
483 check_pr25749b "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "-fPIE" "-pie" "" "passall.out"
484 check_pr25749b "pr25749-2b" "pr25749-2.c" "pr25749-2b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
485 check_pr25749b "pr25749-2b" "pr25749-2.c" "pr25749-2b.s" "-fPIE" "-pie" ""