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