PR26069, strip/objcopy misaligned address accesses
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elf / linux-x86.exp
CommitLineData
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.
23if { ![istarget "i?86-*-linux*"] \
24 && ![istarget "x86_64-*-linux*"] \
25 && ![istarget "amd64-*-linux*"] } {
26 return
27}
28
29run_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 51if { ![isnative] || ![check_compiler_available] } {
241e64e3
L
52 return
53}
54
55# Add $PLT_CFLAGS if PLT is expected.
56global PLT_CFLAGS
57# Add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if non-PIE is required.
58global NOPIE_CFLAGS NOPIE_LDFLAGS
59
60run_ld_link_exec_tests [list \
61 [list \
62 "Run PR ld/23428 test" \
63 "--no-dynamic-linker -z separate-code" \
64 "" \
ab9e3428 65 { linux-x86.S pr23428.c dummy.s } \
241e64e3
L
66 "pr23428" \
67 "pass.out" \
68 "$NOPIE_CFLAGS -fno-asynchronous-unwind-tables" \
69 "asm" \
70 ] \
71]
8a6b075b
L
72
73run_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
85proc 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
111elfedit_test "--enable-x86-feature ibt --disable-x86-feature shstk" \
112 x86-feature-1 x86-feature-1b
113elfedit_test "--enable-x86-feature ibt" x86-feature-1 x86-feature-1b
114elfedit_test "--disable-x86-feature shstk" x86-feature-1 x86-feature-1c
115elfedit_test "--disable-x86-feature ibt" x86-feature-1 x86-feature-1d
116elfedit_test "--enable-x86-feature ibt --enable-x86-feature shstk" \
117 x86-feature-1 x86-feature-1e
382aae06
L
118
119proc 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 set pr25749_bin "$objcopy -B $output_arch -I binary -O $output_target $srcfilea tmpdir/pr25749-bin.o"
138 send_log "$pr25749_bin\n"
139 set got [remote_exec host "$pr25749_bin"]
140 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
141 send_log "$got\n"
142 fail "Convert $srcfilea to $output_target"
143 return
144 }
145
146 if {"$lderror" == ""} {
147 run_cc_link_tests [list \
148 [list \
149 "Build $testname ($ldflags $cflags)" \
150 "$ldflags tmpdir/pr25749-bin.o" \
516231b7 151 "$cflags -I../bfd" \
382aae06
L
152 [list $srcfilea $srcfileb]\
153 {{readelf {-Wr} pr25749.rd}} \
154 "${testname}a" \
155 ] \
156 ]
157 run_ld_link_exec_tests [list \
158 [list \
159 "Run ${testname}a ($ldflags $cflags)" \
160 "$ldflags tmpdir/pr25749-bin.o" \
161 "" \
162 [list $srcfilea $srcfileb]\
163 "${testname}a" \
164 "pass.out" \
516231b7 165 "$cflags -I../bfd" \
382aae06
L
166 ] \
167 ]
168 } else {
169 run_cc_link_tests [list \
170 [list \
171 "Build $testname ($ldflags $cflags)" \
172 "$ldflags tmpdir/pr25749-bin.o" \
516231b7 173 "$cflags -I../bfd" \
382aae06
L
174 [list $srcfilea $srcfileb]\
175 [list [list error_output $lderror]] \
176 "$testname" \
177 ] \
178 ]
179 }
180}
181
182check_pr25749a "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
183check_pr25749a "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "-fPIE" "-pie" ""
184check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
185if { [istarget "i?86-*-linux*"] } {
186 check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" ""
187} else {
188 check_pr25749a "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" "pr25749-1b.err"
189}
190check_pr25749a "pr25749-1c" "pr25749-1.c" "pr25749-1c.c" "-fPIC" "-shared" "pr25749-1b.err"
191check_pr25749a "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
192check_pr25749a "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "-fPIE" "-pie" ""
193check_pr25749a "pr25749-2b" "pr25749-2.c" "pr25749-2b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
194check_pr25749a "pr25749-2b" "pr25749-2.c" "pr25749-2b.s" "-fPIE" "-pie" ""
195check_pr25749a "pr25754-1a" "pr25754-1a.c" "pr25754-1b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
196check_pr25749a "pr25754-1b" "pr25754-1a.c" "pr25754-1b.s" "-fPIE" "$NOPIE_LDFLAGS" ""
197check_pr25749a "pr25754-1c" "pr25754-1a.c" "pr25754-1b.s" "-fPIC" "$NOPIE_LDFLAGS" ""
198check_pr25749a "pr25754-1d" "pr25754-1a.c" "pr25754-1b.s" "-fPIC" "-pie" ""
199if { [istarget "i?86-*-linux*"] || [istarget "x86_64-*-linux*-gnux32"]} {
200 check_pr25749a "pr25754-2a" "pr25754-2a.c" "pr25754-2b.s" "-fPIC" "$NOPIE_LDFLAGS" ""
201 check_pr25749a "pr25754-2b" "pr25754-2a.c" "pr25754-2b.s" "-fPIC" "-pie" ""
202} else {
203 check_pr25749a "pr25754-3a" "pr25754-3a.c" "pr25754-3b.s" "-fPIC" "$NOPIE_LDFLAGS" ""
204 check_pr25749a "pr25754-3b" "pr25754-3a.c" "pr25754-3b.s" "-fPIC" "-pie" ""
205}
206if { [istarget "i?86-*-linux*"] } {
207 check_pr25749a "pr25754-4a" "pr25754-4a.c" "pr25754-4b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
208 check_pr25749a "pr25754-4b" "pr25754-4a.c" "pr25754-4b.s" "-fpie" "-pie" ""
209 check_pr25749a "pr25754-5a" "pr25754-5a.c" "pr25754-5b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
210 check_pr25749a "pr25754-5b" "pr25754-5a.c" "pr25754-5b.s" "-fpie" "-pie" ""
211} else {
212 check_pr25749a "pr25754-4a" "pr25754-4a.c" "pr25754-4c.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
213 check_pr25749a "pr25754-4b" "pr25754-4a.c" "pr25754-4c.s" "-fpie" "-pie" ""
214 check_pr25749a "pr25754-5a" "pr25754-5a.c" "pr25754-5c.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
215 check_pr25749a "pr25754-5b" "pr25754-5a.c" "pr25754-5c.s" "-fpie" "-pie" ""
216 if { ![istarget "x86_64-*-linux*-gnux32"]} {
217 check_pr25749a "pr25754-6a" "pr25754-6a.c" "pr25754-6b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
218 check_pr25749a "pr25754-6b" "pr25754-6a.c" "pr25754-6b.s" "-fpie" "-pie" ""
219 }
220}
221
222proc check_pr25749b {testname srcfilea srcfileb cflags ldflags dsoldflags} {
223 global objcopy
224 global srcdir
225 global subdir
226
227 if { [istarget "i?86-*-linux*"] } {
228 set output_arch "i386:i386"
229 set output_target "elf32-i386"
230 } else {
231 set output_arch "i386:x86-64"
232 if {[istarget "x86_64-*-linux*-gnux32"]} {
233 set output_target "elf32-x86-64"
234 } else {
235 set output_target "elf64-x86-64"
236 }
237 }
238
239 exec cp $srcdir/$subdir/$srcfilea $srcfilea
240 set pr25749_bin "$objcopy -B $output_arch -I binary -O $output_target $srcfilea tmpdir/pr25749-bin.o"
241 send_log "$pr25749_bin\n"
242 set got [remote_exec host "$pr25749_bin"]
243 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
244 send_log "$got\n"
245 fail "Convert $srcfilea to $output_target"
246 return
247 }
248
249 run_cc_link_tests [list \
250 [list \
251 "Build lib${testname}.so ($dsoldflags)" \
252 "-shared $dsoldflags tmpdir/pr25749-bin.o" \
516231b7 253 "-fPIC -I../bfd" \
382aae06
L
254 [list $srcfileb] \
255 {{readelf {-Wr} pr25749.rd}} \
256 "lib${testname}.so" \
257 ] \
258 ]
259 run_ld_link_exec_tests [list \
260 [list \
261 "Run ${testname}b ($ldflags $cflags)" \
262 "$ldflags -Wl,--no-as-needed tmpdir/lib${testname}.so" \
263 "" \
264 [list $srcfilea]\
265 "${testname}b" \
266 "pass.out" \
516231b7 267 "$cflags -I../bfd" \
382aae06
L
268 ] \
269 ]
270}
271
272check_pr25749b "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
273check_pr25749b "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "-fPIE" "-pie" ""
274check_pr25749b "pr25749-1a" "pr25749-1.c" "pr25749-1a.c" "-fPIE" "-pie" "-Wl,-Bsymbolic"
275check_pr25749b "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
276check_pr25749b "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" ""
277check_pr25749b "pr25749-1b" "pr25749-1.c" "pr25749-1b.c" "-fPIE" "-pie" "-Wl,-Bsymbolic"
278check_pr25749b "pr25749-1d" "pr25749-1.c" "pr25749-1d.c" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" "-Wl,-defsym=_begin=0"
279check_pr25749b "pr25749-1d" "pr25749-1.c" "pr25749-1d.c" "-fPIE" "-pie" "-Wl,-defsym=_begin=0"
280check_pr25749b "pr25749-1d" "pr25749-1.c" "pr25749-1d.c" "-fPIE" "-pie" "-Wl,-Bsymbolic -Wl,-defsym=_begin=0"
281check_pr25749b "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
282check_pr25749b "pr25749-2a" "pr25749-2.c" "pr25749-2a.s" "-fPIE" "-pie" ""
283check_pr25749b "pr25749-2b" "pr25749-2.c" "pr25749-2b.s" "$NOPIE_CFLAGS" "$NOPIE_LDFLAGS" ""
284check_pr25749b "pr25749-2b" "pr25749-2.c" "pr25749-2b.s" "-fPIE" "-pie" ""
This page took 0.129258 seconds and 4 git commands to generate.