Commit | Line | Data |
---|---|---|
252b5132 | 1 | # Expect script for ld-shared tests |
9147e853 | 2 | # Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2003 |
a2b64bed | 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. | |
27 | if ![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 |
31 | if { ![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 | 51 | && ![istarget rs6000*-*-aix*] \ |
9147e853 JJ |
52 | && ![istarget powerpc*-*-aix*] \ |
53 | && ![istarget s390*-*-linux*] \ | |
54 | && ![istarget x86_64-*-linux*] } { | |
252b5132 RH |
55 | return |
56 | } | |
57 | ||
99c262f8 ILT |
58 | if { [istarget *-*-linux*aout*] \ |
59 | || [istarget *-*-linux*oldld*] } { | |
252b5132 RH |
60 | return |
61 | } | |
62 | ||
63 | set tmpdir tmpdir | |
64 | set SHCFLAG "" | |
65 | ||
66 | if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
67 | ||
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" | |
73 | ||
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 | |
80 | ||
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] | |
84 | puts $file shlibvar1 | |
85 | puts $file shlibvar2 | |
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 | |
93 | close $file | |
94 | } | |
95 | ||
96 | # The test procedure. | |
97 | proc shared_test { progname testname main sh1 sh2 dat args } { | |
b765d4e3 | 98 | global CC |
252b5132 RH |
99 | global srcdir |
100 | global subdir | |
101 | global exec_output | |
102 | global host_triplet | |
103 | global tmpdir | |
104 | ||
105 | if [llength $args] { set shldflags [lindex $args 0] } else { set shldflags "" } | |
106 | ||
107 | # Build the shared library. | |
108 | # On AIX, we need to use an export file. | |
109 | set shared -shared | |
110 | if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
111 | set shared "-bM:SRE -bE:$tmpdir/xcoff.exp" | |
112 | } | |
b765d4e3 | 113 | if {![ld_simple_link $CC $tmpdir/$progname.so "$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} { |
252b5132 RH |
114 | fail "$testname" |
115 | return | |
116 | } | |
117 | ||
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 | |
121 | # can not find -lc. | |
122 | set rpath $tmpdir | |
123 | if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
124 | set rpath /lib:$tmpdir | |
125 | } | |
b765d4e3 | 126 | if ![ld_simple_link $CC $tmpdir/$progname "-Wl,-rpath,$rpath $tmpdir/$main $tmpdir/$progname.so"] { |
252b5132 RH |
127 | fail "$testname" |
128 | return | |
129 | } | |
130 | ||
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" | |
138 | fail "$testname" | |
139 | return | |
140 | } | |
141 | ||
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] | |
146 | ||
147 | if {![string match "" $exec_output]} then { | |
148 | send_log "$exec_output\n" | |
149 | verbose "$exec_output" | |
150 | fail "$testname" | |
151 | return | |
152 | } | |
153 | ||
154 | pass "$testname" | |
155 | } | |
156 | ||
157 | if [istarget mips*-*-*] { | |
158 | set picflag "" | |
159 | } else { | |
160 | # Unfortunately, the gcc argument is -fpic and the cc argument is | |
161 | # -KPIC. We have to try both. | |
162 | set picflag "-fpic" | |
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*] { | |
173 | set picflag "-pic" | |
174 | } else { | |
175 | set picflag "-KPIC" | |
176 | } | |
177 | } | |
178 | } | |
179 | verbose "Using $picflag to compile PIC code" | |
180 | ||
181 | # Compile the main program. | |
182 | if ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o] { | |
183 | unresolved "shared (non PIC)" | |
184 | unresolved "shared" | |
185 | } else { | |
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 | |
191 | # results. | |
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 | |
197 | } else { | |
198 | # SunOS non PIC shared libraries don't permit some cases of | |
199 | # overriding. | |
200 | setup_xfail "*-*-sunos4*" | |
ad995491 | 201 | setup_xfail "ia64-*-linux*" |
212a6b8e | 202 | setup_xfail "alpha*-*-linux*" |
c0d48c0b DA |
203 | if { ![istarget hppa*64*-*-linux*] } { |
204 | setup_xfail "hppa*-*-linux*" | |
205 | } | |
4dc570c2 JJ |
206 | if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainnp.o] } { |
207 | setup_xfail "sparc*-*-linux*" | |
208 | } | |
9147e853 | 209 | setup_xfail "x86_64-*-linux*" |
4648dfcf | 210 | setup_xfail "s390x-*-linux*" |
252b5132 RH |
211 | shared_test shnp "shared (non PIC)" mainnp.o sh1np.o sh2np.o shared |
212 | ||
213 | # Test ELF shared library relocations with a non-zero load | |
214 | # address for the library. Near as I can tell, the R_*_RELATIVE | |
215 | # relocations for various targets are broken in the case where | |
216 | # the load address is not zero (which is the default). | |
217 | setup_xfail "*-*-sunos4*" | |
b7be1db6 | 218 | setup_xfail "*-*-linux*libc1" |
d1d8dddf | 219 | setup_xfail "powerpc-*-linux*" |
ad995491 | 220 | setup_xfail "ia64-*-linux*" |
212a6b8e | 221 | setup_xfail "alpha*-*-linux*" |
66517a2f | 222 | setup_xfail "mips*-*-linux*" |
c0d48c0b DA |
223 | if { ![istarget hppa*64*-*-linux*] } { |
224 | setup_xfail "hppa*-*-linux*" | |
225 | } | |
4dc570c2 JJ |
226 | if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainnp.o] } { |
227 | setup_xfail "sparc*-*-linux*" | |
228 | } | |
9147e853 | 229 | setup_xfail "x86_64-*-linux*" |
8c37241b | 230 | setup_xfail "s390x-*-linux*" |
252b5132 RH |
231 | shared_test shnp "shared (non PIC, load offset)" \ |
232 | mainnp.o sh1np.o sh2np.o shared \ | |
233 | "-T $srcdir/$subdir/elf-offset.ld" | |
234 | } } | |
235 | ||
236 | # Now compile the code using -fpic. | |
237 | ||
238 | if { ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o] | |
239 | || ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh2.c $tmpdir/sh2p.o] } { | |
240 | unresolved "shared" | |
241 | } else { | |
242 | # SunOS can not compare function pointers correctly | |
243 | if [istarget "*-*-sunos4*"] { | |
244 | shared_test shp "shared" mainnp.o sh1p.o sh2p.o sun4 | |
245 | } else { if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
246 | shared_test shp "shared" mainnp.o sh1p.o sh2p.o xcoff | |
247 | } else { | |
248 | shared_test shp "shared" mainnp.o sh1p.o sh2p.o shared | |
66517a2f L |
249 | ld_compile "$CC $CFLAGS -DSYMBOLIC_TEST -DXCOFF_TEST $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o |
250 | ld_compile "$CC $CFLAGS -DSYMBOLIC_TEST -DXCOFF_TEST $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o | |
f0f077e5 L |
251 | shared_test shp "shared -Bsymbolic" mainnp.o sh1p.o sh2p.o symbolic "-Bsymbolic" |
252 | ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o | |
253 | ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o | |
252b5132 RH |
254 | } } |
255 | } | |
256 | } | |
257 | ||
258 | # Now do the same tests again, but this time compile main.c PIC. | |
259 | if ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/main.c $tmpdir/mainp.o] { | |
260 | unresolved "shared (PIC main, non PIC so)" | |
261 | unresolved "shared (PIC main)" | |
262 | } else { | |
263 | if { [file exists $tmpdir/sh1np.o ] && [ file exists $tmpdir/sh2np.o ] } { | |
264 | if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
265 | shared_test shmpnp "shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o xcoff | |
266 | } else { | |
267 | # SunOS non PIC shared libraries don't permit some cases of | |
268 | # overriding. | |
269 | setup_xfail "*-*-sunos4*" | |
ad995491 | 270 | setup_xfail "ia64-*-linux*" |
212a6b8e | 271 | setup_xfail "alpha*-*-linux*" |
c0d48c0b DA |
272 | if { ![istarget hppa*64*-*-linux*] } { |
273 | setup_xfail "hppa*-*-linux*" | |
274 | } | |
4dc570c2 JJ |
275 | if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainp.o] } { |
276 | setup_xfail "sparc*-*-linux*" | |
277 | } | |
9147e853 | 278 | setup_xfail "x86_64-*-linux*" |
4648dfcf | 279 | setup_xfail "s390x-*-linux*" |
252b5132 RH |
280 | shared_test shmpnp "shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o shared |
281 | } | |
282 | } else { | |
283 | unresolved "shared (PIC main, non PIC so)" | |
284 | } | |
285 | ||
286 | if { [file exists $tmpdir/sh1p.o ] && [ file exists $tmpdir/sh2p.o ] } { | |
287 | if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
288 | shared_test shmpp "shared (PIC main)" mainp.o sh1p.o sh2p.o xcoff | |
289 | } else { | |
290 | shared_test shmpp "shared (PIC main)" mainp.o sh1p.o sh2p.o shared | |
291 | } | |
292 | } else { | |
293 | unresolved "shared (PIC main)" | |
294 | } | |
295 | } | |
296 | ||
297 | if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
298 | # Remove the temporary directory. | |
299 | catch "exec rm -rf $tmpdir" exec_status | |
300 | } |