* ldexp.c: Add LOG2CEIL() builtin function to linker script language
[deliverable/binutils-gdb.git] / ld / testsuite / ld-auto-import / auto-import.exp
CommitLineData
6bdf432d 1# Expect script for ld-auto-import tests
aa820537 2# Copyright 2002, 2005, 2007, 2008, 2009
6bdf432d
NC
3# Free Software Foundation, Inc.
4#
f96b4a7b
NC
5# This file is part of the GNU Binutils.
6#
7# This program is free software; you can redistribute it and/or modify
6bdf432d 8# it under the terms of the GNU General Public License as published by
f96b4a7b 9# the Free Software Foundation; either version 3 of the License, or
6bdf432d 10# (at your option) any later version.
f96b4a7b 11#
6bdf432d
NC
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.
f96b4a7b 16#
6bdf432d
NC
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
f96b4a7b
NC
19# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20# MA 02110-1301, USA.
6bdf432d
NC
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#
e42e4a8b
NC
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.
6bdf432d 39#
e42e4a8b
NC
40# 3. compile and link a client application with the standard import library.
41# This should produce no errors.
6bdf432d 42#
e42e4a8b
NC
43# 4. compile and link a client application with the created dll.
44# This should also produce no errors.
6bdf432d 45#
e42e4a8b
NC
46# 5. compile and link a client application using the "import library".
47# This should also produce no errors.
6bdf432d 48#
e42e4a8b
NC
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
6bdf432d 53#
6bdf432d
NC
54
55# This test can only be run if ld generates native executables.
56if ![isnative] then {return}
57
e42e4a8b 58# This test can only be run on a couple of platforms.
6bdf432d
NC
59# Square bracket expressions seem to confuse istarget.
60if { ![istarget *-pc-cygwin]
61 && ![istarget *-pc-mingw*] } {
62 return
63}
64
e42e4a8b
NC
65if [istarget *-pc-mingw*] {
66 # FIXME: Add support for this target.
67 unsupported "mingw currently not supported"
68}
69
6bdf432d
NC
70# No compiler, no test.
71if { [which $CC] == 0 } {
e42e4a8b 72 untested "Auto import test (compiler not found)"
6bdf432d
NC
73 return
74}
75
76# ld_special_link
77# link a program using ld, without including any libraries
78#
79proc 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
6bdf432d 108 }
e42e4a8b
NC
109
110 verbose -log "$exec_output"
111 return 0
6bdf432d
NC
112}
113
114set tmpdir tmpdir
115set SHCFLAG ""
116
117if [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.
e42e4a8b 122 if ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/dll.c $tmpdir/dll.o] {
6bdf432d 123 fail "compiling shared lib"
e42e4a8b 124 }
588b6e15 125 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 126 fail "linking shared lib"
e42e4a8b
NC
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
6bdf432d 141 } else {
e42e4a8b 142 fail $msg
6bdf432d 143 }
6bdf432d 144
e42e4a8b
NC
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 }
6bdf432d 177}
This page took 0.45293 seconds and 4 git commands to generate.