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 proc elfedit_test { options test output } {
82 set test_name "elfedit $options"
83 send_log "$ELFEDIT $options tmpdir/$test\n"
84 set got [remote_exec host "$ELFEDIT $options tmpdir/$test" "" "/dev/null"]
85 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
87 unresolved "$test_name"
89 send_log "$READELF -n $options tmpdir/$test > tmpdir/$output.out\n"
90 set got [remote_exec host "$READELF -n tmpdir/$test" "" "/dev/null" "tmpdir/$output.out"]
91 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
93 unresolved "$test_name"
95 if { [regexp_diff tmpdir/$output.out $srcdir/$subdir/$output.rd] } then {
102 elfedit_test "--enable-x86-feature ibt --disable-x86-feature shstk" \
103 x86-feature-1 x86-feature-1b
104 elfedit_test "--enable-x86-feature ibt" x86-feature-1 x86-feature-1b
105 elfedit_test "--disable-x86-feature shstk" x86-feature-1 x86-feature-1c
106 elfedit_test "--disable-x86-feature ibt" x86-feature-1 x86-feature-1d
107 elfedit_test "--enable-x86-feature ibt --enable-x86-feature shstk" \
108 x86-feature-1 x86-feature-1e
110 proc check_pr25749a {testname srcfilea srcfileb cflags ldflags lderror} {
115 if { [istarget "i?86-*-linux*"] } {
116 set output_arch "i386:i386"
117 set output_target "elf32-i386"
119 set output_arch "i386:x86-64"
120 if {[istarget "x86_64-*-linux*-gnux32"]} {
121 set output_target "elf32-x86-64"
123 set output_target "elf64-x86-64"
127 # Suppress warning for unsupported attribute from older GCC.
130 exec cp $srcdir/$subdir/$srcfilea $srcfilea
131 exec chmod +w $srcfilea
132 set pr25749_bin "$objcopy -B $output_arch -I binary -O $output_target $srcfilea tmpdir/pr25749-bin.o"
133 send_log "$pr25749_bin\n"
134 set got [remote_exec host "$pr25749_bin"]
135 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
137 fail "Convert $srcfilea to $output_target"
141 if {"$lderror" == ""} {
142 run_cc_link_tests [list \
144 "Build $testname ($ldflags $cflags)" \
145 "$ldflags tmpdir/pr25749-bin.o" \
147 [list $srcfilea $srcfileb]\
148 {{readelf {-Wr} pr25749.rd}} \
152 run_ld_link_exec_tests [list \
154 "Run ${testname}a ($ldflags $cflags)" \
155 "$ldflags tmpdir/pr25749-bin.o" \
157 [list $srcfilea $srcfileb]\
164 run_cc_link_tests [list \
166 "Build $testname ($ldflags $cflags)" \
167 "$ldflags tmpdir/pr25749-bin.o" \
169 [list $srcfilea $srcfileb]\
170 [list [list error_output $lderror]] \
177 check_pr25749a "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
178 check_pr25749a "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "-fPIE" "-pie" ""
179 check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
180 if { [istarget "i?86-*-linux*"] || ![at_least_gcc_version 5 1] } {
181 check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" ""
183 check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" "pr25749-1b.err"
185 check_pr25749a "pr25749-1c" "pr25749-1.c" "pr25749-1c.c" "-fPIC" "-shared" "pr25749-1b.err"
186 check_pr25749a "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
187 check_pr25749a "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "-fPIE" "-pie" ""
188 check_pr25749a "pr25749-2b" "pr25749-2.c" "pr25749-2b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
189 check_pr25749a "pr25749-2b" "pr25749-2.c" "pr25749-2b.s" "-fPIE" "-pie" ""
190 check_pr25749a "pr25754-1a" "pr25754-1a.c" "pr25754-1b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
191 check_pr25749a "pr25754-1b" "pr25754-1a.c" "pr25754-1b.s" "-fPIE" "$NOPIE_LDFLAGS" ""
192 check_pr25749a "pr25754-1c" "pr25754-1a.c" "pr25754-1b.s" "-fPIC" "$NOPIE_LDFLAGS" ""
193 check_pr25749a "pr25754-1d" "pr25754-1a.c" "pr25754-1b.s" "-fPIC" "-pie" ""
194 if { [istarget "i?86-*-linux*"] || [istarget "x86_64-*-linux*-gnux32"]} {
195 check_pr25749a "pr25754-2a" "pr25754-2a.c" "pr25754-2b.s" "-fPIC" "$NOPIE_LDFLAGS" ""
196 check_pr25749a "pr25754-2b" "pr25754-2a.c" "pr25754-2b.s" "-fPIC" "-pie" ""
198 check_pr25749a "pr25754-3a" "pr25754-3a.c" "pr25754-3b.s" "-fPIC" "$NOPIE_LDFLAGS" ""
199 check_pr25749a "pr25754-3b" "pr25754-3a.c" "pr25754-3b.s" "-fPIC" "-pie" ""
201 if { [istarget "i?86-*-linux*"] } {
202 check_pr25749a "pr25754-4a" "pr25754-4a.c" "pr25754-4b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
203 check_pr25749a "pr25754-4b" "pr25754-4a.c" "pr25754-4b.s" "-fpie" "-pie" ""
204 check_pr25749a "pr25754-5a" "pr25754-5a.c" "pr25754-5b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
205 check_pr25749a "pr25754-5b" "pr25754-5a.c" "pr25754-5b.s" "-fpie" "-pie" ""
207 check_pr25749a "pr25754-4a" "pr25754-4a.c" "pr25754-4c.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
208 check_pr25749a "pr25754-4b" "pr25754-4a.c" "pr25754-4c.s" "-fpie" "-pie" ""
209 check_pr25749a "pr25754-5a" "pr25754-5a.c" "pr25754-5c.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
210 check_pr25749a "pr25754-5b" "pr25754-5a.c" "pr25754-5c.s" "-fpie" "-pie" ""
211 if { ![istarget "x86_64-*-linux*-gnux32"]} {
212 check_pr25749a "pr25754-6a" "pr25754-6a.c" "pr25754-6b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
213 check_pr25749a "pr25754-6b" "pr25754-6a.c" "pr25754-6b.s" "-fpie" "-pie" ""
217 proc check_pr25749b {testname srcfilea srcfileb cflags ldflags dsoldflags args} {
222 if { [istarget "i?86-*-linux*"] } {
223 set output_arch "i386:i386"
224 set output_target "elf32-i386"
226 set output_arch "i386:x86-64"
227 if {[istarget "x86_64-*-linux*-gnux32"]} {
228 set output_target "elf32-x86-64"
230 set output_target "elf64-x86-64"
234 exec cp $srcdir/$subdir/$srcfilea $srcfilea
235 exec chmod +w $srcfilea
236 set pr25749_bin "$objcopy -B $output_arch -I binary -O $output_target $srcfilea tmpdir/pr25749-bin.o"
237 send_log "$pr25749_bin\n"
238 set got [remote_exec host "$pr25749_bin"]
239 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
241 fail "Convert $srcfilea to $output_target"
245 run_cc_link_tests [list \
247 "Build lib${testname}.so ($dsoldflags)" \
248 "-shared $dsoldflags tmpdir/pr25749-bin.o" \
251 {{readelf {-Wr} pr25749.rd}} \
252 "lib${testname}.so" \
257 if { [llength $args] > 0 } {
258 set pass [lindex $args 0]
261 run_ld_link_exec_tests [list \
263 "Run ${testname}b ($ldflags $cflags)" \
264 "$ldflags -Wl,--no-as-needed tmpdir/lib${testname}.so" \
274 check_pr25749b "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
275 check_pr25749b "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "-fPIE" "-pie" ""
276 check_pr25749b "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "-fPIE" "-pie" "-Wl,-Bsymbolic"
277 check_pr25749b "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" "" "passall.out"
278 check_pr25749b "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" "" "passall.out"
279 check_pr25749b "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" "-Wl,-Bsymbolic"
280 check_pr25749b "pr25749-1d" "pr25749-1.c" "pr25749-1d.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" "-Wl,-defsym=_begin=0"
281 check_pr25749b "pr25749-1d" "pr25749-1.c" "pr25749-1d.c" "-fPIE" "-pie" "-Wl,-defsym=_begin=0"
282 check_pr25749b "pr25749-1d" "pr25749-1.c" "pr25749-1d.c" "-fPIE" "-pie" "-Wl,-Bsymbolic -Wl,-defsym=_begin=0"
283 check_pr25749b "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" "" "passall.out"
284 check_pr25749b "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "-fPIE" "-pie" "" "passall.out"
285 check_pr25749b "pr25749-2b" "pr25749-2.c" "pr25749-2b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
286 check_pr25749b "pr25749-2b" "pr25749-2.c" "pr25749-2b.s" "-fPIE" "-pie" ""