1 # Expect script
for ld-shared tests
2 # Copyright
(C
) 1994, 1995, 1996, 1997, 1998 Free Software Foundation
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.
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.
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.
18 # Written by Ian Lance Taylor
(ian@cygnus.com
)
21 # Make sure that
ld can generate ELF shared libraries.
22 # Note that linking against ELF shared libraries is tested by the
25 # This test can only be run
if ld generates native executables.
26 if ![isnative
] then {return}
28 # This test can only be run
on a couple of ELF platforms.
29 # Square bracket expressions seem to confuse istarget.
30 if { ![istarget i386
-*-sysv4
*] \
31 && ![istarget i486
-*-sysv4
*] \
32 && ![istarget i586
-*-sysv4
*] \
33 && ![istarget i386
-*-unixware
] \
34 && ![istarget i486
-*-unixware
] \
35 && ![istarget i586
-*-unixware
] \
36 && ![istarget i386
-*-elf
*] \
37 && ![istarget i486
-*-elf
*] \
38 && ![istarget i586
-*-elf
*] \
39 && ![istarget i386
-*-linux
*] \
40 && ![istarget i486
-*-linux
*] \
41 && ![istarget i586
-*-linux
*] \
42 && ![istarget m68k
-*-linux
*] \
43 && ![istarget mips
*-*-irix5
*] \
44 && ![istarget powerpc
-*-elf
*] \
45 && ![istarget powerpc
-*-linux
*] \
46 && ![istarget powerpc
-*-sysv4
*] \
47 && ![istarget sparc
*-*-elf
] \
48 && ![istarget sparc
*-*-solaris2
*] \
49 && ![istarget sparc
*-*-sunos4
*] \
50 && ![istarget rs6000
*-*-aix
*] \
51 && ![istarget powerpc
*-*-aix
*] } {
55 if { [istarget i386
-*-linuxaout
*] \
56 ||
[istarget i486
-*-linuxaout
*] \
57 ||
[istarget i586
-*-linuxaout
*] \
58 ||
[istarget i386
-*-linuxoldld
*] \
59 ||
[istarget i486
-*-linuxoldld
*] \
60 ||
[istarget i586
-*-linuxoldld
*] \
61 ||
[istarget m68k
-*-linuxaout
*] } {
68 if { [istarget rs6000
*-*-aix
*] ||
[istarget powerpc
*-*-aix
*] } {
70 # AIX shared libraries
do not seem to support useful features
,
71 # like overriding the shared library function or letting the
72 # shared library refer to objects defined in the main
program. We
73 # avoid testing those features.
74 set SHCFLAG
"-DXCOFF_TEST"
76 # The AIX
3.2.5 loader appears to randomly fail when loading
77 # shared libraries from NSF mounted partitions
, so we avoid
any
78 # potential problems by using a local directory.
79 catch
{exec
/bin
/sh
-c
"echo $$"} pid
80 set tmpdir
/usr
/tmp
/ld.$pid
81 catch
"exec mkdir $tmpdir" exec_status
83 #
On AIX
, we need to explicitly
export the symbols the shared
84 # library is going to provide
, and need.
85 set file
[open $tmpdir
/xcoff.exp w
]
88 puts $file shlib_shlibvar1
89 puts $file shlib_shlibvar2
90 puts $file shlib_shlibcall
91 puts $file shlib_shlibcalled
92 puts $file shlib_checkfunptr1
93 puts $file shlib_getfunptr1
94 puts $file shlib_check
99 proc shared_test
{ progname testname main sh1 sh2 dat
args } {
107 if [llength $
args] { set shldflags
[lindex $
args 0] } else { set shldflags
"" }
109 # Build the shared library.
110 #
On AIX
, we need to use an
export file.
112 if { [istarget rs6000
*-*-aix
*] ||
[istarget powerpc
*-*-aix
*] } {
113 set shared
"-bM:SRE -bE:$tmpdir/xcoff.exp"
115 if {![ld_simple_link $
ld $tmpdir
/$progname.so
"$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} {
120 # Link against the shared library. Use
-rpath so that the
121 # dynamic linker can locate the shared library at runtime.
122 #
On AIX
, we must
include /lib in
-rpath
, as otherwise the loader
125 if { [istarget rs6000
*-*-aix
*] ||
[istarget powerpc
*-*-aix
*] } {
126 set rpath
/lib
:$tmpdir
128 if ![ld_link $
ld $tmpdir
/$progname
"-rpath $rpath $tmpdir/$main $tmpdir/$progname.so"] {
133 # Run the resulting
program
134 send_log
"$tmpdir/$progname >$tmpdir/$progname.out\n"
135 verbose
"$tmpdir/$progname >$tmpdir/$progname.out"
136 catch
"exec $tmpdir/$progname >$tmpdir/$progname.out" exec_output
137 if ![string match
"" $exec_output] then {
138 send_log
"$exec_output\n"
139 verbose
"$exec_output"
144 send_log
"diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat\n"
145 verbose
"diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat"
146 catch
"exec diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat" exec_output
147 set exec_output
[prune_warnings $exec_output
]
149 if {![string match
"" $exec_output]} then {
150 send_log
"$exec_output\n"
151 verbose
"$exec_output"
159 if [istarget mips
*-*-*] {
162 # Unfortunately
, the gcc
argument is
-fpic and the cc
argument is
163 #
-KPIC. We have to try both.
165 send_log
"$CC $picflag\n"
166 verbose
"$CC $picflag"
167 catch
"exec $CC $picflag" exec_output
168 send_log
"$exec_output\n"
169 verbose
"--" "$exec_output"
170 if { [string match
"*illegal option*" $exec_output] \
171 ||
[string match
"*option ignored*" $exec_output] \
172 ||
[string match
"*unrecognized option*" $exec_output] \
173 ||
[string match
"*passed to ld*" $exec_output] } {
174 if [istarget
*-*-sunos4
*] {
181 verbose
"Using $picflag to compile PIC code"
183 #
Compile the main
program.
184 if ![ld_compile
"$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o] {
185 unresolved
"shared (non PIC)"
188 # The shared library is composed of two files. First
compile them
189 # without using
-fpic. That should work
on an ELF
system,
190 # although it will be less efficient because the dynamic linker
191 # will need to
do more relocation work. However
, note that not
192 # using
-fpic will cause some of the tests to
return different
194 if { ![ld_compile
"$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o]
195 ||
![ld_compile
"$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } {
196 unresolved
"shared (non PIC)"
197 } else { if { [istarget rs6000
*-*-aix
*] ||
[istarget powerpc
*-*-aix
*] } {
198 shared_test shnp
"shared (nonPIC)" mainnp.o sh1np.o sh2np.o xcoff
200 # SunOS non PIC shared libraries don
't permit some cases of
202 setup_xfail "*-*-sunos4*"
203 shared_test shnp "shared (non PIC)" mainnp.o sh1np.o sh2np.o shared
205 # Test ELF shared library relocations with a non-zero load
206 # address for the library. Near as I can tell, the R_*_RELATIVE
207 # relocations for various targets are broken in the case where
208 # the load address is not zero (which is the default).
209 setup_xfail "*-*-sunos4*"
210 shared_test shnp "shared (non PIC, load offset)" \
211 mainnp.o sh1np.o sh2np.o shared \
212 "-T $srcdir/$subdir/elf-offset.ld"
215 # Now compile the code using -fpic.
217 if { ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o]
218 || ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh2.c $tmpdir/sh2p.o] } {
221 # SunOS can not compare function pointers correctly
222 if [istarget "*-*-sunos4*"] {
223 shared_test shp "shared" mainnp.o sh1p.o sh2p.o sun4
224 } else { if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
225 shared_test shp "shared" mainnp.o sh1p.o sh2p.o xcoff
227 shared_test shp "shared" mainnp.o sh1p.o sh2p.o shared
232 # Now do the same tests again, but this time compile main.c PIC.
233 if ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/main.c $tmpdir/mainp.o] {
234 unresolved "shared (PIC main, non PIC so)"
235 unresolved "shared (PIC main)"
237 if { [file exists $tmpdir/sh1np.o ] && [ file exists $tmpdir/sh2np.o ] } {
238 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
239 shared_test shmpnp "shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o xcoff
241 # SunOS non PIC shared libraries don't
permit some cases of
243 setup_xfail
"*-*-sunos4*"
244 shared_test shmpnp
"shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o shared
247 unresolved
"shared (PIC main, non PIC so)"
250 if { [file
exists $tmpdir
/sh1p.o
] && [ file
exists $tmpdir
/sh2p.o
] } {
251 if { [istarget rs6000
*-*-aix
*] ||
[istarget powerpc
*-*-aix
*] } {
252 shared_test shmpp
"shared (PIC main)" mainp.o sh1p.o sh2p.o xcoff
254 shared_test shmpp
"shared (PIC main)" mainp.o sh1p.o sh2p.o shared
257 unresolved
"shared (PIC main)"
261 if { [istarget rs6000
*-*-aix
*] ||
[istarget powerpc
*-*-aix
*] } {
262 # Remove the temporary directory.
263 catch
"exec rm -rf $tmpdir" exec_status