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.
3 # Copyright
(C
) 2020-2022 Free Software Foundation
, Inc.
5 # This file is part of the GNU Binutils.
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.
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.
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
,
22 # Based
on the script pe
-run.exp written by Pedro Alves.
23 # Written by Kai Tietz
<kai.tietz@onevision.com
>
28 # This test checks the
"direct linking to a dll" functionality with stdcall
29 # and fastcall fixup. The dll will be created using a
'def' file
31 # The test has
7 stages
:
33 #
1.
compile and link a test dll with
".dll" extension.
35 #
2.
compile and link a test dll with
".sl" (i.e. != ".dll") extension.
37 #
3.
compile and link a client application linking directly to the
".dll" dll built in 1.
38 # This should produce no errors.
40 #
4.
compile and link a client application linking directly to the
".sl" dll built in 2.
41 # This should produce no errors.
43 #
5.
compile and link a client application linking directly to a symlink into
44 # the
".dll" dll built in 1.
45 # This should produce no errors.
47 #
6.
compile and link a client application linking directly to a symlink into
48 # the
".sl" dll built in 1.
49 # This should produce no errors.
51 #
7. run the produced executables
53 # This test can only be run
on PE
/COFF platforms.
54 if {![is_pecoff_format
]} {
58 # No compiler
, no test.
59 if { ![check_compiler_available
] } {
60 untested
"Direct linking to dll fastcall/stdcall test - no compiler found"
66 proc test_direct2_link_dll_def
{} {
68 global CFLAGS_FOR_TARGET
74 if ![ld_compile
"$CC_FOR_TARGET $CFLAGS_FOR_TARGET" $srcdir/$subdir/direct2_dll.c $tmpdir/direct2_dll.o ] {
75 fail
"compiling shared lib fastcall/stdcall"
76 } elseif
![ld_link
"$CC_FOR_TARGET -shared -Wl,--enable-stdcall-fixup -Wl,--kill-at " $tmpdir/direct2_dll.dll "$tmpdir/direct2_dll.o $srcdir/$subdir/direct2_dll.def" ] {
77 fail
"linking shared lib (.dll) fastcall/stdcall"
78 } elseif
![ld_link
"$CC_FOR_TARGET -shared -Wl,--enable-stdcall-fixup -Wl,--kill-at " $tmpdir/direct2_dll.sl "$tmpdir/direct2_dll.o $srcdir/$subdir/direct2_dll.def" ] {
79 fail
"linking shared lib (.sl) fastcall/stdcall"
81 #
Compile and link the client
program.
82 if ![ld_compile
"$CC_FOR_TARGET $CFLAGS_FOR_TARGET" $srcdir/$subdir/direct2_client.c $tmpdir/direct2_client.o ] {
83 fail
"compiling client fastcall/stdcall"
85 # Check linking to
import library.
86 set msg
"linking client (.dll) fastcall/stdcall"
87 if [ld_link
"$CC_FOR_TARGET $CFLAGS_FOR_TARGET -Wl,--enable-stdcall-fixup -Wl,--enable-auto-import" $tmpdir/direct2_client_dll.exe \
88 "$tmpdir/direct2_client.o -L$tmpdir -ldirect2_dll" ] {
94 # Check linking directly to direct2_dll.dll.
95 set msg
"linking client (.dll) fastcall/stdcall"
96 if [ld_link
"$CC_FOR_TARGET $CFLAGS_FOR_TARGET -Wl,--enable-stdcall-fixup -Wl,--enable-auto-import" $tmpdir/direct2_client_dll.exe \
97 "$tmpdir/direct2_client.o $tmpdir/direct2_dll.dll" ] {
103 # Check linking directly to direct2_dll.sl.
104 set msg
"linking client (.sl) fastcall/stdcall"
105 if [ld_link
"$CC_FOR_TARGET $CFLAGS_FOR_TARGET -Wl,--enable-stdcall-fixup -Wl,--enable-auto-import" $tmpdir/direct2_client_sl.exe \
106 "$tmpdir/direct2_client.o $tmpdir/direct2_dll.sl" ] {
112 # Check dll direct linking through symlink to .dll.
113 # Create symbolic link.
114 catch
"exec ln -fs direct2_dll.dll $tmpdir/libdirect2_dll.dll.a" ln_catch
115 set msg
"linking client (symlink -> .dll) fastcall/stdcall"
116 if [ld_link
"$CC_FOR_TARGET $CFLAGS_FOR_TARGET -Wl,--enable-stdcall-fixup -Wl,--enable-auto-import" $tmpdir/direct2_client_symlink_dll.exe \
117 "$tmpdir/direct2_client.o $tmpdir/libdirect2_dll.dll.a" ] {
123 # Check dll direct linking through symlink to .sl.
124 # Create symbolic link.
125 catch
"exec ln -fs direct2_dll.sl $tmpdir/libdirect2_sl.dll.a" ln_catch
126 set msg
"linking client (symlink -> .sl) fastcall/stdcall"
127 if [ld_link
"$CC_FOR_TARGET $CFLAGS_FOR_TARGET -Wl,--enable-stdcall-fixup -Wl,--enable-auto-import" $tmpdir/direct2_client_symlink_sl.exe \
128 "$tmpdir/direct2_client.o $tmpdir/libdirect2_sl.dll.a" ] {
137 proc directdll_execute
{exe msg
} {
139 catch
"exec $exe" prog_output
140 if [string match $expected $prog_output
] then {
148 test_direct2_link_dll_def
150 # This is as far as we can go with a cross
-compiler
151 if ![isnative
] then {
152 verbose
"Not running natively, so cannot execute binaries"
156 directdll_execute
"$tmpdir/direct2_client_dll.exe" "running direct linked dll (.dll) fastcall/stdcall"
157 directdll_execute
"$tmpdir/direct2_client_sl.exe" "running direct linked dll (.sl) fastcall/stdcall"
158 directdll_execute
"$tmpdir/direct2_client_symlink_sl.exe" "running direct linked dll (symlink -> .sl) fastcall/stdcall"
159 directdll_execute
"$tmpdir/direct2_client_symlink_dll.exe" "running direct linked dll (symlink -> .dll) fastcall/stdcall"