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