Commit | Line | Data |
---|---|---|
6fc49d28 | 1 | # Expect script for ld-visibility tests |
9147e853 | 2 | # Copyright 2000, 2001, 2003 Free Software Foundation, Inc. |
6fc49d28 L |
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 | # | |
18 | # Written by Ian Lance Taylor (ian@cygnus.com) | |
19 | # and H.J. Lu (hjl@gnu.org) | |
20 | # | |
21 | ||
22 | # Make sure that ld can generate ELF shared libraries with visibility. | |
23 | ||
6fc49d28 L |
24 | # This test can only be run on a couple of ELF platforms. |
25 | # Square bracket expressions seem to confuse istarget. | |
19c7c582 AM |
26 | if { ![istarget hppa*64*-*-hpux*] \ |
27 | && ![istarget hppa*-*-linux*] \ | |
28 | && ![istarget i?86-*-linux*] \ | |
ad995491 | 29 | && ![istarget ia64-*-linux*] \ |
6fc49d28 | 30 | && ![istarget m68k-*-linux*] \ |
66517a2f | 31 | && ![istarget mips*-*-linux*] \ |
6fc49d28 | 32 | && ![istarget powerpc-*-linux*] \ |
4f38fc1c | 33 | && ![istarget arm*-*-linux*] \ |
2ffd68ef | 34 | && ![istarget alpha*-*-linux*] \ |
9147e853 JJ |
35 | && ![istarget sparc*-*-linux*] \ |
36 | && ![istarget s390*-*-linux*] \ | |
37 | && ![istarget x86_64-*-linux*] } { | |
6fc49d28 L |
38 | return |
39 | } | |
40 | ||
41 | if { [istarget *-*-linux*aout*] \ | |
42 | || [istarget *-*-linux*oldld*] } { | |
43 | return | |
44 | } | |
45 | ||
04827a14 L |
46 | set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]] |
47 | foreach t $test_list { | |
48 | # We need to strip the ".d", but can leave the dirname. | |
49 | verbose [file rootname $t] | |
50 | run_dump_test [file rootname $t] | |
51 | } | |
52 | ||
3a8260b2 AS |
53 | # The remaining tests can only be run if ld generates native executables. |
54 | if ![isnative] then {return} | |
55 | ||
6fc49d28 L |
56 | set tmpdir tmpdir |
57 | set SHCFLAG "" | |
58 | ||
59 | if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
60 | ||
61 | # AIX shared libraries do not seem to support useful features, | |
62 | # like overriding the shared library function or letting the | |
63 | # shared library refer to objects defined in the main program. We | |
64 | # avoid testing those features. | |
65 | set SHCFLAG "-DXCOFF_TEST" | |
66 | ||
67 | # The AIX 3.2.5 loader appears to randomly fail when loading | |
68 | # shared libraries from NSF mounted partitions, so we avoid any | |
69 | # potential problems by using a local directory. | |
70 | catch {exec /bin/sh -c "echo $$"} pid | |
71 | set tmpdir /usr/tmp/ld.$pid | |
72 | catch "exec mkdir $tmpdir" exec_status | |
73 | ||
74 | # On AIX, we need to explicitly export the symbols the shared | |
75 | # library is going to provide, and need. | |
76 | set file [open $tmpdir/xcoff.exp w] | |
77 | puts $file shlibvar1 | |
78 | puts $file shlibvar2 | |
79 | puts $file shlib_shlibvar1 | |
80 | puts $file shlib_shlibvar2 | |
81 | puts $file shlib_shlibcall | |
82 | puts $file shlib_shlibcalled | |
83 | puts $file shlib_checkfunptr1 | |
84 | puts $file shlib_getfunptr1 | |
85 | puts $file shlib_check | |
86 | close $file | |
87 | } | |
88 | ||
08c44e65 L |
89 | set support_protected "no" |
90 | ||
91 | if [istarget *-*-linux*] { | |
360e9586 | 92 | if [ld_compile "$CC -g $CFLAGS -DPROTECTED_CHECK" $srcdir/$subdir/main.c $tmpdir/main.o] { |
08c44e65 L |
93 | if [ld_link $ld $tmpdir/main "$tmpdir/main.o"] { |
94 | catch "exec $tmpdir/main" support_protected | |
95 | } | |
96 | } | |
97 | } | |
98 | ||
6fc49d28 L |
99 | # The test procedure. |
100 | proc visibility_test { visibility progname testname main sh1 sh2 dat args } { | |
101 | global ld | |
102 | global srcdir | |
103 | global subdir | |
104 | global exec_output | |
105 | global link_output | |
106 | global host_triplet | |
107 | global tmpdir | |
108 | ||
109 | if [llength $args] { set shldflags [lindex $args 0] } else { set shldflags "" } | |
110 | ||
111 | # Build the shared library. | |
112 | # On AIX, we need to use an export file. | |
113 | set shared -shared | |
114 | if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
115 | set shared "-bM:SRE -bE:$tmpdir/xcoff.exp" | |
116 | } | |
117 | if {![ld_simple_link $ld $tmpdir/$progname.so "$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} { | |
7cda33a1 L |
118 | if { [ string match $visibility "hidden_undef" ] |
119 | && [regexp ".*/sh1.c.*: undefined reference to \`visibility\'" $link_output] | |
120 | && [regexp ".*/sh1.c.*: undefined reference to \`visibility_var\'" $link_output] } { | |
121 | pass "$testname" | |
122 | } else { if { [ string match $visibility "protected_undef" ] | |
123 | && [regexp ".*/sh1.c.*: undefined reference to \`visibility\'" $link_output] | |
124 | && [regexp ".*/sh1.c.*: undefined reference to \`visibility_var\'" $link_output] } { | |
125 | pass "$testname" | |
126 | } else { | |
127 | fail "$testname" | |
128 | }} | |
6fc49d28 L |
129 | return |
130 | } | |
131 | ||
132 | # Link against the shared library. Use -rpath so that the | |
133 | # dynamic linker can locate the shared library at runtime. | |
134 | # On AIX, we must include /lib in -rpath, as otherwise the loader | |
135 | # can not find -lc. | |
136 | set rpath $tmpdir | |
137 | if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
138 | set rpath /lib:$tmpdir | |
139 | } | |
140 | if ![ld_link $ld $tmpdir/$progname "-rpath $rpath $tmpdir/$main $tmpdir/$progname.so"] { | |
141 | if { [ string match $visibility "hidden" ] | |
7cda33a1 L |
142 | && [regexp ".*/main.c.*: undefined reference to \`visibility\'" $link_output] |
143 | && [regexp ".*/main.c.*: undefined reference to \`visibility_var\'" $link_output] } { | |
144 | pass "$testname" | |
145 | } else { if { [ string match $visibility "hidden_undef_def" ] | |
146 | && [regexp ".*/main.c.*: undefined reference to \`visibility\'" $link_output] | |
1b1fe8fe L |
147 | && [regexp ".*/main.c.*: undefined reference to \`visibility_def\'" $link_output] |
148 | && [regexp ".*/main.c.*: undefined reference to \`visibility_func\'" $link_output] | |
7cda33a1 | 149 | && [regexp ".*/main.c.*: undefined reference to \`visibility_var\'" $link_output] } { |
6fc49d28 L |
150 | pass "$testname" |
151 | } else { | |
152 | fail "$testname" | |
7cda33a1 | 153 | }} |
6fc49d28 L |
154 | return |
155 | } | |
156 | ||
7cda33a1 L |
157 | if { [ string match $visibility "hidden" ] |
158 | || [ string match $visibility "hidden_undef" ] | |
159 | || [ string match $visibility "protected_undef" ] } { | |
6fc49d28 L |
160 | fail "$testname" |
161 | } | |
162 | ||
163 | # Run the resulting program | |
164 | send_log "$tmpdir/$progname >$tmpdir/$progname.out\n" | |
165 | verbose "$tmpdir/$progname >$tmpdir/$progname.out" | |
166 | catch "exec $tmpdir/$progname >$tmpdir/$progname.out" exec_output | |
167 | if ![string match "" $exec_output] then { | |
168 | send_log "$exec_output\n" | |
169 | verbose "$exec_output" | |
170 | fail "$testname" | |
171 | return | |
172 | } | |
173 | ||
174 | send_log "diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat\n" | |
175 | verbose "diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat" | |
176 | catch "exec diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat" exec_output | |
177 | set exec_output [prune_warnings $exec_output] | |
178 | ||
179 | if {![string match "" $exec_output]} then { | |
180 | send_log "$exec_output\n" | |
181 | verbose "$exec_output" | |
182 | fail "$testname" | |
183 | return | |
184 | } | |
185 | ||
186 | pass "$testname" | |
187 | } | |
188 | ||
189 | proc visibility_run {visibility} { | |
190 | global CC | |
191 | global CFLAGS | |
192 | global SHCFLAG | |
193 | global srcdir | |
194 | global subdir | |
195 | global tmpdir | |
196 | global picflag | |
197 | global target_triplet | |
08c44e65 | 198 | global support_protected |
6fc49d28 L |
199 | |
200 | if [ string match $visibility "hidden" ] { | |
201 | set VSBCFLAG "-DHIDDEN_TEST" | |
202 | } else { if [ string match $visibility "hidden_normal" ] { | |
203 | set VSBCFLAG "-DHIDDEN_NORMAL_TEST" | |
7cda33a1 L |
204 | } else { if [ string match $visibility "hidden_undef" ] { |
205 | set VSBCFLAG "-DHIDDEN_UNDEF_TEST" | |
206 | } else { if [ string match $visibility "hidden_undef_def" ] { | |
207 | set VSBCFLAG "-DHIDDEN_UNDEF_TEST -DDSO_DEFINE_TEST" | |
208 | } else { if [ string match $visibility "hidden_weak" ] { | |
209 | set VSBCFLAG "-DHIDDEN_WEAK_TEST" | |
6fc49d28 L |
210 | } else { if [ string match $visibility "protected" ] { |
211 | set VSBCFLAG "-DPROTECTED_TEST" | |
7cda33a1 L |
212 | } else { if [ string match $visibility "protected_undef" ] { |
213 | set VSBCFLAG "-DPROTECTED_UNDEF_TEST" | |
214 | } else { if [ string match $visibility "protected_undef_def" ] { | |
215 | set VSBCFLAG "-DPROTECTED_UNDEF_TEST -DDSO_DEFINE_TEST" | |
216 | } else { if [ string match $visibility "protected_weak" ] { | |
217 | set VSBCFLAG "-DPROTECTED_WEAK_TEST" | |
6fc49d28 L |
218 | } else { |
219 | set VSBCFLAG "" | |
7cda33a1 | 220 | }}}}}}}}} |
6fc49d28 L |
221 | |
222 | # Compile the main program. | |
360e9586 | 223 | if ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o] { |
6fc49d28 L |
224 | unresolved "visibility ($visibility) (non PIC)" |
225 | unresolved "visibility ($visibility)" | |
226 | } else { | |
227 | # The shared library is composed of two files. First compile them | |
228 | # without using -fpic. That should work on an ELF system, | |
229 | # although it will be less efficient because the dynamic linker | |
230 | # will need to do more relocation work. However, note that not | |
231 | # using -fpic will cause some of the tests to return different | |
232 | # results. | |
360e9586 L |
233 | if { ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o] |
234 | || ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } { | |
6fc49d28 L |
235 | unresolved "visibility ($visibility) (non PIC)" |
236 | } else { if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
ad995491 | 237 | visibility_test $visibility vnp "visibility ($visibility) (non PIC)" mainnp.o sh1np.o sh2np.o xcoff |
6fc49d28 L |
238 | } else { |
239 | # SunOS non PIC shared libraries don't permit some cases of | |
240 | # overriding. | |
1345a0c0 L |
241 | if { [ string match $visibility "protected" ] |
242 | || [ string match $visibility "protected_undef_def" ] } { | |
08c44e65 L |
243 | if [ string match $support_protected "no" ] { |
244 | setup_xfail $target_triplet | |
245 | } | |
6fc49d28 L |
246 | } else { |
247 | setup_xfail "*-*-sunos4*" | |
248 | } | |
d1d8dddf L |
249 | if { [ string match $visibility "hidden_weak" ] |
250 | || [ string match $visibility "protected_weak" ] } { | |
251 | setup_xfail "powerpc-*-linux*" | |
252 | } | |
212a6b8e RH |
253 | |
254 | # Non-pic code uses name binding rules for applications to | |
255 | # reference variables by gp-relative relocs, which can't be | |
256 | # used with overridable symbols. | |
ad995491 L |
257 | if { ![ string match $visibility "hidden_undef" ] |
258 | && ![ string match $visibility "protected_undef" ] } { | |
259 | setup_xfail "ia64-*-linux*" | |
212a6b8e | 260 | setup_xfail "alpha*-*-linux*" |
ad995491 | 261 | } |
4648dfcf MS |
262 | if { ![ string match $visibility "hidden" ] |
263 | && ![ string match $visibility "hidden_undef" ] | |
264 | && ![ string match $visibility "hidden_undef_def" ] | |
265 | && ![ string match $visibility "protected_undef" ] } { | |
266 | setup_xfail "s390x-*-linux*" | |
267 | } | |
9147e853 | 268 | setup_xfail "x86_64-*-linux*" |
212a6b8e | 269 | |
6fc49d28 L |
270 | visibility_test $visibility vnp "visibility ($visibility) (non PIC)" mainnp.o sh1np.o sh2np.o elfvsb |
271 | ||
272 | # Test ELF shared library relocations with a non-zero load | |
273 | # address for the library. Near as I can tell, the R_*_RELATIVE | |
274 | # relocations for various targets are broken in the case where | |
275 | # the load address is not zero (which is the default). | |
1345a0c0 L |
276 | if { [ string match $visibility "protected" ] |
277 | || [ string match $visibility "protected_undef_def" ] } { | |
08c44e65 L |
278 | if [ string match $support_protected "no" ] { |
279 | setup_xfail $target_triplet | |
280 | } | |
6fc49d28 L |
281 | } else { |
282 | setup_xfail "*-*-sunos4*" | |
283 | setup_xfail "*-*-linux*libc1" | |
284 | } | |
d1d8dddf L |
285 | if { [ string match $visibility "hidden_normal" ] |
286 | || [ string match $visibility "hidden_weak" ] | |
287 | || [ string match $visibility "protected" ] | |
288 | || [ string match $visibility "protected_undef_def" ] | |
289 | || [ string match $visibility "protected_weak" ] | |
290 | || [ string match $visibility "normal" ] } { | |
291 | setup_xfail "powerpc-*-linux*" | |
292 | } | |
ad995491 L |
293 | if { ![ string match $visibility "hidden_undef" ] |
294 | && ![ string match $visibility "protected_undef" ] } { | |
295 | setup_xfail "ia64-*-linux*" | |
212a6b8e | 296 | setup_xfail "alpha*-*-linux*" |
66517a2f | 297 | setup_xfail "mips*-*-linux*" |
ad995491 | 298 | } |
9147e853 | 299 | setup_xfail "x86_64-*-linux*" |
6fc49d28 L |
300 | visibility_test $visibility vnp "visibility ($visibility) (non PIC, load offset)" \ |
301 | mainnp.o sh1np.o sh2np.o elfvsb \ | |
302 | "-T $srcdir/$subdir/elf-offset.ld" | |
303 | } } | |
304 | ||
305 | # Now compile the code using -fpic. | |
306 | ||
360e9586 L |
307 | if { ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o] |
308 | || ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG $picflag" $srcdir/$subdir/sh2.c $tmpdir/sh2p.o] } { | |
6fc49d28 L |
309 | unresolved "visibility ($visibility)" |
310 | } else { | |
1345a0c0 L |
311 | if { [ string match $visibility "protected" ] |
312 | || [ string match $visibility "protected_undef_def" ] } { | |
08c44e65 L |
313 | if [ string match $support_protected "no" ] { |
314 | setup_xfail $target_triplet | |
315 | } | |
6fc49d28 L |
316 | } |
317 | # SunOS can not compare function pointers correctly | |
318 | if [istarget "*-*-sunos4*"] { | |
319 | visibility_test $visibility vp "visibility ($visibility)" mainnp.o sh1p.o sh2p.o sun4 | |
320 | } else { if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
321 | visibility_test $visibility vp "visibility ($visibility)" mainnp.o sh1p.o sh2p.o xcoff | |
322 | } else { | |
323 | visibility_test $visibility vp "visibility ($visibility)" mainnp.o sh1p.o sh2p.o elfvsb | |
324 | } } | |
325 | } | |
326 | } | |
327 | ||
328 | # Now do the same tests again, but this time compile main.c PIC. | |
360e9586 | 329 | if ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG $picflag" $srcdir/$subdir/main.c $tmpdir/mainp.o] { |
6fc49d28 L |
330 | unresolved "visibility ($visibility) (PIC main, non PIC so)" |
331 | unresolved "visibility ($visibility) (PIC main)" | |
332 | } else { | |
333 | if { [file exists $tmpdir/sh1np.o ] && [ file exists $tmpdir/sh2np.o ] } { | |
334 | if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
335 | visibility_test $visibility vmpnp "visibility ($visibility) (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o xcoff | |
336 | } else { | |
337 | # SunOS non PIC shared libraries don't permit some cases of | |
338 | # overriding. | |
1345a0c0 L |
339 | if { [ string match $visibility "protected" ] |
340 | || [ string match $visibility "protected_undef_def" ] } { | |
08c44e65 L |
341 | if [ string match $support_protected "no" ] { |
342 | setup_xfail $target_triplet | |
343 | } | |
6fc49d28 L |
344 | } else { |
345 | setup_xfail "*-*-sunos4*" | |
346 | } | |
d1d8dddf L |
347 | if { [ string match $visibility "hidden_weak" ] |
348 | || [ string match $visibility "protected_weak" ] } { | |
349 | setup_xfail "powerpc-*-linux*" | |
350 | } | |
ad995491 L |
351 | if { ![ string match $visibility "hidden_undef" ] |
352 | && ![ string match $visibility "protected_undef" ] } { | |
353 | setup_xfail "ia64-*-linux*" | |
212a6b8e | 354 | setup_xfail "alpha*-*-linux*" |
ad995491 | 355 | } |
4648dfcf MS |
356 | if { ![ string match $visibility "hidden" ] |
357 | && ![ string match $visibility "hidden_undef" ] | |
358 | && ![ string match $visibility "hidden_undef_def" ] | |
359 | && ![ string match $visibility "protected_undef" ] } { | |
360 | setup_xfail "s390x-*-linux*" | |
361 | } | |
9147e853 | 362 | setup_xfail "x86_64-*-linux*" |
6fc49d28 L |
363 | visibility_test $visibility vmpnp "visibility ($visibility) (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o elfvsb |
364 | } | |
365 | } else { | |
366 | unresolved "visibility (PIC main, non PIC so)" | |
367 | } | |
368 | ||
369 | if { [file exists $tmpdir/sh1p.o ] && [ file exists $tmpdir/sh2p.o ] } { | |
1345a0c0 L |
370 | if { [ string match $visibility "protected" ] |
371 | || [ string match $visibility "protected_undef_def" ] } { | |
08c44e65 L |
372 | if [ string match $support_protected "no" ] { |
373 | setup_xfail $target_triplet | |
374 | } | |
6fc49d28 L |
375 | } |
376 | if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
377 | visibility_test $visibility vmpp "visibility ($visibility) (PIC main)" mainp.o sh1p.o sh2p.o xcoff | |
378 | } else { | |
379 | visibility_test $visibility vmpp "visibility ($visibility) (PIC main)" mainp.o sh1p.o sh2p.o elfvsb | |
380 | } | |
381 | } else { | |
382 | unresolved "visibility ($visibility) (PIC main)" | |
383 | } | |
384 | } | |
385 | } | |
386 | ||
387 | if [istarget mips*-*-*] { | |
388 | set picflag "" | |
389 | } else { | |
390 | # Unfortunately, the gcc argument is -fpic and the cc argument is | |
391 | # -KPIC. We have to try both. | |
392 | set picflag "-fpic" | |
393 | send_log "$CC $picflag\n" | |
394 | verbose "$CC $picflag" | |
395 | catch "exec $CC $picflag" exec_output | |
396 | send_log "$exec_output\n" | |
397 | verbose "--" "$exec_output" | |
398 | if { [string match "*illegal option*" $exec_output] \ | |
399 | || [string match "*option ignored*" $exec_output] \ | |
400 | || [string match "*unrecognized option*" $exec_output] \ | |
401 | || [string match "*passed to ld*" $exec_output] } { | |
402 | if [istarget *-*-sunos4*] { | |
403 | set picflag "-pic" | |
404 | } else { | |
405 | set picflag "-KPIC" | |
406 | } | |
407 | } | |
408 | } | |
409 | verbose "Using $picflag to compile PIC code" | |
410 | ||
411 | visibility_run hidden | |
412 | visibility_run hidden_normal | |
7cda33a1 L |
413 | visibility_run hidden_undef |
414 | visibility_run hidden_undef_def | |
415 | visibility_run hidden_weak | |
6fc49d28 | 416 | visibility_run protected |
7cda33a1 L |
417 | visibility_run protected_undef |
418 | visibility_run protected_undef_def | |
419 | visibility_run protected_weak | |
6fc49d28 L |
420 | visibility_run normal |
421 | ||
422 | if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
423 | # Remove the temporary directory. | |
424 | catch "exec rm -rf $tmpdir" exec_status | |
425 | } |