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