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 15 Dec 2006 15:17:21 -0000 @@ -1418,15 +1418,13 @@ gld_${EMULATION_NAME}_recognized_file (l 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 (obj_pe (entry->the_bfd) + && pe_data (entry->the_bfd)->dll) + return pe_implied_import_dll (fbuf); } #endif return FALSE; --- /dev/null 2006-12-15 15:20:26.499625000 +0000 +++ testsuite/ld-pe/direct.exp 2006-12-15 15:12:19.062125000 +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 +# + +# 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.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.exe "$tmpdir/direct_client.o $tmpdir/direct_dll.sl" ] { + pass $msg + } else { + fail $msg + } + } + } +} + +test_direct_link_dll --- /dev/null 2006-12-15 15:20:35.921500000 +0000 +++ testsuite/ld-pe/direct_dll.c 2006-12-15 15:10:30.609000000 +0000 @@ -0,0 +1,5 @@ +__declspec(dllexport) int +dll_func (void) +{ + return 10; +} --- /dev/null 2006-12-15 15:20:40.265250000 +0000 +++ testsuite/ld-pe/direct_client.c 2006-12-15 15:10:50.640250000 +0000 @@ -0,0 +1,8 @@ +__declspec(dllimport) int dll_func (void); + +int +main() +{ + dll_func (); + return 0; +}