1 # Expect script for simple native Linux/x86 tests.
2 # Copyright (C) 2018-2021 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,
23 if { ![istarget "i?86-*-linux*"] \
24 && ![istarget "x86_64-*-linux*"] \
25 && ![istarget "amd64-*-linux*"] } {
29 run_ld_link_tests [list \
42 "-Bdynamic tmpdir/pr24920.so" \
50 # Test very simple native Linux/x86 programs with linux-x86.S.
51 run_ld_link_exec_tests [list \
53 "Run PR ld/23428 test" \
54 "--no-dynamic-linker -z separate-code" \
56 { linux-x86.S pr23428.c dummy.s } \
59 "$NOPIE_CFLAGS $NOSANITIZE_CFLAGS -fno-asynchronous-unwind-tables" \
64 run_ld_link_tests [list \
66 "Build x86-feature-1" \
67 "-z separate-code -z shstk" \
69 "-mx86-used-note=yes" \
71 {{readelf -n x86-feature-1a.rd}} \
76 run_cc_link_tests [list \
78 "Build indirect-extern-access-1.so" \
81 { indirect-extern-access-1a.c } \
83 "indirect-extern-access-1.so" \
86 "Build indirect-extern-access-1a without PIE" \
87 "$NOPIE_LDFLAGS -Wl,--no-as-needed \
88 tmpdir/indirect-extern-access-1.so" \
90 { indirect-extern-access.S indirect-extern-access-1b.c } \
91 {{readelf -rn indirect-extern-access-1.rd}} \
92 "indirect-extern-access-1a" \
95 "Build indirect-extern-access-2.so" \
98 { indirect-extern-access-2a.c } \
100 "indirect-extern-access-2.so" \
103 "Build indirect-extern-access-2a without PIE" \
104 "$NOPIE_LDFLAGS -Wl,--no-as-needed \
105 tmpdir/indirect-extern-access-2.so" \
107 { indirect-extern-access.S indirect-extern-access-1b.c } \
108 {{readelf -rn indirect-extern-access-2.rd}} \
109 "indirect-extern-access-2a" \
112 "Build indirect-extern-access-2b with PIE" \
113 "-pie -Wl,--no-as-needed \
114 tmpdir/indirect-extern-access-2.so" \
116 { indirect-extern-access.S indirect-extern-access-2b.c } \
117 {{readelf -rn indirect-extern-access-3.rd}} \
118 "indirect-extern-access-2b" \
122 "-shared -Wl,-version-script,pr27128.t" \
130 "$NOPIE_LDFLAGS -Wl,--no-as-needed \
134 {{readelf {--dyn-syms -W} pr28158.rd} {nm -D pr28158.nd}} \
139 run_ld_link_exec_tests [list \
141 "Run indirect-extern-access-1a without PIE" \
144 { indirect-extern-access.S indirect-extern-access-1b.c } \
145 "indirect-extern-access-1a" \
150 "tmpdir/indirect-extern-access-1.so" \
153 "Run indirect-extern-access-1b with PIE" \
156 { indirect-extern-access.S indirect-extern-access-1b.c } \
157 "indirect-extern-access-1b" \
162 "tmpdir/indirect-extern-access-1.so" \
165 "Run indirect-extern-access-2a without PIE" \
168 { indirect-extern-access.S indirect-extern-access-2b.c } \
169 "indirect-extern-access-2a" \
174 "tmpdir/indirect-extern-access-2.so" \
177 "Run indirect-extern-access-2b with PIE" \
180 { indirect-extern-access.S indirect-extern-access-2b.c } \
181 "indirect-extern-access-2b" \
186 "tmpdir/indirect-extern-access-2.so" \
190 proc elfedit_test { options test output } {
196 set test_name "elfedit $options"
197 send_log "$ELFEDIT $options tmpdir/$test\n"
198 set got [remote_exec host "$ELFEDIT $options tmpdir/$test" "" "/dev/null"]
199 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
203 send_log "$READELF -n $options tmpdir/$test > tmpdir/$output.out\n"
204 set got [remote_exec host "$READELF -n tmpdir/$test" "" "/dev/null" "tmpdir/$output.out"]
205 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
209 if { [regexp_diff tmpdir/$output.out $srcdir/$subdir/$output.rd] } then {
216 elfedit_test "--enable-x86-feature ibt --disable-x86-feature shstk" \
217 x86-feature-1 x86-feature-1b
218 elfedit_test "--enable-x86-feature ibt" x86-feature-1 x86-feature-1b
219 elfedit_test "--disable-x86-feature shstk" x86-feature-1 x86-feature-1c
220 elfedit_test "--disable-x86-feature ibt" x86-feature-1 x86-feature-1d
221 elfedit_test "--enable-x86-feature ibt --enable-x86-feature shstk" \
222 x86-feature-1 x86-feature-1e
224 proc check_pr25749a {testname srcfilea srcfileb cflags ldflags lderror} {
229 if { [istarget "i?86-*-linux*"] } {
230 set output_arch "i386:i386"
231 set output_target "elf32-i386"
233 set output_arch "i386:x86-64"
234 if {[istarget "x86_64-*-linux*-gnux32"]} {
235 set output_target "elf32-x86-64"
237 set output_target "elf64-x86-64"
241 # Suppress warning for unsupported attribute from older GCC.
244 exec cp $srcdir/$subdir/$srcfilea $srcfilea
245 exec chmod +w $srcfilea
246 set pr25749_bin "$objcopy -B $output_arch -I binary -O $output_target $srcfilea tmpdir/pr25749-bin.o"
247 send_log "$pr25749_bin\n"
248 set got [remote_exec host "$pr25749_bin"]
249 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
251 fail "Convert $srcfilea to $output_target"
255 if {"$lderror" == ""} {
256 run_cc_link_tests [list \
258 "Build $testname ($ldflags $cflags)" \
259 "$ldflags tmpdir/pr25749-bin.o" \
261 [list $srcfilea $srcfileb]\
262 {{readelf {-Wr} pr25749.rd}} \
266 run_ld_link_exec_tests [list \
268 "Run ${testname}a ($ldflags $cflags)" \
269 "$ldflags tmpdir/pr25749-bin.o" \
271 [list $srcfilea $srcfileb]\
278 run_cc_link_tests [list \
280 "Build $testname ($ldflags $cflags)" \
281 "$ldflags tmpdir/pr25749-bin.o" \
283 [list $srcfilea $srcfileb]\
284 [list [list error_output $lderror]] \
291 check_pr25749a "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
292 check_pr25749a "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "-fPIE" "-pie" ""
293 check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
294 if { [istarget "i?86-*-linux*"] || ![at_least_gcc_version 5 1] } {
295 check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" ""
297 check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" "pr25749-1b.err"
299 check_pr25749a "pr25749-1c" "pr25749-1.c" "pr25749-1c.c" "-fPIC" "-shared" "pr25749-1b.err"
300 check_pr25749a "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
301 check_pr25749a "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "-fPIE" "-pie" ""
302 check_pr25749a "pr25749-2b" "pr25749-2.c" "pr25749-2b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
303 check_pr25749a "pr25749-2b" "pr25749-2.c" "pr25749-2b.s" "-fPIE" "-pie" ""
304 check_pr25749a "pr25754-1a" "pr25754-1a.c" "pr25754-1b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
305 check_pr25749a "pr25754-1b" "pr25754-1a.c" "pr25754-1b.s" "-fPIE" "$NOPIE_LDFLAGS" ""
306 check_pr25749a "pr25754-1c" "pr25754-1a.c" "pr25754-1b.s" "-fPIC" "$NOPIE_LDFLAGS" ""
307 check_pr25749a "pr25754-1d" "pr25754-1a.c" "pr25754-1b.s" "-fPIC" "-pie" ""
308 if { [istarget "i?86-*-linux*"] || [istarget "x86_64-*-linux*-gnux32"]} {
309 check_pr25749a "pr25754-2a" "pr25754-2a.c" "pr25754-2b.s" "-fPIC" "$NOPIE_LDFLAGS" ""
310 check_pr25749a "pr25754-2b" "pr25754-2a.c" "pr25754-2b.s" "-fPIC" "-pie" ""
312 check_pr25749a "pr25754-3a" "pr25754-3a.c" "pr25754-3b.s" "-fPIC" "$NOPIE_LDFLAGS" ""
313 check_pr25749a "pr25754-3b" "pr25754-3a.c" "pr25754-3b.s" "-fPIC" "-pie" ""
315 if { [istarget "i?86-*-linux*"] } {
316 check_pr25749a "pr25754-4a" "pr25754-4a.c" "pr25754-4b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
317 check_pr25749a "pr25754-4b" "pr25754-4a.c" "pr25754-4b.s" "-fpie" "-pie" ""
318 check_pr25749a "pr25754-5a" "pr25754-5a.c" "pr25754-5b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
319 check_pr25749a "pr25754-5b" "pr25754-5a.c" "pr25754-5b.s" "-fpie" "-pie" ""
321 check_pr25749a "pr25754-4a" "pr25754-4a.c" "pr25754-4c.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
322 check_pr25749a "pr25754-4b" "pr25754-4a.c" "pr25754-4c.s" "-fpie" "-pie" ""
323 check_pr25749a "pr25754-5a" "pr25754-5a.c" "pr25754-5c.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
324 check_pr25749a "pr25754-5b" "pr25754-5a.c" "pr25754-5c.s" "-fpie" "-pie" ""
325 if { ![istarget "x86_64-*-linux*-gnux32"]} {
326 check_pr25749a "pr25754-6a" "pr25754-6a.c" "pr25754-6b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
327 check_pr25749a "pr25754-6b" "pr25754-6a.c" "pr25754-6b.s" "-fpie" "-pie" ""
331 proc check_pr25749b {testname srcfilea srcfileb cflags ldflags dsoldflags args} {
336 if { [istarget "i?86-*-linux*"] } {
337 set output_arch "i386:i386"
338 set output_target "elf32-i386"
340 set output_arch "i386:x86-64"
341 if {[istarget "x86_64-*-linux*-gnux32"]} {
342 set output_target "elf32-x86-64"
344 set output_target "elf64-x86-64"
348 exec cp $srcdir/$subdir/$srcfilea $srcfilea
349 exec chmod +w $srcfilea
350 set pr25749_bin "$objcopy -B $output_arch -I binary -O $output_target $srcfilea tmpdir/pr25749-bin.o"
351 send_log "$pr25749_bin\n"
352 set got [remote_exec host "$pr25749_bin"]
353 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
355 fail "Convert $srcfilea to $output_target"
359 run_cc_link_tests [list \
361 "Build lib${testname}.so ($dsoldflags)" \
362 "-shared $dsoldflags tmpdir/pr25749-bin.o" \
365 {{readelf {-Wr} pr25749.rd}} \
366 "lib${testname}.so" \
371 if { [llength $args] > 0 } {
372 set pass [lindex $args 0]
375 run_ld_link_exec_tests [list \
377 "Run ${testname}b ($ldflags $cflags)" \
378 "$ldflags -Wl,--no-as-needed tmpdir/lib${testname}.so" \
388 check_pr25749b "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
389 check_pr25749b "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "-fPIE" "-pie" ""
390 check_pr25749b "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "-fPIE" "-pie" "-Wl,-Bsymbolic"
391 check_pr25749b "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" "" "passall.out"
392 check_pr25749b "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" "" "passall.out"
393 check_pr25749b "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" "-Wl,-Bsymbolic"
394 check_pr25749b "pr25749-1d" "pr25749-1.c" "pr25749-1d.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" "-Wl,-defsym=_begin=0"
395 check_pr25749b "pr25749-1d" "pr25749-1.c" "pr25749-1d.c" "-fPIE" "-pie" "-Wl,-defsym=_begin=0"
396 check_pr25749b "pr25749-1d" "pr25749-1.c" "pr25749-1d.c" "-fPIE" "-pie" "-Wl,-Bsymbolic -Wl,-defsym=_begin=0"
397 check_pr25749b "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" "" "passall.out"
398 check_pr25749b "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "-fPIE" "-pie" "" "passall.out"
399 check_pr25749b "pr25749-2b" "pr25749-2.c" "pr25749-2b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
400 check_pr25749b "pr25749-2b" "pr25749-2.c" "pr25749-2b.s" "-fPIE" "-pie" ""