Use better test for usable compiler in ld testsuite.
[external/binutils.git] / ld / testsuite / ld-i386 / no-plt.exp
1 # Expect script for i386 no-PLT tests.
2 #   Copyright (C) 2016-2019 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 # The following tests require running the executable generated by ld,
23 # or enough of a build environment to create a fully linked executable.
24 # This is not commonly available when testing a cross-built linker.
25 if ![isnative] {
26     return
27 }
28
29 if ![is_elf_format] {
30     return
31 }
32
33 if ![istarget "i?86-*-*"] {
34     return
35 }
36
37 # Check to see if the C compiler works
38 if { ![check_compiler_available] } {
39     return
40 }
41
42 # Add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if non-PIE is required.
43 global NOPIE_CFLAGS NOPIE_LDFLAGS
44
45 run_cc_link_tests [list \
46     [list \
47         "Build no-plt-func1.o no-plt-main1.o" \
48         "" \
49         "-fPIE -Wa,-mx86-used-note=yes" \
50         {no-plt-func1.c no-plt-main1.c} \
51     ] \
52     [list \
53         "Build no-plt-check1a.o no-plt-extern1a.o \
54          no-plt-check1b.o no-plt-extern1b.o" \
55         "" \
56         "-Wa,-mrelax-relocations=yes,-mx86-used-note=yes" \
57         {no-plt-check1a.S no-plt-extern1a.S \
58          no-plt-check1b.S no-plt-extern1b.S } \
59     ] \
60     [list \
61         "Build libno-plt-1a.so" \
62         "-shared tmpdir/no-plt-func1.o" \
63         "-Wa,-mx86-used-note=yes" \
64         {dummy.s} \
65         {} \
66         "libno-plt-1a.so" \
67     ] \
68     [list \
69         "Build libno-plt-1b.so" \
70         "-shared tmpdir/no-plt-extern1a.o" \
71         "-Wa,-mx86-used-note=yes" \
72         {dummy.s} \
73         {{readelf -Wr libno-plt-1b.rd} \
74          {objdump -dwrj.text libno-plt-1b.dd}} \
75         "libno-plt-1b.so" \
76     ] \
77     [list \
78         "No PLT (dynamic 1a)" \
79         "$NOPIE_LDFLAGS tmpdir/no-plt-check1a.o tmpdir/no-plt-main1.o \
80          tmpdir/no-plt-func1.o tmpdir/no-plt-extern1a.o" \
81         "-Wa,-mx86-used-note=yes" \
82         {dummy.s} \
83         {{readelf -Wr no-plt-1a.rd} {objdump -dwrj.text no-plt-1a.dd}} \
84         "no-plt-1a" \
85     ] \
86     [list \
87         "No PLT (dynamic 1b)" \
88         "tmpdir/no-plt-check1a.o tmpdir/no-plt-main1.o \
89          tmpdir/libno-plt-1a.so tmpdir/libno-plt-1b.so" \
90         "-Wa,-mx86-used-note=yes" \
91         {dummy.s} \
92         {{readelf -Wr no-plt-1b.rd} {objdump -dwrj.text no-plt-1b.dd}} \
93         "no-plt-1b" \
94     ] \
95     [list \
96         "No PLT (dynamic 1c)" \
97         "$NOPIE_LDFLAGS tmpdir/no-plt-check1a.o tmpdir/no-plt-main1.o \
98          tmpdir/no-plt-func1.o tmpdir/libno-plt-1b.so" \
99         "-Wa,-mx86-used-note=yes" \
100         {dummy.s} \
101         {{readelf -Wr no-plt-1c.rd} {objdump -dwrj.text no-plt-1c.dd}} \
102         "no-plt-1c" \
103     ] \
104     [list \
105         "No PLT (static 1d)" \
106         "-static tmpdir/no-plt-check1a.o tmpdir/no-plt-main1.o \
107          tmpdir/no-plt-func1.o tmpdir/no-plt-extern1a.o" \
108         "-Wa,-mx86-used-note=yes" \
109         {dummy.s} \
110         {{readelf -Wr no-plt-1d.rd} {objdump -dwrj.text no-plt-1d.dd}} \
111         "no-plt-1d" \
112     ] \
113     [list \
114         "No PLT (PIE 1e)" \
115         "-pie tmpdir/no-plt-check1a.o tmpdir/no-plt-main1.o \
116          tmpdir/no-plt-func1.o tmpdir/no-plt-extern1a.o" \
117         "-Wa,-mx86-used-note=yes" \
118         {dummy.s} \
119         {{readelf -Wr no-plt-1e.rd} {objdump -dwrj.text no-plt-1e.dd}} \
120         "no-plt-1e" \
121     ] \
122     [list \
123         "No PLT (PIE 1f)" \
124         "-pie tmpdir/no-plt-check1a.o tmpdir/no-plt-main1.o \
125          tmpdir/libno-plt-1a.so tmpdir/libno-plt-1b.so" \
126         "-Wa,-mx86-used-note=yes" \
127         { dummy.s } \
128         {{readelf -Wr no-plt-1f.rd} {objdump -dwrj.text no-plt-1f.dd}} \
129         "no-plt-1f" \
130     ] \
131     [list \
132         "No PLT (PIE 1g)" \
133         "-pie tmpdir/no-plt-check1a.o tmpdir/no-plt-main1.o \
134          tmpdir/no-plt-func1.o tmpdir/libno-plt-1b.so" \
135         "-Wa,-mx86-used-note=yes" \
136         { dummy.s } \
137         {{readelf -Wr no-plt-1g.rd} {objdump -dwrj.text no-plt-1g.dd}} \
138         "no-plt-1g" \
139     ] \
140     [list \
141         "No PLT (dynamic 1h)" \
142         "$NOPIE_LDFLAGS tmpdir/no-plt-check1b.o tmpdir/no-plt-main1.o \
143          tmpdir/no-plt-func1.o tmpdir/no-plt-extern1b.o" \
144         "-Wa,-mx86-used-note=yes" \
145         {dummy.s} \
146         {{readelf -Wr no-plt-1h.rd} {objdump -dwrj.text no-plt-1h.dd}} \
147         "no-plt-1h" \
148     ] \
149     [list \
150         "No PLT (dynamic 1i)" \
151         "$NOPIE_LDFLAGS tmpdir/no-plt-check1b.o tmpdir/no-plt-main1.o \
152          tmpdir/no-plt-extern1b.o tmpdir/libno-plt-1a.so" \
153         "-Wa,-mx86-used-note=yes" \
154         {dummy.s} \
155         {{readelf -Wr no-plt-1i.rd} {objdump -dwrj.text no-plt-1i.dd}} \
156         "no-plt-1i" \
157     ] \
158     [list \
159         "No PLT (static 1j)" \
160         "-static tmpdir/no-plt-check1b.o tmpdir/no-plt-main1.o \
161          tmpdir/no-plt-func1.o tmpdir/no-plt-extern1b.o" \
162         "-Wa,-mx86-used-note=yes" \
163         {dummy.s} \
164         {{readelf -Wr no-plt-1j.rd} {objdump -dwrj.text no-plt-1j.dd}} \
165         "no-plt-1j" \
166     ] \
167 ]
168
169 run_ld_link_exec_tests [list \
170     [list \
171         "No PLT (dynamic 1a)" \
172         "tmpdir/no-plt-check1a.o tmpdir/no-plt-main1.o \
173          tmpdir/no-plt-func1.o tmpdir/no-plt-extern1a.o" \
174         "-Wa,-mx86-used-note=yes" \
175         { dummy.s } \
176         "no-plt-1a" \
177         "pass.out" \
178     ] \
179     [list \
180         "No PLT (dynamic 1b)" \
181         "tmpdir/no-plt-check1a.o tmpdir/no-plt-main1.o \
182          tmpdir/libno-plt-1a.so tmpdir/libno-plt-1b.so" \
183         "-Wa,-mx86-used-note=yes" \
184         { dummy.s } \
185         "no-plt-1b" \
186         "pass.out" \
187     ] \
188     [list \
189         "No PLT (dynamic 1c)" \
190         "tmpdir/no-plt-check1a.o tmpdir/no-plt-main1.o \
191          tmpdir/no-plt-func1.o tmpdir/libno-plt-1b.so" \
192         "-Wa,-mx86-used-note=yes" \
193         { dummy.s } \
194         "no-plt-1c" \
195         "pass.out" \
196     ] \
197     [list \
198         "No PLT (static 1d)" \
199         "-static tmpdir/no-plt-check1a.o tmpdir/no-plt-main1.o \
200          tmpdir/no-plt-func1.o tmpdir/no-plt-extern1a.o" \
201         "-Wa,-mx86-used-note=yes" \
202         { dummy.s } \
203         "no-plt-1d" \
204         "pass.out" \
205     ] \
206     [list \
207         "No PLT (PIE 1e)" \
208         "-pie tmpdir/no-plt-check1a.o tmpdir/no-plt-main1.o \
209          tmpdir/no-plt-func1.o tmpdir/no-plt-extern1a.o" \
210         "-Wa,-mx86-used-note=yes" \
211         { dummy.s } \
212         "no-plt-1e" \
213         "pass.out" \
214     ] \
215     [list \
216         "No PLT (PIE 1f)" \
217         "-pie tmpdir/no-plt-check1a.o tmpdir/no-plt-main1.o \
218          tmpdir/libno-plt-1a.so tmpdir/libno-plt-1b.so" \
219         "-Wa,-mx86-used-note=yes" \
220         { dummy.s } \
221         "no-plt-1f" \
222         "pass.out" \
223     ] \
224     [list \
225         "No PLT (PIE 1g)" \
226         "-pie tmpdir/no-plt-check1a.o tmpdir/no-plt-main1.o \
227          tmpdir/no-plt-func1.o tmpdir/libno-plt-1b.so" \
228         "-Wa,-mx86-used-note=yes" \
229         { dummy.s } \
230         "no-plt-1g" \
231         "pass.out" \
232     ] \
233     [list \
234         "No PLT (dynamic 1h)" \
235         "$NOPIE_LDFLAGS tmpdir/no-plt-check1b.o tmpdir/no-plt-main1.o \
236          tmpdir/no-plt-func1.o tmpdir/no-plt-extern1b.o" \
237         "-Wa,-mx86-used-note=yes" \
238         {dummy.s} \
239         "no-plt-1h" \
240         "pass.out" \
241     ] \
242     [list \
243         "No PLT (dynamic 1i)" \
244         "$NOPIE_LDFLAGS tmpdir/no-plt-check1b.o tmpdir/no-plt-main1.o \
245          tmpdir/no-plt-extern1b.o tmpdir/libno-plt-1a.so" \
246         "-Wa,-mx86-used-note=yes" \
247         {dummy.s} \
248         "no-plt-1i" \
249         "pass.out" \
250     ] \
251     [list \
252         "No PLT (static 1j)" \
253         "-static tmpdir/no-plt-check1b.o tmpdir/no-plt-main1.o \
254          tmpdir/no-plt-func1.o tmpdir/no-plt-extern1b.o" \
255         "-Wa,-mx86-used-note=yes" \
256         {dummy.s} \
257         "no-plt-1j" \
258         "pass.out" \
259     ] \
260 ]
261
262 # Run-time tests which require working IFUNC support.
263 if { [check_ifunc_available] } {
264     run_cc_link_tests [list \
265         [list \
266             "Build pr20244-3a.o pr20244-3b.o pr20244-3c.o pr20244-3d.o" \
267             "" \
268             "-fPIC -O2 -g -Wa,-mx86-used-note=yes" \
269             { pr20244-3a.c pr20244-3b.S pr20244-3c.S pr20244-3d.S } \
270         ] \
271         [list \
272             "Build pr20253-1a.o pr20253-1b.o pr20253-1c.o pr20253-1d.o" \
273             "" \
274             "-fPIE -O2 -g -Wa,-mx86-used-note=yes" \
275             { pr20253-1a.c pr20253-1b.S pr20253-1c.S pr20253-1d.S } \
276         ] \
277         [list \
278             "Build libpr20253-1a.so" \
279             "-shared tmpdir/pr20253-1b.o \
280              tmpdir/pr20253-1c.o tmpdir/pr20253-1d.o" \
281             "-Wa,-mx86-used-note=yes" \
282             { dummy.s } \
283             {} \
284             "libpr20253-1a.so" \
285         ] \
286         [list \
287             "Build pr20253-2a.o pr20253-2b.o pr20253-2c.o pr20253-2d.o" \
288             "-Wa,-mx86-used-note=yes" \
289             "-fPIE -O2 -g" \
290             { pr20253-2a.c pr20253-2b.S pr20253-2c.S pr20253-2d.S } \
291         ] \
292     ]
293
294     run_ld_link_exec_tests [list \
295         [list \
296             "Run pr20244-3a" \
297             "$NOPIE_LDFLAGS tmpdir/pr20244-3a.o tmpdir/pr20244-3b.o \
298              tmpdir/pr20244-3c.o tmpdir/pr20244-3d.o" \
299             "-Wa,-mx86-used-note=yes" \
300             { dummy.c } \
301             "pr20244-3a" \
302             "pass.out" \
303         ] \
304         [list \
305             "Run pr20244-3b" \
306             "--static tmpdir/pr20244-3a.o tmpdir/pr20244-3b.o \
307             tmpdir/pr20244-3c.o tmpdir/pr20244-3d.o" \
308             "-Wa,-mx86-used-note=yes" \
309             { dummy.c } \
310             "pr20244-3b" \
311             "pass.out" \
312         ] \
313         [list \
314             "Run pr20253-1a" \
315             "tmpdir/pr20253-1a.o tmpdir/pr20253-1b.o \
316              tmpdir/pr20253-1c.o tmpdir/pr20253-1d.o" \
317             "-Wa,-mx86-used-note=yes" \
318             { dummy.s } \
319             "pr20253-1a" \
320             "pass.out" \
321         ] \
322         [list \
323             "Run pr20253-1b" \
324             "--static tmpdir/pr20253-1a.o tmpdir/pr20253-1b.o \
325             tmpdir/pr20253-1c.o tmpdir/pr20253-1d.o" \
326             "-Wa,-mx86-used-note=yes" \
327             { dummy.s } \
328             "pr20253-1b" \
329             "pass.out" \
330         ] \
331         [list \
332             "Run pr20253-1c" \
333             "-pie tmpdir/pr20253-1a.o tmpdir/pr20253-1b.o \
334             tmpdir/pr20253-1c.o tmpdir/pr20253-1d.o" \
335             "-Wa,-mx86-used-note=yes" \
336             { dummy.s } \
337             "pr20253-1c" \
338             "pass.out" \
339         ] \
340         [list \
341             "Run pr20253-1d" \
342             "tmpdir/pr20253-1a.o tmpdir/libpr20253-1a.so" \
343             "-Wa,-mx86-used-note=yes" \
344             { dummy.s } \
345             "pr20253-1d" \
346             "pass.out" \
347         ] \
348         [list \
349             "Run pr20253-1e" \
350             "-pie tmpdir/pr20253-1a.o tmpdir/libpr20253-1a.so" \
351             "-Wa,-mx86-used-note=yes" \
352             { dummy.s } \
353             "pr20253-1e" \
354             "pass.out" \
355         ] \
356         [list \
357             "Run pr20253-1f" \
358             "$NOPIE_LDFLAGS tmpdir/pr20253-1a.o" \
359             "-Wa,-mx86-used-note=yes" \
360             { pr20253-1b.S pr20253-1c.S pr20253-1d.S } \
361             "pr20253-1f" \
362             "pass.out" \
363             "-DCHECK_PLT" \
364         ] \
365         [list \
366             "Run pr20253-1g" \
367             "--static tmpdir/pr20253-1a.o" \
368             "-Wa,-mx86-used-note=yes" \
369             { pr20253-1b.S pr20253-1c.S pr20253-1d.S } \
370             "pr20253-1g" \
371             "pass.out" \
372             "-DCHECK_PLT" \
373         ] \
374         [list \
375             "Run pr20253-2a" \
376             "$NOPIE_LDFLAGS tmpdir/pr20253-2a.o tmpdir/pr20253-2b.o \
377              tmpdir/pr20253-2c.o tmpdir/pr20253-2d.o" \
378             "-Wa,-mx86-used-note=yes" \
379             { dummy.s } \
380             "pr20253-2a" \
381             "pass.out" \
382         ] \
383         [list \
384             "Run pr20253-2b" \
385             "--static tmpdir/pr20253-2a.o tmpdir/pr20253-2b.o \
386             tmpdir/pr20253-2c.o tmpdir/pr20253-2d.o" \
387             "-Wa,-mx86-used-note=yes" \
388             { dummy.s } \
389             "pr20253-2b" \
390             "pass.out" \
391         ] \
392         [list \
393             "Run pr20253-2c" \
394             "$NOPIE_LDFLAGS tmpdir/pr20253-2a.o" \
395             "-Wa,-mx86-used-note=yes" \
396             { pr20253-2b.S pr20253-2c.S pr20253-2d.S } \
397             "pr20253-2c" \
398             "pass.out" \
399             "-DCHECK_PLT" \
400         ] \
401         [list \
402             "Run pr20253-2d" \
403             "--static tmpdir/pr20253-2a.o" \
404             "-Wa,-mx86-used-note=yes" \
405             { pr20253-2b.S pr20253-2c.S pr20253-2d.S } \
406             "pr20253-2d" \
407             "pass.out" \
408             "-DCHECK_PLT" \
409         ] \
410     ]
411 }