1 # Expect script
for ld-auto
-import tests
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.
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.
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
)
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.
30 # The test has
4 stages
:
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
*] } {
59 # No compiler
, no test.
60 if { [which $CC
] == 0 } {
61 untested
"Auto import test"
66 # link a
program using
ld, without including
any libraries
68 proc ld_special_link
{ ld target objects
} {
72 if { [which $
ld] == 0 } then {
73 perror
"$ld does not exist"
77 if [is_endian_output_format $objects
] then {
78 set flags
[big_or_little_endian
]
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 {
98 verbose
-log "$exec_output"
106 if [istarget
*-pc
-cygwin
] {
107 #
Set some libs needed
for cygwin.
108 set MYLIBS
"-L/usr/lib -lcygwin -L/usr/lib/w32api -lkernel32"
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"
116 # Create symbolic link.
117 catch
"exec ln -fs dll.dll $tmpdir/libsymlinked_dll.dll.a" ln_catch
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"
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" ] {
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" ] {
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" ] {
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" ] {
158 if [istarget
*-pc
-mingw
*] {
159 unsupported
"mingw currently not supported"