OSDN Git Service

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