Add new test for cygwin target: building an executable with an export table.
authorNick Clifton <nickc@redhat.com>
Mon, 2 Jun 2003 09:11:01 +0000 (09:11 +0000)
committerNick Clifton <nickc@redhat.com>
Mon, 2 Jun 2003 09:11:01 +0000 (09:11 +0000)
ld/testsuite/ChangeLog
ld/testsuite/ld-cygwin/exe-export.exp [new file with mode: 0644]
ld/testsuite/ld-cygwin/testdll.c [new file with mode: 0644]
ld/testsuite/ld-cygwin/testdll.def [new file with mode: 0644]
ld/testsuite/ld-cygwin/testexe.c [new file with mode: 0644]
ld/testsuite/ld-cygwin/testexe.def [new file with mode: 0644]

index f98a3a2..e3152e3 100644 (file)
@@ -1,3 +1,13 @@
+2003-06-02  Fabrizio Gennari  <fabrizio.ge@tiscalinet.it>
+
+       * ld-cygwin: New directory.
+       * ld-cygwin/exe-export.exp: New test script.  Checks building
+       cygwin executables with an export table.
+       * ld-cygwin/testdll.def: New source file.
+       * ld-cygwin/testexe.def: New source file.
+       * ld-cygwin/testdll.c: New source file.
+       * ld-cygwin/testexe.c: New source file.
+
 2003-05-30  H.J. Lu <hongjiu.lu@intel.com>
 
        * config/default.exp: Load tmpdir/libpath.exp.
diff --git a/ld/testsuite/ld-cygwin/exe-export.exp b/ld/testsuite/ld-cygwin/exe-export.exp
new file mode 100644 (file)
index 0000000..fe2a3ab
--- /dev/null
@@ -0,0 +1,151 @@
+# Expect script for export table in executables tests\r
+#   Copyright 2003\r
+#   Free Software Foundation, Inc.\r
+#\r
+# This file is free software; you can redistribute it and/or modify\r
+# it under the terms of the GNU General Public License as published by\r
+# the Free Software Foundation; either version 2 of the License, or\r
+# (at your option) any later version.\r
+# \r
+# This program is distributed in the hope that it will be useful,\r
+# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+# GNU General Public License for more details.\r
+# \r
+# You should have received a copy of the GNU General Public License\r
+# along with this program; if not, write to the Free Software\r
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+#\r
+# Written by Fabrizio Gennari <fabrizio.ge@tiscalinet.it>\r
+# Based on auto-import.exp  by Ralf.Habacker@freenet.de\r
+#\r
\r
+# This test can only be run on a cygwin platforms.\r
+if {![istarget *-pc-cygwin]} {\r
+    verbose "Not a cygwin target."\r
+    return\r
+}\r
+\r
+# No compiler, no test.\r
+if { [which $CC] == 0 } {\r
+    untested "Exe export test (no compiler available)"\r
+    return\r
+}\r
+\r
+proc run_dlltool { lib_file def_file } {\r
+    global dlltool\r
+    global base_dir\r
+    global as\r
+    \r
+    if ![info exists dlltool] then {\r
+       set dlltool [findfile $base_dir/../binutils/dlltool]\r
+    }\r
+\r
+    if { [which $dlltool] == 0 } then {\r
+       verbose "$dlltool does not exist"\r
+       return 0\r
+    }\r
+\r
+    verbose "$dlltool --as $as -l $lib_file -d $def_file"\r
+    catch "exec $dlltool --as $as -l $lib_file -d $def_file" dlltool_output\r
+\r
+    #remove empty lines\r
+    regsub -all "\n+" $dlltool_output "" dlltool_output\r
+\r
+    if [string match "" $dlltool_output] then {\r
+        return 1\r
+    }\r
+\r
+    verbose -log "$dlltool_output"\r
+    return 0\r
+}\r
+\r
+# ld_special_link\r
+#       A copy of ld_simple_link (from ld-lib.exp) with extra\r
+#       code to strip warnings about creating libraries.\r
+#\r
+proc ld_special_link { ld target objects } {\r
+    global host_triplet\r
+    global link_output\r
+\r
+    if { [which $ld] == 0 } then {\r
+       verbose "$ld does not exist"\r
+       return 0\r
+    }\r
+\r
+    if [is_endian_output_format $objects] then {\r
+        set flags [big_or_little_endian]\r
+    } else {\r
+        set flags ""\r
+    }\r
+\r
+    verbose -log "$ld $flags -o $target $objects"\r
+    catch "exec $ld $flags -o $target $objects" link_output\r
+\r
+    set exec_output [prune_warnings $link_output]\r
+\r
+    # We don't care if we get a warning about a non-existent start\r
+    # symbol, since the default linker script might use ENTRY.\r
+    regsub -all "(^|\n)(\[^\n\]*: warning: cannot find entry symbol\[^\n\]*\n?)" $exec_output "\\1" exec_output\r
+\r
+    # We don't care if we get a message about creating a library file.\r
+    regsub -all "(^|\n)(Creating library file\[^\n\]*\n?)" $exec_output "\\1" exec_output\r
+\r
+    if [string match "" $exec_output] then {\r
+        return 1\r
+    }\r
+\r
+    verbose -log "$exec_output"\r
+    return 0\r
+}\r
+\r
+set tmpdir tmpdir\r
+\r
+# Set some libs needed for cygwin.\r
+set MYLDFLAGS "-Wl,--out-implib,$tmpdir/testexe.lib -nostartfiles -nostdlib"\r
+\r
+# Build an export library for testdll\r
+if ![run_dlltool $tmpdir/testdll.lib $srcdir/$subdir/testdll.def] {\r
+    fail "building an export library for the shared lib"\r
+    return\r
+} \r
+\r
+# Compile the executable.\r
+if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/testexe.c $tmpdir/testexe.o] {\r
+    fail "compiling executable"\r
+    return\r
+}\r
+\r
+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
+    fail "linking executable"\r
+    return\r
+} \r
+\r
+# Compile the dll.\r
+if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/testdll.c $tmpdir/testdll.o] {\r
+    fail "compiling shared lib"\r
+    return\r
+}\r
+\r
+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
+    fail "linking shared lib"\r
+    return\r
+} \r
+\r
+# This is as far as we can go with a cross-compiler\r
+if ![isnative] then {\r
+    verbose "Not running natively, so cannot execute binary"\r
+    pass "Compile and link and executable with an export table"\r
+    return\r
+}\r
+\r
+verbose -log "executing $tmpdir/testexe.exe"\r
+catch "exec $tmpdir/testexe.exe" prog_output\r
+\r
+set expected ""\r
+if [string match $expected $prog_output] then {\r
+    pass "export table in executable"\r
+} else {\r
+    verbose $prog_output\r
+    fail "Output does not match expected string $expected"\r
+}\r
diff --git a/ld/testsuite/ld-cygwin/testdll.c b/ld/testsuite/ld-cygwin/testdll.c
new file mode 100644 (file)
index 0000000..2064307
--- /dev/null
@@ -0,0 +1,14 @@
+extern void exewrite (void);
+__attribute((dllimport)) int  global_a;
+
+void 
+dllwrite (void)
+{
+  global_a = 3;
+  exewrite ();
+}
+
+int _stdcall testdll_main(int p1, unsigned long p2, void* p3)
+{
+       return 1;
+}
diff --git a/ld/testsuite/ld-cygwin/testdll.def b/ld/testsuite/ld-cygwin/testdll.def
new file mode 100644 (file)
index 0000000..05e6c88
--- /dev/null
@@ -0,0 +1,4 @@
+LIBRARY testdll\r
+\r
+EXPORTS\r
+dllwrite\r
diff --git a/ld/testsuite/ld-cygwin/testexe.c b/ld/testsuite/ld-cygwin/testexe.c
new file mode 100644 (file)
index 0000000..333c389
--- /dev/null
@@ -0,0 +1,16 @@
+int global_a = 2;
+
+void 
+exewrite (void)
+{
+  global_a = 1;
+}
+
+extern void dllwrite (void);
+
+int _stdcall
+testexe_main (void* p1, void *p2, char* p3, int p4)
+{
+  dllwrite ();
+  return 0;
+}
diff --git a/ld/testsuite/ld-cygwin/testexe.def b/ld/testsuite/ld-cygwin/testexe.def
new file mode 100644 (file)
index 0000000..7570578
--- /dev/null
@@ -0,0 +1,5 @@
+NAME testexe.exe\r
+\r
+EXPORTS\r
+exewrite\r
+global_a DATA\r