]>
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 | ||
24 | # This test can only be run if ld generates native executables. | |
25 | if ![isnative] then {return} | |
26 | ||
27 | # This test can only be run on a couple of ELF platforms. | |
28 | # Square bracket expressions seem to confuse istarget. | |
19c7c582 AM |
29 | if { ![istarget hppa*64*-*-hpux*] \ |
30 | && ![istarget hppa*-*-linux*] \ | |
31 | && ![istarget i?86-*-linux*] \ | |
ad995491 | 32 | && ![istarget ia64-*-linux*] \ |
6fc49d28 | 33 | && ![istarget m68k-*-linux*] \ |
66517a2f | 34 | && ![istarget mips*-*-linux*] \ |
6fc49d28 | 35 | && ![istarget powerpc-*-linux*] \ |
4f38fc1c | 36 | && ![istarget arm*-*-linux*] \ |
2ffd68ef | 37 | && ![istarget alpha*-*-linux*] \ |
9147e853 JJ |
38 | && ![istarget sparc*-*-linux*] \ |
39 | && ![istarget s390*-*-linux*] \ | |
40 | && ![istarget x86_64-*-linux*] } { | |
6fc49d28 L |
41 | return |
42 | } | |
43 | ||
44 | if { [istarget *-*-linux*aout*] \ | |
45 | || [istarget *-*-linux*oldld*] } { | |
46 | return | |
47 | } | |
48 | ||
04827a14 L |
49 | set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]] |
50 | foreach t $test_list { | |
51 | # We need to strip the ".d", but can leave the dirname. | |
52 | verbose [file rootname $t] | |
53 | run_dump_test [file rootname $t] | |
54 | } | |
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] | |
147 | && [regexp ".*/main.c.*: undefined reference to \`visibility_var\'" $link_output] } { | |
6fc49d28 L |
148 | pass "$testname" |
149 | } else { | |
150 | fail "$testname" | |
7cda33a1 | 151 | }} |
6fc49d28 L |
152 | return |
153 | } | |
154 | ||
7cda33a1 L |
155 | if { [ string match $visibility "hidden" ] |
156 | || [ string match $visibility "hidden_undef" ] | |
157 | || [ string match $visibility "protected_undef" ] } { | |
6fc49d28 L |
158 | fail "$testname" |
159 | } | |
160 | ||
161 | # Run the resulting program | |
162 | send_log "$tmpdir/$progname >$tmpdir/$progname.out\n" | |
163 | verbose "$tmpdir/$progname >$tmpdir/$progname.out" | |
164 | catch "exec $tmpdir/$progname >$tmpdir/$progname.out" exec_output | |
165 | if ![string match "" $exec_output] then { | |
166 | send_log "$exec_output\n" | |
167 | verbose "$exec_output" | |
168 | fail "$testname" | |
169 | return | |
170 | } | |
171 | ||
172 | send_log "diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat\n" | |
173 | verbose "diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat" | |
174 | catch "exec diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat" exec_output | |
175 | set exec_output [prune_warnings $exec_output] | |
176 | ||
177 | if {![string match "" $exec_output]} then { | |
178 | send_log "$exec_output\n" | |
179 | verbose "$exec_output" | |
180 | fail "$testname" | |
181 | return | |
182 | } | |
183 | ||
184 | pass "$testname" | |
185 | } | |
186 | ||
187 | proc visibility_run {visibility} { | |
188 | global CC | |
189 | global CFLAGS | |
190 | global SHCFLAG | |
191 | global srcdir | |
192 | global subdir | |
193 | global tmpdir | |
194 | global picflag | |
195 | global target_triplet | |
08c44e65 | 196 | global support_protected |
6fc49d28 L |
197 | |
198 | if [ string match $visibility "hidden" ] { | |
199 | set VSBCFLAG "-DHIDDEN_TEST" | |
200 | } else { if [ string match $visibility "hidden_normal" ] { | |
201 | set VSBCFLAG "-DHIDDEN_NORMAL_TEST" | |
7cda33a1 L |
202 | } else { if [ string match $visibility "hidden_undef" ] { |
203 | set VSBCFLAG "-DHIDDEN_UNDEF_TEST" | |
204 | } else { if [ string match $visibility "hidden_undef_def" ] { | |
205 | set VSBCFLAG "-DHIDDEN_UNDEF_TEST -DDSO_DEFINE_TEST" | |
206 | } else { if [ string match $visibility "hidden_weak" ] { | |
207 | set VSBCFLAG "-DHIDDEN_WEAK_TEST" | |
6fc49d28 L |
208 | } else { if [ string match $visibility "protected" ] { |
209 | set VSBCFLAG "-DPROTECTED_TEST" | |
7cda33a1 L |
210 | } else { if [ string match $visibility "protected_undef" ] { |
211 | set VSBCFLAG "-DPROTECTED_UNDEF_TEST" | |
212 | } else { if [ string match $visibility "protected_undef_def" ] { | |
213 | set VSBCFLAG "-DPROTECTED_UNDEF_TEST -DDSO_DEFINE_TEST" | |
214 | } else { if [ string match $visibility "protected_weak" ] { | |
215 | set VSBCFLAG "-DPROTECTED_WEAK_TEST" | |
6fc49d28 L |
216 | } else { |
217 | set VSBCFLAG "" | |
7cda33a1 | 218 | }}}}}}}}} |
6fc49d28 L |
219 | |
220 | # Compile the main program. | |
360e9586 | 221 | if ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o] { |
6fc49d28 L |
222 | unresolved "visibility ($visibility) (non PIC)" |
223 | unresolved "visibility ($visibility)" | |
224 | } else { | |
225 | # The shared library is composed of two files. First compile them | |
226 | # without using -fpic. That should work on an ELF system, | |
227 | # although it will be less efficient because the dynamic linker | |
228 | # will need to do more relocation work. However, note that not | |
229 | # using -fpic will cause some of the tests to return different | |
230 | # results. | |
360e9586 L |
231 | if { ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o] |
232 | || ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } { | |
6fc49d28 L |
233 | unresolved "visibility ($visibility) (non PIC)" |
234 | } else { if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
ad995491 | 235 | visibility_test $visibility vnp "visibility ($visibility) (non PIC)" mainnp.o sh1np.o sh2np.o xcoff |
6fc49d28 L |
236 | } else { |
237 | # SunOS non PIC shared libraries don't permit some cases of | |
238 | # overriding. | |
1345a0c0 L |
239 | if { [ string match $visibility "protected" ] |
240 | || [ string match $visibility "protected_undef_def" ] } { | |
08c44e65 L |
241 | if [ string match $support_protected "no" ] { |
242 | setup_xfail $target_triplet | |
243 | } | |
6fc49d28 L |
244 | } else { |
245 | setup_xfail "*-*-sunos4*" | |
246 | } | |
d1d8dddf L |
247 | if { [ string match $visibility "hidden_weak" ] |
248 | || [ string match $visibility "protected_weak" ] } { | |
249 | setup_xfail "powerpc-*-linux*" | |
250 | } | |
212a6b8e RH |
251 | |
252 | # Non-pic code uses name binding rules for applications to | |
253 | # reference variables by gp-relative relocs, which can't be | |
254 | # used with overridable symbols. | |
ad995491 L |
255 | if { ![ string match $visibility "hidden_undef" ] |
256 | && ![ string match $visibility "protected_undef" ] } { | |
257 | setup_xfail "ia64-*-linux*" | |
212a6b8e | 258 | setup_xfail "alpha*-*-linux*" |
ad995491 | 259 | } |
9147e853 | 260 | setup_xfail "x86_64-*-linux*" |
212a6b8e | 261 | |
6fc49d28 L |
262 | visibility_test $visibility vnp "visibility ($visibility) (non PIC)" mainnp.o sh1np.o sh2np.o elfvsb |
263 | ||
264 | # Test ELF shared library relocations with a non-zero load | |
265 | # address for the library. Near as I can tell, the R_*_RELATIVE | |
266 | # relocations for various targets are broken in the case where | |
267 | # the load address is not zero (which is the default). | |
1345a0c0 L |
268 | if { [ string match $visibility "protected" ] |
269 | || [ string match $visibility "protected_undef_def" ] } { | |
08c44e65 L |
270 | if [ string match $support_protected "no" ] { |
271 | setup_xfail $target_triplet | |
272 | } | |
6fc49d28 L |
273 | } else { |
274 | setup_xfail "*-*-sunos4*" | |
275 | setup_xfail "*-*-linux*libc1" | |
276 | } | |
d1d8dddf L |
277 | if { [ string match $visibility "hidden_normal" ] |
278 | || [ string match $visibility "hidden_weak" ] | |
279 | || [ string match $visibility "protected" ] | |
280 | || [ string match $visibility "protected_undef_def" ] | |
281 | || [ string match $visibility "protected_weak" ] | |
282 | || [ string match $visibility "normal" ] } { | |
283 | setup_xfail "powerpc-*-linux*" | |
284 | } | |
ad995491 L |
285 | if { ![ string match $visibility "hidden_undef" ] |
286 | && ![ string match $visibility "protected_undef" ] } { | |
287 | setup_xfail "ia64-*-linux*" | |
212a6b8e | 288 | setup_xfail "alpha*-*-linux*" |
66517a2f | 289 | setup_xfail "mips*-*-linux*" |
ad995491 | 290 | } |
9147e853 | 291 | setup_xfail "x86_64-*-linux*" |
6fc49d28 L |
292 | visibility_test $visibility vnp "visibility ($visibility) (non PIC, load offset)" \ |
293 | mainnp.o sh1np.o sh2np.o elfvsb \ | |
294 | "-T $srcdir/$subdir/elf-offset.ld" | |
295 | } } | |
296 | ||
297 | # Now compile the code using -fpic. | |
298 | ||
360e9586 L |
299 | if { ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o] |
300 | || ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG $picflag" $srcdir/$subdir/sh2.c $tmpdir/sh2p.o] } { | |
6fc49d28 L |
301 | unresolved "visibility ($visibility)" |
302 | } else { | |
1345a0c0 L |
303 | if { [ string match $visibility "protected" ] |
304 | || [ string match $visibility "protected_undef_def" ] } { | |
08c44e65 L |
305 | if [ string match $support_protected "no" ] { |
306 | setup_xfail $target_triplet | |
307 | } | |
6fc49d28 L |
308 | } |
309 | # SunOS can not compare function pointers correctly | |
310 | if [istarget "*-*-sunos4*"] { | |
311 | visibility_test $visibility vp "visibility ($visibility)" mainnp.o sh1p.o sh2p.o sun4 | |
312 | } else { if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
313 | visibility_test $visibility vp "visibility ($visibility)" mainnp.o sh1p.o sh2p.o xcoff | |
314 | } else { | |
315 | visibility_test $visibility vp "visibility ($visibility)" mainnp.o sh1p.o sh2p.o elfvsb | |
316 | } } | |
317 | } | |
318 | } | |
319 | ||
320 | # Now do the same tests again, but this time compile main.c PIC. | |
360e9586 | 321 | if ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG $picflag" $srcdir/$subdir/main.c $tmpdir/mainp.o] { |
6fc49d28 L |
322 | unresolved "visibility ($visibility) (PIC main, non PIC so)" |
323 | unresolved "visibility ($visibility) (PIC main)" | |
324 | } else { | |
325 | if { [file exists $tmpdir/sh1np.o ] && [ file exists $tmpdir/sh2np.o ] } { | |
326 | if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
327 | visibility_test $visibility vmpnp "visibility ($visibility) (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o xcoff | |
328 | } else { | |
329 | # SunOS non PIC shared libraries don't permit some cases of | |
330 | # overriding. | |
1345a0c0 L |
331 | if { [ string match $visibility "protected" ] |
332 | || [ string match $visibility "protected_undef_def" ] } { | |
08c44e65 L |
333 | if [ string match $support_protected "no" ] { |
334 | setup_xfail $target_triplet | |
335 | } | |
6fc49d28 L |
336 | } else { |
337 | setup_xfail "*-*-sunos4*" | |
338 | } | |
d1d8dddf L |
339 | if { [ string match $visibility "hidden_weak" ] |
340 | || [ string match $visibility "protected_weak" ] } { | |
341 | setup_xfail "powerpc-*-linux*" | |
342 | } | |
ad995491 L |
343 | if { ![ string match $visibility "hidden_undef" ] |
344 | && ![ string match $visibility "protected_undef" ] } { | |
345 | setup_xfail "ia64-*-linux*" | |
212a6b8e | 346 | setup_xfail "alpha*-*-linux*" |
ad995491 | 347 | } |
9147e853 | 348 | setup_xfail "x86_64-*-linux*" |
6fc49d28 L |
349 | visibility_test $visibility vmpnp "visibility ($visibility) (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o elfvsb |
350 | } | |
351 | } else { | |
352 | unresolved "visibility (PIC main, non PIC so)" | |
353 | } | |
354 | ||
355 | if { [file exists $tmpdir/sh1p.o ] && [ file exists $tmpdir/sh2p.o ] } { | |
1345a0c0 L |
356 | if { [ string match $visibility "protected" ] |
357 | || [ string match $visibility "protected_undef_def" ] } { | |
08c44e65 L |
358 | if [ string match $support_protected "no" ] { |
359 | setup_xfail $target_triplet | |
360 | } | |
6fc49d28 L |
361 | } |
362 | if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
363 | visibility_test $visibility vmpp "visibility ($visibility) (PIC main)" mainp.o sh1p.o sh2p.o xcoff | |
364 | } else { | |
365 | visibility_test $visibility vmpp "visibility ($visibility) (PIC main)" mainp.o sh1p.o sh2p.o elfvsb | |
366 | } | |
367 | } else { | |
368 | unresolved "visibility ($visibility) (PIC main)" | |
369 | } | |
370 | } | |
371 | } | |
372 | ||
373 | if [istarget mips*-*-*] { | |
374 | set picflag "" | |
375 | } else { | |
376 | # Unfortunately, the gcc argument is -fpic and the cc argument is | |
377 | # -KPIC. We have to try both. | |
378 | set picflag "-fpic" | |
379 | send_log "$CC $picflag\n" | |
380 | verbose "$CC $picflag" | |
381 | catch "exec $CC $picflag" exec_output | |
382 | send_log "$exec_output\n" | |
383 | verbose "--" "$exec_output" | |
384 | if { [string match "*illegal option*" $exec_output] \ | |
385 | || [string match "*option ignored*" $exec_output] \ | |
386 | || [string match "*unrecognized option*" $exec_output] \ | |
387 | || [string match "*passed to ld*" $exec_output] } { | |
388 | if [istarget *-*-sunos4*] { | |
389 | set picflag "-pic" | |
390 | } else { | |
391 | set picflag "-KPIC" | |
392 | } | |
393 | } | |
394 | } | |
395 | verbose "Using $picflag to compile PIC code" | |
396 | ||
397 | visibility_run hidden | |
398 | visibility_run hidden_normal | |
7cda33a1 L |
399 | visibility_run hidden_undef |
400 | visibility_run hidden_undef_def | |
401 | visibility_run hidden_weak | |
6fc49d28 | 402 | visibility_run protected |
7cda33a1 L |
403 | visibility_run protected_undef |
404 | visibility_run protected_undef_def | |
405 | visibility_run protected_weak | |
6fc49d28 L |
406 | visibility_run normal |
407 | ||
408 | if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
409 | # Remove the temporary directory. | |
410 | catch "exec rm -rf $tmpdir" exec_status | |
411 | } |