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) 2006-2019 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
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 { [which $CC] == 0 } {
60 untested "Direct linking to dll fastcall/stdcall test"
66 proc test_direct2_link_dll {} {
74 if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/direct2_dll.c $tmpdir/direct2_dll.o ] {
75 fail "compiling shared lib fastcall/stdcall"
76 } elseif ![ld_link "$CC -shared -Wl,--enable-stdcall-fixup -Wl,--kill-at " $tmpdir/direct2_dll.dll "$tmpdir/direct2_dll.o" ] {
77 fail "linking shared lib (.dll) fastcall/stdcall"
78 } elseif ![ld_link "$CC -shared -Wl,--enable-stdcall-fixup -Wl,--kill-at " $tmpdir/direct2_dll.sl "$tmpdir/direct2_dll.o" ] {
79 fail "linking shared lib (.sl) fastcall/stdcall"
81 # Compile and link the client program.
82 if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/direct2_client.c $tmpdir/direct2_client.o ] {
83 fail "compiling client fastcall/stdcall"
85 # Check linking directly to direct2_dll.dll.
86 set msg "linking client (.dll) fastcall/stdcall"
87 if [ld_link "$CC $CFLAGS -Wl,--enable-stdcall-fixup -Wl,--enable-auto-import" $tmpdir/direct2_client_dll.exe \
88 "$tmpdir/direct2_client.o $tmpdir/direct2_dll.dll" ] {
94 # Check linking directly to direct2_dll.sl.
95 set msg "linking client (.sl) fastcall/stdcall"
96 if [ld_link "$CC $CFLAGS -Wl,--enable-stdcall-fixup -Wl,--enable-auto-import" $tmpdir/direct2_client_sl.exe \
97 "$tmpdir/direct2_client.o $tmpdir/direct2_dll.sl" ] {
103 # Check dll direct linking through symlink to .dll.
104 # Create symbolic link.
105 catch "exec ln -fs direct2_dll.dll $tmpdir/libdirect2_dll.dll.a" ln_catch
106 set msg "linking client (symlink -> .dll) fastcall/stdcall"
107 if [ld_link "$CC $CFLAGS -Wl,--enable-stdcall-fixup -Wl,--enable-auto-import" $tmpdir/direct2_client_symlink_dll.exe \
108 "$tmpdir/direct2_client.o $tmpdir/libdirect2_dll.dll.a" ] {
114 # Check dll direct linking through symlink to .sl.
115 # Create symbolic link.
116 catch "exec ln -fs direct2_dll.sl $tmpdir/libdirect2_sl.dll.a" ln_catch
117 set msg "linking client (symlink -> .sl) fastcall/stdcall"
118 if [ld_link "$CC $CFLAGS -Wl,--enable-stdcall-fixup -Wl,--enable-auto-import" $tmpdir/direct2_client_symlink_sl.exe \
119 "$tmpdir/direct2_client.o $tmpdir/libdirect2_sl.dll.a" ] {
128 proc directdll_execute {exe msg} {
130 catch "exec $exe" prog_output
131 if [string match $expected $prog_output] then {
139 test_direct2_link_dll
141 # This is as far as we can go with a cross-compiler
142 if ![isnative] then {
143 verbose "Not running natively, so cannot execute binaries"
147 directdll_execute "$tmpdir/direct2_client_dll.exe" "running direct linked dll (.dll) fastcall/stdcall"
148 directdll_execute "$tmpdir/direct2_client_sl.exe" "running direct linked dll (.sl) fastcall/stdcall"
149 directdll_execute "$tmpdir/direct2_client_symlink_sl.exe" "running direct linked dll (symlink -> .sl) fastcall/stdcall"
150 directdll_execute "$tmpdir/direct2_client_symlink_dll.exe" "running direct linked dll (symlink -> .dll) fastcall/stdcall"