1 # Expect script
for ld-auto
-import tests
2 # Copyright
(C
) 2002-2019 Free Software Foundation
, Inc.
4 # This file is part of the GNU Binutils.
6 # This
program is free software
; you can redistribute it and
/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation
; either version
3 of the License
, or
9 #
(at your option
) any later version.
11 # This
program is distributed in the hope that it will be useful
,
12 # but WITHOUT
ANY WARRANTY
; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License
for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this
program; if not
, write to the Free Software
18 # Foundation
, Inc.
, 51 Franklin Street
- Fifth Floor
, Boston
,
21 # Written by Ralf.Habacker@freenet.de
22 # Based
on ls
-shared
/shared.exp by Ian Lance Taylor
(ian@cygnus.com
)
27 # This script tests some auto
-import functionality
:
29 # A.
"auto importing direct from a dll" functionality, which dramatically reduces the
30 # linking time
for big libraries and applications by skipping creating
/using
31 #
import libraries. Instead it links directly to the related dll or to a symlinked
32 # dll
for replacing regular
import libraries. The test has
6 stages
:
34 #
1.
compile and link a test dll exporting some
text and data symbols and a
35 # standard
import library
37 #
2. create a symbolic link to this dll to simulate a replaced
import library.
39 #
3.
compile and link a client application with the standard
import library.
40 # This should produce no errors.
42 #
4.
compile and link a client application with the created dll.
43 # This should also produce no errors.
45 #
5.
compile and link a client application using the
"import library".
46 # This should also produce no errors.
48 #
6.
compile and link a client application with auto
-import disabled.
49 # This should produce a linking error.
51 # B. runtime check
if there are no segfaults when importing const data variables
54 # This test can only be run
if ld generates native executables.
55 if ![isnative
] then {return}
57 # This test can only be run
on a couple of platforms.
58 # Square bracket expressions seem to confuse istarget.
59 if { ![istarget
*-pc
-cygwin
]
60 && ![istarget
*-pc
-mingw
*] } {
64 if [istarget
*-pc
-mingw
*] {
65 # FIXME
: Add support
for this target.
66 unsupported
"mingw currently not supported"
69 # No compiler
, no test.
70 if { ![check_compiler_available
] } {
71 untested
"Auto import test (compiler not found)"
76 # link a
program using
ld, without including
any libraries
78 proc ld_special_link
{ ld target objects
} {
82 if { [which $
ld] == 0 } then {
83 perror
"$ld does not exist"
87 if [is_endian_output_format $objects
] then {
88 set flags
[big_or_little_endian
]
93 verbose
-log "$ld $flags -o $target $objects"
95 catch
"exec $ld $flags -o $target $objects" link_output
96 set exec_output
[prune_warnings $link_output
]
98 # We don
't care if we get a warning about a non-existent start
99 # symbol, since the default linker script might use ENTRY.
100 regsub -all "(^|\n)(\[^\n\]*: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
102 # We don't care
if we
get a message about creating a library file.
103 regsub
-all
"(^|\n)(Creating library file\[^\n\]*\n?)" $exec_output "\\1" exec_output
105 if [string match
"" $exec_output] then {
109 verbose
-log "$exec_output"
116 if [istarget
*-pc
-cygwin
] {
117 #
Set some libs needed
for cygwin.
118 set MYLIBS
"-L/usr/lib -lcygwin -L/usr/lib/w32api -lkernel32"
121 if ![ld_compile
"$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/dll.c $tmpdir/dll.o] {
122 fail
"compiling shared lib"
124 if ![ld_special_link
"$ld -shared --enable-auto-import -e __cygwin_dll_entry@12 --out-implib=$tmpdir/libstandard.dll.a" $tmpdir/dll.dll "$tmpdir/dll.o $MYLIBS"] {
125 fail
"linking shared lib"
128 # Create symbolic link.
129 catch
"exec ln -fs dll.dll $tmpdir/libsymlinked_dll.dll.a" ln_catch
131 #
Compile and link the client
program.
132 if ![ld_compile
"$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/client.c $tmpdir/client.o] {
133 fail
"compiling client"
136 # Check linking with
import library.
137 set msg
"linking auto-import client using a standard import library"
138 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"] {
144 # Check linking directly with dll.
145 set msg
"linking auto-import client using the dll"
146 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"] {
152 # Check linking with symlinked dll.
153 set msg
"linking auto-import client using symbolic linked dll"
154 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"] {
160 # Check linking with disabled auto
-import, this must produce linking error.
161 set msg
"linking with disabled auto-import"
162 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"] {
168 # Check that the app works
- ie that there is output when the applications runs.
169 set msg
"application runtime segfault check"
170 catch
"exec $tmpdir/client-linklib.exe" exec_output
171 if ![string match
"" $exec_output] then {