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