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