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