2007-01-11 Paolo Bonzini <bonzini@gnu.org>
[binutils.git] / ld / testsuite / ld-auto-import / auto-import.exp
blobe052b31516082891257a1205be89c4b4f63ddefa
1 # Expect script for ld-auto-import tests
2 #   Copyright 2002
3 #   Free Software Foundation, Inc.
5 # This file is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
19 # Written by Ralf.Habacker@freenet.de
20 # Based on ls-shared/shared.exp by Ian Lance Taylor (ian@cygnus.com)
23 # Note: 
24
25 # This test checks the "auto importing direct from a dll" functionality, 
26 # which dramatically reduces the linking time for big libraries and applications 
27 # by skipping creating/using import libraries. Instead it links directly to the 
28 # related dll or to a symlinked dll for replacing regular import libraries. 
29
30 # The test has 4 stages: 
31
32 # 1. compile and link a test dll exporting some text and data symbols and a 
33 #    standard import library
35 # 2. create a symbolic link to this dll to simulate a replaced import library. 
37 # 3. compile and link a client application with the standard import library. 
38 #    This should produce no errors. 
40 # 4. compile and link a client application with the created dll. 
41 #    This should also produce no errors. 
43 # 5. compile and link a client application using the "import library". 
44 #    This should also produce no errors. 
46 # 6. compile and link a client application with auto-import disabled. 
47 #    This should produce a linking error. 
49 # This test can only be run if ld generates native executables.
50 if ![isnative] then {return}
52 # This test can only be run on a couple of ELF platforms.
53 # Square bracket expressions seem to confuse istarget.
54 if { ![istarget *-pc-cygwin]    
55      && ![istarget *-pc-mingw*] } {
56     return
59 # No compiler, no test.
60 if { [which $CC] == 0 } {
61     untested "Auto import test"
62     return
65 # ld_special_link
66 #       link a program using ld, without including any libraries
68 proc ld_special_link { ld target objects } {
69     global host_triplet
70     global link_output
72     if { [which $ld] == 0 } then {
73         perror "$ld does not exist"
74         return 0
75     }
77     if [is_endian_output_format $objects] then {
78         set flags [big_or_little_endian]
79     } else {
80         set flags ""
81     }
83     verbose -log "$ld $flags -o $target $objects"
85     catch "exec $ld $flags -o $target $objects" link_output
86     set exec_output [prune_warnings $link_output]
88     # We don't care if we get a warning about a non-existent start
89     # symbol, since the default linker script might use ENTRY.
90     regsub -all "(^|\n)(\[^\n\]*: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
92     # We don't care if we get a message about creating a library file.
93     regsub -all "(^|\n)(Creating library file\[^\n\]*\n?)" $exec_output "\\1" exec_output
95     if [string match "" $exec_output] then {
96         return 1
97     } else {
98         verbose -log "$exec_output"
99         return 0
100     }
103 set tmpdir tmpdir
104 set SHCFLAG ""
106 if [istarget *-pc-cygwin] {
107     # Set some libs needed for cygwin.
108     set MYLIBS "-L/usr/lib -lcygwin -L/usr/lib/w32api -lkernel32"
109     
110     # Compile the dll.
111     if ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/dll.c $tmpdir/dll.o ] {
112         fail "compiling shared lib"
113     } elseif ![ld_special_link "$ld -shared --out-implib=$tmpdir/libstandard.dll.a" $tmpdir/dll.dll "$tmpdir/dll.o $MYLIBS" ] {
114         fail "linking shared lib"
115     } else {
116         # Create symbolic link.
117         catch "exec ln -fs dll.dll $tmpdir/libsymlinked_dll.dll.a" ln_catch
118         
119         # Compile and link the client program.
120         if ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/client.c $tmpdir/client.o ] {
121             fail "compiling client"
122         } else {
123             # Check linking with import library.
124             set msg "linking auto-import client using a standard import library"
125             if [ld_special_link $ld $tmpdir/client.exe "--enable-auto-import /lib/crt0.o $tmpdir/client.o -L$tmpdir -lstandard $MYLIBS" ] {
126                 pass $msg
127             } else {
128                 fail $msg 
129             }
131             # Check linking directly with dll.
132             set msg "linking auto-import client using the dll"
133             if [ld_special_link $ld $tmpdir/client.exe "--enable-auto-import /lib/crt0.o $tmpdir/client.o -L$tmpdir -ldll $MYLIBS" ] {
134                 pass $msg
135             } else {
136                 fail $msg 
137             }
139             # Check linking with symlinked dll.
140             set msg "linking auto-import client using symbolic linked dll"
141             if [ld_special_link $ld $tmpdir/clientimport.exe "--enable-auto-import /lib/crt0.o $tmpdir/client.o -L$tmpdir -lsymlinked_dll $MYLIBS" ] {
142                 pass $msg
143             }   else {
144                 fail $msg 
145             }
147             # Check linking with disabled auto-import, this must produce linking error.
148             set msg "linking with disabled auto-import"
149             if ![ld_special_link $ld $tmpdir/clientimport.exe "--disable-auto-import /lib/crt0.o $tmpdir/client.o -L$tmpdir -ldll $MYLIBS" ] {
150                 pass $msg
151             }   else {
152                 fail $msg
153             }
154         }
155     }
158 if [istarget *-pc-mingw*] {
159     unsupported "mingw currently not supported"