]>
Commit | Line | Data |
---|---|---|
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. | |
fd67aa11 | 3 | # Copyright (C) 2006-2024 Free Software Foundation, Inc. |
f6fe8b45 | 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 | |
f6fe8b45 | 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 |
f6fe8b45 | 10 | # (at your option) any later version. |
f96b4a7b | 11 | # |
f6fe8b45 CF |
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 | # |
f6fe8b45 CF |
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. | |
f6fe8b45 CF |
21 | # |
22 | # Written by Pedro Alves <pedro_alves@portugalmail.pt> | |
23 | # | |
24 | ||
25 | # Note: | |
26 | # | |
27 | # This test checks the "direct linking to a dll" functionality. | |
28 | # | |
29 | # The test has 7 stages: | |
30 | # | |
31 | # 1. compile and link a test dll with ".dll" extension. | |
32 | # | |
33 | # 2. compile and link a test dll with ".sl" (i.e. != ".dll") extension. | |
34 | # | |
35 | # 3. compile and link a client application linking directly to the ".dll" dll built in 1. | |
36 | # This should produce no errors. | |
37 | # | |
38 | # 4. compile and link a client application linking directly to the ".sl" dll built in 2. | |
39 | # This should produce no errors. | |
40 | # | |
41 | # 5. compile and link a client application linking directly to a symlink into | |
42 | # the ".dll" dll built in 1. | |
43 | # This should produce no errors. | |
44 | # | |
45 | # 6. compile and link a client application linking directly to a symlink into | |
46 | # the ".sl" dll built in 1. | |
47 | # This should produce no errors. | |
48 | # | |
49 | # 7. run the produced executables | |
50 | ||
51 | # This test can only be run on PE/COFF platforms. | |
d127ecce | 52 | if {![is_pecoff_format]} { |
f6fe8b45 CF |
53 | return |
54 | } | |
55 | ||
56 | # No compiler, no test. | |
44ed8092 | 57 | if { ![check_compiler_available] } { |
f6fe8b45 CF |
58 | untested "Direct linking to dll test" |
59 | return | |
60 | } | |
61 | ||
62 | set tmpdir tmpdir | |
63 | ||
64 | proc test_direct_link_dll {} { | |
ad77db1c | 65 | global CC_FOR_TARGET |
f6fe8b45 CF |
66 | global srcdir |
67 | global subdir | |
68 | global tmpdir | |
c1711530 | 69 | |
f6fe8b45 | 70 | # Compile the dll. |
669d5115 | 71 | if ![ld_compile $CC_FOR_TARGET $srcdir/$subdir/direct_dll.c $tmpdir/direct_dll.o ] { |
f6fe8b45 | 72 | fail "compiling shared lib" |
ad77db1c | 73 | } elseif ![ld_link "$CC_FOR_TARGET -shared" $tmpdir/direct_dll.dll "$tmpdir/direct_dll.o" ] { |
f6fe8b45 | 74 | fail "linking shared lib (.dll)" |
ad77db1c | 75 | } elseif ![ld_link "$CC_FOR_TARGET -shared" $tmpdir/direct_dll.sl "$tmpdir/direct_dll.o" ] { |
f6fe8b45 CF |
76 | fail "linking shared lib (.sl)" |
77 | } else { | |
78 | # Compile and link the client program. | |
669d5115 | 79 | if ![ld_compile $CC_FOR_TARGET $srcdir/$subdir/direct_client.c $tmpdir/direct_client.o ] { |
f6fe8b45 CF |
80 | fail "compiling client" |
81 | } else { | |
82 | # Check linking directly to direct_dll.dll. | |
83 | set msg "linking client (.dll)" | |
ad77db1c | 84 | if [ld_link "$CC_FOR_TARGET -Wl,--enable-auto-import" $tmpdir/direct_client_dll.exe \ |
470c710e | 85 | "$tmpdir/direct_client.o $tmpdir/direct_dll.dll" ] { |
f6fe8b45 CF |
86 | pass $msg |
87 | } else { | |
88 | fail $msg | |
89 | } | |
90 | ||
91 | # Check linking directly to direct_dll.sl. | |
92 | set msg "linking client (.sl)" | |
ad77db1c | 93 | if [ld_link "$CC_FOR_TARGET -Wl,--enable-auto-import" $tmpdir/direct_client_sl.exe \ |
470c710e | 94 | "$tmpdir/direct_client.o $tmpdir/direct_dll.sl" ] { |
f6fe8b45 CF |
95 | pass $msg |
96 | } else { | |
97 | fail $msg | |
98 | } | |
99 | ||
100 | # Check dll direct linking through symlink to .dll. | |
101 | # Create symbolic link. | |
102 | catch "exec ln -fs direct_dll.dll $tmpdir/libdirect_dll.dll.a" ln_catch | |
103 | set msg "linking client (symlink -> .dll)" | |
ad77db1c | 104 | if [ld_link "$CC_FOR_TARGET -Wl,--enable-auto-import" $tmpdir/direct_client_symlink_dll.exe \ |
470c710e | 105 | "$tmpdir/direct_client.o $tmpdir/libdirect_dll.dll.a" ] { |
f6fe8b45 CF |
106 | pass $msg |
107 | } else { | |
108 | fail $msg | |
109 | } | |
110 | ||
111 | # Check dll direct linking through symlink to .sl. | |
112 | # Create symbolic link. | |
113 | catch "exec ln -fs direct_dll.sl $tmpdir/libdirect_sl.dll.a" ln_catch | |
114 | set msg "linking client (symlink -> .sl)" | |
ad77db1c | 115 | if [ld_link "$CC_FOR_TARGET -Wl,--enable-auto-import" $tmpdir/direct_client_symlink_sl.exe \ |
470c710e | 116 | "$tmpdir/direct_client.o $tmpdir/libdirect_sl.dll.a" ] { |
f6fe8b45 CF |
117 | pass $msg |
118 | } else { | |
119 | fail $msg | |
120 | } | |
121 | } | |
122 | } | |
123 | } | |
124 | ||
125 | proc directdll_execute {exe msg} { | |
126 | set expected "" | |
127 | catch "exec $exe" prog_output | |
128 | if [string match $expected $prog_output] then { | |
129 | pass $msg | |
130 | } else { | |
131 | verbose $prog_output | |
132 | fail $msg | |
133 | } | |
134 | } | |
135 | ||
136 | test_direct_link_dll | |
137 | ||
138 | # This is as far as we can go with a cross-compiler | |
139 | if ![isnative] then { | |
140 | verbose "Not running natively, so cannot execute binaries" | |
141 | return | |
142 | } | |
143 | ||
144 | directdll_execute "$tmpdir/direct_client_dll.exe" "running direct linked dll (.dll)" | |
145 | directdll_execute "$tmpdir/direct_client_sl.exe" "running direct linked dll (.sl)" | |
146 | directdll_execute "$tmpdir/direct_client_symlink_sl.exe" "running direct linked dll (symlink -> .sl)" | |
147 | directdll_execute "$tmpdir/direct_client_symlink_dll.exe" "running direct linked dll (symlink -> .dll)" |