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