1 # Expect script for ld-shared tests
2 # Copyright (C) 1994,1995 Free Software Foundation
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.
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.
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. */
18 # Written by Ian Lance Taylor (ian@cygnus.com)
21 # Make sure that ld can generate ELF shared libraries.
22 # Note that linking against ELF shared libraries is tested by the
25 # This test can only be run if ld generates native executables.
26 if ![isnative] then {return}
28 # This test can only be run on a couple of ELF platforms.
29 # Square bracket expressions seem to confuse istarget.
30 if { ![istarget i386-*-sysv4*] \
31 && ![istarget i486-*-sysv4*] \
32 && ![istarget i586-*-sysv4*] \
33 && ![istarget i386-*-unixware] \
34 && ![istarget i486-*-unixware] \
35 && ![istarget i586-*-unixware] \
36 && ![istarget i386-*-elf*] \
37 && ![istarget i486-*-elf*] \
38 && ![istarget i586-*-elf*] \
39 && ![istarget sparc*-*-elf] \
40 && ![istarget sparc*-*-solaris2*]} then {
45 proc shared_test { progname testname main sh1 sh2 } {
52 # Build the shared library.
53 if {![ld_simple_link $ld tmpdir/$progname.so "-shared tmpdir/$sh1 tmpdir/$sh2"]} {
58 # Link against the shared library. Use -rpath so that the
59 # dynamic linker can locate the shared library at runtime.
60 if ![ld_link $ld tmpdir/$progname "-rpath tmpdir tmpdir/$main tmpdir/$progname.so"] {
65 # Run the resulting program
66 send_log "tmpdir/$progname >tmpdir/$progname.out\n"
67 verbose "tmpdir/$progname >tmpdir/$progname.out"
68 catch "exec tmpdir/$progname >tmpdir/$progname.out" exec_output
69 if ![string match "" $exec_output] then {
70 send_log "$exec_output\n"
71 verbose "$exec_output"
76 send_log "diff tmpdir/$progname.out $srcdir$subdir/shared.dat\n"
77 verbose "diff tmpdir/$progname.out $srcdir$subdir/shared.dat"
78 catch "exec diff tmpdir/$progname.out $srcdir$subdir/shared.dat" exec_output
79 set exec_output [prune_system_crud $host_triplet $exec_output]
81 if {![string match "" $exec_output]} then {
82 send_log "$exec_output\n"
83 verbose "$exec_output"
91 # Unfortunately, the gcc argument is -fpic and the cc argument is
92 # -KPIC. We have to try both.
95 send_log "$CC $picflag\n"
96 verbose "$CC $picflag"
97 catch "exec $CC $picflag" exec_output
98 send_log "$exec_output\n"
99 verbose "--" "$exec_output"
100 if { [string match "*illegal option*" $exec_output] \
101 || [string match "*option ignored*" $exec_output] \
102 || [string match "*unrecognized option*" $exec_output] } then {
105 verbose "Using $picflag to compile PIC code"
107 # Compile the main program.
108 if ![ld_compile "$CC $CFLAGS" $srcdir$subdir/main.c tmpdir/mainnp.o] {
109 unresolved "shared (non PIC)"
112 # The shared library is composed of two files. First compile them
113 # without using -fpic. That should work on an ELF system,
114 # although it will be less efficient because the dynamic linker
115 # will need to do more relocation work. However, note that not
116 # using -fpic will cause some of the tests to return different
118 if { ![ld_compile "$CC $CFLAGS" $srcdir$subdir/sh1.c tmpdir/sh1np.o]
119 || ![ld_compile "$CC $CFLAGS" $srcdir$subdir/sh2.c tmpdir/sh2np.o] } {
120 unresolved "shared (non PIC)"
122 shared_test shnp "shared (non PIC)" mainnp.o sh1np.o sh2np.o
125 # Now compile the code using -fpic.
127 if { ![ld_compile "$CC $CFLAGS $picflag" $srcdir$subdir/sh1.c tmpdir/sh1p.o]
128 || ![ld_compile "$CC $CFLAGS $picflag" $srcdir$subdir/sh2.c tmpdir/sh2p.o] } {
131 shared_test shp "shared" mainnp.o sh1p.o sh2p.o
135 # Now do the same tests again, but this time compile main.c PIC.
136 if ![ld_compile "$CC $CFLAGS $picflag" $srcdir$subdir/main.c tmpdir/mainp.o] {
137 unresolved "shared (PIC main, non PIC so)"
138 unresolved "shared (PIC main)"
140 if { [file exists tmpdir/sh1np.o ] && [ file exists tmpdir/sh2np.o ] } {
141 shared_test shmpnp "shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o
143 unresolved "shared (PIC main, non PIC so)"
146 if { [file exists tmpdir/sh1p.o ] && [ file exists tmpdir/sh2p.o ] } {
147 shared_test shmpp "shared (PIC main)" mainp.o sh1p.o sh2p.o
149 unresolved "shared (PIC main)"