Commit | Line | Data |
---|---|---|
d2dee3b2 | 1 | # Expect script for various ELF tests. |
2571583a | 2 | # Copyright (C) 2006-2017 Free Software Foundation, Inc. |
d2dee3b2 | 3 | # |
f96b4a7b NC |
4 | # This file is part of the GNU Binutils. |
5 | # | |
6 | # This program is free software; you can redistribute it and/or modify | |
d2dee3b2 | 7 | # it under the terms of the GNU General Public License as published by |
f96b4a7b | 8 | # the Free Software Foundation; either version 3 of the License, or |
d2dee3b2 L |
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 | |
f96b4a7b NC |
18 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
19 | # MA 02110-1301, USA. | |
d2dee3b2 L |
20 | # |
21 | ||
22 | # Exclude non-ELF targets. | |
23 | ||
24 | if ![is_elf_format] { | |
25 | return | |
26 | } | |
27 | ||
dd98f8d2 | 28 | # Check to see if the C compiler works |
d2dee3b2 L |
29 | if { [which $CC] == 0 } { |
30 | return | |
31 | } | |
32 | ||
fb2c6e43 | 33 | # Add -ldl to extralibs if needed |
d9816402 | 34 | set extralibs "" |
fb2c6e43 AT |
35 | if { ![istarget *-*-freebsd*]} { |
36 | set extralibs "-ldl" | |
37 | } | |
38 | ||
d2dee3b2 L |
39 | set build_tests { |
40 | {"Build libfoo.so" | |
41 | "-shared" "-fPIC" | |
42 | {foo.c} {} "libfoo.so"} | |
43 | {"Build versioned libfoo.so" | |
44 | "-shared -Wl,--version-script=foo.map" "-fPIC" | |
55255dae | 45 | {foo.c} {} "libfoov.so"} |
d2dee3b2 L |
46 | {"Build libbar.so" |
47 | "-shared" "-fPIC" | |
48 | {begin.c end.c} {} "libbar.so"} | |
fab4a87f L |
49 | {"Build warn libbar.so" |
50 | "-shared" "-fPIC" | |
df71cb5c | 51 | {beginwarn.c end.c} {{readelf {-S --wide} libbarw.rd}} "libbarw.so" |
d9816402 | 52 | "c" {^.*\): warning: function foo is deprecated$} } |
d2dee3b2 L |
53 | {"Build hidden libbar.so" |
54 | "-shared" "-fPIC" | |
55 | {begin.c endhidden.c} {} "libbarh.so"} | |
56 | {"Build protected libbar.so" | |
57 | "-shared" "-fPIC" | |
58 | {begin.c endprotected.c} {} "libbarp.so"} | |
59 | {"Build libbar.so with libfoo.so" | |
60 | "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC" | |
61 | {end.c} {} "libbarfoo.so"} | |
62 | {"Build libar.so with versioned libfoo.so" | |
63 | "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC" | |
64 | {end.c} {} "libbarfoov.so"} | |
65 | {"Build hidden libbar.so with libfoo.so" | |
66 | "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC" | |
67 | {endhidden.c} {} "libbarhfoo.so"} | |
68 | {"Build hidden libar.so with versioned libfoo.so" | |
69 | "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC" | |
70 | {endhidden.c} {} "libbarhfoov.so"} | |
71 | {"Build protected libbar.so with libfoo.so" | |
72 | "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC" | |
73 | {endprotected.c} {} "libbarpfoo.so"} | |
74 | {"Build protected libbar.so with versioned libfoo.so" | |
75 | "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC" | |
76 | {endprotected.c} {} "libbarpfoov.so"} | |
55255dae L |
77 | {"Build libdl1.so" |
78 | "-shared" "-fPIC" | |
79 | {dl1.c} {} "libdl1.so"} | |
80 | {"Build libdl2a.so with --dynamic-list=dl2.list" | |
81 | "-shared -Wl,--dynamic-list=dl2.list" "-fPIC" | |
82 | {dl2.c dl2xxx.c} {} "libdl2a.so"} | |
b7b7fe3f AS |
83 | {"Build libdl2a.so with --dynamic-list=dl2a.list" |
84 | "-shared -Wl,--dynamic-list=dl2a.list" "-fPIC" | |
85 | {dl2.c dl2xxx.c} {} "libdl2a.so"} | |
40b36307 L |
86 | {"Build libdl2a.so with --dynamic-list-data" |
87 | "-shared -Wl,--dynamic-list-data" "-fPIC" | |
88 | {dl2.c dl2xxx.c} {} "libdl2a.so"} | |
55255dae L |
89 | {"Build libdl2b.so with --dynamic-list=dl2.list and dl2xxx.list" |
90 | "-shared -Wl,--dynamic-list=dl2.list,--dynamic-list=dl2xxx.list" "-fPIC" | |
91 | {dl2.c dl2xxx.c} {} "libdl2b.so"} | |
d8cf8b51 | 92 | {"Build libdl2c.so with --dynamic-list-data and dl2xxx.list" |
40b36307 | 93 | "-shared -Wl,--dynamic-list-data,--dynamic-list=dl2xxx.list" "-fPIC" |
d8cf8b51 | 94 | {dl2.c dl2xxx.c} {} "libdl2c.so"} |
c555238b L |
95 | {"Build libdl4a.so with --dynamic-list=dl4.list" |
96 | "-shared -Wl,--dynamic-list=dl4.list" "-fPIC" | |
97 | {dl4.c dl4xxx.c} {} "libdl4a.so"} | |
d8cf8b51 | 98 | {"Build libdl4b.so with --dynamic-list-data" |
40b36307 | 99 | "-shared -Wl,--dynamic-list-data" "-fPIC" |
c555238b | 100 | {dl4.c dl4xxx.c} {} "libdl4b.so"} |
d8cf8b51 L |
101 | {"Build libdl4c.so with --dynamic-list=dl4.list and dl4xxx.list" |
102 | "-shared -Wl,--dynamic-list=dl4.list,--dynamic-list=dl4xxx.list" "-fPIC" | |
103 | {dl4.c dl4xxx.c} {} "libdl4c.so"} | |
104 | {"Build libdl4d.so with --dynamic-list-data and dl4xxx.list" | |
40b36307 | 105 | "-shared -Wl,--dynamic-list-data,--dynamic-list=dl4xxx.list" "-fPIC" |
d8cf8b51 L |
106 | {dl4.c dl4xxx.c} {} "libdl4d.so"} |
107 | {"Build libdl4e.so with -Bsymbolic-functions --dynamic-list-cpp-new" | |
108 | "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC" | |
109 | {dl4.c dl4xxx.c} {} "libdl4e.so"} | |
110 | {"Build libdl4f.so with --dynamic-list-cpp-new -Bsymbolic-functions" | |
111 | "-shared -Wl,--dynamic-list-cpp-new,-Bsymbolic-functions" "-fPIC" | |
112 | {dl4.c dl4xxx.c} {} "libdl4f.so"} | |
113 | {"Build libdl6a.so" | |
114 | "-shared" "-fPIC" | |
115 | {dl6.c} {} "libdl6a.so"} | |
116 | {"Build libdl6b.so with -Bsymbolic --dynamic-list-data" | |
117 | "-shared -Wl,-Bsymbolic,--dynamic-list-data" "-fPIC" | |
118 | {dl6.c} {} "libdl6b.so"} | |
119 | {"Build libdl6c.so with -Bsymbolic" | |
120 | "-shared -Wl,-Bsymbolic" "-fPIC" | |
121 | {dl6.c} {} "libdl6c.so"} | |
122 | {"Build libdl6d.so with --dynamic-list-data -Bsymbolic" | |
123 | "-shared -Wl,--dynamic-list-data,-Bsymbolic" "-fPIC" | |
124 | {dl6.c} {} "libdl6d.so"} | |
43edfb7f L |
125 | {"Build libdata1.so" |
126 | "-shared" "-fPIC" | |
127 | {data1.c} {} "libdata1.so"} | |
a47edf27 L |
128 | {"Build libdata2.so" |
129 | "-shared" "-fPIC" | |
130 | {data2.c} {} "libdata2.so"} | |
0a36a439 L |
131 | {"Build libcomm1.o" |
132 | "-r -nostdlib" "" | |
133 | {comm1.c} {} "libcomm1.o"} | |
134 | {"Build libfunc1.so" | |
135 | "-shared" "-fPIC" | |
136 | {func1.c} {} "libfunc1.so"} | |
d8880531 L |
137 | {"Build libpr9676-1.a" |
138 | "" "-fPIC" | |
139 | {pr9676-1.c} {} "libpr9676-1.a"} | |
140 | {"Build libpr9676-2.a" | |
141 | "" "-fPIC" | |
142 | {pr9676-2.c} {} "libpr9676-2.a"} | |
143 | {"Build libpr9676-3.so" | |
144 | "-shared" "-fPIC" | |
145 | {pr9676-3.c} {} "libpr9676-3.so"} | |
146 | {"Build libpr9676-4.so" | |
147 | "-shared" "-fPIC" | |
148 | {pr9676-4.c} {} "libpr9676-4.so"} | |
149 | {"Build libpr9676-4a.so" | |
150 | "-shared tmpdir/pr9676-4.o -Ltmpdir -lpr9676-3 -Wl,--start-group -lpr9676-1 -lpr9676-2 -Wl,--end-group" | |
151 | "-fPIC" | |
152 | {dummy.c} {{readelf {-s} pr9676.rd}} "libpr9676-4a.so"} | |
54ac0771 L |
153 | {"Build libpr9679.so" |
154 | "-shared" "-fPIC -O0" | |
155 | {pr9679-1.c pr9679-2.c} {{readelf {-s} pr9679.rd}} "libpr9679.so"} | |
d023c380 L |
156 | {"Build libpr11138-1.so" |
157 | "-shared -Wl,--version-script=pr11138-1.map" "-fPIC" | |
158 | {pr11138-1.c} {} "libpr11138-1.so"} | |
159 | {"Build libpr11138-2.o" | |
160 | "-r -nostdlib" "" | |
161 | {pr11138-2.c} {} "libpr11138-2.o"} | |
3e0882af L |
162 | {"Build pr13250-1.so" |
163 | "-shared" "-fPIC" | |
164 | {pr13250-1.c} {} "libpr13250-1.so"} | |
165 | {"Build pr13250-2.so with libpr13250-1.so" | |
5cb49709 | 166 | "-shared -Wl,--no-as-needed tmpdir/libpr13250-1.so" "-fPIC" |
3e0882af L |
167 | {pr13250-2.c} {} "libpr13250-2.so"} |
168 | {"Build libpr13250-3.o" | |
169 | "-r -nostdlib" "" | |
170 | {pr13250-3.c} {} "libpr13250-3.o"} | |
bc9ad2e4 L |
171 | {"Build libpr14323-2.so" |
172 | "-shared" "-fPIC" | |
173 | {pr14323-2.c} {} "libpr14323-2.so"} | |
dda8ddc5 L |
174 | {"Build pr14862-1.o" |
175 | "-r -nostdlib" "" | |
176 | {pr14862-1.c} {} "libpr14862-1.o"} | |
177 | {"Build libpr14862.so" | |
178 | "-shared -Wl,--version-script=pr11138-1.map" "-fPIC" | |
179 | {pr14862-2.c} {} "libpr14862.so"} | |
63406f0a L |
180 | {"Build libneeded1b.so" |
181 | "-shared" "-fPIC" | |
182 | {needed1b.c} {} "libneeded1b.so"} | |
183 | {"Build libneeded1a.so" | |
2eb64a9f | 184 | "-shared -Wl,--add-needed,--no-as-needed -Ltmpdir -lneeded1b" "-fPIC" |
63406f0a L |
185 | {needed1a.c} {} "libneeded1a.so"} |
186 | {"Build libneeded1c.o" | |
187 | "-r -nostdlib" "" | |
188 | {needed1c.c} {} "libneeded1c.o"} | |
8fbb09e8 L |
189 | {"Build libneeded1pic.o" |
190 | "-r -nostdlib" "-fPIC" | |
191 | {needed1c.c} {} "libneeded1pic.o"} | |
192 | {"Build needed1a.so with --add-needed" | |
193 | "-shared tmpdir/libneeded1pic.o -Wl,--add-needed,-rpath=tmpdir,-z,defs -Ltmpdir -lneeded1a" "" | |
194 | {dummy.c} {} "needed1a.so"} | |
195 | {"Build needed1b.so with --copy-dt-needed-entries" | |
196 | "-shared tmpdir/libneeded1pic.o -Wl,--copy-dt-needed-entries,-rpath=tmpdir,-z,defs -Ltmpdir -lneeded1a" "" | |
197 | {dummy.c} {} "needed1b.so"} | |
198 | {"Build needed1a.so with --no-add-needed" | |
199 | "-shared tmpdir/libneeded1pic.o -Wl,--no-add-needed -Ltmpdir -lneeded1a" "" | |
200 | {dummy.c} {} "needed1c.so"} | |
201 | {"Build needed1b.so with --no-copy-dt-needed-entries" | |
202 | "-shared tmpdir/libneeded1pic.o -Wl,--no-copy-dt-needed-entries -Ltmpdir -lneeded1a" "" | |
203 | {dummy.c} {} "needed1d.so"} | |
8877b5e5 AM |
204 | {"Build librel.so" |
205 | "-shared" "-fPIC" | |
206 | {rel.c} {} "librel.so"} | |
5e319dd3 L |
207 | {"Build libneeded2a.so" |
208 | "-shared" "-fPIC" | |
209 | {needed2a.c} {} "libneeded2a.so"} | |
210 | {"Build libneeded2b.so" | |
211 | "-shared -Wl,--version-script,needed2.ver" "-fPIC" | |
212 | {needed2b.c} {} "libneeded2b.so"} | |
213 | {"Build libneeded2c.o" | |
214 | "-r -nostdlib" "" | |
215 | {needed2c.c} {} "libneeded2c.o"} | |
216 | {"Build needed2" | |
217 | "tmpdir/libneeded2c.o -Wl,--as-needed tmpdir/libneeded2a.so tmpdir/libneeded2b.so" "" | |
218 | {dummy.c} {} "needed2"} | |
1240be6b AM |
219 | {"Build libneeded3a.so" |
220 | "-shared -Wl,--no-add-needed" "-fPIC" | |
221 | {needed1a.c} {} "libneeded3a.so"} | |
222 | {"Build libneeded3b.so" | |
223 | "-shared -Wl,--no-as-needed,--add-needed -Ltmpdir -lneeded1b" "-fPIC" | |
224 | {dummy.c} {} "libneeded3b.so"} | |
225 | {"Build needed3.o" | |
226 | "-r -nostdlib" "" | |
227 | {needed3.c} {} "libneeded3.so"} | |
228 | {"Build needed3" | |
229 | "tmpdir/needed3.o -Wl,--as-needed -Ltmpdir -lneeded3a -lneeded3b -lneeded1b" "" | |
230 | {dummy.c} {} "needed3"} | |
cec2c50d L |
231 | {"Build libpr2404a.so" |
232 | "-shared" "-fPIC" | |
233 | {pr2404a.c} {} "libpr2404a.so"} | |
234 | {"Build libpr2404b.a" | |
235 | "" "" | |
236 | {pr2404b.c} {} "libpr2404b.a"} | |
50a53d3f L |
237 | {"Build rdynamic-1" |
238 | "-rdynamic -Wl,--gc-sections" "-ffunction-sections" | |
239 | {rdynamic-1.c} {{readelf {-s} rdynamic-1.rd}} "rdynamic-1"} | |
d6f6f455 L |
240 | {"Build dynamic-1" |
241 | "-Wl,--dynamic-list,dynamic-1.syms -Wl,--gc-sections" "-ffunction-sections" | |
242 | {dynamic-1.c} {{readelf {-s} dynamic-1.rd}} "dynamic-1"} | |
bb4d2ac2 L |
243 | {"Build libpr16496a.so" |
244 | "-shared -Wl,--version-script=pr16496a.map" "-fPIC" | |
245 | {pr16496a.c} {} "libpr16496a.so"} | |
246 | {"Build libpr16496b.a" | |
247 | "" "-fPIC" | |
248 | {pr16496b.c} {} "libpr16496b.a"} | |
249 | {"Build libpr16496b.so" | |
250 | "-shared tmpdir/pr16496b.o tmpdir/libpr16496a.so" "" | |
251 | {dummy.c} {{objdump {-R} pr16496b.od}} "libpr16496b.so"} | |
fb389763 L |
252 | {"Build libpr16452a.so" |
253 | "-shared -Wl,-soname,libpr16452a.so,--version-script=pr16452.map" "-fPIC" | |
254 | {pr16452a.c} {} "libpr16452a.so"} | |
255 | {"Build libpr16452b.so" | |
256 | "-shared -Wl,-soname,libpr16452b.so,--no-as-needed tmpdir/libpr16452a.so" "-fPIC" | |
257 | {dummy.c} {} "libpr16452b.so"} | |
258 | {"Build pr16452" | |
259 | "tmpdir/libpr16452b.so -Wl,-rpath=tmpdir" "" | |
260 | {pr16452b.c} {{objdump {-p} pr16452.od}} "pr16452"} | |
261 | {"Build pr16457" | |
262 | "tmpdir/libpr16452b.so -Wl,-rpath=tmpdir" "" | |
263 | {pr16452b.c} {{objdump {-p} pr16457.od}} "pr16457"} | |
8ded2ddc L |
264 | {"Build libpr18458a.so" |
265 | "-shared -Wl,-z,now" "-fPIC" | |
266 | {pr18458a.c} {} "libpr18458a.so"} | |
267 | {"Build libpr18458b.so" | |
268 | "-shared -Wl,-z,now tmpdir/libpr18458a.so" "-fPIC" | |
269 | {pr18458b.c} {} "libpr18458b.so"} | |
4373f8af L |
270 | {"Build pr19073a.o" |
271 | "-r -nostdlib" "" | |
272 | {pr19073.s} {} "pr19073a.o"} | |
273 | {"Build libpr19073.so" | |
274 | "-shared -Wl,--version-script=pr19073.map tmpdir/pr19073a.o" "-fPIC" | |
275 | {dummy.c} {{readelf {--dyn-syms --wide} pr19073.rd}} "libpr19073.so"} | |
d2dee3b2 L |
276 | } |
277 | ||
dd98f8d2 NC |
278 | run_cc_link_tests $build_tests |
279 | ||
d9816402 AM |
280 | set run_tests [list \ |
281 | [list "Run normal with libfoo.so" \ | |
282 | "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/end.o" "" \ | |
283 | {main.c} "normal" "normal.out" ] \ | |
284 | [list "Run protected with libfoo.so" \ | |
285 | "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/endprotected.o" "" \ | |
286 | {main.c} "protected" "normal.out" ] \ | |
287 | [list "Run hidden with libfoo.so" \ | |
288 | "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/endhidden.o" "" \ | |
289 | {main.c} "hidden" "hidden.out" ] \ | |
290 | [list "Run normal with versioned libfoo.so" \ | |
291 | "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/end.o" "" \ | |
292 | {main.c} "normalv" "normal.out" ] \ | |
293 | [list "Run warn with versioned libfoo.so" \ | |
294 | "-Wl,--no-as-needed tmpdir/beginwarn.o tmpdir/libfoov.so" "" \ | |
295 | {main.c} "warn" "warn.out" \ | |
296 | "" "c" {^.*\): warning: function foo is deprecated$} ] \ | |
297 | [list "Run protected with versioned libfoo.so" \ | |
298 | "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/endprotected.o" "" \ | |
299 | {main.c} "protected" "normal.out" ] \ | |
300 | [list "Run hidden with versioned libfoo.so" \ | |
301 | "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/endhidden.o" "" \ | |
302 | {main.c} "hiddenv" "hidden.out" ] \ | |
303 | [list "Run normal libbar.so with libfoo.so" \ | |
304 | "-Wl,--no-as-needed tmpdir/libbarfoo.so tmpdir/libfoo.so" "" \ | |
305 | {main.c} "normal" "normal.out" ] \ | |
306 | [list "Run protected libbar.so with libfoo.so" \ | |
307 | "-Wl,--no-as-needed tmpdir/libbarpfoo.so tmpdir/libfoo.so" "" \ | |
308 | {main.c} "protected" "normal.out" ] \ | |
309 | [list "Run hidden libbar.so with libfoo.so" \ | |
310 | "-Wl,--no-as-needed tmpdir/libbarhfoo.so tmpdir/libfoo.so" "" \ | |
311 | {main.c} "hidden" "hidden.out" ] \ | |
312 | [list "Run normal libbar.so with versioned libfoo.so" \ | |
313 | "-Wl,--no-as-needed tmpdir/libbarfoov.so tmpdir/libfoov.so" "" \ | |
314 | {main.c} "normal" "normal.out" ] \ | |
315 | [list "Run protected libbar.so with versioned libfoo.so" \ | |
316 | "-Wl,--no-as-needed tmpdir/libbarpfoov.so tmpdir/libfoov.so" "" \ | |
317 | {main.c} "protected" "normal.out" ] \ | |
318 | [list "Run hidden libbar.so with versioned libfoo.so" \ | |
319 | "-Wl,--no-as-needed tmpdir/libbarhfoov.so tmpdir/libfoov.so" "" \ | |
320 | {main.c} "hidden" "hidden.out" ] \ | |
321 | [list "Run dl1a with --dynamic-list=dl1.list and dlopen on libdl1.so" \ | |
322 | "-Wl,--no-as-needed,--dynamic-list=dl1.list $extralibs" "" \ | |
323 | {dl1main.c} "dl1a" "dl1.out" ] \ | |
324 | [list "Run dl1b with --dynamic-list-data and dlopen on libdl1.so" \ | |
325 | "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \ | |
326 | {dl1main.c} "dl1b" "dl1.out" ] \ | |
327 | [list "Run with libdl2a.so" \ | |
328 | "-Wl,--no-as-needed tmpdir/libdl2a.so" "" \ | |
329 | {dl2main.c} "dl2a" "dl2a.out" ] \ | |
330 | [list "Run with libdl2b.so" \ | |
331 | "-Wl,--no-as-needed tmpdir/libdl2b.so" "" \ | |
332 | {dl2main.c} "dl2b" "dl2b.out" ] \ | |
333 | [list "Run with libdl2c.so" \ | |
334 | "-Wl,--no-as-needed tmpdir/libdl2c.so" "" \ | |
335 | {dl2main.c} "dl2c" "dl2b.out" ] \ | |
336 | [list "Run with libdl4a.so" \ | |
337 | "-Wl,--no-as-needed tmpdir/libdl4a.so" "" \ | |
338 | {dl4main.c} "dl4a" "dl4a.out" ] \ | |
339 | [list "Run with libdl4b.so" \ | |
340 | "-Wl,--no-as-needed tmpdir/libdl4b.so" "" \ | |
341 | {dl4main.c} "dl4b" "dl4a.out" ] \ | |
342 | [list "Run with libdl4c.so" \ | |
343 | "-Wl,--no-as-needed tmpdir/libdl4c.so" "" \ | |
344 | {dl4main.c} "dl4c" "dl4b.out" ] \ | |
345 | [list "Run with libdl4d.so" \ | |
346 | "-Wl,--no-as-needed tmpdir/libdl4d.so" "" \ | |
347 | {dl4main.c} "dl4d" "dl4b.out" ] \ | |
348 | [list "Run with libdl4e.so" \ | |
349 | "-Wl,--no-as-needed tmpdir/libdl4e.so" "" \ | |
350 | {dl4main.c} "dl4e" "dl4a.out" ] \ | |
351 | [list "Run with libdl4f.so" \ | |
352 | "-Wl,--no-as-needed tmpdir/libdl4f.so" "" \ | |
353 | {dl4main.c} "dl4f" "dl4a.out" ] \ | |
354 | [list "Run dl6a1 with --dynamic-list-data and dlopen on libdl6a.so" \ | |
355 | "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \ | |
356 | {dl6amain.c} "dl6a1" "dl6a.out" ] \ | |
357 | [list "Run dl6a2 with -Bsymbolic-functions and dlopen on libdl6a.so" \ | |
358 | "-Wl,--no-as-needed,-Bsymbolic-functions $extralibs" "" \ | |
359 | {dl6amain.c} "dl6a2" "dl6b.out" ] \ | |
360 | [list "Run dl6a3 with -Bsymbolic and dlopen on libdl6a.so" \ | |
361 | "-Wl,--no-as-needed,-Bsymbolic $extralibs" "" \ | |
362 | {dl6amain.c} "dl6a3" "dl6b.out" ] \ | |
363 | [list "Run dl6a4 with -Bsymbolic --dynamic-list-data and dlopen on libdl6a.so" \ | |
364 | "-Wl,--no-as-needed,-Bsymbolic,--dynamic-list-data $extralibs" "" \ | |
365 | {dl6amain.c} "dl6a4" "dl6a.out" ] \ | |
366 | [list "Run dl6a5 with -Bsymbolic-functions --dynamic-list-cpp-new and dlopen on libdl6a.so" \ | |
367 | "-Wl,--no-as-needed,-Bsymbolic-functions,--dynamic-list-cpp-new $extralibs" "" \ | |
368 | {dl6amain.c} "dl6a5" "dl6b.out" ] \ | |
369 | [list "Run dl6a6 with --dynamic-list-cpp-new -Bsymbolic-functions and dlopen on libdl6a.so" \ | |
370 | "-Wl,--no-as-needed,--dynamic-list-cpp-new,-Bsymbolic-functions $extralibs" "" \ | |
371 | {dl6amain.c} "dl6a6" "dl6b.out" ] \ | |
372 | [list "Run dl6a7 with --dynamic-list-data -Bsymbolic and dlopen on libdl6a.so" \ | |
373 | "-Wl,--no-as-needed,--dynamic-list-data,-Bsymbolic $extralibs" "" \ | |
374 | {dl6amain.c} "dl6a7" "dl6a.out" ] \ | |
375 | [list "Run dl6b1 with --dynamic-list-data and dlopen on libdl6b.so" \ | |
376 | "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \ | |
377 | {dl6bmain.c} "dl6b1" "dl6a.out" ] \ | |
378 | [list "Run dl6b2 with dlopen on libdl6b.so" \ | |
379 | "-Wl,--no-as-needed $extralibs" "" \ | |
380 | {dl6bmain.c} "dl6b2" "dl6b.out" ] \ | |
381 | [list "Run dl6c1 with --dynamic-list-data and dlopen on libdl6c.so" \ | |
382 | "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \ | |
383 | {dl6cmain.c} "dl6c1" "dl6b.out" ] \ | |
384 | [list "Run dl6d1 with --dynamic-list-data and dlopen on libdl6d.so" \ | |
385 | "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \ | |
386 | {dl6dmain.c} "dl6d1" "dl6b.out" ] \ | |
387 | [list "Run with libdata1.so" \ | |
388 | "-Wl,--no-as-needed tmpdir/libdata1.so" "" \ | |
389 | {dynbss1.c} "dynbss1" "pass.out" ] \ | |
390 | [list "Run with libdata2.so" \ | |
391 | "-Wl,--no-as-needed tmpdir/libdata2.so" "" \ | |
392 | {weakdef1.c} "weakdef1" "pass.out" ] \ | |
393 | [list "Run with libfunc1.so comm1.o" \ | |
394 | "-Wl,--no-as-needed tmpdir/libfunc1.so tmpdir/comm1.o" "" \ | |
395 | {dummy.c} "comm1" "pass.out" ] \ | |
396 | [list "Run with comm1.o libfunc1.so" \ | |
397 | "-Wl,--no-as-needed tmpdir/comm1.o tmpdir/libfunc1.so" "" \ | |
398 | {dummy.c} "comm1" "pass.out" ] \ | |
399 | [list "Run with pr11138-2.c libpr11138-1.so" \ | |
400 | "-Wl,--no-as-needed,--version-script=pr11138-2.map tmpdir/pr11138-2.o tmpdir/libpr11138-1.so" "" \ | |
401 | {dummy.c} "pr11138a" "pr11138.out" ] \ | |
402 | [list "Run with libpr11138-1.so pr11138-2.c" \ | |
403 | "-Wl,--no-as-needed,--version-script=pr11138-2.map tmpdir/libpr11138-1.so tmpdir/pr11138-2.o" "" \ | |
404 | {dummy.c} "pr11138b" "pr11138.out" ] \ | |
405 | [list "Run with pr13250-3.c, libpr13250-1.so and libpr13250-2.so" \ | |
406 | "-Wl,--as-needed tmpdir/pr13250-3.o tmpdir/libpr13250-1.so tmpdir/libpr13250-2.so" "" \ | |
407 | {dummy.c} "pr13250" "pass.out" ] \ | |
408 | [list "Run with pr14323-1.c pr14323-2.so" \ | |
409 | "-Wl,--no-as-needed tmpdir/libpr14323-2.so" "" \ | |
410 | {pr14323-1.c} "pr14323" "pass.out" ] \ | |
411 | [list "Run with pr14862-1.c libpr14862.so" \ | |
412 | "-Wl,--as-needed tmpdir/libpr14862-1.o tmpdir/libpr14862.so" "" \ | |
413 | {dummy.c} "pr14862" "pr14862.out" ] \ | |
414 | [list "Link with --add-needed" \ | |
415 | "tmpdir/libneeded1c.o -Wl,--no-as-needed,--add-needed,-rpath=tmpdir -Ltmpdir -lneeded1a" "" \ | |
416 | {dummy.c} "needed1a" "needed1.out" ] \ | |
417 | [list "Link with --copy-dt-needed-entries" \ | |
418 | "tmpdir/libneeded1c.o -Wl,--no-as-needed,--copy-dt-needed-entries,-rpath=tmpdir -Ltmpdir -lneeded1a" "" \ | |
419 | {dummy.c} "needed1b" "needed1.out" ] \ | |
420 | [list "Run relmain" \ | |
421 | "-Wl,--no-as-needed,-rpath=tmpdir -Ltmpdir -lrel" "" \ | |
422 | {relmain.c} "relmain" "relmain.out" ] \ | |
423 | [list "Run pr2404" \ | |
424 | "-Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404a.so" "" \ | |
425 | {dummy.c} "pr2404" "pr2404.out" ] \ | |
426 | [list "Run pr18458" \ | |
427 | "-Wl,--no-as-needed,-z,now tmpdir/libpr18458a.so tmpdir/libpr18458b.so" "" \ | |
428 | {pr18458c.c} "pr18458" "pass.out" ] \ | |
429 | ] | |
d2dee3b2 | 430 | |
d2dee3b2 | 431 | # NetBSD ELF systems do not currently support the .*_array sections. |
982c6f26 | 432 | run_ld_link_exec_tests $run_tests "*-*-netbsdelf*" |
55255dae | 433 | |
63406f0a L |
434 | # Check --no-add-needed and --no-copy-dt-needed-entries |
435 | set testname "--no-add-needed" | |
f1d7f4a6 | 436 | set exec_output [run_host_cmd "$CC" "tmpdir/libneeded1c.o -Wl,--no-add-needed,-rpath-link=tmpdir -Ltmpdir -lneeded1a"] |
e65cb106 | 437 | if { [ regexp "tmpdir/libneeded1b.so: .*: DSO missing" $exec_output ] } { |
63406f0a L |
438 | pass $testname |
439 | } { | |
440 | fail $testname | |
441 | } | |
442 | set testname "--no-copy-dt-needed-entries" | |
f1d7f4a6 | 443 | set exec_output [run_host_cmd "$CC" "tmpdir/libneeded1c.o -Wl,--no-copy-dt-needed-entries,-rpath-link=tmpdir -Ltmpdir -lneeded1a"] |
e65cb106 | 444 | if { [ regexp "tmpdir/libneeded1b.so: .*: DSO missing" $exec_output ] } { |
63406f0a L |
445 | pass $testname |
446 | } { | |
447 | fail $testname | |
448 | } | |
8fbb09e8 | 449 | set testname "--no-add-needed -shared" |
f1d7f4a6 | 450 | set exec_output [run_host_cmd "$CC" "-shared tmpdir/libneeded1pic.o -Wl,--no-add-needed,-z,defs -Ltmpdir -lneeded1a"] |
4e95fbcd | 451 | if { [ regexp "undefined reference to `\.?bar'" $exec_output ] } { |
8fbb09e8 L |
452 | pass $testname |
453 | } { | |
454 | fail $testname | |
455 | } | |
456 | set testname "--no-copy-dt-needed-entries -shared" | |
f1d7f4a6 | 457 | set exec_output [run_host_cmd "$CC" "-shared tmpdir/libneeded1pic.o -Wl,--no-copy-dt-needed-entries,-z,defs -Ltmpdir -lneeded1a"] |
4e95fbcd | 458 | if { [ regexp "undefined reference to `\.?bar'" $exec_output ] } { |
8fbb09e8 L |
459 | pass $testname |
460 | } { | |
461 | fail $testname | |
462 | } | |
63406f0a | 463 | |
dd98f8d2 | 464 | # Check to see if the C++ compiler works |
55255dae L |
465 | if { [which $CXX] == 0 } { |
466 | return | |
467 | } | |
468 | ||
469 | set build_cxx_tests { | |
470 | {"Build libdl3a.so with --dynamic-list=dl3.list" | |
471 | "-shared -Wl,--dynamic-list=dl3.list" "-fPIC" | |
472 | {dl3.cc} {} "libdl3a.so" "c++"} | |
473 | {"Build libdl3b.so with -Bsymbolic" | |
474 | "-shared -Wl,-Bsymbolic" "-fPIC" | |
475 | {dl3.cc} {} "libdl3b.so" "c++"} | |
476 | {"Build libdl3a.so with --dynamic-list-cpp-typeinfo" | |
477 | "-shared -Wl,--dynamic-list-cpp-typeinfo" "-fPIC" | |
478 | {dl3.cc} {} "libdl3c.so" "c++"} | |
d8cf8b51 | 479 | {"Build libdnew1a.so with --Bsymbolic-functions --dynamic-list-cpp-new" |
40b36307 | 480 | "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC" |
d8cf8b51 L |
481 | {del.cc new.cc} {} "libnew1a.so" "c++"} |
482 | {"Build libdnew1b.so with --dynamic-list-data --dynamic-list-cpp-new" | |
483 | "-shared -Wl,--dynamic-list-data,--dynamic-list-cpp-new" "-fPIC" | |
484 | {del.cc new.cc} {} "libnew1b.so" "c++"} | |
55255dae L |
485 | } |
486 | ||
b37470e4 L |
487 | # "-shared -Bsymbolic" only works with gcc 4.5.0 and newer. |
488 | # {"Run with libdl3b.so" | |
489 | # "tmpdir/libdl3b.so" "" | |
490 | # {dl3main.cc} "dl3b" "dl3b.out" "" "c++"} | |
cb5ab6c8 L |
491 | set run_cxx_tests { |
492 | {"Run with libdl3a.so" | |
493 | "-Wl,--no-as-needed tmpdir/libdl3a.so" "" | |
494 | {dl3main.cc} "dl3a" "dl3a.out" "" "c++"} | |
55255dae | 495 | {"Run with libdl3c.so" |
5cb49709 | 496 | "-Wl,--no-as-needed tmpdir/libdl3c.so" "" |
55255dae | 497 | {dl3main.cc} "dl3c" "dl3a.out" "" "c++"} |
d8cf8b51 | 498 | {"Run with libnew1a.so" |
d9816402 | 499 | "-Wl,--no-as-needed tmpdir/libnew1a.so" "" |
d8cf8b51 L |
500 | {dl5.cc} "dl5a" "dl5.out" "" "c++"} |
501 | {"Run with libnew1b.so" | |
d9816402 | 502 | "-Wl,--no-as-needed tmpdir/libnew1b.so" "" |
d8cf8b51 | 503 | {dl5.cc} "dl5b" "dl5.out" "" "c++"} |
55255dae L |
504 | } |
505 | ||
506 | run_cc_link_tests $build_cxx_tests | |
982c6f26 | 507 | run_ld_link_exec_tests $run_cxx_tests |
22ef172a L |
508 | |
509 | if { [istarget *-*-linux*] | |
510 | || [istarget *-*-nacl*] | |
511 | || [istarget *-*-gnu*] } { | |
512 | run_cc_link_tests [list \ | |
513 | [list \ | |
514 | "Build libpr2404b.a with PIE" \ | |
515 | "" \ | |
516 | "-fPIE" \ | |
517 | { pr2404b.c } \ | |
518 | {} \ | |
519 | "libpr2404b.a" \ | |
520 | ] \ | |
07492f66 L |
521 | [list \ |
522 | "Build pr19579a.o" \ | |
523 | "" "-fPIE" \ | |
524 | {pr19579a.c} \ | |
525 | {} \ | |
526 | "libpr19579a.a" \ | |
527 | ] \ | |
528 | [list \ | |
529 | "Build libpr19579.so" \ | |
530 | "-shared" \ | |
531 | "-fPIC" \ | |
532 | {pr19579b.c} \ | |
533 | {} \ | |
534 | "libpr19579.so" \ | |
535 | ] \ | |
22ef172a | 536 | ] |
982c6f26 | 537 | run_ld_link_exec_tests [list \ |
22ef172a L |
538 | [list \ |
539 | "Run pr2404 with PIE" \ | |
d9816402 | 540 | "-pie -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404a.so" \ |
22ef172a L |
541 | "" \ |
542 | { dummy.c } \ | |
543 | "pr2404pie" \ | |
544 | "pr2404.out" \ | |
545 | "-fPIE" \ | |
546 | ] \ | |
1659f720 L |
547 | [list \ |
548 | "Run pr18718" \ | |
549 | "" \ | |
550 | "" \ | |
c45bd4fd | 551 | { pr18718.c check-ptr-eq.c } \ |
1659f720 L |
552 | "pr18718" \ |
553 | "pass.out" \ | |
edcab5e8 | 554 | "-O2 -I../bfd" \ |
1659f720 L |
555 | ] \ |
556 | [list \ | |
557 | "Run pr18718 with PIE (1)" \ | |
558 | "-pie" \ | |
559 | "" \ | |
c45bd4fd | 560 | { pr18718.c check-ptr-eq.c } \ |
1659f720 L |
561 | "pr18718pie1" \ |
562 | "pass.out" \ | |
edcab5e8 | 563 | "-O2 -fPIE -I../bfd" \ |
1659f720 L |
564 | ] \ |
565 | [list \ | |
566 | "Run pr18718 with PIE (2)" \ | |
567 | "" \ | |
568 | "" \ | |
c45bd4fd | 569 | { pr18718.c check-ptr-eq.c } \ |
1659f720 L |
570 | "pr18718pie2" \ |
571 | "pass.out" \ | |
edcab5e8 | 572 | "-O2 -fPIE -I../bfd" \ |
1659f720 L |
573 | ] \ |
574 | [list \ | |
575 | "Run pr18718 with PIC (1)" \ | |
576 | "" \ | |
577 | "" \ | |
c45bd4fd | 578 | { pr18718.c check-ptr-eq.c } \ |
1659f720 L |
579 | "pr18718pic1" \ |
580 | "pass.out" \ | |
edcab5e8 | 581 | "-O2 -fPIC -I../bfd" \ |
1659f720 L |
582 | ] \ |
583 | [list \ | |
584 | "Run pr18718 with PIC (2)" \ | |
585 | "-pie" \ | |
586 | "" \ | |
c45bd4fd | 587 | { pr18718.c check-ptr-eq.c } \ |
1659f720 L |
588 | "pr18718pic2" \ |
589 | "pass.out" \ | |
edcab5e8 | 590 | "-O2 -fPIC -I../bfd" \ |
1659f720 | 591 | ] \ |
07492f66 L |
592 | [list \ |
593 | "Run pr19579" \ | |
d9816402 | 594 | "-pie -Wl,--no-as-needed,-z,text tmpdir/pr19579a.o tmpdir/libpr19579.so" \ |
07492f66 L |
595 | "" \ |
596 | {dummy.c} \ | |
597 | "pr19579" \ | |
598 | "pass.out" \ | |
599 | "-fPIE" \ | |
600 | ] \ | |
22ef172a L |
601 | ] |
602 | } | |
aec6b87e | 603 | |
f1b2ca70 | 604 | proc mix_pic_and_non_pic {xfails cflags ldflags exe} { |
aec6b87e L |
605 | run_cc_link_tests [list \ |
606 | [list \ | |
607 | "Build libpr19719a.so" \ | |
608 | "-shared -Wl,-soname,libpr19719.so" \ | |
609 | "-fPIC" \ | |
610 | { pr19719d.c } \ | |
611 | {} \ | |
612 | "libpr19719a.so" \ | |
613 | ] \ | |
614 | [list \ | |
615 | "Build libpr19719b.so" \ | |
616 | "-shared -Wl,-soname,libpr19719.so" \ | |
617 | "-fPIC" \ | |
618 | { dummy.c } \ | |
619 | {} \ | |
620 | "libpr19719b.so" \ | |
621 | ] \ | |
622 | [list \ | |
f1b2ca70 | 623 | "Build libpr19719b.o" \ |
aec6b87e L |
624 | "-r -nostdlib" \ |
625 | "-fPIC" \ | |
626 | { pr19719b.c } \ | |
627 | {} \ | |
628 | "libpr19719b.o" \ | |
629 | ] \ | |
630 | ] | |
631 | ||
f1b2ca70 | 632 | send_log "cp tmpdir/libpr19719b.so tmpdir/libpr19719.so\n" |
aec6b87e L |
633 | exec cp tmpdir/libpr19719b.so tmpdir/libpr19719.so |
634 | ||
982c6f26 | 635 | run_ld_link_exec_tests [list \ |
aec6b87e | 636 | [list \ |
f1b2ca70 | 637 | "Run $exe fun defined" \ |
d9816402 | 638 | "-Wl,--no-as-needed,-rpath,tmpdir $ldflags tmpdir/libpr19719b.o tmpdir/libpr19719.so" \ |
aec6b87e L |
639 | "" \ |
640 | { pr19719a.c pr19719c.c } \ | |
f1b2ca70 | 641 | $exe \ |
aec6b87e L |
642 | "pass.out" \ |
643 | "$cflags" \ | |
644 | ] \ | |
645 | ] | |
646 | ||
f1b2ca70 | 647 | send_log "cp tmpdir/libpr19719a.so tmpdir/libpr19719.so\n" |
aec6b87e L |
648 | exec cp tmpdir/libpr19719a.so tmpdir/libpr19719.so |
649 | ||
7494161b L |
650 | foreach targ $xfails { |
651 | setup_xfail $targ | |
652 | } | |
653 | ||
d9816402 AM |
654 | if ![isnative] { |
655 | unsupported "Run $exe fun undefined" | |
656 | return | |
657 | } | |
658 | ||
f1b2ca70 | 659 | set exec_output [run_host_cmd "tmpdir/$exe" ""] |
aec6b87e | 660 | if {![string match "PASS" $exec_output]} { |
f1b2ca70 | 661 | fail "Run $exe fun undefined" |
aec6b87e | 662 | } else { |
f1b2ca70 | 663 | pass "Run $exe fun undefined" |
aec6b87e L |
664 | } |
665 | } | |
666 | ||
f1b2ca70 AM |
667 | mix_pic_and_non_pic [list "arm*-*-*" "aarch64*-*-*"] "" "" "pr19719" |
668 | mix_pic_and_non_pic [] "-fPIE" "-pie" "pr19719pie" |