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