This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] PE direct linking to dlls, accept any filename.


Hi Danny,

First of all, thanks for taking the trouble of testing this.

I installed stock MinGW + msys + 'a few GnuWin32 (bison/texutils/flex/libiconv/libintl)
apps' to be able to build binutils.  It built fine, but I don't know yet how
to run the testsuite (no runtest/dejagnu).  So I ran the test manually.  More comments
below.

Danny Smith escreveu:


The new direct_dll.sl test fails on mingw32.


gcc -B/develop/cvs/binutils/build/ld/tmpdir/ld/ -L/mingw/mingw32/lib
-L/mingw/lib -L/usr/local/lib -L/lib -L/usr/lib  -o
tmpdir/direct_client.exe tmpdir/direct_client.o tmpdir/direct_dll.sl
tmpdir/direct_dll.sl: In function `atexit':
C:/develop/cvs/winsup/src/winsup/mingw/dllcrt1.c:161: multiple
definition of `atexit'
c:/mingw/bin/../lib/gcc/i686-pc-mingw32dw2/4.2.0/../../../crt2.o:C:\deve
lop\cvs\winsup\src\winsup\mingw/crt1.c:272: first defined here
tmpdir/direct_dll.sl: In function `onexit':
C:/develop/cvs/winsup/src/winsup/mingw/dllcrt1.c:177: multiple
definition of `_onexit'
c:/mingw/bin/../lib/gcc/i686-pc-mingw32dw2/4.2.0/../../../crt2.o:C:\deve
lop\cvs\winsup\src\winsup\mingw/crt1.c:280: first defined here
tmpdir/direct_dll.sl: In function `onexit':
tmpdir/direct_client.o:direct_client.c:(.text+0x18): undefined reference
to `_imp__dll_func'
collect2: ld returned 1 exit status
FAIL: linking client (.sl)>


This is exactly what happens when linking with the unpatched ld. Don't you have an ld.exe link/copy to ../../ld-new.exe in /develop/cvs/binutils/build/ld/tmpdir/ld/ ? If there isn't one, then the one in the system will be picked up. Maybe I missed something in direct.exp? This is surelly a test bug, since my manual testing was successful once I copied ld-new.exe to tmpdir/ld/ld.exe.

What does adding -Wl,-v show?
gcc -v -B/d/cegccsf/cegcc/cegcc/src/build-binutils_cvs_mingw/ld/tmpdir/ld/ \
   -o tmpdir/direct_client_dll.exe tmpdir/direct_client.o \
   tmpdir/direct_dll.sl -Wl,-v

It should show the something like:
GNU ld version 2.17.50 20061215

I will google a bit to see how to install/run dejagnu on msys/MinGW.  If you have any
hints, they would be appreciated.

Attached is an updated/cleanup patch.  Same functionality, just moved the dll detection
into pe-dll.c, and updated direct.exp to link both exes with different names.

Cheers,
Pedro Alves

----
ld/

2006-12-16 Pedro Alves <pedro_alves@portugalmail.pt>

     * pe-dll.c (pe_bfd_is_dll): New function.
     * pe-dll.h (pe_bfd_is_dll): Declare.
     * emultempl/pe.em (gld_${EMULATION_NAME}_recognized_file):
     Recognize dlls using pe_bfd_is_dll instead of the filename extension.

ld/testsuite/

2006-12-16 Pedro Alves <pedro_alves@portugalmail.pt>

     * ld-pe/direct.exp: New file.
     * ld-pe/direct_client.c: Likewise.
     * ld-pe/direct_dll.c: Likewise.


Index: pe-dll.c
===================================================================
RCS file: /cvs/src/src/ld/pe-dll.c,v
retrieving revision 1.92
diff -u -p -r1.92 pe-dll.c
--- pe-dll.c	1 Nov 2006 00:48:25 -0000	1.92
+++ pe-dll.c	16 Dec 2006 12:59:30 -0000
@@ -2830,3 +2830,11 @@ pe_exe_fill_sections (bfd *abfd, struct 
     }
   reloc_s->contents = reloc_d;
 }
+
+bfd_boolean
+pe_bfd_is_dll (bfd *abfd)
+{
+  return (bfd_get_format (abfd) == bfd_object
+          && obj_pe (abfd)
+          && pe_data (abfd)->dll);
+}
Index: pe-dll.h
===================================================================
RCS file: /cvs/src/src/ld/pe-dll.h,v
retrieving revision 1.13
diff -u -p -r1.13 pe-dll.h
--- pe-dll.h	12 May 2005 07:32:03 -0000	1.13
+++ pe-dll.h	16 Dec 2006 12:59:31 -0000
@@ -59,4 +59,7 @@ extern void pe_walk_relocs_of_symbol
   (struct bfd_link_info *, const char *, int (*) (arelent *, asection *));
 extern void pe_create_import_fixup
   (arelent * rel, asection *, int);
+extern bfd_boolean pe_bfd_is_dll
+  (bfd *);
+
 #endif /* PE_DLL_H */
Index: emultempl/pe.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/pe.em,v
retrieving revision 1.121
diff -u -p -r1.121 pe.em
--- emultempl/pe.em	3 Oct 2006 10:06:26 -0000	1.121
+++ emultempl/pe.em	16 Dec 2006 12:59:35 -0000
@@ -1415,18 +1415,12 @@ gld_${EMULATION_NAME}_recognized_file (l
 #ifdef TARGET_IS_arm_wince_pe
   pe_dll_id_target ("pei-arm-wince-little");
 #endif
-  if (bfd_get_format (entry->the_bfd) == bfd_object)
+  if (pe_bfd_is_dll (entry->the_bfd))
     {
       char fbuf[LD_PATHMAX + 1];
-      const char *ext;
-
       if (REALPATH (entry->filename, fbuf) == NULL)
-	strncpy (fbuf, entry->filename, sizeof (fbuf));
-
-      ext = fbuf + strlen (fbuf) - 4;
-
-      if (strcmp (ext, ".dll") == 0 || strcmp (ext, ".DLL") == 0)
-	return pe_implied_import_dll (fbuf);
+        strncpy (fbuf, entry->filename, sizeof (fbuf));
+      return pe_implied_import_dll (fbuf);
     }
 #endif
   return FALSE;
--- /dev/null	2006-12-16 15:37:30.154362700 +0000
+++ testsuite/ld-pe/direct.exp	2006-12-16 13:07:56.000000000 +0000
@@ -0,0 +1,91 @@
+# Expect script for direct linking from dll tests
+#   Copyright 2006
+#   Free Software Foundation, Inc.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# Written by Pedro Alves <pedro_alves@portugalmail.pt>
+#
+ 
+# Note: 
+# 
+# This test checks the "direct linking to a dll" functionality.
+# 
+# The test has 4 stages: 
+# 
+# 1. compile and link a test dll with ".dll" extension.
+#
+# 2. compile and link a test dll with ".sl" (i.e. != ".dll") extension.
+#
+# 3. compile and link a client application linking directly to the ".dll" dll built in 1. 
+#    This should produce no errors. 
+#
+# 4. compile and link a client application linking directly to the ".sl" dll built in 2. 
+#    This should produce no errors. 
+
+# This test can only be run on PE/COFF platforms.
+if {    ![istarget *-*-cygwin*]
+     && ![istarget *-*-mingw*]
+     && ![istarget *-*-pe] } {
+    return
+}
+
+# No compiler, no test.
+if { [which $CC] == 0 } {
+    untested "Direct linking to dll test"
+    return
+}
+
+set tmpdir tmpdir
+
+proc test_direct_link_dll {} {
+    global CC
+    global CFLAGS
+    global srcdir
+    global subdir
+    global tmpdir
+    
+    # Compile the dll.
+    if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/direct_dll.c $tmpdir/direct_dll.o ] {
+	fail "compiling shared lib"
+    } elseif ![ld_simple_link "$CC -shared" $tmpdir/direct_dll.dll "$tmpdir/direct_dll.o" ] {
+	fail "linking shared lib (.dll)"
+    } elseif ![ld_simple_link "$CC -shared" $tmpdir/direct_dll.sl "$tmpdir/direct_dll.o" ] {
+	fail "linking shared lib (.sl)"
+    } else {
+	# Compile and link the client program.
+	if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/direct_client.c $tmpdir/direct_client.o ] {
+	    fail "compiling client"
+	} else {
+	    # Check linking directly to direct_dll.dll.
+	    set msg "linking client (.dll)"
+	    if [ld_simple_link $CC $tmpdir/direct_client_dll.exe "$tmpdir/direct_client.o $tmpdir/direct_dll.dll" ] {
+		pass $msg
+	    } else {
+		fail $msg 
+	    }
+
+	    # Check linking directly to direct_dll.sl.
+	    set msg "linking client (.sl)"
+	    if [ld_simple_link $CC $tmpdir/direct_client_sl.exe "$tmpdir/direct_client.o $tmpdir/direct_dll.sl" ] {
+		pass $msg
+	    } else {
+		fail $msg 
+	    }
+	}
+    }
+}
+
+test_direct_link_dll
--- /dev/null	2006-12-16 15:37:41.761052300 +0000
+++ testsuite/ld-pe/direct_dll.c	2006-12-15 20:47:14.000000000 +0000
@@ -0,0 +1,5 @@
+__declspec(dllexport) int
+dll_func (void)
+{
+  return 10;
+}
--- /dev/null	2006-12-16 15:37:46.728194700 +0000
+++ testsuite/ld-pe/direct_client.c	2006-12-15 20:47:14.000000000 +0000
@@ -0,0 +1,8 @@
+__declspec(dllimport) int dll_func (void);
+
+int
+main()
+{
+  dll_func ();
+  return 0;
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]