* ld-elfvers/vers.exp: Enable test for powerpc64.
[binutils.git] / ld / testsuite / ld-shared / shared.exp
blob521b9255722ffbd432e69bf284c05e272bd60e18
1 # Expect script for ld-shared tests
2 # Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 # 2004, 2005, 2007, 2008, 2009
4 # Free Software Foundation, Inc.
6 # This file is part of the GNU Binutils.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 # MA 02110-1301, USA.
23 # Written by Ian Lance Taylor (ian@cygnus.com)
26 # Make sure that ld can generate ELF shared libraries.
27 # Note that linking against ELF shared libraries is tested by the
28 # bootstrap test.
30 # This test can only be run if ld generates native executables.
31 if ![isnative] then {return}
33 # This test can only be run on a couple of ELF platforms.
34 # Square bracket expressions seem to confuse istarget.
35 if { ![istarget hppa*64*-*-hpux*] \
36 && ![istarget hppa*-*-linux*] \
37 && ![istarget i?86-*-sysv4*] \
38 && ![istarget i?86-*-unixware] \
39 && ![istarget i?86-*-elf*] \
40 && ![istarget i?86-*-linux*] \
41 && ![istarget ia64-*-elf*] \
42 && ![istarget ia64-*-linux*] \
43 && ![istarget m68k-*-linux*] \
44 && ![istarget mips*-*-irix5*] \
45 && ![istarget mips*-*-linux*] \
46 && ![istarget powerpc*-*-elf*] \
47 && ![istarget powerpc*-*-linux*] \
48 && ![istarget powerpc*-*-sysv4*] \
49 && ![istarget sparc*-*-elf] \
50 && ![istarget sparc*-*-solaris2*] \
51 && ![istarget sparc*-*-sunos4*] \
52 && ![istarget sparc*-*-linux*] \
53 && ![istarget arm*-*-linux*] \
54 && ![istarget alpha*-*-linux*] \
55 && ![istarget rs6000*-*-aix*] \
56 && ![istarget powerpc*-*-aix*] \
57 && ![istarget s390*-*-linux*] \
58 && ![istarget x86_64-*-linux*] } {
59 return
62 if { [istarget *-*-linux*aout*] \
63 || [istarget *-*-linux*oldld*] } {
64 return
67 set tmpdir tmpdir
68 set SHCFLAG ""
69 set shared_needs_pic "no"
71 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
73 # AIX shared libraries do not seem to support useful features,
74 # like overriding the shared library function or letting the
75 # shared library refer to objects defined in the main program. We
76 # avoid testing those features.
77 set SHCFLAG "-DXCOFF_TEST"
79 # The AIX 3.2.5 loader appears to randomly fail when loading
80 # shared libraries from NSF mounted partitions, so we avoid any
81 # potential problems by using a local directory.
82 catch {exec /bin/sh -c "echo $$"} pid
83 set tmpdir /usr/tmp/ld.$pid
84 catch "exec mkdir $tmpdir" exec_status
86 # On AIX, we need to explicitly export the symbols the shared
87 # library is going to provide, and need.
88 set file [open $tmpdir/xcoff.exp w]
89 puts $file shlibvar1
90 puts $file shlibvar2
91 puts $file shlib_shlibvar1
92 puts $file shlib_shlibvar2
93 puts $file shlib_shlibcall
94 puts $file shlib_shlibcalled
95 puts $file shlib_checkfunptr1
96 puts $file shlib_getfunptr1
97 puts $file shlib_check
98 close $file
101 if [istarget arm*-*-linux*] {
102 # On ARM section anchors can change the symbol pre-emptability for
103 # non-PIC shared libraries, causing these tests to fail. Turn section
104 # anchors off.
105 set SHCFLAG "-fno-section-anchors"
107 # On targets that have MOVW the compiler will emit relocations which
108 # the linker doesn't support when compiling -shared without -fpic. The
109 # test to find out whether we want to XFAIL the non-PIC tests requires
110 # a compile - so we pre-calculate it here. We also note that this can
111 # only affect arm*-*-*eabi targets as the old ABI doesn't support v7.
112 if [istarget arm*-*-*eabi] {
113 set file [open $tmpdir/movw-detect.c w]
114 puts $file "void foo(void) { __asm (\"movw r0, #0\"); }"
115 close $file
116 if [run_host_cmd_yesno "$CC" "$CFLAGS -c $tmpdir/movw-detect.c -o $tmpdir/movw-detect.o"] {
117 set shared_needs_pic "yes"
122 # The test procedure.
123 proc shared_test { progname testname main sh1 sh2 dat args } {
124 global CC
125 global srcdir
126 global subdir
127 global exec_output
128 global host_triplet
129 global tmpdir
131 if [llength $args] { set shldflags [lindex $args 0] } else { set shldflags "" }
133 # Build the shared library.
134 # On AIX, we need to use an export file.
135 set shared -shared
136 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
137 set shared "-bM:SRE -bE:$tmpdir/xcoff.exp"
139 if {![ld_simple_link $CC $tmpdir/$progname.so "$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} {
140 fail "$testname"
141 return
144 # Link against the shared library. Use -rpath so that the
145 # dynamic linker can locate the shared library at runtime.
146 # On AIX, we must include /lib in -rpath, as otherwise the loader
147 # can not find -lc.
148 set rpath $tmpdir
149 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
150 set rpath /lib:$tmpdir
152 if ![ld_simple_link $CC $tmpdir/$progname "-Wl,-rpath,$rpath $tmpdir/$main $tmpdir/$progname.so"] {
153 fail "$testname"
154 return
157 # Run the resulting program
158 send_log "$tmpdir/$progname >$tmpdir/$progname.out\n"
159 verbose "$tmpdir/$progname >$tmpdir/$progname.out"
160 catch "exec $tmpdir/$progname >$tmpdir/$progname.out" exec_output
161 if ![string match "" $exec_output] then {
162 send_log "$exec_output\n"
163 verbose "$exec_output"
164 fail "$testname"
165 return
168 send_log "diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat\n"
169 verbose "diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat"
170 catch "exec diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat" exec_output
171 set exec_output [prune_warnings $exec_output]
173 if {![string match "" $exec_output]} then {
174 send_log "$exec_output\n"
175 verbose "$exec_output"
176 fail "$testname"
177 return
180 pass "$testname"
183 if [istarget mips*-*-*] {
184 set picflag ""
185 } else {
186 # Unfortunately, the gcc argument is -fpic and the cc argument is
187 # -KPIC. We have to try both.
188 set picflag "-fpic"
189 send_log "$CC $picflag\n"
190 verbose "$CC $picflag"
191 catch "exec $CC $picflag" exec_output
192 send_log "$exec_output\n"
193 verbose "--" "$exec_output"
194 if { [string match "*illegal option*" $exec_output] \
195 || [string match "*option ignored*" $exec_output] \
196 || [string match "*unrecognized option*" $exec_output] \
197 || [string match "*passed to ld*" $exec_output] } {
198 if [istarget *-*-sunos4*] {
199 set picflag "-pic"
200 } else {
201 set picflag "-KPIC"
205 verbose "Using $picflag to compile PIC code"
207 # Compile the main program.
208 if ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o] {
209 unresolved "shared (non PIC)"
210 unresolved "shared"
211 } else {
212 # The shared library is composed of two files. First compile them
213 # without using -fpic. That should work on an ELF system,
214 # although it will be less efficient because the dynamic linker
215 # will need to do more relocation work. However, note that not
216 # using -fpic will cause some of the tests to return different
217 # results.
218 if { ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o]
219 || ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } {
220 unresolved "shared (non PIC)"
221 } else { if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
222 shared_test shnp "shared (nonPIC)" mainnp.o sh1np.o sh2np.o xcoff
223 } else {
224 # SunOS non PIC shared libraries don't permit some cases of
225 # overriding.
226 setup_xfail "*-*-sunos4*"
227 setup_xfail "ia64-*-linux*"
228 setup_xfail "alpha*-*-linux*"
229 setup_xfail "powerpc64*-*-*"
230 if { ![istarget hppa*64*-*-linux*] } {
231 setup_xfail "hppa*-*-linux*"
233 if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainnp.o] } {
234 setup_xfail "sparc*-*-linux*"
236 setup_xfail "x86_64-*-linux*"
237 setup_xfail "s390x-*-linux*"
238 if [ string match $shared_needs_pic "yes" ] {
239 setup_xfail "arm*-*-linux*"
241 shared_test shnp "shared (non PIC)" mainnp.o sh1np.o sh2np.o shared
243 # Test ELF shared library relocations with a non-zero load
244 # address for the library. Near as I can tell, the R_*_RELATIVE
245 # relocations for various targets are broken in the case where
246 # the load address is not zero (which is the default).
247 setup_xfail "*-*-sunos4*"
248 setup_xfail "*-*-linux*libc1"
249 setup_xfail "powerpc*-*-linux*"
250 setup_xfail "ia64-*-linux*"
251 setup_xfail "alpha*-*-linux*"
252 setup_xfail "mips*-*-linux*"
253 if { ![istarget hppa*64*-*-linux*] } {
254 setup_xfail "hppa*-*-linux*"
256 if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainnp.o] } {
257 setup_xfail "sparc*-*-linux*"
259 setup_xfail "x86_64-*-linux*"
260 setup_xfail "s390x-*-linux*"
261 if [ string match $shared_needs_pic "yes" ] {
262 setup_xfail "arm*-*-linux*"
264 shared_test shnp "shared (non PIC, load offset)" \
265 mainnp.o sh1np.o sh2np.o shared \
266 "-T $srcdir/$subdir/elf-offset.ld"
269 # Now compile the code using -fpic.
271 if { ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o]
272 || ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh2.c $tmpdir/sh2p.o] } {
273 unresolved "shared"
274 } else {
275 # SunOS can not compare function pointers correctly
276 if [istarget "*-*-sunos4*"] {
277 shared_test shp "shared" mainnp.o sh1p.o sh2p.o sun4
278 } else { if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
279 shared_test shp "shared" mainnp.o sh1p.o sh2p.o xcoff
280 } else {
281 shared_test shp "shared" mainnp.o sh1p.o sh2p.o shared
282 ld_compile "$CC $CFLAGS -DSYMBOLIC_TEST -DXCOFF_TEST $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o
283 ld_compile "$CC $CFLAGS -DSYMBOLIC_TEST -DXCOFF_TEST $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o
284 shared_test shp "shared -Bsymbolic" mainnp.o sh1p.o sh2p.o symbolic "-Bsymbolic"
285 ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o
286 ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o
291 # Now do the same tests again, but this time compile main.c PIC.
292 if ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/main.c $tmpdir/mainp.o] {
293 unresolved "shared (PIC main, non PIC so)"
294 unresolved "shared (PIC main)"
295 } else {
296 if { [file exists $tmpdir/sh1np.o ] && [ file exists $tmpdir/sh2np.o ] } {
297 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
298 shared_test shmpnp "shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o xcoff
299 } else {
300 # SunOS non PIC shared libraries don't permit some cases of
301 # overriding.
302 setup_xfail "*-*-sunos4*"
303 setup_xfail "ia64-*-linux*"
304 setup_xfail "alpha*-*-linux*"
305 setup_xfail "powerpc64*-*-*"
306 if { ![istarget hppa*64*-*-linux*] } {
307 setup_xfail "hppa*-*-linux*"
309 if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainp.o] } {
310 setup_xfail "sparc*-*-linux*"
312 setup_xfail "x86_64-*-linux*"
313 setup_xfail "s390x-*-linux*"
314 if [ string match $shared_needs_pic "yes" ] {
315 setup_xfail "arm*-*-linux*"
317 shared_test shmpnp "shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o shared
319 } else {
320 unresolved "shared (PIC main, non PIC so)"
323 if { [file exists $tmpdir/sh1p.o ] && [ file exists $tmpdir/sh2p.o ] } {
324 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
325 shared_test shmpp "shared (PIC main)" mainp.o sh1p.o sh2p.o xcoff
326 } else {
327 shared_test shmpp "shared (PIC main)" mainp.o sh1p.o sh2p.o shared
329 } else {
330 unresolved "shared (PIC main)"
334 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
335 # Remove the temporary directory.
336 catch "exec rm -rf $tmpdir" exec_status