Unbreak Windows-hosted cross debugger builds.
[deliverable/binutils-gdb.git] / ld / testsuite / ld-pe / pe-run.exp
CommitLineData
c1711530
DK
1# Expect script for complex PE tests that require a C compiler and the ability
2# to run target executables natively, in addition to the just-built binutils.
aa820537 3# Copyright 2006, 2007, 2009
f6fe8b45
CF
4# Free Software Foundation, Inc.
5#
f96b4a7b
NC
6# This file is part of the GNU Binutils.
7#
8# This program is free software; you can redistribute it and/or modify
f6fe8b45 9# it under the terms of the GNU General Public License as published by
f96b4a7b 10# the Free Software Foundation; either version 3 of the License, or
f6fe8b45 11# (at your option) any later version.
f96b4a7b 12#
f6fe8b45
CF
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
f96b4a7b 17#
f6fe8b45
CF
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
f96b4a7b
NC
20# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21# MA 02110-1301, USA.
f6fe8b45
CF
22#
23# Written by Pedro Alves <pedro_alves@portugalmail.pt>
24#
25
26# Note:
27#
28# This test checks the "direct linking to a dll" functionality.
29#
30# The test has 7 stages:
31#
32# 1. compile and link a test dll with ".dll" extension.
33#
34# 2. compile and link a test dll with ".sl" (i.e. != ".dll") extension.
35#
36# 3. compile and link a client application linking directly to the ".dll" dll built in 1.
37# This should produce no errors.
38#
39# 4. compile and link a client application linking directly to the ".sl" dll built in 2.
40# This should produce no errors.
41#
42# 5. compile and link a client application linking directly to a symlink into
43# the ".dll" dll built in 1.
44# This should produce no errors.
45#
46# 6. compile and link a client application linking directly to a symlink into
47# the ".sl" dll built in 1.
48# This should produce no errors.
49#
50# 7. run the produced executables
51
52# This test can only be run on PE/COFF platforms.
d127ecce 53if {![is_pecoff_format]} {
f6fe8b45
CF
54 return
55}
56
57# No compiler, no test.
58if { [which $CC] == 0 } {
59 untested "Direct linking to dll test"
60 return
61}
62
63set tmpdir tmpdir
64
65proc test_direct_link_dll {} {
66 global CC
67 global CFLAGS
68 global srcdir
69 global subdir
70 global tmpdir
c1711530 71
f6fe8b45
CF
72 # Compile the dll.
73 if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/direct_dll.c $tmpdir/direct_dll.o ] {
74 fail "compiling shared lib"
75 } elseif ![ld_simple_link "$CC -shared" $tmpdir/direct_dll.dll "$tmpdir/direct_dll.o" ] {
76 fail "linking shared lib (.dll)"
77 } elseif ![ld_simple_link "$CC -shared" $tmpdir/direct_dll.sl "$tmpdir/direct_dll.o" ] {
78 fail "linking shared lib (.sl)"
79 } else {
80 # Compile and link the client program.
81 if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/direct_client.c $tmpdir/direct_client.o ] {
82 fail "compiling client"
83 } else {
84 # Check linking directly to direct_dll.dll.
85 set msg "linking client (.dll)"
11275b5a 86 if [ld_simple_link "$CC -Wl,--enable-auto-import" $tmpdir/direct_client_dll.exe \
470c710e 87 "$tmpdir/direct_client.o $tmpdir/direct_dll.dll" ] {
f6fe8b45
CF
88 pass $msg
89 } else {
90 fail $msg
91 }
92
93 # Check linking directly to direct_dll.sl.
94 set msg "linking client (.sl)"
11275b5a 95 if [ld_simple_link "$CC -Wl,--enable-auto-import" $tmpdir/direct_client_sl.exe \
470c710e 96 "$tmpdir/direct_client.o $tmpdir/direct_dll.sl" ] {
f6fe8b45
CF
97 pass $msg
98 } else {
99 fail $msg
100 }
101
102 # Check dll direct linking through symlink to .dll.
103 # Create symbolic link.
104 catch "exec ln -fs direct_dll.dll $tmpdir/libdirect_dll.dll.a" ln_catch
105 set msg "linking client (symlink -> .dll)"
11275b5a 106 if [ld_simple_link "$CC -Wl,--enable-auto-import" $tmpdir/direct_client_symlink_dll.exe \
470c710e 107 "$tmpdir/direct_client.o $tmpdir/libdirect_dll.dll.a" ] {
f6fe8b45
CF
108 pass $msg
109 } else {
110 fail $msg
111 }
112
113 # Check dll direct linking through symlink to .sl.
114 # Create symbolic link.
115 catch "exec ln -fs direct_dll.sl $tmpdir/libdirect_sl.dll.a" ln_catch
116 set msg "linking client (symlink -> .sl)"
11275b5a 117 if [ld_simple_link "$CC -Wl,--enable-auto-import" $tmpdir/direct_client_symlink_sl.exe \
470c710e 118 "$tmpdir/direct_client.o $tmpdir/libdirect_sl.dll.a" ] {
f6fe8b45
CF
119 pass $msg
120 } else {
121 fail $msg
122 }
123 }
124 }
125}
126
127proc directdll_execute {exe msg} {
128 set expected ""
129 catch "exec $exe" prog_output
130 if [string match $expected $prog_output] then {
131 pass $msg
132 } else {
133 verbose $prog_output
134 fail $msg
135 }
136}
137
138test_direct_link_dll
139
140# This is as far as we can go with a cross-compiler
141if ![isnative] then {
142 verbose "Not running natively, so cannot execute binaries"
143 return
144}
145
146directdll_execute "$tmpdir/direct_client_dll.exe" "running direct linked dll (.dll)"
147directdll_execute "$tmpdir/direct_client_sl.exe" "running direct linked dll (.sl)"
148directdll_execute "$tmpdir/direct_client_symlink_sl.exe" "running direct linked dll (symlink -> .sl)"
149directdll_execute "$tmpdir/direct_client_symlink_dll.exe" "running direct linked dll (symlink -> .dll)"
This page took 0.26986 seconds and 4 git commands to generate.