2003-02-12 Michael Chastain <mec@shout.net>
[deliverable/binutils-gdb.git] / ld / testsuite / ld-shared / shared.exp
CommitLineData
252b5132 1# Expect script for ld-shared tests
a2b64bed
NC
2# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3# Free Software Foundation, Inc.
252b5132
RH
4#
5# This file is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18#
19# Written by Ian Lance Taylor (ian@cygnus.com)
20#
21
22# Make sure that ld can generate ELF shared libraries.
23# Note that linking against ELF shared libraries is tested by the
24# bootstrap test.
25
26# This test can only be run if ld generates native executables.
27if ![isnative] then {return}
28
29# This test can only be run on a couple of ELF platforms.
30# Square bracket expressions seem to confuse istarget.
19c7c582
AM
31if { ![istarget hppa*64*-*-hpux*] \
32 && ![istarget hppa*-*-linux*] \
33 && ![istarget i?86-*-sysv4*] \
ad995491
L
34 && ![istarget i?86-*-unixware] \
35 && ![istarget i?86-*-elf*] \
36 && ![istarget i?86-*-linux*] \
37 && ![istarget ia64-*-elf*] \
38 && ![istarget ia64-*-linux*] \
252b5132
RH
39 && ![istarget m68k-*-linux*] \
40 && ![istarget mips*-*-irix5*] \
66517a2f 41 && ![istarget mips*-*-linux*] \
252b5132
RH
42 && ![istarget powerpc-*-elf*] \
43 && ![istarget powerpc-*-linux*] \
44 && ![istarget powerpc-*-sysv4*] \
45 && ![istarget sparc*-*-elf] \
46 && ![istarget sparc*-*-solaris2*] \
47 && ![istarget sparc*-*-sunos4*] \
b33b6e45 48 && ![istarget sparc*-*-linux*] \
4f38fc1c 49 && ![istarget arm*-*-linux*] \
2ffd68ef 50 && ![istarget alpha*-*-linux*] \
252b5132
RH
51 && ![istarget rs6000*-*-aix*] \
52 && ![istarget powerpc*-*-aix*] } {
53 return
54}
55
99c262f8
ILT
56if { [istarget *-*-linux*aout*] \
57 || [istarget *-*-linux*oldld*] } {
252b5132
RH
58 return
59}
60
61set tmpdir tmpdir
62set SHCFLAG ""
63
64if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
65
66 # AIX shared libraries do not seem to support useful features,
67 # like overriding the shared library function or letting the
68 # shared library refer to objects defined in the main program. We
69 # avoid testing those features.
70 set SHCFLAG "-DXCOFF_TEST"
71
72 # The AIX 3.2.5 loader appears to randomly fail when loading
73 # shared libraries from NSF mounted partitions, so we avoid any
74 # potential problems by using a local directory.
75 catch {exec /bin/sh -c "echo $$"} pid
76 set tmpdir /usr/tmp/ld.$pid
77 catch "exec mkdir $tmpdir" exec_status
78
79 # On AIX, we need to explicitly export the symbols the shared
80 # library is going to provide, and need.
81 set file [open $tmpdir/xcoff.exp w]
82 puts $file shlibvar1
83 puts $file shlibvar2
84 puts $file shlib_shlibvar1
85 puts $file shlib_shlibvar2
86 puts $file shlib_shlibcall
87 puts $file shlib_shlibcalled
88 puts $file shlib_checkfunptr1
89 puts $file shlib_getfunptr1
90 puts $file shlib_check
91 close $file
92}
93
94# The test procedure.
95proc shared_test { progname testname main sh1 sh2 dat args } {
96 global ld
97 global srcdir
98 global subdir
99 global exec_output
100 global host_triplet
101 global tmpdir
102
103 if [llength $args] { set shldflags [lindex $args 0] } else { set shldflags "" }
104
105 # Build the shared library.
106 # On AIX, we need to use an export file.
107 set shared -shared
108 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
109 set shared "-bM:SRE -bE:$tmpdir/xcoff.exp"
110 }
111 if {![ld_simple_link $ld $tmpdir/$progname.so "$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} {
112 fail "$testname"
113 return
114 }
115
116 # Link against the shared library. Use -rpath so that the
117 # dynamic linker can locate the shared library at runtime.
118 # On AIX, we must include /lib in -rpath, as otherwise the loader
119 # can not find -lc.
120 set rpath $tmpdir
121 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
122 set rpath /lib:$tmpdir
123 }
124 if ![ld_link $ld $tmpdir/$progname "-rpath $rpath $tmpdir/$main $tmpdir/$progname.so"] {
125 fail "$testname"
126 return
127 }
128
129 # Run the resulting program
130 send_log "$tmpdir/$progname >$tmpdir/$progname.out\n"
131 verbose "$tmpdir/$progname >$tmpdir/$progname.out"
132 catch "exec $tmpdir/$progname >$tmpdir/$progname.out" exec_output
133 if ![string match "" $exec_output] then {
134 send_log "$exec_output\n"
135 verbose "$exec_output"
136 fail "$testname"
137 return
138 }
139
140 send_log "diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat\n"
141 verbose "diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat"
142 catch "exec diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat" exec_output
143 set exec_output [prune_warnings $exec_output]
144
145 if {![string match "" $exec_output]} then {
146 send_log "$exec_output\n"
147 verbose "$exec_output"
148 fail "$testname"
149 return
150 }
151
152 pass "$testname"
153}
154
155if [istarget mips*-*-*] {
156 set picflag ""
157} else {
158 # Unfortunately, the gcc argument is -fpic and the cc argument is
159 # -KPIC. We have to try both.
160 set picflag "-fpic"
161 send_log "$CC $picflag\n"
162 verbose "$CC $picflag"
163 catch "exec $CC $picflag" exec_output
164 send_log "$exec_output\n"
165 verbose "--" "$exec_output"
166 if { [string match "*illegal option*" $exec_output] \
167 || [string match "*option ignored*" $exec_output] \
168 || [string match "*unrecognized option*" $exec_output] \
169 || [string match "*passed to ld*" $exec_output] } {
170 if [istarget *-*-sunos4*] {
171 set picflag "-pic"
172 } else {
173 set picflag "-KPIC"
174 }
175 }
176}
177verbose "Using $picflag to compile PIC code"
178
179# Compile the main program.
180if ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o] {
181 unresolved "shared (non PIC)"
182 unresolved "shared"
183} else {
184 # The shared library is composed of two files. First compile them
185 # without using -fpic. That should work on an ELF system,
186 # although it will be less efficient because the dynamic linker
187 # will need to do more relocation work. However, note that not
188 # using -fpic will cause some of the tests to return different
189 # results.
190 if { ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o]
191 || ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } {
192 unresolved "shared (non PIC)"
193 } else { if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
194 shared_test shnp "shared (nonPIC)" mainnp.o sh1np.o sh2np.o xcoff
195 } else {
196 # SunOS non PIC shared libraries don't permit some cases of
197 # overriding.
198 setup_xfail "*-*-sunos4*"
ad995491 199 setup_xfail "ia64-*-linux*"
212a6b8e 200 setup_xfail "alpha*-*-linux*"
252b5132
RH
201 shared_test shnp "shared (non PIC)" mainnp.o sh1np.o sh2np.o shared
202
203 # Test ELF shared library relocations with a non-zero load
204 # address for the library. Near as I can tell, the R_*_RELATIVE
205 # relocations for various targets are broken in the case where
206 # the load address is not zero (which is the default).
207 setup_xfail "*-*-sunos4*"
b7be1db6 208 setup_xfail "*-*-linux*libc1"
d1d8dddf 209 setup_xfail "powerpc-*-linux*"
ad995491 210 setup_xfail "ia64-*-linux*"
212a6b8e 211 setup_xfail "alpha*-*-linux*"
66517a2f 212 setup_xfail "mips*-*-linux*"
252b5132
RH
213 shared_test shnp "shared (non PIC, load offset)" \
214 mainnp.o sh1np.o sh2np.o shared \
215 "-T $srcdir/$subdir/elf-offset.ld"
216 } }
217
218 # Now compile the code using -fpic.
219
220 if { ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o]
221 || ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh2.c $tmpdir/sh2p.o] } {
222 unresolved "shared"
223 } else {
224 # SunOS can not compare function pointers correctly
225 if [istarget "*-*-sunos4*"] {
226 shared_test shp "shared" mainnp.o sh1p.o sh2p.o sun4
227 } else { if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
228 shared_test shp "shared" mainnp.o sh1p.o sh2p.o xcoff
229 } else {
230 shared_test shp "shared" mainnp.o sh1p.o sh2p.o shared
66517a2f
L
231 ld_compile "$CC $CFLAGS -DSYMBOLIC_TEST -DXCOFF_TEST $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o
232 ld_compile "$CC $CFLAGS -DSYMBOLIC_TEST -DXCOFF_TEST $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o
f0f077e5
L
233 shared_test shp "shared -Bsymbolic" mainnp.o sh1p.o sh2p.o symbolic "-Bsymbolic"
234 ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o
235 ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o
252b5132
RH
236 } }
237 }
238}
239
240# Now do the same tests again, but this time compile main.c PIC.
241if ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/main.c $tmpdir/mainp.o] {
242 unresolved "shared (PIC main, non PIC so)"
243 unresolved "shared (PIC main)"
244} else {
245 if { [file exists $tmpdir/sh1np.o ] && [ file exists $tmpdir/sh2np.o ] } {
246 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
247 shared_test shmpnp "shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o xcoff
248 } else {
249 # SunOS non PIC shared libraries don't permit some cases of
250 # overriding.
251 setup_xfail "*-*-sunos4*"
ad995491 252 setup_xfail "ia64-*-linux*"
212a6b8e 253 setup_xfail "alpha*-*-linux*"
252b5132
RH
254 shared_test shmpnp "shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o shared
255 }
256 } else {
257 unresolved "shared (PIC main, non PIC so)"
258 }
259
260 if { [file exists $tmpdir/sh1p.o ] && [ file exists $tmpdir/sh2p.o ] } {
261 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
262 shared_test shmpp "shared (PIC main)" mainp.o sh1p.o sh2p.o xcoff
263 } else {
264 shared_test shmpp "shared (PIC main)" mainp.o sh1p.o sh2p.o shared
265 }
266 } else {
267 unresolved "shared (PIC main)"
268 }
269}
270
271if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
272 # Remove the temporary directory.
273 catch "exec rm -rf $tmpdir" exec_status
274}
This page took 0.160912 seconds and 4 git commands to generate.