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