* value.c (show_convenience): Tweak comment.
[deliverable/binutils-gdb.git] / ld / testsuite / ld-shared / shared.exp
CommitLineData
252b5132 1# Expect script for ld-shared tests
aef6203b 2# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
5a68afcf 3# 2004, 2005, 2007, 2008, 2009, 2010, 2012
a2b64bed 4# Free Software Foundation, Inc.
252b5132 5#
f96b4a7b
NC
6# This file is part of the GNU Binutils.
7#
8# This program is free software; you can redistribute it and/or modify
252b5132 9# it under the terms of the GNU General Public License as published by
f96b4a7b 10# the Free Software Foundation; either version 3 of the License, or
252b5132 11# (at your option) any later version.
f96b4a7b 12#
252b5132
RH
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.
f96b4a7b 17#
252b5132
RH
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
f96b4a7b
NC
20# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21# MA 02110-1301, USA.
252b5132
RH
22#
23# Written by Ian Lance Taylor (ian@cygnus.com)
24#
25
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.
29
30# This test can only be run if ld generates native executables.
31if ![isnative] then {return}
32
33# This test can only be run on a couple of ELF platforms.
34# Square bracket expressions seem to confuse istarget.
19c7c582
AM
35if { ![istarget hppa*64*-*-hpux*] \
36 && ![istarget hppa*-*-linux*] \
37 && ![istarget i?86-*-sysv4*] \
ad995491
L
38 && ![istarget i?86-*-unixware] \
39 && ![istarget i?86-*-elf*] \
40 && ![istarget i?86-*-linux*] \
5940a93c 41 && ![istarget i?86-*-gnu*] \
5a68afcf 42 && ![istarget *-*-nacl*] \
ad995491
L
43 && ![istarget ia64-*-elf*] \
44 && ![istarget ia64-*-linux*] \
252b5132
RH
45 && ![istarget m68k-*-linux*] \
46 && ![istarget mips*-*-irix5*] \
66517a2f 47 && ![istarget mips*-*-linux*] \
24b01a74
AM
48 && ![istarget powerpc*-*-elf*] \
49 && ![istarget powerpc*-*-linux*] \
50 && ![istarget powerpc*-*-sysv4*] \
252b5132
RH
51 && ![istarget sparc*-*-elf] \
52 && ![istarget sparc*-*-solaris2*] \
53 && ![istarget sparc*-*-sunos4*] \
b33b6e45 54 && ![istarget sparc*-*-linux*] \
4f38fc1c 55 && ![istarget arm*-*-linux*] \
2ffd68ef 56 && ![istarget alpha*-*-linux*] \
252b5132 57 && ![istarget rs6000*-*-aix*] \
9147e853
JJ
58 && ![istarget powerpc*-*-aix*] \
59 && ![istarget s390*-*-linux*] \
60 && ![istarget x86_64-*-linux*] } {
252b5132
RH
61 return
62}
63
99c262f8
ILT
64if { [istarget *-*-linux*aout*] \
65 || [istarget *-*-linux*oldld*] } {
252b5132
RH
66 return
67}
68
69set tmpdir tmpdir
70set SHCFLAG ""
a9f844b1 71set shared_needs_pic "no"
252b5132
RH
72
73if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
74
75 # AIX shared libraries do not seem to support useful features,
76 # like overriding the shared library function or letting the
77 # shared library refer to objects defined in the main program. We
78 # avoid testing those features.
79 set SHCFLAG "-DXCOFF_TEST"
80
81 # The AIX 3.2.5 loader appears to randomly fail when loading
82 # shared libraries from NSF mounted partitions, so we avoid any
83 # potential problems by using a local directory.
84 catch {exec /bin/sh -c "echo $$"} pid
85 set tmpdir /usr/tmp/ld.$pid
86 catch "exec mkdir $tmpdir" exec_status
87
88 # On AIX, we need to explicitly export the symbols the shared
89 # library is going to provide, and need.
90 set file [open $tmpdir/xcoff.exp w]
91 puts $file shlibvar1
92 puts $file shlibvar2
93 puts $file shlib_shlibvar1
94 puts $file shlib_shlibvar2
95 puts $file shlib_shlibcall
96 puts $file shlib_shlibcalled
97 puts $file shlib_checkfunptr1
98 puts $file shlib_getfunptr1
99 puts $file shlib_check
100 close $file
101}
102
a9f844b1
NC
103if [istarget arm*-*-linux*] {
104 # On ARM section anchors can change the symbol pre-emptability for
5a68afcf 105 # non-PIC shared libraries, causing these tests to fail. Turn section
a9f844b1
NC
106 # anchors off.
107 set SHCFLAG "-fno-section-anchors"
108
5a68afcf 109 # On targets that have MOVW the compiler will emit relocations which
a9f844b1 110 # the linker doesn't support when compiling -shared without -fpic. The
5a68afcf 111 # test to find out whether we want to XFAIL the non-PIC tests requires
a9f844b1
NC
112 # a compile - so we pre-calculate it here. We also note that this can
113 # only affect arm*-*-*eabi targets as the old ABI doesn't support v7.
114 if [istarget arm*-*-*eabi] {
115 set file [open $tmpdir/movw-detect.c w]
116 puts $file "void foo(void) { __asm (\"movw r0, #0\"); }"
117 close $file
118 if [run_host_cmd_yesno "$CC" "$CFLAGS -c $tmpdir/movw-detect.c -o $tmpdir/movw-detect.o"] {
119 set shared_needs_pic "yes"
120 }
121 }
122}
123
252b5132
RH
124# The test procedure.
125proc shared_test { progname testname main sh1 sh2 dat args } {
b765d4e3 126 global CC
252b5132
RH
127 global srcdir
128 global subdir
129 global exec_output
130 global host_triplet
131 global tmpdir
132
133 if [llength $args] { set shldflags [lindex $args 0] } else { set shldflags "" }
134
135 # Build the shared library.
136 # On AIX, we need to use an export file.
137 set shared -shared
138 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
139 set shared "-bM:SRE -bE:$tmpdir/xcoff.exp"
140 }
b765d4e3 141 if {![ld_simple_link $CC $tmpdir/$progname.so "$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} {
252b5132
RH
142 fail "$testname"
143 return
144 }
145
146 # Link against the shared library. Use -rpath so that the
147 # dynamic linker can locate the shared library at runtime.
148 # On AIX, we must include /lib in -rpath, as otherwise the loader
149 # can not find -lc.
150 set rpath $tmpdir
151 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
152 set rpath /lib:$tmpdir
153 }
b765d4e3 154 if ![ld_simple_link $CC $tmpdir/$progname "-Wl,-rpath,$rpath $tmpdir/$main $tmpdir/$progname.so"] {
252b5132
RH
155 fail "$testname"
156 return
157 }
158
159 # Run the resulting program
160 send_log "$tmpdir/$progname >$tmpdir/$progname.out\n"
161 verbose "$tmpdir/$progname >$tmpdir/$progname.out"
162 catch "exec $tmpdir/$progname >$tmpdir/$progname.out" exec_output
163 if ![string match "" $exec_output] then {
164 send_log "$exec_output\n"
165 verbose "$exec_output"
166 fail "$testname"
167 return
168 }
169
170 send_log "diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat\n"
171 verbose "diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat"
172 catch "exec diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat" exec_output
173 set exec_output [prune_warnings $exec_output]
174
175 if {![string match "" $exec_output]} then {
176 send_log "$exec_output\n"
177 verbose "$exec_output"
178 fail "$testname"
179 return
180 }
181
182 pass "$testname"
183}
184
fb35d3d8
DD
185# Old version of GCC for MIPS default to enabling -fpic
186# and get confused if it is used on the command line.
187if { [istarget mips*-*-*] && ! [at_least_gcc_version 4 3] } then {
252b5132
RH
188 set picflag ""
189} else {
190 # Unfortunately, the gcc argument is -fpic and the cc argument is
191 # -KPIC. We have to try both.
192 set picflag "-fpic"
193 send_log "$CC $picflag\n"
194 verbose "$CC $picflag"
195 catch "exec $CC $picflag" exec_output
196 send_log "$exec_output\n"
197 verbose "--" "$exec_output"
198 if { [string match "*illegal option*" $exec_output] \
199 || [string match "*option ignored*" $exec_output] \
200 || [string match "*unrecognized option*" $exec_output] \
201 || [string match "*passed to ld*" $exec_output] } {
202 if [istarget *-*-sunos4*] {
203 set picflag "-pic"
204 } else {
205 set picflag "-KPIC"
206 }
207 }
208}
209verbose "Using $picflag to compile PIC code"
210
211# Compile the main program.
212if ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o] {
213 unresolved "shared (non PIC)"
214 unresolved "shared"
215} else {
216 # The shared library is composed of two files. First compile them
217 # without using -fpic. That should work on an ELF system,
218 # although it will be less efficient because the dynamic linker
219 # will need to do more relocation work. However, note that not
220 # using -fpic will cause some of the tests to return different
221 # results.
222 if { ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o]
223 || ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } {
224 unresolved "shared (non PIC)"
225 } else { if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
226 shared_test shnp "shared (nonPIC)" mainnp.o sh1np.o sh2np.o xcoff
227 } else {
228 # SunOS non PIC shared libraries don't permit some cases of
229 # overriding.
230 setup_xfail "*-*-sunos4*"
ad995491 231 setup_xfail "ia64-*-linux*"
212a6b8e 232 setup_xfail "alpha*-*-linux*"
24b01a74 233 setup_xfail "powerpc64*-*-*"
c0d48c0b
DA
234 if { ![istarget hppa*64*-*-linux*] } {
235 setup_xfail "hppa*-*-linux*"
236 }
4dc570c2
JJ
237 if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainnp.o] } {
238 setup_xfail "sparc*-*-linux*"
239 }
8b778942
L
240 if { [is_elf64 $tmpdir/mainnp.o] } {
241 setup_xfail "x86_64-*-linux*"
242 }
3c995545 243 setup_xfail "x86_64-*-linux-gnux32"
4648dfcf 244 setup_xfail "s390x-*-linux*"
a9f844b1
NC
245 if [ string match $shared_needs_pic "yes" ] {
246 setup_xfail "arm*-*-linux*"
247 }
252b5132
RH
248 shared_test shnp "shared (non PIC)" mainnp.o sh1np.o sh2np.o shared
249
250 # Test ELF shared library relocations with a non-zero load
251 # address for the library. Near as I can tell, the R_*_RELATIVE
252 # relocations for various targets are broken in the case where
253 # the load address is not zero (which is the default).
254 setup_xfail "*-*-sunos4*"
b7be1db6 255 setup_xfail "*-*-linux*libc1"
24b01a74 256 setup_xfail "powerpc*-*-linux*"
ad995491 257 setup_xfail "ia64-*-linux*"
212a6b8e 258 setup_xfail "alpha*-*-linux*"
66517a2f 259 setup_xfail "mips*-*-linux*"
c0d48c0b
DA
260 if { ![istarget hppa*64*-*-linux*] } {
261 setup_xfail "hppa*-*-linux*"
262 }
4dc570c2
JJ
263 if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainnp.o] } {
264 setup_xfail "sparc*-*-linux*"
265 }
8b778942
L
266 if { [is_elf64 $tmpdir/mainnp.o] } {
267 setup_xfail "x86_64-*-linux*"
268 }
3c995545 269 setup_xfail "x86_64-*-linux-gnux32"
8c37241b 270 setup_xfail "s390x-*-linux*"
a9f844b1
NC
271 if [ string match $shared_needs_pic "yes" ] {
272 setup_xfail "arm*-*-linux*"
273 }
252b5132
RH
274 shared_test shnp "shared (non PIC, load offset)" \
275 mainnp.o sh1np.o sh2np.o shared \
276 "-T $srcdir/$subdir/elf-offset.ld"
277 } }
278
279 # Now compile the code using -fpic.
280
5a68afcf 281 if { ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o]
252b5132
RH
282 || ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh2.c $tmpdir/sh2p.o] } {
283 unresolved "shared"
284 } else {
285 # SunOS can not compare function pointers correctly
286 if [istarget "*-*-sunos4*"] {
287 shared_test shp "shared" mainnp.o sh1p.o sh2p.o sun4
288 } else { if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
289 shared_test shp "shared" mainnp.o sh1p.o sh2p.o xcoff
290 } else {
291 shared_test shp "shared" mainnp.o sh1p.o sh2p.o shared
66517a2f
L
292 ld_compile "$CC $CFLAGS -DSYMBOLIC_TEST -DXCOFF_TEST $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o
293 ld_compile "$CC $CFLAGS -DSYMBOLIC_TEST -DXCOFF_TEST $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o
5a68afcf 294 shared_test shp "shared -Bsymbolic" mainnp.o sh1p.o sh2p.o symbolic "-Bsymbolic"
f0f077e5
L
295 ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o
296 ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o
252b5132
RH
297 } }
298 }
299}
300
301# Now do the same tests again, but this time compile main.c PIC.
302if ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/main.c $tmpdir/mainp.o] {
303 unresolved "shared (PIC main, non PIC so)"
304 unresolved "shared (PIC main)"
305} else {
306 if { [file exists $tmpdir/sh1np.o ] && [ file exists $tmpdir/sh2np.o ] } {
307 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
308 shared_test shmpnp "shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o xcoff
309 } else {
310 # SunOS non PIC shared libraries don't permit some cases of
311 # overriding.
312 setup_xfail "*-*-sunos4*"
ad995491 313 setup_xfail "ia64-*-linux*"
212a6b8e 314 setup_xfail "alpha*-*-linux*"
24b01a74 315 setup_xfail "powerpc64*-*-*"
c0d48c0b
DA
316 if { ![istarget hppa*64*-*-linux*] } {
317 setup_xfail "hppa*-*-linux*"
318 }
4dc570c2
JJ
319 if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainp.o] } {
320 setup_xfail "sparc*-*-linux*"
321 }
8b778942
L
322 if { [is_elf64 $tmpdir/mainp.o] } {
323 setup_xfail "x86_64-*-linux*"
324 }
3c995545 325 setup_xfail "x86_64-*-linux-gnux32"
4648dfcf 326 setup_xfail "s390x-*-linux*"
a9f844b1
NC
327 if [ string match $shared_needs_pic "yes" ] {
328 setup_xfail "arm*-*-linux*"
329 }
252b5132
RH
330 shared_test shmpnp "shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o shared
331 }
332 } else {
333 unresolved "shared (PIC main, non PIC so)"
334 }
335
336 if { [file exists $tmpdir/sh1p.o ] && [ file exists $tmpdir/sh2p.o ] } {
337 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
338 shared_test shmpp "shared (PIC main)" mainp.o sh1p.o sh2p.o xcoff
339 } else {
340 shared_test shmpp "shared (PIC main)" mainp.o sh1p.o sh2p.o shared
341 }
342 } else {
343 unresolved "shared (PIC main)"
344 }
345}
346
347if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
348 # Remove the temporary directory.
349 catch "exec rm -rf $tmpdir" exec_status
350}
This page took 0.539744 seconds and 4 git commands to generate.