1 |
38 |
julius |
# Expect script for ld-auto-import tests
|
2 |
|
|
# Copyright 2002, 2007, 2008
|
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 script tests some auto-import functionality:
|
29 |
|
|
#
|
30 |
|
|
# A. "auto importing direct from a dll" functionality, which dramatically reduces the
|
31 |
|
|
# linking time for big libraries and applications by skipping creating/using
|
32 |
|
|
# import libraries. Instead it links directly to the related dll or to a symlinked
|
33 |
|
|
# dll for replacing regular import libraries. The test has 6 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 |
|
|
# B. runtime check if there are no segfaults when importing const data variables
|
53 |
|
|
#
|
54 |
|
|
|
55 |
|
|
# This test can only be run if ld generates native executables.
|
56 |
|
|
if ![isnative] then {return}
|
57 |
|
|
|
58 |
|
|
# This test can only be run on a couple of platforms.
|
59 |
|
|
# Square bracket expressions seem to confuse istarget.
|
60 |
|
|
if { ![istarget *-pc-cygwin]
|
61 |
|
|
&& ![istarget *-pc-mingw*] } {
|
62 |
|
|
return
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
if [istarget *-pc-mingw*] {
|
66 |
|
|
# FIXME: Add support for this target.
|
67 |
|
|
unsupported "mingw currently not supported"
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
# No compiler, no test.
|
71 |
|
|
if { [which $CC] == 0 } {
|
72 |
|
|
untested "Auto import test (compiler not found)"
|
73 |
|
|
return
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
# ld_special_link
|
77 |
|
|
# link a program using ld, without including any libraries
|
78 |
|
|
#
|
79 |
|
|
proc ld_special_link { ld target objects } {
|
80 |
|
|
global host_triplet
|
81 |
|
|
global link_output
|
82 |
|
|
|
83 |
|
|
if { [which $ld] == 0 } then {
|
84 |
|
|
perror "$ld does not exist"
|
85 |
|
|
return 0
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
if [is_endian_output_format $objects] then {
|
89 |
|
|
set flags [big_or_little_endian]
|
90 |
|
|
} else {
|
91 |
|
|
set flags ""
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
verbose -log "$ld $flags -o $target $objects"
|
95 |
|
|
|
96 |
|
|
catch "exec $ld $flags -o $target $objects" link_output
|
97 |
|
|
set exec_output [prune_warnings $link_output]
|
98 |
|
|
|
99 |
|
|
# We don't care if we get a warning about a non-existent start
|
100 |
|
|
# symbol, since the default linker script might use ENTRY.
|
101 |
|
|
regsub -all "(^|\n)(\[^\n\]*: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
|
102 |
|
|
|
103 |
|
|
# We don't care if we get a message about creating a library file.
|
104 |
|
|
regsub -all "(^|\n)(Creating library file\[^\n\]*\n?)" $exec_output "\\1" exec_output
|
105 |
|
|
|
106 |
|
|
if [string match "" $exec_output] then {
|
107 |
|
|
return 1
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
verbose -log "$exec_output"
|
111 |
|
|
return 0
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
set tmpdir tmpdir
|
115 |
|
|
set SHCFLAG ""
|
116 |
|
|
|
117 |
|
|
if [istarget *-pc-cygwin] {
|
118 |
|
|
# Set some libs needed for cygwin.
|
119 |
|
|
set MYLIBS "-L/usr/lib -lcygwin -L/usr/lib/w32api -lkernel32"
|
120 |
|
|
|
121 |
|
|
# Compile the dll.
|
122 |
|
|
if ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/dll.c $tmpdir/dll.o] {
|
123 |
|
|
fail "compiling shared lib"
|
124 |
|
|
}
|
125 |
|
|
if ![ld_special_link "$ld -shared --enable-auto-import --out-implib=$tmpdir/libstandard.dll.a" $tmpdir/dll.dll "$tmpdir/dll.o $MYLIBS"] {
|
126 |
|
|
fail "linking shared lib"
|
127 |
|
|
}
|
128 |
|
|
|
129 |
|
|
# Create symbolic link.
|
130 |
|
|
catch "exec ln -fs dll.dll $tmpdir/libsymlinked_dll.dll.a" ln_catch
|
131 |
|
|
|
132 |
|
|
# Compile and link the client program.
|
133 |
|
|
if ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/client.c $tmpdir/client.o] {
|
134 |
|
|
fail "compiling client"
|
135 |
|
|
}
|
136 |
|
|
|
137 |
|
|
# Check linking with import library.
|
138 |
|
|
set msg "linking auto-import client using a standard import library"
|
139 |
|
|
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"] {
|
140 |
|
|
pass $msg
|
141 |
|
|
} else {
|
142 |
|
|
fail $msg
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
# Check linking directly with dll.
|
146 |
|
|
set msg "linking auto-import client using the dll"
|
147 |
|
|
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"] {
|
148 |
|
|
pass $msg
|
149 |
|
|
} else {
|
150 |
|
|
fail $msg
|
151 |
|
|
}
|
152 |
|
|
|
153 |
|
|
# Check linking with symlinked dll.
|
154 |
|
|
set msg "linking auto-import client using symbolic linked dll"
|
155 |
|
|
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"] {
|
156 |
|
|
pass $msg
|
157 |
|
|
} else {
|
158 |
|
|
fail $msg
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
# Check linking with disabled auto-import, this must produce linking error.
|
162 |
|
|
set msg "linking with disabled auto-import"
|
163 |
|
|
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"] {
|
164 |
|
|
pass $msg
|
165 |
|
|
} else {
|
166 |
|
|
fail $msg
|
167 |
|
|
}
|
168 |
|
|
|
169 |
|
|
# Check that the app works - ie that there is output when the applications runs.
|
170 |
|
|
set msg "application runtime segfault check"
|
171 |
|
|
catch "exec $tmpdir/client-linklib.exe" exec_output
|
172 |
|
|
if ![string match "" $exec_output] then {
|
173 |
|
|
pass $msg
|
174 |
|
|
} else {
|
175 |
|
|
fail $msg
|
176 |
|
|
}
|
177 |
|
|
}
|