ld/
[external/binutils.git] / ld / testsuite / ld-elf / shared.exp
1 # Expect script for various ELF tests.
2 #   Copyright 2006 Free Software Foundation, Inc.
3 #
4 # This file is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
17 #
18
19 # Exclude non-ELF targets.
20
21 if ![is_elf_format] {
22     return
23 }
24
25 # The following tests require running the executable generated by ld.
26 if ![isnative] {
27     return
28 }
29
30 # Check if compiler works
31 if { [which $CC] == 0 } {
32     return
33 }
34
35 set build_tests {
36   {"Build libfoo.so"
37    "-shared" "-fPIC"
38    {foo.c} {} "libfoo.so"}
39   {"Build versioned libfoo.so"
40    "-shared -Wl,--version-script=foo.map" "-fPIC"
41    {foo.c} {} "libfoov.so"}
42   {"Build libbar.so"
43    "-shared" "-fPIC"
44    {begin.c end.c} {} "libbar.so"}
45   {"Build hidden libbar.so"
46    "-shared" "-fPIC"
47    {begin.c endhidden.c} {} "libbarh.so"}
48   {"Build protected libbar.so"
49    "-shared" "-fPIC"
50    {begin.c endprotected.c} {} "libbarp.so"}
51   {"Build libbar.so with libfoo.so"
52    "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
53    {end.c} {} "libbarfoo.so"}
54   {"Build libar.so with versioned libfoo.so"
55    "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
56    {end.c} {} "libbarfoov.so"}
57   {"Build hidden libbar.so with libfoo.so"
58    "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
59    {endhidden.c} {} "libbarhfoo.so"}
60   {"Build hidden libar.so with versioned libfoo.so"
61    "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
62    {endhidden.c} {} "libbarhfoov.so"}
63   {"Build protected libbar.so with libfoo.so"
64    "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
65    {endprotected.c} {} "libbarpfoo.so"}
66   {"Build protected libbar.so with versioned libfoo.so"
67    "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
68    {endprotected.c} {} "libbarpfoov.so"}
69   {"Build libdl1.so"
70    "-shared" "-fPIC"
71    {dl1.c} {} "libdl1.so"}
72   {"Build libdl2a.so with --dynamic-list=dl2.list"
73    "-shared -Wl,--dynamic-list=dl2.list" "-fPIC"
74    {dl2.c dl2xxx.c} {} "libdl2a.so"}
75   {"Build libdl2a.so with --dynamic-list-data"
76    "-shared -Wl,--dynamic-list-data" "-fPIC"
77    {dl2.c dl2xxx.c} {} "libdl2a.so"}
78   {"Build libdl2b.so with --dynamic-list=dl2.list and dl2xxx.list"
79    "-shared -Wl,--dynamic-list=dl2.list,--dynamic-list=dl2xxx.list" "-fPIC"
80    {dl2.c dl2xxx.c} {} "libdl2b.so"}
81   {"Build libdl2c.so with --dynamic-list-data and dl2xxx.list"
82    "-shared -Wl,--dynamic-list-data,--dynamic-list=dl2xxx.list" "-fPIC"
83    {dl2.c dl2xxx.c} {} "libdl2c.so"}
84   {"Build libdl4a.so with --dynamic-list=dl4.list"
85    "-shared -Wl,--dynamic-list=dl4.list" "-fPIC"
86    {dl4.c dl4xxx.c} {} "libdl4a.so"}
87   {"Build libdl4b.so with --dynamic-list-data"
88    "-shared -Wl,--dynamic-list-data" "-fPIC"
89    {dl4.c dl4xxx.c} {} "libdl4b.so"}
90   {"Build libdl4c.so with --dynamic-list=dl4.list and dl4xxx.list"
91    "-shared -Wl,--dynamic-list=dl4.list,--dynamic-list=dl4xxx.list" "-fPIC"
92    {dl4.c dl4xxx.c} {} "libdl4c.so"}
93   {"Build libdl4d.so with --dynamic-list-data and dl4xxx.list"
94    "-shared -Wl,--dynamic-list-data,--dynamic-list=dl4xxx.list" "-fPIC"
95    {dl4.c dl4xxx.c} {} "libdl4d.so"}
96   {"Build libdl4e.so with -Bsymbolic-functions --dynamic-list-cpp-new"
97    "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC"
98    {dl4.c dl4xxx.c} {} "libdl4e.so"}
99   {"Build libdl4f.so with --dynamic-list-cpp-new -Bsymbolic-functions"
100    "-shared -Wl,--dynamic-list-cpp-new,-Bsymbolic-functions" "-fPIC"
101    {dl4.c dl4xxx.c} {} "libdl4f.so"}
102   {"Build libdl6a.so"
103    "-shared" "-fPIC"
104    {dl6.c} {} "libdl6a.so"}
105   {"Build libdl6b.so with -Bsymbolic --dynamic-list-data"
106    "-shared -Wl,-Bsymbolic,--dynamic-list-data" "-fPIC"
107    {dl6.c} {} "libdl6b.so"}
108   {"Build libdl6c.so with -Bsymbolic"
109    "-shared -Wl,-Bsymbolic" "-fPIC"
110    {dl6.c} {} "libdl6c.so"}
111   {"Build libdl6d.so with --dynamic-list-data -Bsymbolic"
112    "-shared -Wl,--dynamic-list-data,-Bsymbolic" "-fPIC"
113    {dl6.c} {} "libdl6d.so"}
114 }
115
116 set run_tests {
117     {"Run normal with libfoo.so"
118      "tmpdir/begin.o tmpdir/libfoo.so tmpdir/end.o" ""
119      {main.c} "normal" "normal.out"}
120     {"Run protected with libfoo.so"
121      "tmpdir/begin.o tmpdir/libfoo.so tmpdir/endprotected.o" ""
122      {main.c} "protected" "normal.out"}
123     {"Run hidden with libfoo.so"
124      "tmpdir/begin.o tmpdir/libfoo.so tmpdir/endhidden.o" ""
125      {main.c} "hidden" "hidden.out"}
126     {"Run normal with versioned libfoo.so"
127      "tmpdir/begin.o tmpdir/libfoov.so tmpdir/end.o" ""
128      {main.c} "normalv" "normal.out"}
129     {"Run protected with versioned libfoo.so"
130      "tmpdir/begin.o tmpdir/libfoov.so tmpdir/endprotected.o" ""
131      {main.c} "protected" "normal.out"}
132     {"Run hidden with versioned libfoo.so"
133      "tmpdir/begin.o tmpdir/libfoov.so tmpdir/endhidden.o" ""
134      {main.c} "hiddenv" "hidden.out"}
135     {"Run normal libbar.so with libfoo.so"
136      "tmpdir/libbarfoo.so tmpdir/libfoo.so" ""
137      {main.c} "normal" "normal.out"}
138     {"Run protected libbar.so with libfoo.so"
139      "tmpdir/libbarpfoo.so tmpdir/libfoo.so" ""
140      {main.c} "protected" "normal.out"}
141     {"Run hidden libbar.so with libfoo.so"
142      "tmpdir/libbarhfoo.so tmpdir/libfoo.so" ""
143      {main.c} "hidden" "hidden.out"}
144     {"Run normal libbar.so with versioned libfoo.so"
145      "tmpdir/libbarfoov.so tmpdir/libfoov.so" ""
146      {main.c} "normal" "normal.out"}
147     {"Run protected libbar.so with versioned libfoo.so"
148      "tmpdir/libbarpfoov.so tmpdir/libfoov.so" ""
149      {main.c} "protected" "normal.out"}
150     {"Run hidden libbar.so with versioned libfoo.so"
151      "tmpdir/libbarhfoov.so tmpdir/libfoov.so" ""
152      {main.c} "hidden" "hidden.out"}
153     {"Run dl1a with --dynamic-list=dl1.list and dlopen on libdl1.so"
154      "--dynamic-list=dl1.list -ldl" ""
155      {dl1main.c} "dl1a" "dl1.out"}
156     {"Run dl1b with --dynamic-list-data and dlopen on libdl1.so"
157      "--dynamic-list-data -ldl" ""
158      {dl1main.c} "dl1b" "dl1.out"}
159     {"Run with libdl2a.so"
160      "tmpdir/libdl2a.so" ""
161      {dl2main.c} "dl2a" "dl2a.out"}
162     {"Run with libdl2b.so"
163      "tmpdir/libdl2b.so" ""
164      {dl2main.c} "dl2b" "dl2b.out"}
165     {"Run with libdl2c.so"
166      "tmpdir/libdl2c.so" ""
167      {dl2main.c} "dl2c" "dl2b.out"}
168     {"Run with libdl4a.so"
169      "tmpdir/libdl4a.so" ""
170      {dl4main.c} "dl4a" "dl4a.out"}
171     {"Run with libdl4b.so"
172      "tmpdir/libdl4b.so" ""
173      {dl4main.c} "dl4b" "dl4a.out"}
174     {"Run with libdl4c.so"
175      "tmpdir/libdl4c.so" ""
176      {dl4main.c} "dl4c" "dl4b.out"}
177     {"Run with libdl4d.so"
178      "tmpdir/libdl4d.so" ""
179      {dl4main.c} "dl4d" "dl4b.out"}
180     {"Run with libdl4e.so"
181      "tmpdir/libdl4e.so" ""
182      {dl4main.c} "dl4e" "dl4a.out"}
183     {"Run with libdl4f.so"
184      "tmpdir/libdl4f.so" ""
185      {dl4main.c} "dl4f" "dl4a.out"}
186     {"Run dl6a1 with --dynamic-list-data and dlopen on libdl6a.so"
187      "--dynamic-list-data -ldl" ""
188      {dl6amain.c} "dl6a1" "dl6a.out"}
189     {"Run dl6a2 with -Bsymbolic-functions and dlopen on libdl6a.so"
190      "-Bsymbolic-functions -ldl" ""
191      {dl6amain.c} "dl6a2" "dl6b.out"}
192     {"Run dl6a3 with -Bsymbolic and dlopen on libdl6a.so"
193      "-Bsymbolic -ldl" ""
194      {dl6amain.c} "dl6a3" "dl6b.out"}
195     {"Run dl6a4 with -Bsymbolic --dynamic-list-data and dlopen on libdl6a.so"
196      "-Bsymbolic --dynamic-list-data -ldl" ""
197      {dl6amain.c} "dl6a4" "dl6a.out"}
198     {"Run dl6a5 with -Bsymbolic-functions --dynamic-list-cpp-new and dlopen on libdl6a.so"
199      "-Bsymbolic-functions --dynamic-list-cpp-new -ldl" ""
200      {dl6amain.c} "dl6a5" "dl6b.out"}
201     {"Run dl6a6 with --dynamic-list-cpp-new -Bsymbolic-functions and dlopen on libdl6a.so"
202      "--dynamic-list-cpp-new -Bsymbolic-functions -ldl" ""
203      {dl6amain.c} "dl6a6" "dl6b.out"}
204     {"Run dl6a7 with --dynamic-list-data -Bsymbolic and dlopen on libdl6a.so"
205      "--dynamic-list-data -Bsymbolic -ldl" ""
206      {dl6amain.c} "dl6a7" "dl6a.out"}
207     {"Run dl6b1 with --dynamic-list-data and dlopen on libdl6b.so"
208      "--dynamic-list-data -ldl" ""
209      {dl6bmain.c} "dl6b1" "dl6a.out"}
210     {"Run dl6b2 with dlopen on libdl6b.so"
211      "-ldl" ""
212      {dl6bmain.c} "dl6b2" "dl6b.out"}
213     {"Run dl6c1 with --dynamic-list-data and dlopen on libdl6c.so"
214      "--dynamic-list-data -ldl" ""
215      {dl6cmain.c} "dl6c1" "dl6b.out"}
216     {"Run dl6d1 with --dynamic-list-data and dlopen on libdl6d.so"
217      "--dynamic-list-data -ldl" ""
218      {dl6dmain.c} "dl6d1" "dl6b.out"}
219 }
220
221 run_cc_link_tests $build_tests
222 # NetBSD ELF systems do not currently support the .*_array sections.
223 run_ld_link_exec_tests [list "*-*-netbsdelf*"] $run_tests
224
225 # Check if compiler works
226 if { [which $CXX] == 0 } {
227     return
228 }
229
230 set build_cxx_tests {
231   {"Build libdl3a.so with --dynamic-list=dl3.list"
232    "-shared -Wl,--dynamic-list=dl3.list" "-fPIC"
233    {dl3.cc} {} "libdl3a.so" "c++"}
234   {"Build libdl3b.so with -Bsymbolic"
235    "-shared -Wl,-Bsymbolic" "-fPIC"
236    {dl3.cc} {} "libdl3b.so" "c++"}
237   {"Build libdl3a.so with --dynamic-list-cpp-typeinfo"
238    "-shared -Wl,--dynamic-list-cpp-typeinfo" "-fPIC"
239    {dl3.cc} {} "libdl3c.so" "c++"}
240   {"Build libdnew1a.so with --Bsymbolic-functions --dynamic-list-cpp-new"
241    "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC"
242    {del.cc new.cc} {} "libnew1a.so" "c++"}
243   {"Build libdnew1b.so with --dynamic-list-data --dynamic-list-cpp-new"
244    "-shared -Wl,--dynamic-list-data,--dynamic-list-cpp-new" "-fPIC"
245    {del.cc new.cc} {} "libnew1b.so" "c++"}
246 }
247
248 set run_cxx_tests {
249     {"Run with libdl3a.so"
250      "tmpdir/libdl3a.so" ""
251      {dl3main.cc} "dl3a" "dl3a.out" "" "c++"}
252     {"Run with libdl3b.so"
253      "tmpdir/libdl3b.so" ""
254      {dl3main.cc} "dl3b" "dl3b.out" "" "c++"}
255     {"Run with libdl3c.so"
256      "tmpdir/libdl3c.so" ""
257      {dl3main.cc} "dl3c" "dl3a.out" "" "c++"}
258     {"Run with libnew1a.so"
259      "tmpdir/libnew1a.so" ""
260      {dl5.cc} "dl5a" "dl5.out" "" "c++"}
261     {"Run with libnew1b.so"
262      "tmpdir/libnew1b.so" ""
263      {dl5.cc} "dl5b" "dl5.out" "" "c++"}
264 }
265
266 run_cc_link_tests $build_cxx_tests
267 run_ld_link_exec_tests [] $run_cxx_tests