PR ld/12761
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elf / shared.exp
1 # Expect script for various ELF tests.
2 # Copyright 2006, 2007, 2008, 2009 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 # Exclude non-ELF targets.
23
24 if ![is_elf_format] {
25 return
26 }
27
28 # Check to see if the C compiler works
29 if { [which $CC] == 0 } {
30 return
31 }
32
33 set build_tests {
34 {"Build libfoo.so"
35 "-shared" "-fPIC"
36 {foo.c} {} "libfoo.so"}
37 {"Build versioned libfoo.so"
38 "-shared -Wl,--version-script=foo.map" "-fPIC"
39 {foo.c} {} "libfoov.so"}
40 {"Build libbar.so"
41 "-shared" "-fPIC"
42 {begin.c end.c} {} "libbar.so"}
43 {"Build warn libbar.so"
44 "-shared" "-fPIC"
45 {beginwarn.c end.c} {} "libbarw.so"
46 "C" "^.*\\\): warning: function foo is deprecated$"}
47 {"Build hidden libbar.so"
48 "-shared" "-fPIC"
49 {begin.c endhidden.c} {} "libbarh.so"}
50 {"Build protected libbar.so"
51 "-shared" "-fPIC"
52 {begin.c endprotected.c} {} "libbarp.so"}
53 {"Build libbar.so with libfoo.so"
54 "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
55 {end.c} {} "libbarfoo.so"}
56 {"Build libar.so with versioned libfoo.so"
57 "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
58 {end.c} {} "libbarfoov.so"}
59 {"Build hidden libbar.so with libfoo.so"
60 "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
61 {endhidden.c} {} "libbarhfoo.so"}
62 {"Build hidden libar.so with versioned libfoo.so"
63 "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
64 {endhidden.c} {} "libbarhfoov.so"}
65 {"Build protected libbar.so with libfoo.so"
66 "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
67 {endprotected.c} {} "libbarpfoo.so"}
68 {"Build protected libbar.so with versioned libfoo.so"
69 "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
70 {endprotected.c} {} "libbarpfoov.so"}
71 {"Build libdl1.so"
72 "-shared" "-fPIC"
73 {dl1.c} {} "libdl1.so"}
74 {"Build libdl2a.so with --dynamic-list=dl2.list"
75 "-shared -Wl,--dynamic-list=dl2.list" "-fPIC"
76 {dl2.c dl2xxx.c} {} "libdl2a.so"}
77 {"Build libdl2a.so with --dynamic-list=dl2a.list"
78 "-shared -Wl,--dynamic-list=dl2a.list" "-fPIC"
79 {dl2.c dl2xxx.c} {} "libdl2a.so"}
80 {"Build libdl2a.so with --dynamic-list-data"
81 "-shared -Wl,--dynamic-list-data" "-fPIC"
82 {dl2.c dl2xxx.c} {} "libdl2a.so"}
83 {"Build libdl2b.so with --dynamic-list=dl2.list and dl2xxx.list"
84 "-shared -Wl,--dynamic-list=dl2.list,--dynamic-list=dl2xxx.list" "-fPIC"
85 {dl2.c dl2xxx.c} {} "libdl2b.so"}
86 {"Build libdl2c.so with --dynamic-list-data and dl2xxx.list"
87 "-shared -Wl,--dynamic-list-data,--dynamic-list=dl2xxx.list" "-fPIC"
88 {dl2.c dl2xxx.c} {} "libdl2c.so"}
89 {"Build libdl4a.so with --dynamic-list=dl4.list"
90 "-shared -Wl,--dynamic-list=dl4.list" "-fPIC"
91 {dl4.c dl4xxx.c} {} "libdl4a.so"}
92 {"Build libdl4b.so with --dynamic-list-data"
93 "-shared -Wl,--dynamic-list-data" "-fPIC"
94 {dl4.c dl4xxx.c} {} "libdl4b.so"}
95 {"Build libdl4c.so with --dynamic-list=dl4.list and dl4xxx.list"
96 "-shared -Wl,--dynamic-list=dl4.list,--dynamic-list=dl4xxx.list" "-fPIC"
97 {dl4.c dl4xxx.c} {} "libdl4c.so"}
98 {"Build libdl4d.so with --dynamic-list-data and dl4xxx.list"
99 "-shared -Wl,--dynamic-list-data,--dynamic-list=dl4xxx.list" "-fPIC"
100 {dl4.c dl4xxx.c} {} "libdl4d.so"}
101 {"Build libdl4e.so with -Bsymbolic-functions --dynamic-list-cpp-new"
102 "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC"
103 {dl4.c dl4xxx.c} {} "libdl4e.so"}
104 {"Build libdl4f.so with --dynamic-list-cpp-new -Bsymbolic-functions"
105 "-shared -Wl,--dynamic-list-cpp-new,-Bsymbolic-functions" "-fPIC"
106 {dl4.c dl4xxx.c} {} "libdl4f.so"}
107 {"Build libdl6a.so"
108 "-shared" "-fPIC"
109 {dl6.c} {} "libdl6a.so"}
110 {"Build libdl6b.so with -Bsymbolic --dynamic-list-data"
111 "-shared -Wl,-Bsymbolic,--dynamic-list-data" "-fPIC"
112 {dl6.c} {} "libdl6b.so"}
113 {"Build libdl6c.so with -Bsymbolic"
114 "-shared -Wl,-Bsymbolic" "-fPIC"
115 {dl6.c} {} "libdl6c.so"}
116 {"Build libdl6d.so with --dynamic-list-data -Bsymbolic"
117 "-shared -Wl,--dynamic-list-data,-Bsymbolic" "-fPIC"
118 {dl6.c} {} "libdl6d.so"}
119 {"Build libdata1.so"
120 "-shared" "-fPIC"
121 {data1.c} {} "libdata1.so"}
122 {"Build libcomm1.o"
123 "-r -nostdlib" ""
124 {comm1.c} {} "libcomm1.o"}
125 {"Build libfunc1.so"
126 "-shared" "-fPIC"
127 {func1.c} {} "libfunc1.so"}
128 {"Build libpr9676-1.a"
129 "" "-fPIC"
130 {pr9676-1.c} {} "libpr9676-1.a"}
131 {"Build libpr9676-2.a"
132 "" "-fPIC"
133 {pr9676-2.c} {} "libpr9676-2.a"}
134 {"Build libpr9676-3.so"
135 "-shared" "-fPIC"
136 {pr9676-3.c} {} "libpr9676-3.so"}
137 {"Build libpr9676-4.so"
138 "-shared" "-fPIC"
139 {pr9676-4.c} {} "libpr9676-4.so"}
140 {"Build libpr9676-4a.so"
141 "-shared tmpdir/pr9676-4.o -Ltmpdir -lpr9676-3 -Wl,--start-group -lpr9676-1 -lpr9676-2 -Wl,--end-group"
142 "-fPIC"
143 {dummy.c} {{readelf {-s} pr9676.rd}} "libpr9676-4a.so"}
144 {"Build libpr9679.so"
145 "-shared" "-fPIC -O0"
146 {pr9679-1.c pr9679-2.c} {{readelf {-s} pr9679.rd}} "libpr9679.so"}
147 {"Build libpr11138-1.so"
148 "-shared -Wl,--version-script=pr11138-1.map" "-fPIC"
149 {pr11138-1.c} {} "libpr11138-1.so"}
150 {"Build libpr11138-2.o"
151 "-r -nostdlib" ""
152 {pr11138-2.c} {} "libpr11138-2.o"}
153 }
154
155 run_cc_link_tests $build_tests
156
157 # The following tests require running the executable generated by ld.
158 if ![isnative] {
159 return
160 }
161
162 set run_tests {
163 {"Run normal with libfoo.so"
164 "tmpdir/begin.o tmpdir/libfoo.so tmpdir/end.o" ""
165 {main.c} "normal" "normal.out"}
166 {"Run protected with libfoo.so"
167 "tmpdir/begin.o tmpdir/libfoo.so tmpdir/endprotected.o" ""
168 {main.c} "protected" "normal.out"}
169 {"Run hidden with libfoo.so"
170 "tmpdir/begin.o tmpdir/libfoo.so tmpdir/endhidden.o" ""
171 {main.c} "hidden" "hidden.out"}
172 {"Run normal with versioned libfoo.so"
173 "tmpdir/begin.o tmpdir/libfoov.so tmpdir/end.o" ""
174 {main.c} "normalv" "normal.out"}
175 {"Run warn with versioned libfoo.so"
176 "tmpdir/beginwarn.o tmpdir/libfoov.so" ""
177 {main.c} "warn" "warn.out"
178 "" "" "^.*\\\): warning: function foo is deprecated$"}
179 {"Run protected with versioned libfoo.so"
180 "tmpdir/begin.o tmpdir/libfoov.so tmpdir/endprotected.o" ""
181 {main.c} "protected" "normal.out"}
182 {"Run hidden with versioned libfoo.so"
183 "tmpdir/begin.o tmpdir/libfoov.so tmpdir/endhidden.o" ""
184 {main.c} "hiddenv" "hidden.out"}
185 {"Run normal libbar.so with libfoo.so"
186 "tmpdir/libbarfoo.so tmpdir/libfoo.so" ""
187 {main.c} "normal" "normal.out"}
188 {"Run protected libbar.so with libfoo.so"
189 "tmpdir/libbarpfoo.so tmpdir/libfoo.so" ""
190 {main.c} "protected" "normal.out"}
191 {"Run hidden libbar.so with libfoo.so"
192 "tmpdir/libbarhfoo.so tmpdir/libfoo.so" ""
193 {main.c} "hidden" "hidden.out"}
194 {"Run normal libbar.so with versioned libfoo.so"
195 "tmpdir/libbarfoov.so tmpdir/libfoov.so" ""
196 {main.c} "normal" "normal.out"}
197 {"Run protected libbar.so with versioned libfoo.so"
198 "tmpdir/libbarpfoov.so tmpdir/libfoov.so" ""
199 {main.c} "protected" "normal.out"}
200 {"Run hidden libbar.so with versioned libfoo.so"
201 "tmpdir/libbarhfoov.so tmpdir/libfoov.so" ""
202 {main.c} "hidden" "hidden.out"}
203 {"Run dl1a with --dynamic-list=dl1.list and dlopen on libdl1.so"
204 "--dynamic-list=dl1.list -ldl" ""
205 {dl1main.c} "dl1a" "dl1.out"}
206 {"Run dl1b with --dynamic-list-data and dlopen on libdl1.so"
207 "--dynamic-list-data -ldl" ""
208 {dl1main.c} "dl1b" "dl1.out"}
209 {"Run with libdl2a.so"
210 "tmpdir/libdl2a.so" ""
211 {dl2main.c} "dl2a" "dl2a.out"}
212 {"Run with libdl2b.so"
213 "tmpdir/libdl2b.so" ""
214 {dl2main.c} "dl2b" "dl2b.out"}
215 {"Run with libdl2c.so"
216 "tmpdir/libdl2c.so" ""
217 {dl2main.c} "dl2c" "dl2b.out"}
218 {"Run with libdl4a.so"
219 "tmpdir/libdl4a.so" ""
220 {dl4main.c} "dl4a" "dl4a.out"}
221 {"Run with libdl4b.so"
222 "tmpdir/libdl4b.so" ""
223 {dl4main.c} "dl4b" "dl4a.out"}
224 {"Run with libdl4c.so"
225 "tmpdir/libdl4c.so" ""
226 {dl4main.c} "dl4c" "dl4b.out"}
227 {"Run with libdl4d.so"
228 "tmpdir/libdl4d.so" ""
229 {dl4main.c} "dl4d" "dl4b.out"}
230 {"Run with libdl4e.so"
231 "tmpdir/libdl4e.so" ""
232 {dl4main.c} "dl4e" "dl4a.out"}
233 {"Run with libdl4f.so"
234 "tmpdir/libdl4f.so" ""
235 {dl4main.c} "dl4f" "dl4a.out"}
236 {"Run dl6a1 with --dynamic-list-data and dlopen on libdl6a.so"
237 "--dynamic-list-data -ldl" ""
238 {dl6amain.c} "dl6a1" "dl6a.out"}
239 {"Run dl6a2 with -Bsymbolic-functions and dlopen on libdl6a.so"
240 "-Bsymbolic-functions -ldl" ""
241 {dl6amain.c} "dl6a2" "dl6b.out"}
242 {"Run dl6a3 with -Bsymbolic and dlopen on libdl6a.so"
243 "-Bsymbolic -ldl" ""
244 {dl6amain.c} "dl6a3" "dl6b.out"}
245 {"Run dl6a4 with -Bsymbolic --dynamic-list-data and dlopen on libdl6a.so"
246 "-Bsymbolic --dynamic-list-data -ldl" ""
247 {dl6amain.c} "dl6a4" "dl6a.out"}
248 {"Run dl6a5 with -Bsymbolic-functions --dynamic-list-cpp-new and dlopen on libdl6a.so"
249 "-Bsymbolic-functions --dynamic-list-cpp-new -ldl" ""
250 {dl6amain.c} "dl6a5" "dl6b.out"}
251 {"Run dl6a6 with --dynamic-list-cpp-new -Bsymbolic-functions and dlopen on libdl6a.so"
252 "--dynamic-list-cpp-new -Bsymbolic-functions -ldl" ""
253 {dl6amain.c} "dl6a6" "dl6b.out"}
254 {"Run dl6a7 with --dynamic-list-data -Bsymbolic and dlopen on libdl6a.so"
255 "--dynamic-list-data -Bsymbolic -ldl" ""
256 {dl6amain.c} "dl6a7" "dl6a.out"}
257 {"Run dl6b1 with --dynamic-list-data and dlopen on libdl6b.so"
258 "--dynamic-list-data -ldl" ""
259 {dl6bmain.c} "dl6b1" "dl6a.out"}
260 {"Run dl6b2 with dlopen on libdl6b.so"
261 "-ldl" ""
262 {dl6bmain.c} "dl6b2" "dl6b.out"}
263 {"Run dl6c1 with --dynamic-list-data and dlopen on libdl6c.so"
264 "--dynamic-list-data -ldl" ""
265 {dl6cmain.c} "dl6c1" "dl6b.out"}
266 {"Run dl6d1 with --dynamic-list-data and dlopen on libdl6d.so"
267 "--dynamic-list-data -ldl" ""
268 {dl6dmain.c} "dl6d1" "dl6b.out"}
269 {"Run with libdata1.so"
270 "tmpdir/libdata1.so" ""
271 {dynbss1.c} "dynbss1" "pass.out"}
272 {"Run with libfunc1.so comm1.o"
273 "tmpdir/libfunc1.so tmpdir/comm1.o" ""
274 {dummy.c} "comm1" "pass.out"}
275 {"Run with comm1.o libfunc1.so"
276 "tmpdir/comm1.o tmpdir/libfunc1.so" ""
277 {dummy.c} "comm1" "pass.out"}
278 {"Run with pr11138-2.c libpr11138-1.so"
279 "--version-script=pr11138-2.map tmpdir/pr11138-2.o tmpdir/libpr11138-1.so" ""
280 {dummy.c} "pr11138a" "pr11138.out"}
281 {"Run with libpr11138-1.so pr11138-2.c"
282 "--version-script=pr11138-2.map tmpdir/libpr11138-1.so tmpdir/pr11138-2.o" ""
283 {dummy.c} "pr11138b" "pr11138.out"}
284 }
285
286 # NetBSD ELF systems do not currently support the .*_array sections.
287 run_ld_link_exec_tests [list "*-*-netbsdelf*"] $run_tests
288
289 # Check to see if the C++ compiler works
290 if { [which $CXX] == 0 } {
291 return
292 }
293
294 set build_cxx_tests {
295 {"Build libdl3a.so with --dynamic-list=dl3.list"
296 "-shared -Wl,--dynamic-list=dl3.list" "-fPIC"
297 {dl3.cc} {} "libdl3a.so" "c++"}
298 {"Build libdl3b.so with -Bsymbolic"
299 "-shared -Wl,-Bsymbolic" "-fPIC"
300 {dl3.cc} {} "libdl3b.so" "c++"}
301 {"Build libdl3a.so with --dynamic-list-cpp-typeinfo"
302 "-shared -Wl,--dynamic-list-cpp-typeinfo" "-fPIC"
303 {dl3.cc} {} "libdl3c.so" "c++"}
304 {"Build libdnew1a.so with --Bsymbolic-functions --dynamic-list-cpp-new"
305 "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC"
306 {del.cc new.cc} {} "libnew1a.so" "c++"}
307 {"Build libdnew1b.so with --dynamic-list-data --dynamic-list-cpp-new"
308 "-shared -Wl,--dynamic-list-data,--dynamic-list-cpp-new" "-fPIC"
309 {del.cc new.cc} {} "libnew1b.so" "c++"}
310 }
311
312 set run_cxx_tests {
313 {"Run with libdl3a.so"
314 "tmpdir/libdl3a.so" ""
315 {dl3main.cc} "dl3a" "dl3a.out" "" "c++"}
316 # "-shared -Bsymbolic" only works with gcc 4.5.0 and newer.
317 # {"Run with libdl3b.so"
318 # "tmpdir/libdl3b.so" ""
319 # {dl3main.cc} "dl3b" "dl3b.out" "" "c++"}
320 {"Run with libdl3c.so"
321 "tmpdir/libdl3c.so" ""
322 {dl3main.cc} "dl3c" "dl3a.out" "" "c++"}
323 {"Run with libnew1a.so"
324 "tmpdir/libnew1a.so" ""
325 {dl5.cc} "dl5a" "dl5.out" "" "c++"}
326 {"Run with libnew1b.so"
327 "tmpdir/libnew1b.so" ""
328 {dl5.cc} "dl5b" "dl5.out" "" "c++"}
329 }
330
331 run_cc_link_tests $build_cxx_tests
332 run_ld_link_exec_tests [] $run_cxx_tests
This page took 0.037912 seconds and 4 git commands to generate.