1 # Expect script
for ld-shared tests
2 # Copyright
1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2003
3 # Free Software Foundation
, Inc.
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.
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.
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.
19 # Written by Ian Lance Taylor
(ian@cygnus.com
)
22 # Make sure that
ld can generate ELF shared libraries.
23 # Note that linking against ELF shared libraries is tested by the
26 # This test can only be run
if ld generates native executables.
27 if ![isnative
] then {return}
29 # This test can only be run
on a couple of ELF platforms.
30 # Square bracket expressions seem to confuse istarget.
31 if { ![istarget hppa
*64*-*-hpux
*] \
32 && ![istarget hppa
*-*-linux
*] \
33 && ![istarget i?
86-*-sysv4
*] \
34 && ![istarget i?
86-*-unixware
] \
35 && ![istarget i?
86-*-elf
*] \
36 && ![istarget i?
86-*-linux
*] \
37 && ![istarget ia64
-*-elf
*] \
38 && ![istarget ia64
-*-linux
*] \
39 && ![istarget m68k
-*-linux
*] \
40 && ![istarget mips
*-*-irix5
*] \
41 && ![istarget mips
*-*-linux
*] \
42 && ![istarget powerpc
-*-elf
*] \
43 && ![istarget powerpc
-*-linux
*] \
44 && ![istarget powerpc
-*-sysv4
*] \
45 && ![istarget sparc
*-*-elf
] \
46 && ![istarget sparc
*-*-solaris2
*] \
47 && ![istarget sparc
*-*-sunos4
*] \
48 && ![istarget sparc
*-*-linux
*] \
49 && ![istarget arm
*-*-linux
*] \
50 && ![istarget alpha
*-*-linux
*] \
51 && ![istarget rs6000
*-*-aix
*] \
52 && ![istarget powerpc
*-*-aix
*] \
53 && ![istarget s390
*-*-linux
*] \
54 && ![istarget x86_64
-*-linux
*] } {
58 if { [istarget
*-*-linux
*aout
*] \
59 ||
[istarget
*-*-linux
*oldld
*] } {
66 if { [istarget rs6000
*-*-aix
*] ||
[istarget powerpc
*-*-aix
*] } {
68 # AIX shared libraries
do not seem to support useful features
,
69 # like overriding the shared library function or letting the
70 # shared library refer to objects defined in the main
program. We
71 # avoid testing those features.
72 set SHCFLAG
"-DXCOFF_TEST"
74 # The AIX
3.2.5 loader appears to randomly fail when loading
75 # shared libraries from NSF mounted partitions
, so we avoid
any
76 # potential problems by using a local directory.
77 catch
{exec
/bin
/sh
-c
"echo $$"} pid
78 set tmpdir
/usr
/tmp
/ld.$pid
79 catch
"exec mkdir $tmpdir" exec_status
81 #
On AIX
, we need to explicitly
export the symbols the shared
82 # library is going to provide
, and need.
83 set file
[open $tmpdir
/xcoff.exp w
]
86 puts $file shlib_shlibvar1
87 puts $file shlib_shlibvar2
88 puts $file shlib_shlibcall
89 puts $file shlib_shlibcalled
90 puts $file shlib_checkfunptr1
91 puts $file shlib_getfunptr1
92 puts $file shlib_check
97 proc shared_test
{ progname testname main sh1 sh2 dat
args } {
105 if [llength $
args] { set shldflags
[lindex $
args 0] } else { set shldflags
"" }
107 # Build the shared library.
108 #
On AIX
, we need to use an
export file.
110 if { [istarget rs6000
*-*-aix
*] ||
[istarget powerpc
*-*-aix
*] } {
111 set shared
"-bM:SRE -bE:$tmpdir/xcoff.exp"
113 if {![ld_simple_link $CC $tmpdir
/$progname.so
"$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} {
118 # Link against the shared library. Use
-rpath so that the
119 # dynamic linker can locate the shared library at runtime.
120 #
On AIX
, we must
include /lib in
-rpath
, as otherwise the loader
123 if { [istarget rs6000
*-*-aix
*] ||
[istarget powerpc
*-*-aix
*] } {
124 set rpath
/lib
:$tmpdir
126 if ![ld_simple_link $CC $tmpdir
/$progname
"-Wl,-rpath,$rpath $tmpdir/$main $tmpdir/$progname.so"] {
131 # Run the resulting
program
132 send_log
"$tmpdir/$progname >$tmpdir/$progname.out\n"
133 verbose
"$tmpdir/$progname >$tmpdir/$progname.out"
134 catch
"exec $tmpdir/$progname >$tmpdir/$progname.out" exec_output
135 if ![string match
"" $exec_output] then {
136 send_log
"$exec_output\n"
137 verbose
"$exec_output"
142 send_log
"diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat\n"
143 verbose
"diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat"
144 catch
"exec diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat" exec_output
145 set exec_output
[prune_warnings $exec_output
]
147 if {![string match
"" $exec_output]} then {
148 send_log
"$exec_output\n"
149 verbose
"$exec_output"
157 if [istarget mips
*-*-*] {
160 # Unfortunately
, the gcc
argument is
-fpic and the cc
argument is
161 #
-KPIC. We have to try both.
163 send_log
"$CC $picflag\n"
164 verbose
"$CC $picflag"
165 catch
"exec $CC $picflag" exec_output
166 send_log
"$exec_output\n"
167 verbose
"--" "$exec_output"
168 if { [string match
"*illegal option*" $exec_output] \
169 ||
[string match
"*option ignored*" $exec_output] \
170 ||
[string match
"*unrecognized option*" $exec_output] \
171 ||
[string match
"*passed to ld*" $exec_output] } {
172 if [istarget
*-*-sunos4
*] {
179 verbose
"Using $picflag to compile PIC code"
181 #
Compile the main
program.
182 if ![ld_compile
"$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o] {
183 unresolved
"shared (non PIC)"
186 # The shared library is composed of two files. First
compile them
187 # without using
-fpic. That should work
on an ELF
system,
188 # although it will be less efficient because the dynamic linker
189 # will need to
do more relocation work. However
, note that not
190 # using
-fpic will cause some of the tests to
return different
192 if { ![ld_compile
"$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o]
193 ||
![ld_compile
"$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } {
194 unresolved
"shared (non PIC)"
195 } else { if { [istarget rs6000
*-*-aix
*] ||
[istarget powerpc
*-*-aix
*] } {
196 shared_test shnp
"shared (nonPIC)" mainnp.o sh1np.o sh2np.o xcoff
198 # SunOS non PIC shared libraries don
't permit some cases of
200 setup_xfail "*-*-sunos4*"
201 setup_xfail "ia64-*-linux*"
202 setup_xfail "alpha*-*-linux*"
203 if { ![istarget hppa*64*-*-linux*] } {
204 setup_xfail "hppa*-*-linux*"
206 setup_xfail "x86_64-*-linux*"
207 setup_xfail "s390x-*-linux*"
208 shared_test shnp "shared (non PIC)" mainnp.o sh1np.o sh2np.o shared
210 # Test ELF shared library relocations with a non-zero load
211 # address for the library. Near as I can tell, the R_*_RELATIVE
212 # relocations for various targets are broken in the case where
213 # the load address is not zero (which is the default).
214 setup_xfail "*-*-sunos4*"
215 setup_xfail "*-*-linux*libc1"
216 setup_xfail "powerpc-*-linux*"
217 setup_xfail "ia64-*-linux*"
218 setup_xfail "alpha*-*-linux*"
219 setup_xfail "mips*-*-linux*"
220 if { ![istarget hppa*64*-*-linux*] } {
221 setup_xfail "hppa*-*-linux*"
223 setup_xfail "x86_64-*-linux*"
224 shared_test shnp "shared (non PIC, load offset)" \
225 mainnp.o sh1np.o sh2np.o shared \
226 "-T $srcdir/$subdir/elf-offset.ld"
229 # Now compile the code using -fpic.
231 if { ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o]
232 || ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh2.c $tmpdir/sh2p.o] } {
235 # SunOS can not compare function pointers correctly
236 if [istarget "*-*-sunos4*"] {
237 shared_test shp "shared" mainnp.o sh1p.o sh2p.o sun4
238 } else { if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
239 shared_test shp "shared" mainnp.o sh1p.o sh2p.o xcoff
241 shared_test shp "shared" mainnp.o sh1p.o sh2p.o shared
242 ld_compile "$CC $CFLAGS -DSYMBOLIC_TEST -DXCOFF_TEST $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o
243 ld_compile "$CC $CFLAGS -DSYMBOLIC_TEST -DXCOFF_TEST $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o
244 shared_test shp "shared -Bsymbolic" mainnp.o sh1p.o sh2p.o symbolic "-Bsymbolic"
245 ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o
246 ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o
251 # Now do the same tests again, but this time compile main.c PIC.
252 if ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/main.c $tmpdir/mainp.o] {
253 unresolved "shared (PIC main, non PIC so)"
254 unresolved "shared (PIC main)"
256 if { [file exists $tmpdir/sh1np.o ] && [ file exists $tmpdir/sh2np.o ] } {
257 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
258 shared_test shmpnp "shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o xcoff
260 # SunOS non PIC shared libraries don't
permit some cases of
262 setup_xfail
"*-*-sunos4*"
263 setup_xfail
"ia64-*-linux*"
264 setup_xfail
"alpha*-*-linux*"
265 if { ![istarget hppa
*64*-*-linux
*] } {
266 setup_xfail
"hppa*-*-linux*"
268 setup_xfail
"x86_64-*-linux*"
269 setup_xfail
"s390x-*-linux*"
270 shared_test shmpnp
"shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o shared
273 unresolved
"shared (PIC main, non PIC so)"
276 if { [file
exists $tmpdir
/sh1p.o
] && [ file
exists $tmpdir
/sh2p.o
] } {
277 if { [istarget rs6000
*-*-aix
*] ||
[istarget powerpc
*-*-aix
*] } {
278 shared_test shmpp
"shared (PIC main)" mainp.o sh1p.o sh2p.o xcoff
280 shared_test shmpp
"shared (PIC main)" mainp.o sh1p.o sh2p.o shared
283 unresolved
"shared (PIC main)"
287 if { [istarget rs6000
*-*-aix
*] ||
[istarget powerpc
*-*-aix
*] } {
288 # Remove the temporary directory.
289 catch
"exec rm -rf $tmpdir" exec_status