2002-12-18 16:05:10 +00:00
|
|
|
# Expect script for ld-auto-import tests
|
2008-02-20 17:51:18 +00:00
|
|
|
# Copyright 2002, 2007, 2008
|
2002-12-18 16:05:10 +00:00
|
|
|
# Free Software Foundation, Inc.
|
|
|
|
#
|
2007-07-06 14:09:45 +00:00
|
|
|
# This file is part of the GNU Binutils.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
2002-12-18 16:05:10 +00:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
2007-07-06 14:09:45 +00:00
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
2002-12-18 16:05:10 +00:00
|
|
|
# (at your option) any later version.
|
2007-07-06 14:09:45 +00:00
|
|
|
#
|
2002-12-18 16:05:10 +00:00
|
|
|
# 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.
|
2007-07-06 14:09:45 +00:00
|
|
|
#
|
2002-12-18 16:05:10 +00:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
2007-07-06 14:09:45 +00:00
|
|
|
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
|
|
|
|
# MA 02110-1301, USA.
|
2002-12-18 16:05:10 +00:00
|
|
|
#
|
|
|
|
# Written by Ralf.Habacker@freenet.de
|
|
|
|
# Based on ls-shared/shared.exp by Ian Lance Taylor (ian@cygnus.com)
|
|
|
|
#
|
|
|
|
|
|
|
|
# Note:
|
|
|
|
#
|
2007-10-02 12:47:08 +00:00
|
|
|
# This script tests some auto-import functionality:
|
|
|
|
#
|
|
|
|
# A. "auto importing direct from a dll" functionality, which dramatically reduces the
|
|
|
|
# linking time for big libraries and applications by skipping creating/using
|
|
|
|
# import libraries. Instead it links directly to the related dll or to a symlinked
|
|
|
|
# dll for replacing regular import libraries. The test has 6 stages:
|
|
|
|
#
|
|
|
|
# 1. compile and link a test dll exporting some text and data symbols and a
|
|
|
|
# standard import library
|
|
|
|
#
|
|
|
|
# 2. create a symbolic link to this dll to simulate a replaced import library.
|
2002-12-18 16:05:10 +00:00
|
|
|
#
|
2007-10-02 12:47:08 +00:00
|
|
|
# 3. compile and link a client application with the standard import library.
|
|
|
|
# This should produce no errors.
|
2002-12-18 16:05:10 +00:00
|
|
|
#
|
2007-10-02 12:47:08 +00:00
|
|
|
# 4. compile and link a client application with the created dll.
|
|
|
|
# This should also produce no errors.
|
2002-12-18 16:05:10 +00:00
|
|
|
#
|
2007-10-02 12:47:08 +00:00
|
|
|
# 5. compile and link a client application using the "import library".
|
|
|
|
# This should also produce no errors.
|
2002-12-18 16:05:10 +00:00
|
|
|
#
|
2007-10-02 12:47:08 +00:00
|
|
|
# 6. compile and link a client application with auto-import disabled.
|
|
|
|
# This should produce a linking error.
|
|
|
|
#
|
|
|
|
# B. runtime check if there are no segfaults when importing const data variables
|
2002-12-18 16:05:10 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
# This test can only be run if ld generates native executables.
|
|
|
|
if ![isnative] then {return}
|
|
|
|
|
2007-10-02 12:47:08 +00:00
|
|
|
# This test can only be run on a couple of platforms.
|
2002-12-18 16:05:10 +00:00
|
|
|
# Square bracket expressions seem to confuse istarget.
|
|
|
|
if { ![istarget *-pc-cygwin]
|
|
|
|
&& ![istarget *-pc-mingw*] } {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2007-10-02 12:47:08 +00:00
|
|
|
if [istarget *-pc-mingw*] {
|
|
|
|
# FIXME: Add support for this target.
|
|
|
|
unsupported "mingw currently not supported"
|
|
|
|
}
|
|
|
|
|
2002-12-18 16:05:10 +00:00
|
|
|
# No compiler, no test.
|
|
|
|
if { [which $CC] == 0 } {
|
2007-10-02 12:47:08 +00:00
|
|
|
untested "Auto import test (compiler not found)"
|
2002-12-18 16:05:10 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
# ld_special_link
|
|
|
|
# link a program using ld, without including any libraries
|
|
|
|
#
|
|
|
|
proc ld_special_link { ld target objects } {
|
|
|
|
global host_triplet
|
|
|
|
global link_output
|
|
|
|
|
|
|
|
if { [which $ld] == 0 } then {
|
|
|
|
perror "$ld does not exist"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
if [is_endian_output_format $objects] then {
|
|
|
|
set flags [big_or_little_endian]
|
|
|
|
} else {
|
|
|
|
set flags ""
|
|
|
|
}
|
|
|
|
|
|
|
|
verbose -log "$ld $flags -o $target $objects"
|
|
|
|
|
|
|
|
catch "exec $ld $flags -o $target $objects" link_output
|
|
|
|
set exec_output [prune_warnings $link_output]
|
|
|
|
|
|
|
|
# We don't care if we get a warning about a non-existent start
|
|
|
|
# symbol, since the default linker script might use ENTRY.
|
|
|
|
regsub -all "(^|\n)(\[^\n\]*: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
|
|
|
|
|
|
|
|
# We don't care if we get a message about creating a library file.
|
|
|
|
regsub -all "(^|\n)(Creating library file\[^\n\]*\n?)" $exec_output "\\1" exec_output
|
|
|
|
|
|
|
|
if [string match "" $exec_output] then {
|
|
|
|
return 1
|
|
|
|
}
|
2007-10-02 12:47:08 +00:00
|
|
|
|
|
|
|
verbose -log "$exec_output"
|
|
|
|
return 0
|
2002-12-18 16:05:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set tmpdir tmpdir
|
|
|
|
set SHCFLAG ""
|
|
|
|
|
|
|
|
if [istarget *-pc-cygwin] {
|
|
|
|
# Set some libs needed for cygwin.
|
|
|
|
set MYLIBS "-L/usr/lib -lcygwin -L/usr/lib/w32api -lkernel32"
|
|
|
|
|
|
|
|
# Compile the dll.
|
2007-10-02 12:47:08 +00:00
|
|
|
if ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/dll.c $tmpdir/dll.o] {
|
2002-12-18 16:05:10 +00:00
|
|
|
fail "compiling shared lib"
|
2007-10-02 12:47:08 +00:00
|
|
|
}
|
2008-02-20 17:51:18 +00:00
|
|
|
if ![ld_special_link "$ld -shared --enable-auto-import --out-implib=$tmpdir/libstandard.dll.a" $tmpdir/dll.dll "$tmpdir/dll.o $MYLIBS"] {
|
2002-12-18 16:05:10 +00:00
|
|
|
fail "linking shared lib"
|
2007-10-02 12:47:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Create symbolic link.
|
|
|
|
catch "exec ln -fs dll.dll $tmpdir/libsymlinked_dll.dll.a" ln_catch
|
|
|
|
|
|
|
|
# Compile and link the client program.
|
|
|
|
if ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/client.c $tmpdir/client.o] {
|
|
|
|
fail "compiling client"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check linking with import library.
|
|
|
|
set msg "linking auto-import client using a standard import library"
|
|
|
|
if [ld_special_link $ld $tmpdir/client-linklib.exe "--enable-auto-import --enable-runtime-pseudo-reloc /lib/crt0.o $tmpdir/client.o -L$tmpdir -lstandard $MYLIBS"] {
|
|
|
|
pass $msg
|
2002-12-18 16:05:10 +00:00
|
|
|
} else {
|
2007-10-02 12:47:08 +00:00
|
|
|
fail $msg
|
2002-12-18 16:05:10 +00:00
|
|
|
}
|
|
|
|
|
2007-10-02 12:47:08 +00:00
|
|
|
# Check linking directly with dll.
|
|
|
|
set msg "linking auto-import client using the dll"
|
|
|
|
if [ld_special_link $ld $tmpdir/client-linkdll.exe "--enable-auto-import --enable-runtime-pseudo-reloc /lib/crt0.o $tmpdir/client.o -L$tmpdir -ldll $MYLIBS"] {
|
|
|
|
pass $msg
|
|
|
|
} else {
|
|
|
|
fail $msg
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check linking with symlinked dll.
|
|
|
|
set msg "linking auto-import client using symbolic linked dll"
|
|
|
|
if [ld_special_link $ld $tmpdir/client-symlinkeddll.exe "--enable-auto-import --enable-runtime-pseudo-reloc /lib/crt0.o $tmpdir/client.o -L$tmpdir -lsymlinked_dll $MYLIBS"] {
|
|
|
|
pass $msg
|
|
|
|
} else {
|
|
|
|
fail $msg
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check linking with disabled auto-import, this must produce linking error.
|
|
|
|
set msg "linking with disabled auto-import"
|
|
|
|
if ![ld_special_link $ld $tmpdir/client-failed.exe "--disable-auto-import --enable-runtime-pseudo-reloc /lib/crt0.o $tmpdir/client.o -L$tmpdir -ldll $MYLIBS"] {
|
|
|
|
pass $msg
|
|
|
|
} else {
|
|
|
|
fail $msg
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check that the app works - ie that there is output when the applications runs.
|
|
|
|
set msg "application runtime segfault check"
|
|
|
|
catch "exec $tmpdir/client-linklib.exe" exec_output
|
|
|
|
if ![string match "" $exec_output] then {
|
|
|
|
pass $msg
|
|
|
|
} else {
|
|
|
|
fail $msg
|
|
|
|
}
|
2002-12-18 16:05:10 +00:00
|
|
|
}
|