Commit | Line | Data |
---|---|---|
6bdf432d | 1 | # Expect script for ld-auto-import tests |
2571583a | 2 | # Copyright (C) 2002-2017 Free Software Foundation, Inc. |
6bdf432d | 3 | # |
f96b4a7b NC |
4 | # This file is part of the GNU Binutils. |
5 | # | |
6 | # This program is free software; you can redistribute it and/or modify | |
6bdf432d | 7 | # it under the terms of the GNU General Public License as published by |
f96b4a7b | 8 | # the Free Software Foundation; either version 3 of the License, or |
6bdf432d | 9 | # (at your option) any later version. |
f96b4a7b | 10 | # |
6bdf432d NC |
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. | |
f96b4a7b | 15 | # |
6bdf432d NC |
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 | |
f96b4a7b NC |
18 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
19 | # MA 02110-1301, USA. | |
6bdf432d NC |
20 | # |
21 | # Written by Ralf.Habacker@freenet.de | |
22 | # Based on ls-shared/shared.exp by Ian Lance Taylor (ian@cygnus.com) | |
23 | # | |
24 | ||
25 | # Note: | |
26 | # | |
e42e4a8b NC |
27 | # This script tests some auto-import functionality: |
28 | # | |
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: | |
33 | # | |
34 | # 1. compile and link a test dll exporting some text and data symbols and a | |
35 | # standard import library | |
36 | # | |
37 | # 2. create a symbolic link to this dll to simulate a replaced import library. | |
6bdf432d | 38 | # |
e42e4a8b NC |
39 | # 3. compile and link a client application with the standard import library. |
40 | # This should produce no errors. | |
6bdf432d | 41 | # |
e42e4a8b NC |
42 | # 4. compile and link a client application with the created dll. |
43 | # This should also produce no errors. | |
6bdf432d | 44 | # |
e42e4a8b NC |
45 | # 5. compile and link a client application using the "import library". |
46 | # This should also produce no errors. | |
6bdf432d | 47 | # |
e42e4a8b NC |
48 | # 6. compile and link a client application with auto-import disabled. |
49 | # This should produce a linking error. | |
50 | # | |
51 | # B. runtime check if there are no segfaults when importing const data variables | |
6bdf432d | 52 | # |
6bdf432d NC |
53 | |
54 | # This test can only be run if ld generates native executables. | |
55 | if ![isnative] then {return} | |
56 | ||
e42e4a8b | 57 | # This test can only be run on a couple of platforms. |
6bdf432d NC |
58 | # Square bracket expressions seem to confuse istarget. |
59 | if { ![istarget *-pc-cygwin] | |
60 | && ![istarget *-pc-mingw*] } { | |
61 | return | |
62 | } | |
63 | ||
e42e4a8b NC |
64 | if [istarget *-pc-mingw*] { |
65 | # FIXME: Add support for this target. | |
66 | unsupported "mingw currently not supported" | |
67 | } | |
68 | ||
6bdf432d NC |
69 | # No compiler, no test. |
70 | if { [which $CC] == 0 } { | |
e42e4a8b | 71 | untested "Auto import test (compiler not found)" |
6bdf432d NC |
72 | return |
73 | } | |
74 | ||
75 | # ld_special_link | |
76 | # link a program using ld, without including any libraries | |
77 | # | |
78 | proc ld_special_link { ld target objects } { | |
79 | global host_triplet | |
80 | global link_output | |
81 | ||
82 | if { [which $ld] == 0 } then { | |
83 | perror "$ld does not exist" | |
84 | return 0 | |
85 | } | |
86 | ||
87 | if [is_endian_output_format $objects] then { | |
88 | set flags [big_or_little_endian] | |
89 | } else { | |
90 | set flags "" | |
91 | } | |
92 | ||
93 | verbose -log "$ld $flags -o $target $objects" | |
94 | ||
95 | catch "exec $ld $flags -o $target $objects" link_output | |
96 | set exec_output [prune_warnings $link_output] | |
97 | ||
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 | |
101 | ||
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 | |
104 | ||
105 | if [string match "" $exec_output] then { | |
106 | return 1 | |
6bdf432d | 107 | } |
e42e4a8b NC |
108 | |
109 | verbose -log "$exec_output" | |
110 | return 0 | |
6bdf432d NC |
111 | } |
112 | ||
113 | set tmpdir tmpdir | |
114 | set SHCFLAG "" | |
115 | ||
116 | if [istarget *-pc-cygwin] { | |
117 | # Set some libs needed for cygwin. | |
118 | set MYLIBS "-L/usr/lib -lcygwin -L/usr/lib/w32api -lkernel32" | |
119 | ||
120 | # Compile the dll. | |
e42e4a8b | 121 | if ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/dll.c $tmpdir/dll.o] { |
6bdf432d | 122 | fail "compiling shared lib" |
e42e4a8b | 123 | } |
588b6e15 | 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"] { |
6bdf432d | 125 | fail "linking shared lib" |
e42e4a8b NC |
126 | } |
127 | ||
128 | # Create symbolic link. | |
129 | catch "exec ln -fs dll.dll $tmpdir/libsymlinked_dll.dll.a" ln_catch | |
130 | ||
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" | |
134 | } | |
135 | ||
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"] { | |
139 | pass $msg | |
6bdf432d | 140 | } else { |
e42e4a8b | 141 | fail $msg |
6bdf432d | 142 | } |
6bdf432d | 143 | |
e42e4a8b NC |
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"] { | |
147 | pass $msg | |
148 | } else { | |
149 | fail $msg | |
150 | } | |
151 | ||
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"] { | |
155 | pass $msg | |
156 | } else { | |
157 | fail $msg | |
158 | } | |
159 | ||
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"] { | |
163 | pass $msg | |
164 | } else { | |
165 | fail $msg | |
166 | } | |
167 | ||
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 { | |
172 | pass $msg | |
173 | } else { | |
174 | fail $msg | |
175 | } | |
6bdf432d | 176 | } |