1 # Expect script
for ld-shared tests
2 # Copyright
1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 # Free Software Foundation
, Inc.
6 # This file is free software
; you can redistribute it and
/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation
; either version
2 of the License
, or
9 #
(at your option
) any later version.
11 # This
program is distributed in the hope that it will be useful
,
12 # but WITHOUT
ANY WARRANTY
; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License
for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this
program; if not
, write to the Free Software
18 # Foundation
, Inc.
, 51 Franklin Street
- Fifth Floor
, Boston
, MA
02110-1301, USA.
20 # Written by Ian Lance Taylor
(ian@cygnus.com
)
23 # Make sure that
ld can generate ELF shared libraries.
24 # Note that linking against ELF shared libraries is tested by the
27 # This test can only be run
if ld generates native executables.
28 if ![isnative
] then {return}
30 # This test can only be run
on a couple of ELF platforms.
31 # Square bracket expressions seem to confuse istarget.
32 if { ![istarget hppa
*64*-*-hpux
*] \
33 && ![istarget hppa
*-*-linux
*] \
34 && ![istarget i?
86-*-sysv4
*] \
35 && ![istarget i?
86-*-unixware
] \
36 && ![istarget i?
86-*-elf
*] \
37 && ![istarget i?
86-*-linux
*] \
38 && ![istarget ia64
-*-elf
*] \
39 && ![istarget ia64
-*-linux
*] \
40 && ![istarget m68k
-*-linux
*] \
41 && ![istarget mips
*-*-irix5
*] \
42 && ![istarget mips
*-*-linux
*] \
43 && ![istarget powerpc
-*-elf
*] \
44 && ![istarget powerpc
-*-linux
*] \
45 && ![istarget powerpc
-*-sysv4
*] \
46 && ![istarget sparc
*-*-elf
] \
47 && ![istarget sparc
*-*-solaris2
*] \
48 && ![istarget sparc
*-*-sunos4
*] \
49 && ![istarget sparc
*-*-linux
*] \
50 && ![istarget arm
*-*-linux
*] \
51 && ![istarget alpha
*-*-linux
*] \
52 && ![istarget rs6000
*-*-aix
*] \
53 && ![istarget powerpc
*-*-aix
*] \
54 && ![istarget s390
*-*-linux
*] \
55 && ![istarget x86_64
-*-linux
*] } {
59 if { [istarget
*-*-linux
*aout
*] \
60 ||
[istarget
*-*-linux
*oldld
*] } {
67 if { [istarget rs6000
*-*-aix
*] ||
[istarget powerpc
*-*-aix
*] } {
69 # AIX shared libraries
do not seem to support useful features
,
70 # like overriding the shared library function or letting the
71 # shared library refer to objects defined in the main
program. We
72 # avoid testing those features.
73 set SHCFLAG
"-DXCOFF_TEST"
75 # The AIX
3.2.5 loader appears to randomly fail when loading
76 # shared libraries from NSF mounted partitions
, so we avoid
any
77 # potential problems by using a local directory.
78 catch
{exec
/bin
/sh
-c
"echo $$"} pid
79 set tmpdir
/usr
/tmp
/ld.$pid
80 catch
"exec mkdir $tmpdir" exec_status
82 #
On AIX
, we need to explicitly
export the symbols the shared
83 # library is going to provide
, and need.
84 set file
[open $tmpdir
/xcoff.exp w
]
87 puts $file shlib_shlibvar1
88 puts $file shlib_shlibvar2
89 puts $file shlib_shlibcall
90 puts $file shlib_shlibcalled
91 puts $file shlib_checkfunptr1
92 puts $file shlib_getfunptr1
93 puts $file shlib_check
98 proc shared_test
{ progname testname main sh1 sh2 dat
args } {
106 if [llength $
args] { set shldflags
[lindex $
args 0] } else { set shldflags
"" }
108 # Build the shared library.
109 #
On AIX
, we need to use an
export file.
111 if { [istarget rs6000
*-*-aix
*] ||
[istarget powerpc
*-*-aix
*] } {
112 set shared
"-bM:SRE -bE:$tmpdir/xcoff.exp"
114 if {![ld_simple_link $CC $tmpdir
/$progname.so
"$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} {
119 # Link against the shared library. Use
-rpath so that the
120 # dynamic linker can locate the shared library at runtime.
121 #
On AIX
, we must
include /lib in
-rpath
, as otherwise the loader
124 if { [istarget rs6000
*-*-aix
*] ||
[istarget powerpc
*-*-aix
*] } {
125 set rpath
/lib
:$tmpdir
127 if ![ld_simple_link $CC $tmpdir
/$progname
"-Wl,-rpath,$rpath $tmpdir/$main $tmpdir/$progname.so"] {
132 # Run the resulting
program
133 send_log
"$tmpdir/$progname >$tmpdir/$progname.out\n"
134 verbose
"$tmpdir/$progname >$tmpdir/$progname.out"
135 catch
"exec $tmpdir/$progname >$tmpdir/$progname.out" exec_output
136 if ![string match
"" $exec_output] then {
137 send_log
"$exec_output\n"
138 verbose
"$exec_output"
143 send_log
"diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat\n"
144 verbose
"diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat"
145 catch
"exec diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat" exec_output
146 set exec_output
[prune_warnings $exec_output
]
148 if {![string match
"" $exec_output]} then {
149 send_log
"$exec_output\n"
150 verbose
"$exec_output"
158 if [istarget mips
*-*-*] {
161 # Unfortunately
, the gcc
argument is
-fpic and the cc
argument is
162 #
-KPIC. We have to try both.
164 send_log
"$CC $picflag\n"
165 verbose
"$CC $picflag"
166 catch
"exec $CC $picflag" exec_output
167 send_log
"$exec_output\n"
168 verbose
"--" "$exec_output"
169 if { [string match
"*illegal option*" $exec_output] \
170 ||
[string match
"*option ignored*" $exec_output] \
171 ||
[string match
"*unrecognized option*" $exec_output] \
172 ||
[string match
"*passed to ld*" $exec_output] } {
173 if [istarget
*-*-sunos4
*] {
180 verbose
"Using $picflag to compile PIC code"
182 #
Compile the main
program.
183 if ![ld_compile
"$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o] {
184 unresolved
"shared (non PIC)"
187 # The shared library is composed of two files. First
compile them
188 # without using
-fpic. That should work
on an ELF
system,
189 # although it will be less efficient because the dynamic linker
190 # will need to
do more relocation work. However
, note that not
191 # using
-fpic will cause some of the tests to
return different
193 if { ![ld_compile
"$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o]
194 ||
![ld_compile
"$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } {
195 unresolved
"shared (non PIC)"
196 } else { if { [istarget rs6000
*-*-aix
*] ||
[istarget powerpc
*-*-aix
*] } {
197 shared_test shnp
"shared (nonPIC)" mainnp.o sh1np.o sh2np.o xcoff
199 # SunOS non PIC shared libraries don
't permit some cases of
201 setup_xfail "*-*-sunos4*"
202 setup_xfail "ia64-*-linux*"
203 setup_xfail "alpha*-*-linux*"
204 if { ![istarget hppa*64*-*-linux*] } {
205 setup_xfail "hppa*-*-linux*"
207 if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainnp.o] } {
208 setup_xfail "sparc*-*-linux*"
210 setup_xfail "x86_64-*-linux*"
211 setup_xfail "s390x-*-linux*"
212 shared_test shnp "shared (non PIC)" mainnp.o sh1np.o sh2np.o shared
214 # Test ELF shared library relocations with a non-zero load
215 # address for the library. Near as I can tell, the R_*_RELATIVE
216 # relocations for various targets are broken in the case where
217 # the load address is not zero (which is the default).
218 setup_xfail "*-*-sunos4*"
219 setup_xfail "*-*-linux*libc1"
220 setup_xfail "powerpc-*-linux*"
221 setup_xfail "ia64-*-linux*"
222 setup_xfail "alpha*-*-linux*"
223 setup_xfail "mips*-*-linux*"
224 if { ![istarget hppa*64*-*-linux*] } {
225 setup_xfail "hppa*-*-linux*"
227 if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainnp.o] } {
228 setup_xfail "sparc*-*-linux*"
230 setup_xfail "x86_64-*-linux*"
231 setup_xfail "s390x-*-linux*"
232 shared_test shnp "shared (non PIC, load offset)" \
233 mainnp.o sh1np.o sh2np.o shared \
234 "-T $srcdir/$subdir/elf-offset.ld"
237 # Now compile the code using -fpic.
239 if { ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o]
240 || ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh2.c $tmpdir/sh2p.o] } {
243 # SunOS can not compare function pointers correctly
244 if [istarget "*-*-sunos4*"] {
245 shared_test shp "shared" mainnp.o sh1p.o sh2p.o sun4
246 } else { if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
247 shared_test shp "shared" mainnp.o sh1p.o sh2p.o xcoff
249 shared_test shp "shared" mainnp.o sh1p.o sh2p.o shared
250 ld_compile "$CC $CFLAGS -DSYMBOLIC_TEST -DXCOFF_TEST $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o
251 ld_compile "$CC $CFLAGS -DSYMBOLIC_TEST -DXCOFF_TEST $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o
252 shared_test shp "shared -Bsymbolic" mainnp.o sh1p.o sh2p.o symbolic "-Bsymbolic"
253 ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o
254 ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o
259 # Now do the same tests again, but this time compile main.c PIC.
260 if ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/main.c $tmpdir/mainp.o] {
261 unresolved "shared (PIC main, non PIC so)"
262 unresolved "shared (PIC main)"
264 if { [file exists $tmpdir/sh1np.o ] && [ file exists $tmpdir/sh2np.o ] } {
265 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
266 shared_test shmpnp "shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o xcoff
268 # SunOS non PIC shared libraries don't
permit some cases of
270 setup_xfail
"*-*-sunos4*"
271 setup_xfail
"ia64-*-linux*"
272 setup_xfail
"alpha*-*-linux*"
273 if { ![istarget hppa
*64*-*-linux
*] } {
274 setup_xfail
"hppa*-*-linux*"
276 if { [istarget sparc
*-*-linux
*] && [is_elf64 $tmpdir
/mainp.o
] } {
277 setup_xfail
"sparc*-*-linux*"
279 setup_xfail
"x86_64-*-linux*"
280 setup_xfail
"s390x-*-linux*"
281 shared_test shmpnp
"shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o shared
284 unresolved
"shared (PIC main, non PIC so)"
287 if { [file
exists $tmpdir
/sh1p.o
] && [ file
exists $tmpdir
/sh2p.o
] } {
288 if { [istarget rs6000
*-*-aix
*] ||
[istarget powerpc
*-*-aix
*] } {
289 shared_test shmpp
"shared (PIC main)" mainp.o sh1p.o sh2p.o xcoff
291 shared_test shmpp
"shared (PIC main)" mainp.o sh1p.o sh2p.o shared
294 unresolved
"shared (PIC main)"
298 if { [istarget rs6000
*-*-aix
*] ||
[istarget powerpc
*-*-aix
*] } {
299 # Remove the temporary directory.
300 catch
"exec rm -rf $tmpdir" exec_status