fe2a3abad2c4f8fdf01b7d11375235c64f6225d5
[deliverable/binutils-gdb.git] / ld / testsuite / ld-cygwin / exe-export.exp
1 # Expect script for export table in executables tests
2 # Copyright 2003
3 # Free Software Foundation, Inc.
4 #
5 # This file is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 #
19 # Written by Fabrizio Gennari <fabrizio.ge@tiscalinet.it>
20 # Based on auto-import.exp by Ralf.Habacker@freenet.de
21 #
22
23 # This test can only be run on a cygwin platforms.
24 if {![istarget *-pc-cygwin]} {
25 verbose "Not a cygwin target."
26 return
27 }
28
29 # No compiler, no test.
30 if { [which $CC] == 0 } {
31 untested "Exe export test (no compiler available)"
32 return
33 }
34
35 proc run_dlltool { lib_file def_file } {
36 global dlltool
37 global base_dir
38 global as
39
40 if ![info exists dlltool] then {
41 set dlltool [findfile $base_dir/../binutils/dlltool]
42 }
43
44 if { [which $dlltool] == 0 } then {
45 verbose "$dlltool does not exist"
46 return 0
47 }
48
49 verbose "$dlltool --as $as -l $lib_file -d $def_file"
50 catch "exec $dlltool --as $as -l $lib_file -d $def_file" dlltool_output
51
52 #remove empty lines
53 regsub -all "\n+" $dlltool_output "" dlltool_output
54
55 if [string match "" $dlltool_output] then {
56 return 1
57 }
58
59 verbose -log "$dlltool_output"
60 return 0
61 }
62
63 # ld_special_link
64 # A copy of ld_simple_link (from ld-lib.exp) with extra
65 # code to strip warnings about creating libraries.
66 #
67 proc ld_special_link { ld target objects } {
68 global host_triplet
69 global link_output
70
71 if { [which $ld] == 0 } then {
72 verbose "$ld does not exist"
73 return 0
74 }
75
76 if [is_endian_output_format $objects] then {
77 set flags [big_or_little_endian]
78 } else {
79 set flags ""
80 }
81
82 verbose -log "$ld $flags -o $target $objects"
83 catch "exec $ld $flags -o $target $objects" link_output
84
85 set exec_output [prune_warnings $link_output]
86
87 # We don't care if we get a warning about a non-existent start
88 # symbol, since the default linker script might use ENTRY.
89 regsub -all "(^|\n)(\[^\n\]*: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output
90
91 # We don't care if we get a message about creating a library file.
92 regsub -all "(^|\n)(Creating library file\[^\n\]*\n?)" $exec_output "\\1" exec_output
93
94 if [string match "" $exec_output] then {
95 return 1
96 }
97
98 verbose -log "$exec_output"
99 return 0
100 }
101
102 set tmpdir tmpdir
103
104 # Set some libs needed for cygwin.
105 set MYLDFLAGS "-Wl,--out-implib,$tmpdir/testexe.lib -nostartfiles -nostdlib"
106
107 # Build an export library for testdll
108 if ![run_dlltool $tmpdir/testdll.lib $srcdir/$subdir/testdll.def] {
109 fail "building an export library for the shared lib"
110 return
111 }
112
113 # Compile the executable.
114 if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/testexe.c $tmpdir/testexe.o] {
115 fail "compiling executable"
116 return
117 }
118
119 if ![ld_special_link "$CC $LDFLAGS $MYLDFLAGS -e _testexe_main@16" $tmpdir/testexe.exe "$tmpdir/testexe.o $srcdir/$subdir/testexe.def $tmpdir/testdll.lib"] {
120 fail "linking executable"
121 return
122 }
123
124 # Compile the dll.
125 if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/testdll.c $tmpdir/testdll.o] {
126 fail "compiling shared lib"
127 return
128 }
129
130 if ![ld_special_link "$CC $LDFLAGS -nostartfiles -nostdlib -e _testdll_main@12" $tmpdir/testdll.dll "$tmpdir/testdll.o $srcdir/$subdir/testdll.def $tmpdir/testexe.lib"] {
131 fail "linking shared lib"
132 return
133 }
134
135 # This is as far as we can go with a cross-compiler
136 if ![isnative] then {
137 verbose "Not running natively, so cannot execute binary"
138 pass "Compile and link and executable with an export table"
139 return
140 }
141
142 verbose -log "executing $tmpdir/testexe.exe"
143 catch "exec $tmpdir/testexe.exe" prog_output
144
145 set expected ""
146 if [string match $expected $prog_output] then {
147 pass "export table in executable"
148 } else {
149 verbose $prog_output
150 fail "Output does not match expected string $expected"
151 }
This page took 0.032995 seconds and 3 git commands to generate.