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