# Expect script for ld-shared tests # Copyright (C) 1994 Free Software Foundation # # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ # # Written by Ian Lance Taylor (ian@cygnus.com) # # Make sure that ld can generate ELF shared libraries. # Note that linking against ELF shared libraries is tested by the # bootstrap test. # This test can only be run if ld generates native executables. if ![isnative] then {return} # This test can only be run on a couple of ELF platforms. # Square bracket expressions seem to confuse istarget. if { ![istarget i386-*-sysv4*] \ && ![istarget i486-*-sysv4*] \ && ![istarget i586-*-sysv4*] \ && ![istarget i386-*-unixware] \ && ![istarget i486-*-unixware] \ && ![istarget i586-*-unixware] \ && ![istarget i386-*-elf*] \ && ![istarget i486-*-elf*] \ && ![istarget i586-*-elf*] \ && ![istarget sparc*-*-elf] \ && ![istarget sparc*-*-solaris2*]} then { return } # Compile the main program. if ![ld_compile "$CC $CFLAGS" $srcdir$subdir/main.c tmpdir/main.o] { return } # The shared library is composed of two files. First compile them # without using -fpic. That should work on an ELF system, although it # will be less efficient because the dynamic linker will need to do # more relocation work. However, note that not using -fpic will cause # some of the tests to return different results. if ![ld_compile "$CC $CFLAGS" $srcdir$subdir/sh1.c tmpdir/sh1.o] { return } if ![ld_compile "$CC $CFLAGS" $srcdir$subdir/sh2.c tmpdir/sh2.o] { return } # Build the shared library. if ![ld_simple_link $ld tmpdir/shnonpic.so {-shared tmpdir/sh1.o tmpdir/sh2.o}] { fail "shared (non PIC)" } else { # Link against the shared library. Use -rpath so that the dynamic # linker can locate the shared library at runtime. if ![ld_link $ld tmpdir/shnonpic {-rpath tmpdir tmpdir/main.o tmpdir/shnonpic.so}] { fail "shared (non PIC)" } else { # Run the resulting program send_log "tmpdir/shnonpic >tmpdir/shnonpic.out\n" verbose "tmpdir/shnonpic >tmpdir/shnonpic.out" catch "exec tmpdir/shnonpic >tmpdir/shnonpic.out" exec_output if ![string match "" $exec_output] then { send_log "$exec_output\n" verbose "$exec_output" fail "shared (non PIC)" } else { send_log "diff tmpdir/shnonpic.out $srcdir$subdir/shared.dat\n" verbose "diff tmpdir/shnonpic.out $srcdir$subdir/shared.dat" catch "exec diff tmpdir/shnonpic.out $srcdir$subdir/shared.dat" exec_output if [string match "" $exec_output] then { pass "shared (non PIC)" } else { send_log "$exec_output\n" verbose "$exec_output" fail "shared (non PIC)" } } } } # Now compile the code using -fpic. Unfortunately, the gcc argument # is -fpic and the cc argument is -KPIC. We have to try both. set picflag "-fpic" send_log "$CC $picflag\n" verbose "$CC $picflag" catch "exec $CC $picflag" exec_output send_log "$exec_output\n" verbose "--" "$exec_output" if { [string match "*illegal option*" $exec_output] \ || [string match "*option ignored*" $exec_output] \ || [string match "*unrecognized option*" $exec_output] } then { set picflag "-KPIC" } verbose "Using $picflag to compile PIC code" if ![ld_compile "$CC $CFLAGS $picflag" $srcdir$subdir/sh1.c tmpdir/sh1.o] { return } if ![ld_compile "$CC $CFLAGS $picflag" $srcdir$subdir/sh2.c tmpdir/sh2.o] { return } # Build the shared library. if ![ld_simple_link $ld tmpdir/shpic.so {-shared tmpdir/sh1.o tmpdir/sh2.o}] { fail "shared" } else { # Link against the shared library. Use -rpath so that the dynamic # linker can locate the shared library at runtime. if ![ld_link $ld tmpdir/shpic {-rpath tmpdir tmpdir/main.o tmpdir/shpic.so}] { fail "shared" } else { # Run the resulting program send_log "tmpdir/shpic >tmpdir/shpic.out\n" verbose "tmpdir/shpic >tmpdir/shpic.out" catch "exec tmpdir/shpic >tmpdir/shpic.out" exec_output if ![string match "" $exec_output] then { send_log "$exec_output\n" verbose "$exec_output" fail "shared" } else { send_log "diff tmpdir/shpic.out $srcdir$subdir/shared.dat\n" verbose "diff tmpdir/shpic.out $srcdir$subdir/shared.dat" catch "exec diff tmpdir/shpic.out $srcdir$subdir/shared.dat" exec_output if [string match "" $exec_output] then { pass "shared" } else { send_log "$exec_output\n" verbose "$exec_output" fail "shared" } } } }