ld: xfail several shared (non PIC) tests on Solaris
[deliverable/binutils-gdb.git] / ld / testsuite / ld-shared / shared.exp
1 # Expect script for ld-shared tests
2 # Copyright (C) 1994-2020 Free Software Foundation, Inc.
3 #
4 # This file is part of the GNU Binutils.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20 #
21 # Written by Ian Lance Taylor (ian@cygnus.com)
22 #
23
24 # Make sure that ld can generate ELF shared libraries.
25 # Note that linking against ELF shared libraries is tested by the
26 # bootstrap test.
27
28 # Check to see if the C compiler works
29 if { ![check_compiler_available] } {
30 return
31 }
32
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 i?86-*-gnu*] \
42 && ![istarget *-*-nacl*] \
43 && ![istarget ia64-*-elf*] \
44 && ![istarget ia64-*-linux*] \
45 && ![istarget m68k-*-linux*] \
46 && ![istarget mips*-*-irix5*] \
47 && ![istarget mips*-*-linux*] \
48 && ![istarget powerpc*-*-elf*] \
49 && ![istarget powerpc*-*-linux*] \
50 && ![istarget powerpc*-*-sysv4*] \
51 && ![istarget sparc*-*-elf] \
52 && ![istarget sparc*-*-solaris2*] \
53 && ![istarget sparc*-*-linux*] \
54 && ![istarget arm*-*-linux*] \
55 && ![istarget alpha*-*-linux*] \
56 && ![istarget rs6000*-*-aix*] \
57 && ![istarget powerpc*-*-aix*] \
58 && ![istarget s390*-*-linux*] \
59 && ![istarget aarch64*-*-linux*] \
60 && ![istarget x86_64-*-linux*] } {
61 return
62 }
63
64 set tmpdir tmpdir
65 set SHCFLAG ""
66 set shared_needs_pic "no"
67
68 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
69
70 # AIX shared libraries do not seem to support useful features,
71 # like overriding the shared library function or letting the
72 # shared library refer to objects defined in the main program. We
73 # avoid testing those features.
74 set SHCFLAG "-DXCOFF_TEST"
75
76 # The AIX 3.2.5 loader appears to randomly fail when loading
77 # shared libraries from NSF mounted partitions, so we avoid any
78 # potential problems by using a local directory.
79 catch {exec /bin/sh -c "echo $$"} pid
80 set tmpdir /usr/tmp/ld.$pid
81 catch "exec mkdir $tmpdir" exec_status
82
83 # On AIX, we need to explicitly export the symbols the shared
84 # library is going to provide, and need.
85 set file [open $tmpdir/xcoff.exp w]
86 puts $file shlibvar1
87 puts $file shlibvar2
88 puts $file shlib_shlibvar1
89 puts $file shlib_shlibvar2
90 puts $file shlib_shlibcall
91 puts $file shlib_shlibcalled
92 puts $file shlib_checkfunptr1
93 puts $file shlib_getfunptr1
94 puts $file shlib_check
95 close $file
96 }
97
98 if [istarget arm*-*-linux*] {
99 # On ARM section anchors can change the symbol pre-emptability for
100 # non-PIC shared libraries, causing these tests to fail. Turn section
101 # anchors off.
102 set SHCFLAG "-fno-section-anchors"
103
104 # On targets that have MOVW the compiler will emit relocations which
105 # the linker doesn't support when compiling -shared without -fpic. The
106 # test to find out whether we want to XFAIL the non-PIC tests requires
107 # a compile - so we pre-calculate it here. We also note that this can
108 # only affect arm*-*-*eabi* targets as the old ABI doesn't support v7.
109 if [istarget arm*-*-*eabi*] {
110 set file [open $tmpdir/movw-detect.c w]
111 puts $file "void foo(void) { __asm (\"movw r0, #0\"); }"
112 close $file
113 if [run_host_cmd_yesno "$CC" "$CFLAGS -c $tmpdir/movw-detect.c -o $tmpdir/movw-detect.o"] {
114 set shared_needs_pic "yes"
115 }
116 }
117 }
118
119 # The test procedure.
120 proc shared_test { progname testname main sh1 sh2 dat args } {
121 global CC
122 global srcdir
123 global subdir
124 global exec_output
125 global host_triplet
126 global tmpdir
127
128 if [llength $args] { set shldflags [lindex $args 0] } else { set shldflags "" }
129
130 # Build the shared library.
131 # On AIX, we need to use an export file.
132 set shared -shared
133 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
134 set shared "-bM:SRE -bE:$tmpdir/xcoff.exp"
135 }
136 if {![ld_link $CC $tmpdir/$progname.so "$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} {
137 fail "$testname"
138 return
139 }
140
141 # Link against the shared library. Use -rpath so that the
142 # dynamic linker can locate the shared library at runtime.
143 # On AIX, we must include /lib in -rpath, as otherwise the loader
144 # can not find -lc.
145 set rpath $tmpdir
146 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
147 set rpath /lib:$tmpdir
148 }
149 if ![ld_link $CC $tmpdir/$progname "-Wl,-rpath,$rpath $tmpdir/$main $tmpdir/$progname.so"] {
150 fail "$testname"
151 return
152 }
153
154 if ![isnative] {
155 unsupported $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
185 # Old version of GCC for MIPS default to enabling -fpic
186 # and get confused if it is used on the command line.
187 if { [istarget mips*-*-*] && ! [at_least_gcc_version 4 3] } then {
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 set picflag "-KPIC"
203 }
204 }
205 verbose "Using $picflag to compile PIC code"
206
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. Make sure that PLT is used since PLT is expected.
218 global PLT_CFLAGS NOPIE_CFLAGS
219 if { ![ld_compile "$CC $PLT_CFLAGS $NOPIE_CFLAGS $CFLAGS $SHCFLAG" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o]
220 || ![ld_compile "$CC $PLT_CFLAGS $CFLAGS $SHCFLAG" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } {
221 unresolved "shared (non PIC)"
222 } else { if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
223 shared_test shnp "shared (nonPIC)" mainnp.o sh1np.o sh2np.o xcoff
224 } else {
225 # Solaris defaults to -z text.
226 setup_xfail "*-*-solaris2*"
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*"
232 }
233 if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainnp.o] } {
234 setup_xfail "sparc*-*-linux*"
235 }
236 if { [is_elf64 $tmpdir/mainnp.o] } {
237 setup_xfail "x86_64-*-linux*"
238 }
239 setup_xfail "x86_64-*-linux-gnux32"
240 setup_xfail "s390x-*-linux*"
241 if [ string match $shared_needs_pic "yes" ] {
242 setup_xfail "arm*-*-linux*"
243 }
244 setup_xfail "aarch64*-*-linux*"
245 shared_test shnp "shared (non PIC)" mainnp.o sh1np.o sh2np.o shared
246
247 # Test ELF shared library relocations with a non-zero load
248 # address for the library. Near as I can tell, the R_*_RELATIVE
249 # relocations for various targets are broken in the case where
250 # the load address is not zero (which is the default).
251 setup_xfail "*-*-linux*libc1"
252 setup_xfail "powerpc*-*-linux*"
253 setup_xfail "ia64-*-linux*"
254 setup_xfail "alpha*-*-linux*"
255 setup_xfail "mips*-*-linux*"
256 if { ![istarget hppa*64*-*-linux*] } {
257 setup_xfail "hppa*-*-linux*"
258 }
259 if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainnp.o] } {
260 setup_xfail "sparc*-*-linux*"
261 }
262 if { [is_elf64 $tmpdir/mainnp.o] } {
263 setup_xfail "x86_64-*-linux*"
264 }
265 setup_xfail "x86_64-*-linux-gnux32"
266 setup_xfail "s390x-*-linux*"
267 if [ string match $shared_needs_pic "yes" ] {
268 setup_xfail "arm*-*-linux*"
269 }
270 setup_xfail "aarch64*-*-linux*"
271 # Solaris defaults to -z text.
272 setup_xfail "*-*-solaris2*"
273 shared_test shnp "shared (non PIC, load offset)" \
274 mainnp.o sh1np.o sh2np.o shared \
275 "-Wl,-T,$srcdir/$subdir/elf-offset.ld,--hash-style=sysv"
276 } }
277
278 # Now compile the code using -fpic.
279
280 if { ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o]
281 || ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh2.c $tmpdir/sh2p.o] } {
282 unresolved "shared"
283 } else {
284 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
285 shared_test shp "shared" mainnp.o sh1p.o sh2p.o xcoff
286 } else {
287 shared_test shp "shared" mainnp.o sh1p.o sh2p.o shared
288 ld_compile "$CC $CFLAGS -DSYMBOLIC_TEST -DXCOFF_TEST $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o
289 ld_compile "$CC $CFLAGS -DSYMBOLIC_TEST -DXCOFF_TEST $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o
290 shared_test shp "shared -Bsymbolic" mainnp.o sh1p.o sh2p.o symbolic "-Bsymbolic"
291 ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o
292 ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o
293 }
294 }
295 }
296
297 # Now do the same tests again, but this time compile main.c PIC.
298 if ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/main.c $tmpdir/mainp.o] {
299 unresolved "shared (PIC main, non PIC so)"
300 unresolved "shared (PIC main)"
301 } else {
302 if { [file exists $tmpdir/sh1np.o ] && [ file exists $tmpdir/sh2np.o ] } {
303 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
304 shared_test shmpnp "shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o xcoff
305 } else {
306 # Solaris defaults to -z text.
307 setup_xfail "*-*-solaris2*"
308 setup_xfail "ia64-*-linux*"
309 setup_xfail "alpha*-*-linux*"
310 setup_xfail "powerpc64*-*-*"
311 if { ![istarget hppa*64*-*-linux*] } {
312 setup_xfail "hppa*-*-linux*"
313 }
314 if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainp.o] } {
315 setup_xfail "sparc*-*-linux*"
316 }
317 if { [is_elf64 $tmpdir/mainp.o] } {
318 setup_xfail "x86_64-*-linux*"
319 }
320 setup_xfail "x86_64-*-linux-gnux32"
321 setup_xfail "s390x-*-linux*"
322 if [ string match $shared_needs_pic "yes" ] {
323 setup_xfail "arm*-*-linux*"
324 }
325 setup_xfail "aarch64*-*-linux*"
326 shared_test shmpnp "shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o shared
327 }
328 } else {
329 unresolved "shared (PIC main, non PIC so)"
330 }
331
332 if { [file exists $tmpdir/sh1p.o ] && [ file exists $tmpdir/sh2p.o ] } {
333 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
334 shared_test shmpp "shared (PIC main)" mainp.o sh1p.o sh2p.o xcoff
335 } else {
336 shared_test shmpp "shared (PIC main)" mainp.o sh1p.o sh2p.o shared
337 }
338 } else {
339 unresolved "shared (PIC main)"
340 }
341 }
342
343 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
344 # Remove the temporary directory.
345 catch "exec rm -rf $tmpdir" exec_status
346 }
This page took 0.059624 seconds and 4 git commands to generate.