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.


Danny Smith wrote:

Could you add a test for symlinks (on cygwin), eg where libfoo.a is a
symlink to $PATH/foo.dll.
This is what if (REALPATH (entry->filename, fbuf) == NULL)
strncpy (fbuf, entry->filename, sizeof (fbuf));
is about I think.



You're right. Then, the REALPATH call isn't needed anymore. It was there so we could get the filename extension of the dll in the case you mention.

I've added tests for symlinks.  Should I guard them for MinGW?  How?
The symlink functionality comes from the host not from the target.
Using msys or 'gcc -mno-cygwin' should work, no?

Attached is the new patch, tested on i686-pc-cygwin. I'll try
testing on MinGW later.

Cheers,
Pedro Alves
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	18 Dec 2006 10:32:46 -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	18 Dec 2006 10:32:46 -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	18 Dec 2006 10:33:28 -0000
@@ -1415,19 +1415,8 @@ 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)
-    {
-      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);
-    }
+  if (pe_bfd_is_dll (entry->the_bfd))
+    return pe_implied_import_dll (entry->filename);
 #endif
   return FALSE;
 }
--- /dev/null	2006-12-18 11:44:12.140625000 +0000
+++ testsuite/ld-pe/direct.exp	2006-12-18 11:43:44.500000000 +0000
@@ -0,0 +1,143 @@
+# 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 7 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.
+#
+# 5. compile and link a client application linking directly to a symlink into 
+#    the ".dll" dll built in 1.
+#    This should produce no errors.
+#
+# 6. compile and link a client application linking directly to a symlink into 
+#    the ".sl" dll built in 1.
+#    This should produce no errors.
+#
+# 7. run the produced executables
+
+# 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 
+	    }
+
+	    # Check dll direct linking through symlink to .dll.
+	    # Create symbolic link.
+	    catch "exec ln -fs direct_dll.dll $tmpdir/libdirect_dll.dll.a" ln_catch
+	    set msg "linking client (symlink -> .dll)"
+	    if [ld_simple_link $CC $tmpdir/direct_client_symlink_dll.exe "$tmpdir/direct_client.o $tmpdir/libdirect_dll.dll.a" ] {
+	        pass $msg
+	    } else {
+		fail $msg
+	    }
+		
+	    # Check dll direct linking through symlink to .sl.
+	    # Create symbolic link.
+	    catch "exec ln -fs direct_dll.sl $tmpdir/libdirect_sl.dll.a" ln_catch
+	    set msg "linking client (symlink -> .sl)"
+	    if [ld_simple_link $CC $tmpdir/direct_client_symlink_sl.exe "$tmpdir/direct_client.o $tmpdir/libdirect_sl.dll.a" ] {
+		pass $msg
+	    } else {
+		fail $msg 
+	    }
+	}
+    }
+}
+
+proc directdll_execute {exe msg} {
+    set expected ""
+    catch "exec $exe" prog_output
+    if [string match $expected $prog_output] then {
+        pass $msg
+    } else {
+        verbose $prog_output
+        fail $msg
+    }
+}
+
+test_direct_link_dll
+
+# This is as far as we can go with a cross-compiler
+if ![isnative] then {
+    verbose "Not running natively, so cannot execute binaries"
+    return
+}
+
+directdll_execute "$tmpdir/direct_client_dll.exe" "running direct linked dll (.dll)"
+directdll_execute "$tmpdir/direct_client_sl.exe" "running direct linked dll (.sl)"
+directdll_execute "$tmpdir/direct_client_symlink_sl.exe" "running direct linked dll (symlink -> .sl)"
+directdll_execute "$tmpdir/direct_client_symlink_dll.exe" "running direct linked dll (symlink -> .dll)"
--- /dev/null	2006-12-18 11:44:19.578125000 +0000
+++ testsuite/ld-pe/direct_dll.c	2006-12-18 10:32:46.671875000 +0000
@@ -0,0 +1,5 @@
+__declspec(dllexport) int
+dll_func (void)
+{
+  return 10;
+}
--- /dev/null	2006-12-18 11:44:24.765625000 +0000
+++ testsuite/ld-pe/direct_client.c	2006-12-18 10:32:46.671875000 +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]