* hppa.h (pa_opcodes): Use "cX" completer instead of "cx" in fstqx
[external/binutils.git] / ld / testsuite / ld-elf / shared.exp
1 # Expect script for various ELF tests.
2 #   Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 #   Free Software Foundation, Inc.
4 #
5 # This file is part of the GNU Binutils.
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 # MA 02110-1301, USA.
21 #
22
23 # Exclude non-ELF targets.
24
25 # The following tests require running the executable generated by ld,
26 # or enough of a build environment to create a fully linked executable.
27 # This is not commonly available when testing a cross-built linker.
28 if ![isnative] {
29     return
30 }
31
32 if ![is_elf_format] {
33     return
34 }
35
36 # Check to see if the C compiler works
37 if { [which $CC] == 0 } {
38     return
39 }
40
41 set build_tests {
42   {"Build libfoo.so"
43    "-shared" "-fPIC"
44    {foo.c} {} "libfoo.so"}
45   {"Build versioned libfoo.so"
46    "-shared -Wl,--version-script=foo.map" "-fPIC"
47    {foo.c} {} "libfoov.so"}
48   {"Build libbar.so"
49    "-shared" "-fPIC"
50    {begin.c end.c} {} "libbar.so"}
51   {"Build warn libbar.so"
52    "-shared" "-fPIC"
53    {beginwarn.c end.c} {} "libbarw.so"
54     "C" "^.*\\\): warning: function foo is deprecated$"}
55   {"Build hidden libbar.so"
56    "-shared" "-fPIC"
57    {begin.c endhidden.c} {} "libbarh.so"}
58   {"Build protected libbar.so"
59    "-shared" "-fPIC"
60    {begin.c endprotected.c} {} "libbarp.so"}
61   {"Build libbar.so with libfoo.so"
62    "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
63    {end.c} {} "libbarfoo.so"}
64   {"Build libar.so with versioned libfoo.so"
65    "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
66    {end.c} {} "libbarfoov.so"}
67   {"Build hidden libbar.so with libfoo.so"
68    "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
69    {endhidden.c} {} "libbarhfoo.so"}
70   {"Build hidden libar.so with versioned libfoo.so"
71    "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
72    {endhidden.c} {} "libbarhfoov.so"}
73   {"Build protected libbar.so with libfoo.so"
74    "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
75    {endprotected.c} {} "libbarpfoo.so"}
76   {"Build protected libbar.so with versioned libfoo.so"
77    "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
78    {endprotected.c} {} "libbarpfoov.so"}
79   {"Build libdl1.so"
80    "-shared" "-fPIC"
81    {dl1.c} {} "libdl1.so"}
82   {"Build libdl2a.so with --dynamic-list=dl2.list"
83    "-shared -Wl,--dynamic-list=dl2.list" "-fPIC"
84    {dl2.c dl2xxx.c} {} "libdl2a.so"}
85   {"Build libdl2a.so with --dynamic-list=dl2a.list"
86    "-shared -Wl,--dynamic-list=dl2a.list" "-fPIC"
87    {dl2.c dl2xxx.c} {} "libdl2a.so"}
88   {"Build libdl2a.so with --dynamic-list-data"
89    "-shared -Wl,--dynamic-list-data" "-fPIC"
90    {dl2.c dl2xxx.c} {} "libdl2a.so"}
91   {"Build libdl2b.so with --dynamic-list=dl2.list and dl2xxx.list"
92    "-shared -Wl,--dynamic-list=dl2.list,--dynamic-list=dl2xxx.list" "-fPIC"
93    {dl2.c dl2xxx.c} {} "libdl2b.so"}
94   {"Build libdl2c.so with --dynamic-list-data and dl2xxx.list"
95    "-shared -Wl,--dynamic-list-data,--dynamic-list=dl2xxx.list" "-fPIC"
96    {dl2.c dl2xxx.c} {} "libdl2c.so"}
97   {"Build libdl4a.so with --dynamic-list=dl4.list"
98    "-shared -Wl,--dynamic-list=dl4.list" "-fPIC"
99    {dl4.c dl4xxx.c} {} "libdl4a.so"}
100   {"Build libdl4b.so with --dynamic-list-data"
101    "-shared -Wl,--dynamic-list-data" "-fPIC"
102    {dl4.c dl4xxx.c} {} "libdl4b.so"}
103   {"Build libdl4c.so with --dynamic-list=dl4.list and dl4xxx.list"
104    "-shared -Wl,--dynamic-list=dl4.list,--dynamic-list=dl4xxx.list" "-fPIC"
105    {dl4.c dl4xxx.c} {} "libdl4c.so"}
106   {"Build libdl4d.so with --dynamic-list-data and dl4xxx.list"
107    "-shared -Wl,--dynamic-list-data,--dynamic-list=dl4xxx.list" "-fPIC"
108    {dl4.c dl4xxx.c} {} "libdl4d.so"}
109   {"Build libdl4e.so with -Bsymbolic-functions --dynamic-list-cpp-new"
110    "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC"
111    {dl4.c dl4xxx.c} {} "libdl4e.so"}
112   {"Build libdl4f.so with --dynamic-list-cpp-new -Bsymbolic-functions"
113    "-shared -Wl,--dynamic-list-cpp-new,-Bsymbolic-functions" "-fPIC"
114    {dl4.c dl4xxx.c} {} "libdl4f.so"}
115   {"Build libdl6a.so"
116    "-shared" "-fPIC"
117    {dl6.c} {} "libdl6a.so"}
118   {"Build libdl6b.so with -Bsymbolic --dynamic-list-data"
119    "-shared -Wl,-Bsymbolic,--dynamic-list-data" "-fPIC"
120    {dl6.c} {} "libdl6b.so"}
121   {"Build libdl6c.so with -Bsymbolic"
122    "-shared -Wl,-Bsymbolic" "-fPIC"
123    {dl6.c} {} "libdl6c.so"}
124   {"Build libdl6d.so with --dynamic-list-data -Bsymbolic"
125    "-shared -Wl,--dynamic-list-data,-Bsymbolic" "-fPIC"
126    {dl6.c} {} "libdl6d.so"}
127   {"Build libdata1.so"
128    "-shared" "-fPIC"
129    {data1.c} {} "libdata1.so"}
130   {"Build libdata2.so"
131    "-shared" "-fPIC"
132    {data2.c} {} "libdata2.so"}
133   {"Build libcomm1.o"
134    "-r -nostdlib" ""
135    {comm1.c} {} "libcomm1.o"}
136   {"Build libfunc1.so"
137    "-shared" "-fPIC"
138    {func1.c} {} "libfunc1.so"}
139   {"Build libpr9676-1.a"
140    "" "-fPIC"
141    {pr9676-1.c} {} "libpr9676-1.a"}
142   {"Build libpr9676-2.a"
143    "" "-fPIC"
144    {pr9676-2.c} {} "libpr9676-2.a"}
145   {"Build libpr9676-3.so"
146    "-shared" "-fPIC"
147    {pr9676-3.c} {} "libpr9676-3.so"}
148   {"Build libpr9676-4.so"
149    "-shared" "-fPIC"
150    {pr9676-4.c} {} "libpr9676-4.so"}
151   {"Build libpr9676-4a.so"
152    "-shared tmpdir/pr9676-4.o -Ltmpdir -lpr9676-3 -Wl,--start-group -lpr9676-1 -lpr9676-2 -Wl,--end-group"
153    "-fPIC"
154    {dummy.c} {{readelf {-s} pr9676.rd}} "libpr9676-4a.so"}
155   {"Build libpr9679.so"
156    "-shared" "-fPIC -O0"
157    {pr9679-1.c pr9679-2.c} {{readelf {-s} pr9679.rd}} "libpr9679.so"}
158   {"Build libpr11138-1.so"
159    "-shared -Wl,--version-script=pr11138-1.map" "-fPIC"
160    {pr11138-1.c} {} "libpr11138-1.so"}
161   {"Build libpr11138-2.o"
162    "-r -nostdlib" ""
163    {pr11138-2.c} {} "libpr11138-2.o"}
164   {"Build pr13250-1.so"
165    "-shared" "-fPIC"
166    {pr13250-1.c} {} "libpr13250-1.so"}
167   {"Build pr13250-2.so with libpr13250-1.so"
168    "-shared -Wl,--no-as-needed tmpdir/libpr13250-1.so" "-fPIC"
169    {pr13250-2.c} {} "libpr13250-2.so"}
170   {"Build libpr13250-3.o"
171    "-r -nostdlib" ""
172    {pr13250-3.c} {} "libpr13250-3.o"}
173   {"Build libpr14323-2.so"
174    "-shared" "-fPIC"
175    {pr14323-2.c} {} "libpr14323-2.so"}
176 }
177
178 run_cc_link_tests $build_tests
179
180 set run_tests {
181     {"Run normal with libfoo.so"
182      "tmpdir/begin.o tmpdir/libfoo.so tmpdir/end.o" ""
183      {main.c} "normal" "normal.out"}
184     {"Run protected with libfoo.so"
185      "tmpdir/begin.o tmpdir/libfoo.so tmpdir/endprotected.o" ""
186      {main.c} "protected" "normal.out"}
187     {"Run hidden with libfoo.so"
188      "tmpdir/begin.o tmpdir/libfoo.so tmpdir/endhidden.o" ""
189      {main.c} "hidden" "hidden.out"}
190     {"Run normal with versioned libfoo.so"
191      "tmpdir/begin.o tmpdir/libfoov.so tmpdir/end.o" ""
192      {main.c} "normalv" "normal.out"}
193     {"Run warn with versioned libfoo.so"
194      "tmpdir/beginwarn.o tmpdir/libfoov.so" ""
195      {main.c} "warn" "warn.out"
196      "" "" "^.*\\\): warning: function foo is deprecated$"}
197     {"Run protected with versioned libfoo.so"
198      "tmpdir/begin.o tmpdir/libfoov.so tmpdir/endprotected.o" ""
199      {main.c} "protected" "normal.out"}
200     {"Run hidden with versioned libfoo.so"
201      "tmpdir/begin.o tmpdir/libfoov.so tmpdir/endhidden.o" ""
202      {main.c} "hiddenv" "hidden.out"}
203     {"Run normal libbar.so with libfoo.so"
204      "tmpdir/libbarfoo.so tmpdir/libfoo.so" ""
205      {main.c} "normal" "normal.out"}
206     {"Run protected libbar.so with libfoo.so"
207      "tmpdir/libbarpfoo.so tmpdir/libfoo.so" ""
208      {main.c} "protected" "normal.out"}
209     {"Run hidden libbar.so with libfoo.so"
210      "tmpdir/libbarhfoo.so tmpdir/libfoo.so" ""
211      {main.c} "hidden" "hidden.out"}
212     {"Run normal libbar.so with versioned libfoo.so"
213      "tmpdir/libbarfoov.so tmpdir/libfoov.so" ""
214      {main.c} "normal" "normal.out"}
215     {"Run protected libbar.so with versioned libfoo.so"
216      "tmpdir/libbarpfoov.so tmpdir/libfoov.so" ""
217      {main.c} "protected" "normal.out"}
218     {"Run hidden libbar.so with versioned libfoo.so"
219      "tmpdir/libbarhfoov.so tmpdir/libfoov.so" ""
220      {main.c} "hidden" "hidden.out"}
221     {"Run dl1a with --dynamic-list=dl1.list and dlopen on libdl1.so"
222      "--dynamic-list=dl1.list -ldl" ""
223      {dl1main.c} "dl1a" "dl1.out"}
224     {"Run dl1b with --dynamic-list-data and dlopen on libdl1.so"
225      "--dynamic-list-data -ldl" ""
226      {dl1main.c} "dl1b" "dl1.out"}
227     {"Run with libdl2a.so"
228      "tmpdir/libdl2a.so" ""
229      {dl2main.c} "dl2a" "dl2a.out"}
230     {"Run with libdl2b.so"
231      "tmpdir/libdl2b.so" ""
232      {dl2main.c} "dl2b" "dl2b.out"}
233     {"Run with libdl2c.so"
234      "tmpdir/libdl2c.so" ""
235      {dl2main.c} "dl2c" "dl2b.out"}
236     {"Run with libdl4a.so"
237      "tmpdir/libdl4a.so" ""
238      {dl4main.c} "dl4a" "dl4a.out"}
239     {"Run with libdl4b.so"
240      "tmpdir/libdl4b.so" ""
241      {dl4main.c} "dl4b" "dl4a.out"}
242     {"Run with libdl4c.so"
243      "tmpdir/libdl4c.so" ""
244      {dl4main.c} "dl4c" "dl4b.out"}
245     {"Run with libdl4d.so"
246      "tmpdir/libdl4d.so" ""
247      {dl4main.c} "dl4d" "dl4b.out"}
248     {"Run with libdl4e.so"
249      "tmpdir/libdl4e.so" ""
250      {dl4main.c} "dl4e" "dl4a.out"}
251     {"Run with libdl4f.so"
252      "tmpdir/libdl4f.so" ""
253      {dl4main.c} "dl4f" "dl4a.out"}
254     {"Run dl6a1 with --dynamic-list-data and dlopen on libdl6a.so"
255      "--dynamic-list-data -ldl" ""
256      {dl6amain.c} "dl6a1" "dl6a.out"}
257     {"Run dl6a2 with -Bsymbolic-functions and dlopen on libdl6a.so"
258      "-Bsymbolic-functions -ldl" ""
259      {dl6amain.c} "dl6a2" "dl6b.out"}
260     {"Run dl6a3 with -Bsymbolic and dlopen on libdl6a.so"
261      "-Bsymbolic -ldl" ""
262      {dl6amain.c} "dl6a3" "dl6b.out"}
263     {"Run dl6a4 with -Bsymbolic --dynamic-list-data and dlopen on libdl6a.so"
264      "-Bsymbolic --dynamic-list-data -ldl" ""
265      {dl6amain.c} "dl6a4" "dl6a.out"}
266     {"Run dl6a5 with -Bsymbolic-functions --dynamic-list-cpp-new and dlopen on libdl6a.so"
267      "-Bsymbolic-functions --dynamic-list-cpp-new -ldl" ""
268      {dl6amain.c} "dl6a5" "dl6b.out"}
269     {"Run dl6a6 with --dynamic-list-cpp-new -Bsymbolic-functions and dlopen on libdl6a.so"
270      "--dynamic-list-cpp-new -Bsymbolic-functions -ldl" ""
271      {dl6amain.c} "dl6a6" "dl6b.out"}
272     {"Run dl6a7 with --dynamic-list-data -Bsymbolic and dlopen on libdl6a.so"
273      "--dynamic-list-data -Bsymbolic -ldl" ""
274      {dl6amain.c} "dl6a7" "dl6a.out"}
275     {"Run dl6b1 with --dynamic-list-data and dlopen on libdl6b.so"
276      "--dynamic-list-data -ldl" ""
277      {dl6bmain.c} "dl6b1" "dl6a.out"}
278     {"Run dl6b2 with dlopen on libdl6b.so"
279      "-ldl" ""
280      {dl6bmain.c} "dl6b2" "dl6b.out"}
281     {"Run dl6c1 with --dynamic-list-data and dlopen on libdl6c.so"
282      "--dynamic-list-data -ldl" ""
283      {dl6cmain.c} "dl6c1" "dl6b.out"}
284     {"Run dl6d1 with --dynamic-list-data and dlopen on libdl6d.so"
285      "--dynamic-list-data -ldl" ""
286      {dl6dmain.c} "dl6d1" "dl6b.out"}
287     {"Run with libdata1.so"
288      "tmpdir/libdata1.so" ""
289      {dynbss1.c} "dynbss1" "pass.out"}
290     {"Run with libdata2.so"
291      "tmpdir/libdata2.so" ""
292      {weakdef1.c} "weakdef1" "pass.out"}
293     {"Run with libfunc1.so comm1.o"
294      "tmpdir/libfunc1.so tmpdir/comm1.o" ""
295      {dummy.c} "comm1" "pass.out"}
296     {"Run with comm1.o libfunc1.so"
297      "tmpdir/comm1.o tmpdir/libfunc1.so" ""
298      {dummy.c} "comm1" "pass.out"}
299     {"Run with pr11138-2.c libpr11138-1.so"
300      "--version-script=pr11138-2.map tmpdir/pr11138-2.o tmpdir/libpr11138-1.so" ""
301      {dummy.c} "pr11138a" "pr11138.out"}
302     {"Run with libpr11138-1.so pr11138-2.c"
303      "--version-script=pr11138-2.map tmpdir/libpr11138-1.so tmpdir/pr11138-2.o" ""
304      {dummy.c} "pr11138b" "pr11138.out"}
305     {"Run with pr13250-3.c, libpr13250-1.so and libpr13250-2.so"
306      "--as-needed tmpdir/pr13250-3.o tmpdir/libpr13250-1.so tmpdir/libpr13250-2.so" ""
307      {dummy.c} "pr13250" "pass.out"}
308     {"Run with pr14323-1.c pr14323-2.so"
309      "tmpdir/libpr14323-2.so" ""
310      {pr14323-1.c} "pr14323" "pass.out"}
311 }
312
313 # NetBSD ELF systems do not currently support the .*_array sections.
314 run_ld_link_exec_tests [list "*-*-netbsdelf*"] $run_tests
315
316 # Check to see if the C++ compiler works
317 if { [which $CXX] == 0 } {
318     return
319 }
320
321 set build_cxx_tests {
322   {"Build libdl3a.so with --dynamic-list=dl3.list"
323    "-shared -Wl,--dynamic-list=dl3.list" "-fPIC"
324    {dl3.cc} {} "libdl3a.so" "c++"}
325   {"Build libdl3b.so with -Bsymbolic"
326    "-shared -Wl,-Bsymbolic" "-fPIC"
327    {dl3.cc} {} "libdl3b.so" "c++"}
328   {"Build libdl3a.so with --dynamic-list-cpp-typeinfo"
329    "-shared -Wl,--dynamic-list-cpp-typeinfo" "-fPIC"
330    {dl3.cc} {} "libdl3c.so" "c++"}
331   {"Build libdnew1a.so with --Bsymbolic-functions --dynamic-list-cpp-new"
332    "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC"
333    {del.cc new.cc} {} "libnew1a.so" "c++"}
334   {"Build libdnew1b.so with --dynamic-list-data --dynamic-list-cpp-new"
335    "-shared -Wl,--dynamic-list-data,--dynamic-list-cpp-new" "-fPIC"
336    {del.cc new.cc} {} "libnew1b.so" "c++"}
337 }
338
339 # "-shared -Bsymbolic" only works with gcc 4.5.0 and newer.
340 #    {"Run with libdl3b.so"
341 #     "tmpdir/libdl3b.so" ""
342 #     {dl3main.cc} "dl3b" "dl3b.out" "" "c++"}
343 set run_cxx_tests {
344     {"Run with libdl3a.so"
345      "-Wl,--no-as-needed tmpdir/libdl3a.so" ""
346      {dl3main.cc} "dl3a" "dl3a.out" "" "c++"}
347     {"Run with libdl3c.so"
348      "-Wl,--no-as-needed tmpdir/libdl3c.so" ""
349      {dl3main.cc} "dl3c" "dl3a.out" "" "c++"}
350     {"Run with libnew1a.so"
351      "tmpdir/libnew1a.so" ""
352      {dl5.cc} "dl5a" "dl5.out" "" "c++"}
353     {"Run with libnew1b.so"
354      "tmpdir/libnew1b.so" ""
355      {dl5.cc} "dl5b" "dl5.out" "" "c++"}
356 }
357
358 run_cc_link_tests $build_cxx_tests
359 run_ld_link_exec_tests [] $run_cxx_tests