]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/testsuite/ld-elf/linux-x86.exp
elf: Add GNU_PROPERTY_1_NEEDED check
[thirdparty/binutils-gdb.git] / ld / testsuite / ld-elf / linux-x86.exp
1 # Expect script for simple native Linux/x86 tests.
2 # Copyright (C) 2018-2021 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 run_ld_link_exec_tests [list \
52 [list \
53 "Run PR ld/23428 test" \
54 "--no-dynamic-linker -z separate-code" \
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 ] \
62 ]
63
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 ] \
74 ]
75
76 run_cc_link_tests [list \
77 [list \
78 "Build indirect-extern-access-1.so" \
79 "-shared" \
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 \
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" \
101 ] \
102 [list \
103 "Build indirect-extern-access-2a without PIE" \
104 "$NOPIE_LDFLAGS -Wl,--no-as-needed \
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" \
110 ] \
111 [list \
112 "Build indirect-extern-access-2b with PIE" \
113 "-pie -Wl,--no-as-needed \
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" \
119 ] \
120 ]
121
122 run_ld_link_exec_tests [list \
123 [list \
124 "Run indirect-extern-access-1a without PIE" \
125 "$NOPIE_LDFLAGS" \
126 "" \
127 { indirect-extern-access.S indirect-extern-access-1b.c } \
128 "indirect-extern-access-1a" \
129 "pass.out" \
130 "$NOPIE_CFLAGS" \
131 "" \
132 "" \
133 "tmpdir/indirect-extern-access-1.so" \
134 ] \
135 [list \
136 "Run indirect-extern-access-1b with PIE" \
137 "-pie" \
138 "" \
139 { indirect-extern-access.S indirect-extern-access-1b.c } \
140 "indirect-extern-access-1b" \
141 "pass.out" \
142 "-fpie" \
143 "" \
144 "" \
145 "tmpdir/indirect-extern-access-1.so" \
146 ] \
147 [list \
148 "Run indirect-extern-access-2a without PIE" \
149 "$NOPIE_LDFLAGS" \
150 "" \
151 { indirect-extern-access.S indirect-extern-access-2b.c } \
152 "indirect-extern-access-2a" \
153 "pass.out" \
154 "$NOPIE_CFLAGS" \
155 "" \
156 "" \
157 "tmpdir/indirect-extern-access-2.so" \
158 ] \
159 [list \
160 "Run indirect-extern-access-2b with PIE" \
161 "-pie" \
162 "" \
163 { indirect-extern-access.S indirect-extern-access-2b.c } \
164 "indirect-extern-access-2b" \
165 "pass.out" \
166 "-fpie" \
167 "" \
168 "" \
169 "tmpdir/indirect-extern-access-2.so" \
170 ] \
171 ]
172
173 proc elfedit_test { options test output } {
174 global ELFEDIT
175 global READELF
176 global srcdir
177 global subdir
178
179 set test_name "elfedit $options"
180 send_log "$ELFEDIT $options tmpdir/$test\n"
181 set got [remote_exec host "$ELFEDIT $options tmpdir/$test" "" "/dev/null"]
182 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
183 send_log "$got\n"
184 fail "$test_name"
185 }
186 send_log "$READELF -n $options tmpdir/$test > tmpdir/$output.out\n"
187 set got [remote_exec host "$READELF -n tmpdir/$test" "" "/dev/null" "tmpdir/$output.out"]
188 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
189 send_log "$got\n"
190 fail "$test_name"
191 }
192 if { [regexp_diff tmpdir/$output.out $srcdir/$subdir/$output.rd] } then {
193 fail "$test_name"
194 } else {
195 pass "$test_name"
196 }
197 }
198
199 elfedit_test "--enable-x86-feature ibt --disable-x86-feature shstk" \
200 x86-feature-1 x86-feature-1b
201 elfedit_test "--enable-x86-feature ibt" x86-feature-1 x86-feature-1b
202 elfedit_test "--disable-x86-feature shstk" x86-feature-1 x86-feature-1c
203 elfedit_test "--disable-x86-feature ibt" x86-feature-1 x86-feature-1d
204 elfedit_test "--enable-x86-feature ibt --enable-x86-feature shstk" \
205 x86-feature-1 x86-feature-1e
206
207 proc check_pr25749a {testname srcfilea srcfileb cflags ldflags lderror} {
208 global objcopy
209 global srcdir
210 global subdir
211
212 if { [istarget "i?86-*-linux*"] } {
213 set output_arch "i386:i386"
214 set output_target "elf32-i386"
215 } else {
216 set output_arch "i386:x86-64"
217 if {[istarget "x86_64-*-linux*-gnux32"]} {
218 set output_target "elf32-x86-64"
219 } else {
220 set output_target "elf64-x86-64"
221 }
222 }
223
224 # Suppress warning for unsupported attribute from older GCC.
225 append cflags " -w"
226
227 exec cp $srcdir/$subdir/$srcfilea $srcfilea
228 exec chmod +w $srcfilea
229 set pr25749_bin "$objcopy -B $output_arch -I binary -O $output_target $srcfilea tmpdir/pr25749-bin.o"
230 send_log "$pr25749_bin\n"
231 set got [remote_exec host "$pr25749_bin"]
232 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
233 send_log "$got\n"
234 fail "Convert $srcfilea to $output_target"
235 return
236 }
237
238 if {"$lderror" == ""} {
239 run_cc_link_tests [list \
240 [list \
241 "Build $testname ($ldflags $cflags)" \
242 "$ldflags tmpdir/pr25749-bin.o" \
243 "$cflags -I../bfd" \
244 [list $srcfilea $srcfileb]\
245 {{readelf {-Wr} pr25749.rd}} \
246 "${testname}a" \
247 ] \
248 ]
249 run_ld_link_exec_tests [list \
250 [list \
251 "Run ${testname}a ($ldflags $cflags)" \
252 "$ldflags tmpdir/pr25749-bin.o" \
253 "" \
254 [list $srcfilea $srcfileb]\
255 "${testname}a" \
256 "pass.out" \
257 "$cflags -I../bfd" \
258 ] \
259 ]
260 } else {
261 run_cc_link_tests [list \
262 [list \
263 "Build $testname ($ldflags $cflags)" \
264 "$ldflags tmpdir/pr25749-bin.o" \
265 "$cflags -I../bfd" \
266 [list $srcfilea $srcfileb]\
267 [list [list error_output $lderror]] \
268 "$testname" \
269 ] \
270 ]
271 }
272 }
273
274 check_pr25749a "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
275 check_pr25749a "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "-fPIE" "-pie" ""
276 check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
277 if { [istarget "i?86-*-linux*"] || ![at_least_gcc_version 5 1] } {
278 check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" ""
279 } else {
280 check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" "pr25749-1b.err"
281 }
282 check_pr25749a "pr25749-1c" "pr25749-1.c" "pr25749-1c.c" "-fPIC" "-shared" "pr25749-1b.err"
283 check_pr25749a "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
284 check_pr25749a "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "-fPIE" "-pie" ""
285 check_pr25749a "pr25749-2b" "pr25749-2.c" "pr25749-2b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
286 check_pr25749a "pr25749-2b" "pr25749-2.c" "pr25749-2b.s" "-fPIE" "-pie" ""
287 check_pr25749a "pr25754-1a" "pr25754-1a.c" "pr25754-1b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
288 check_pr25749a "pr25754-1b" "pr25754-1a.c" "pr25754-1b.s" "-fPIE" "$NOPIE_LDFLAGS" ""
289 check_pr25749a "pr25754-1c" "pr25754-1a.c" "pr25754-1b.s" "-fPIC" "$NOPIE_LDFLAGS" ""
290 check_pr25749a "pr25754-1d" "pr25754-1a.c" "pr25754-1b.s" "-fPIC" "-pie" ""
291 if { [istarget "i?86-*-linux*"] || [istarget "x86_64-*-linux*-gnux32"]} {
292 check_pr25749a "pr25754-2a" "pr25754-2a.c" "pr25754-2b.s" "-fPIC" "$NOPIE_LDFLAGS" ""
293 check_pr25749a "pr25754-2b" "pr25754-2a.c" "pr25754-2b.s" "-fPIC" "-pie" ""
294 } else {
295 check_pr25749a "pr25754-3a" "pr25754-3a.c" "pr25754-3b.s" "-fPIC" "$NOPIE_LDFLAGS" ""
296 check_pr25749a "pr25754-3b" "pr25754-3a.c" "pr25754-3b.s" "-fPIC" "-pie" ""
297 }
298 if { [istarget "i?86-*-linux*"] } {
299 check_pr25749a "pr25754-4a" "pr25754-4a.c" "pr25754-4b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
300 check_pr25749a "pr25754-4b" "pr25754-4a.c" "pr25754-4b.s" "-fpie" "-pie" ""
301 check_pr25749a "pr25754-5a" "pr25754-5a.c" "pr25754-5b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
302 check_pr25749a "pr25754-5b" "pr25754-5a.c" "pr25754-5b.s" "-fpie" "-pie" ""
303 } else {
304 check_pr25749a "pr25754-4a" "pr25754-4a.c" "pr25754-4c.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
305 check_pr25749a "pr25754-4b" "pr25754-4a.c" "pr25754-4c.s" "-fpie" "-pie" ""
306 check_pr25749a "pr25754-5a" "pr25754-5a.c" "pr25754-5c.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
307 check_pr25749a "pr25754-5b" "pr25754-5a.c" "pr25754-5c.s" "-fpie" "-pie" ""
308 if { ![istarget "x86_64-*-linux*-gnux32"]} {
309 check_pr25749a "pr25754-6a" "pr25754-6a.c" "pr25754-6b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
310 check_pr25749a "pr25754-6b" "pr25754-6a.c" "pr25754-6b.s" "-fpie" "-pie" ""
311 }
312 }
313
314 proc check_pr25749b {testname srcfilea srcfileb cflags ldflags dsoldflags args} {
315 global objcopy
316 global srcdir
317 global subdir
318
319 if { [istarget "i?86-*-linux*"] } {
320 set output_arch "i386:i386"
321 set output_target "elf32-i386"
322 } else {
323 set output_arch "i386:x86-64"
324 if {[istarget "x86_64-*-linux*-gnux32"]} {
325 set output_target "elf32-x86-64"
326 } else {
327 set output_target "elf64-x86-64"
328 }
329 }
330
331 exec cp $srcdir/$subdir/$srcfilea $srcfilea
332 exec chmod +w $srcfilea
333 set pr25749_bin "$objcopy -B $output_arch -I binary -O $output_target $srcfilea tmpdir/pr25749-bin.o"
334 send_log "$pr25749_bin\n"
335 set got [remote_exec host "$pr25749_bin"]
336 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
337 send_log "$got\n"
338 fail "Convert $srcfilea to $output_target"
339 return
340 }
341
342 run_cc_link_tests [list \
343 [list \
344 "Build lib${testname}.so ($dsoldflags)" \
345 "-shared $dsoldflags tmpdir/pr25749-bin.o" \
346 "-fPIC -I../bfd" \
347 [list $srcfileb] \
348 {{readelf {-Wr} pr25749.rd}} \
349 "lib${testname}.so" \
350 ] \
351 ]
352
353 set pass "pass.out"
354 if { [llength $args] > 0 } {
355 set pass [lindex $args 0]
356 }
357
358 run_ld_link_exec_tests [list \
359 [list \
360 "Run ${testname}b ($ldflags $cflags)" \
361 "$ldflags -Wl,--no-as-needed tmpdir/lib${testname}.so" \
362 "" \
363 [list $srcfilea]\
364 "${testname}b" \
365 "$pass" \
366 "$cflags -I../bfd" \
367 ] \
368 ]
369 }
370
371 check_pr25749b "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
372 check_pr25749b "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "-fPIE" "-pie" ""
373 check_pr25749b "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "-fPIE" "-pie" "-Wl,-Bsymbolic"
374 check_pr25749b "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" "" "passall.out"
375 check_pr25749b "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" "" "passall.out"
376 check_pr25749b "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" "-Wl,-Bsymbolic"
377 check_pr25749b "pr25749-1d" "pr25749-1.c" "pr25749-1d.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" "-Wl,-defsym=_begin=0"
378 check_pr25749b "pr25749-1d" "pr25749-1.c" "pr25749-1d.c" "-fPIE" "-pie" "-Wl,-defsym=_begin=0"
379 check_pr25749b "pr25749-1d" "pr25749-1.c" "pr25749-1d.c" "-fPIE" "-pie" "-Wl,-Bsymbolic -Wl,-defsym=_begin=0"
380 check_pr25749b "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" "" "passall.out"
381 check_pr25749b "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "-fPIE" "-pie" "" "passall.out"
382 check_pr25749b "pr25749-2b" "pr25749-2.c" "pr25749-2b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
383 check_pr25749b "pr25749-2b" "pr25749-2.c" "pr25749-2b.s" "-fPIE" "-pie" ""