ld: fix ld-elf/linux-x86.exp for r/o source tree
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elf / linux-x86.exp
1 # Expect script for simple native Linux/x86 tests.
2 # Copyright (C) 2018-2020 Free Software Foundation, Inc.
3 #
4 # This file is part of the GNU Binutils.
5 #
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.
10 #
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.
15 #
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.
20 #
21
22 # Linux/x86 tests.
23 if { ![istarget "i?86-*-linux*"] \
24 && ![istarget "x86_64-*-linux*"] \
25 && ![istarget "amd64-*-linux*"] } {
26 return
27 }
28
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 ] \
48 ]
49
50 # Test very simple native Linux/x86 programs with linux-x86.S.
51 if { ![isnative] || ![check_compiler_available] } {
52 return
53 }
54
55 # Add $PLT_CFLAGS if PLT is expected.
56 global PLT_CFLAGS
57 # Add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if non-PIE is required.
58 global NOPIE_CFLAGS NOPIE_LDFLAGS
59
60 run_ld_link_exec_tests [list \
61 [list \
62 "Run PR ld/23428 test" \
63 "--no-dynamic-linker -z separate-code" \
64 "" \
65 { linux-x86.S pr23428.c dummy.s } \
66 "pr23428" \
67 "pass.out" \
68 "$NOPIE_CFLAGS -fno-asynchronous-unwind-tables" \
69 "asm" \
70 ] \
71 ]
72
73 run_ld_link_tests [list \
74 [list \
75 "Build x86-feature-1" \
76 "-z separate-code -z shstk" \
77 "" \
78 "-mx86-used-note=yes" \
79 { start.s } \
80 {{readelf -n x86-feature-1a.rd}} \
81 "x86-feature-1" \
82 ] \
83 ]
84
85 proc elfedit_test { options test output } {
86 global ELFEDIT
87 global READELF
88 global srcdir
89 global subdir
90
91 set test_name "elfedit $options"
92 send_log "$ELFEDIT $options tmpdir/$test\n"
93 set got [remote_exec host "$ELFEDIT $options tmpdir/$test" "" "/dev/null"]
94 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
95 send_log "$got\n"
96 unresolved "$test_name"
97 }
98 send_log "$READELF -n $options tmpdir/$test > tmpdir/$output.out\n"
99 set got [remote_exec host "$READELF -n tmpdir/$test" "" "/dev/null" "tmpdir/$output.out"]
100 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
101 send_log "$got\n"
102 unresolved "$test_name"
103 }
104 if { [regexp_diff tmpdir/$output.out $srcdir/$subdir/$output.rd] } then {
105 fail "$test_name"
106 } else {
107 pass "$test_name"
108 }
109 }
110
111 elfedit_test "--enable-x86-feature ibt --disable-x86-feature shstk" \
112 x86-feature-1 x86-feature-1b
113 elfedit_test "--enable-x86-feature ibt" x86-feature-1 x86-feature-1b
114 elfedit_test "--disable-x86-feature shstk" x86-feature-1 x86-feature-1c
115 elfedit_test "--disable-x86-feature ibt" x86-feature-1 x86-feature-1d
116 elfedit_test "--enable-x86-feature ibt --enable-x86-feature shstk" \
117 x86-feature-1 x86-feature-1e
118
119 proc check_pr25749a {testname srcfilea srcfileb cflags ldflags lderror} {
120 global objcopy
121 global srcdir
122 global subdir
123
124 if { [istarget "i?86-*-linux*"] } {
125 set output_arch "i386:i386"
126 set output_target "elf32-i386"
127 } else {
128 set output_arch "i386:x86-64"
129 if {[istarget "x86_64-*-linux*-gnux32"]} {
130 set output_target "elf32-x86-64"
131 } else {
132 set output_target "elf64-x86-64"
133 }
134 }
135
136 exec cp $srcdir/$subdir/$srcfilea $srcfilea
137 exec chmod +w $srcfilea
138 set pr25749_bin "$objcopy -B $output_arch -I binary -O $output_target $srcfilea tmpdir/pr25749-bin.o"
139 send_log "$pr25749_bin\n"
140 set got [remote_exec host "$pr25749_bin"]
141 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
142 send_log "$got\n"
143 fail "Convert $srcfilea to $output_target"
144 return
145 }
146
147 if {"$lderror" == ""} {
148 run_cc_link_tests [list \
149 [list \
150 "Build $testname ($ldflags $cflags)" \
151 "$ldflags tmpdir/pr25749-bin.o" \
152 "$cflags -I../bfd" \
153 [list $srcfilea $srcfileb]\
154 {{readelf {-Wr} pr25749.rd}} \
155 "${testname}a" \
156 ] \
157 ]
158 run_ld_link_exec_tests [list \
159 [list \
160 "Run ${testname}a ($ldflags $cflags)" \
161 "$ldflags tmpdir/pr25749-bin.o" \
162 "" \
163 [list $srcfilea $srcfileb]\
164 "${testname}a" \
165 "pass.out" \
166 "$cflags -I../bfd" \
167 ] \
168 ]
169 } else {
170 run_cc_link_tests [list \
171 [list \
172 "Build $testname ($ldflags $cflags)" \
173 "$ldflags tmpdir/pr25749-bin.o" \
174 "$cflags -I../bfd" \
175 [list $srcfilea $srcfileb]\
176 [list [list error_output $lderror]] \
177 "$testname" \
178 ] \
179 ]
180 }
181 }
182
183 check_pr25749a "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
184 check_pr25749a "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "-fPIE" "-pie" ""
185 check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
186 if { [istarget "i?86-*-linux*"] } {
187 check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" ""
188 } else {
189 check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" "pr25749-1b.err"
190 }
191 check_pr25749a "pr25749-1c" "pr25749-1.c" "pr25749-1c.c" "-fPIC" "-shared" "pr25749-1b.err"
192 check_pr25749a "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
193 check_pr25749a "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "-fPIE" "-pie" ""
194 check_pr25749a "pr25749-2b" "pr25749-2.c" "pr25749-2b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
195 check_pr25749a "pr25749-2b" "pr25749-2.c" "pr25749-2b.s" "-fPIE" "-pie" ""
196 check_pr25749a "pr25754-1a" "pr25754-1a.c" "pr25754-1b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
197 check_pr25749a "pr25754-1b" "pr25754-1a.c" "pr25754-1b.s" "-fPIE" "$NOPIE_LDFLAGS" ""
198 check_pr25749a "pr25754-1c" "pr25754-1a.c" "pr25754-1b.s" "-fPIC" "$NOPIE_LDFLAGS" ""
199 check_pr25749a "pr25754-1d" "pr25754-1a.c" "pr25754-1b.s" "-fPIC" "-pie" ""
200 if { [istarget "i?86-*-linux*"] || [istarget "x86_64-*-linux*-gnux32"]} {
201 check_pr25749a "pr25754-2a" "pr25754-2a.c" "pr25754-2b.s" "-fPIC" "$NOPIE_LDFLAGS" ""
202 check_pr25749a "pr25754-2b" "pr25754-2a.c" "pr25754-2b.s" "-fPIC" "-pie" ""
203 } else {
204 check_pr25749a "pr25754-3a" "pr25754-3a.c" "pr25754-3b.s" "-fPIC" "$NOPIE_LDFLAGS" ""
205 check_pr25749a "pr25754-3b" "pr25754-3a.c" "pr25754-3b.s" "-fPIC" "-pie" ""
206 }
207 if { [istarget "i?86-*-linux*"] } {
208 check_pr25749a "pr25754-4a" "pr25754-4a.c" "pr25754-4b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
209 check_pr25749a "pr25754-4b" "pr25754-4a.c" "pr25754-4b.s" "-fpie" "-pie" ""
210 check_pr25749a "pr25754-5a" "pr25754-5a.c" "pr25754-5b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
211 check_pr25749a "pr25754-5b" "pr25754-5a.c" "pr25754-5b.s" "-fpie" "-pie" ""
212 } else {
213 check_pr25749a "pr25754-4a" "pr25754-4a.c" "pr25754-4c.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
214 check_pr25749a "pr25754-4b" "pr25754-4a.c" "pr25754-4c.s" "-fpie" "-pie" ""
215 check_pr25749a "pr25754-5a" "pr25754-5a.c" "pr25754-5c.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
216 check_pr25749a "pr25754-5b" "pr25754-5a.c" "pr25754-5c.s" "-fpie" "-pie" ""
217 if { ![istarget "x86_64-*-linux*-gnux32"]} {
218 check_pr25749a "pr25754-6a" "pr25754-6a.c" "pr25754-6b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
219 check_pr25749a "pr25754-6b" "pr25754-6a.c" "pr25754-6b.s" "-fpie" "-pie" ""
220 }
221 }
222
223 proc check_pr25749b {testname srcfilea srcfileb cflags ldflags dsoldflags} {
224 global objcopy
225 global srcdir
226 global subdir
227
228 if { [istarget "i?86-*-linux*"] } {
229 set output_arch "i386:i386"
230 set output_target "elf32-i386"
231 } else {
232 set output_arch "i386:x86-64"
233 if {[istarget "x86_64-*-linux*-gnux32"]} {
234 set output_target "elf32-x86-64"
235 } else {
236 set output_target "elf64-x86-64"
237 }
238 }
239
240 exec cp $srcdir/$subdir/$srcfilea $srcfilea
241 exec chmod +w $srcfilea
242 set pr25749_bin "$objcopy -B $output_arch -I binary -O $output_target $srcfilea tmpdir/pr25749-bin.o"
243 send_log "$pr25749_bin\n"
244 set got [remote_exec host "$pr25749_bin"]
245 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
246 send_log "$got\n"
247 fail "Convert $srcfilea to $output_target"
248 return
249 }
250
251 run_cc_link_tests [list \
252 [list \
253 "Build lib${testname}.so ($dsoldflags)" \
254 "-shared $dsoldflags tmpdir/pr25749-bin.o" \
255 "-fPIC -I../bfd" \
256 [list $srcfileb] \
257 {{readelf {-Wr} pr25749.rd}} \
258 "lib${testname}.so" \
259 ] \
260 ]
261 run_ld_link_exec_tests [list \
262 [list \
263 "Run ${testname}b ($ldflags $cflags)" \
264 "$ldflags -Wl,--no-as-needed tmpdir/lib${testname}.so" \
265 "" \
266 [list $srcfilea]\
267 "${testname}b" \
268 "pass.out" \
269 "$cflags -I../bfd" \
270 ] \
271 ]
272 }
273
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" ""
278 check_pr25749b "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" ""
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" ""
284 check_pr25749b "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "-fPIE" "-pie" ""
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" ""
This page took 0.037784 seconds and 5 git commands to generate.