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-2017 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 # Written by Pedro Alves <pedro_alves@portugalmail.pt>
27 # This test checks the "direct linking to a dll" functionality.
29 # The test has 7 stages:
31 # 1. compile and link a test dll with ".dll" extension.
33 # 2. compile and link a test dll with ".sl" (i.e. != ".dll") extension.
35 # 3. compile and link a client application linking directly to the ".dll" dll built in 1.
36 # This should produce no errors.
38 # 4. compile and link a client application linking directly to the ".sl" dll built in 2.
39 # This should produce no errors.
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.
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.
49 # 7. run the produced executables
51 # This test can only be run on PE/COFF platforms.
52 if {![is_pecoff_format]} {
56 # No compiler, no test.
57 if { [which $CC] == 0 } {
58 untested "Direct linking to dll test"
64 proc test_direct_link_dll {} {
72 if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/direct_dll.c $tmpdir/direct_dll.o ] {
73 fail "compiling shared lib"
74 } elseif ![ld_simple_link "$CC -shared" $tmpdir/direct_dll.dll "$tmpdir/direct_dll.o" ] {
75 fail "linking shared lib (.dll)"
76 } elseif ![ld_simple_link "$CC -shared" $tmpdir/direct_dll.sl "$tmpdir/direct_dll.o" ] {
77 fail "linking shared lib (.sl)"
79 # Compile and link the client program.
80 if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/direct_client.c $tmpdir/direct_client.o ] {
81 fail "compiling client"
83 # Check linking directly to direct_dll.dll.
84 set msg "linking client (.dll)"
85 if [ld_simple_link "$CC -Wl,--enable-auto-import" $tmpdir/direct_client_dll.exe \
86 "$tmpdir/direct_client.o $tmpdir/direct_dll.dll" ] {
92 # Check linking directly to direct_dll.sl.
93 set msg "linking client (.sl)"
94 if [ld_simple_link "$CC -Wl,--enable-auto-import" $tmpdir/direct_client_sl.exe \
95 "$tmpdir/direct_client.o $tmpdir/direct_dll.sl" ] {
101 # Check dll direct linking through symlink to .dll.
102 # Create symbolic link.
103 catch "exec ln -fs direct_dll.dll $tmpdir/libdirect_dll.dll.a" ln_catch
104 set msg "linking client (symlink -> .dll)"
105 if [ld_simple_link "$CC -Wl,--enable-auto-import" $tmpdir/direct_client_symlink_dll.exe \
106 "$tmpdir/direct_client.o $tmpdir/libdirect_dll.dll.a" ] {
112 # Check dll direct linking through symlink to .sl.
113 # Create symbolic link.
114 catch "exec ln -fs direct_dll.sl $tmpdir/libdirect_sl.dll.a" ln_catch
115 set msg "linking client (symlink -> .sl)"
116 if [ld_simple_link "$CC -Wl,--enable-auto-import" $tmpdir/direct_client_symlink_sl.exe \
117 "$tmpdir/direct_client.o $tmpdir/libdirect_sl.dll.a" ] {
126 proc directdll_execute {exe msg} {
128 catch "exec $exe" prog_output
129 if [string match $expected $prog_output] then {
139 # This is as far as we can go with a cross-compiler
140 if ![isnative] then {
141 verbose "Not running natively, so cannot execute binaries"
145 directdll_execute "$tmpdir/direct_client_dll.exe" "running direct linked dll (.dll)"
146 directdll_execute "$tmpdir/direct_client_sl.exe" "running direct linked dll (.sl)"
147 directdll_execute "$tmpdir/direct_client_symlink_sl.exe" "running direct linked dll (symlink -> .sl)"
148 directdll_execute "$tmpdir/direct_client_symlink_dll.exe" "running direct linked dll (symlink -> .dll)"