Index: emultempl/pe.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/pe.em,v
retrieving revision 1.114
diff -c -3 -p -r1.114 pe.em
*** emultempl/pe.em	11 May 2006 08:48:58 -0000	1.114
--- emultempl/pe.em	19 Jun 2006 00:46:33 -0000
*************** gld_${EMULATION_NAME}_open_dynamic_archi
*** 1695,1780 ****
     lang_input_statement_type *entry)
  {
    const char * filename;
!   char * string;
  
    if (! entry->is_archive)
      return FALSE;
  
    filename = entry->filename;
  
!   string = (char *) xmalloc (strlen (search->name)
! 			     + strlen (filename)
! 			     + sizeof "/lib.a.dll"
  #ifdef DLL_SUPPORT
! 			     + (pe_dll_search_prefix ? strlen (pe_dll_search_prefix) : 0)
  #endif
! 			     + 1);
  
!   /* Try "libfoo.dll.a" first (preferred explicit import library for dll's.  */
!   sprintf (string, "%s/lib%s.dll.a", search->name, filename);
! 
!   if (! ldfile_try_open_bfd (string, entry))
      {
!       /* Try "foo.dll.a" next (alternate explicit import library for dll's.  */
!       sprintf (string, "%s/%s.dll.a", search->name, filename);
!       if (! ldfile_try_open_bfd (string, entry))
  	{
! 	  /* Try libfoo.a next. Normally, this would be interpreted as a static
! 	     library, but it *could* be an import library. For backwards compatibility,
! 	     libfoo.a needs to ==precede== libfoo.dll and foo.dll in the search,
! 	     or sometimes errors occur when building legacy packages.
! 
! 	     Putting libfoo.a here means that in a failure case (i.e. the library
! 	     -lfoo is not found) we will search for libfoo.a twice before
! 	     giving up -- once here, and once when searching for a "static" lib.
! 	     for a "static" lib.  */
! 	  /* Try "libfoo.a" (import lib, or static lib, but must
! 	     take precedence over dll's).  */
! 	  sprintf (string, "%s/lib%s.a", search->name, filename);
! 	  if (! ldfile_try_open_bfd (string, entry))
! 	    {
! #ifdef DLL_SUPPORT
! 	      if (pe_dll_search_prefix)
! 		{
! 		  /* Try "<prefix>foo.dll" (preferred dll name, if specified).  */
! 		  sprintf (string, "%s/%s%s.dll", search->name, pe_dll_search_prefix, filename);
! 		  if (! ldfile_try_open_bfd (string, entry))
! 		    {
! 		      /* Try "libfoo.dll" (default preferred dll name).  */
! 		      sprintf (string, "%s/lib%s.dll", search->name, filename);
! 		      if (! ldfile_try_open_bfd (string, entry))
! 			{
! 			  /* Finally, try "foo.dll" (alternate dll name).  */
! 			  sprintf (string, "%s/%s.dll", search->name, filename);
! 			  if (! ldfile_try_open_bfd (string, entry))
! 			    {
! 			      free (string);
! 			      return FALSE;
! 			    }
! 			}
! 		    }
! 		}
! 	      else /* pe_dll_search_prefix not specified.  */
! #endif
! 		{
! 		  /* Try "libfoo.dll" (preferred dll name).  */
! 		  sprintf (string, "%s/lib%s.dll", search->name, filename);
! 		  if (! ldfile_try_open_bfd (string, entry))
! 		    {
! 		      /* Finally, try "foo.dll" (alternate dll name).  */
! 		      sprintf (string, "%s/%s.dll", search->name, filename);
! 		      if (! ldfile_try_open_bfd (string, entry))
! 			{
! 			  free (string);
! 			  return FALSE;
! 			}
! 		    }
! 		}
! 	    }
  	}
      }
  
!   entry->filename = string;
  
    return TRUE;
  }
--- 1695,1773 ----
     lang_input_statement_type *entry)
  {
    const char * filename;
!   char * full_string,  * base_string;
! 
!   static const struct
!     {
!       const char *format;
!       bfd_boolean use_prefix;
!     }
!   libname_fmt [] =
!     {
!       /* Preferred explicit import library for dll's.  */
!       { "lib%s.dll.a", FALSE },
!       /* Alternate explicit import library for dll's.  */
!       { "%s.dll.a", FALSE },
!       /* "libfoo.a" could be either an import lib or a static lib.
!           For backwards compatibility, libfoo.a needs to precede
!          "libfoo.dll" and "foo.dll" in the search,  */
!       { "lib%s.a" , FALSE },
!       /* The 'native' spelling of an import lib name is "foo.lib".  */  	
!       { "%s.lib", FALSE },
! #ifdef DLL_SUPPORT
!       /* Try "<prefix>foo.dll" (preferred dll name, if specified).  */
!       {	"%s%s.dll", TRUE },
! #endif
!       /* Try "libfoo.dll" (default preferred dll name).  */
!       {	"lib%s.dll", FALSE },
!       /* Finally try 'native' dll name "foo.dll".  */
!       {  "%s.dll", FALSE },
!       { NULL, FALSE }
!     };
! 
!   int i;
  
    if (! entry->is_archive)
      return FALSE;
  
    filename = entry->filename;
  
!   full_string = (char *) xmalloc (strlen (search->name)
! 			     	  + strlen (filename)
! 				  + sizeof "/lib.a.dll"
  #ifdef DLL_SUPPORT
! 				  + (pe_dll_search_prefix
! 				     ? strlen (pe_dll_search_prefix)
! 				     : 0)
  #endif
! 				  + 1);
  
!   sprintf (full_string, "%s/", search->name);
!   base_string = full_string + strlen (full_string);
!   
!   for (i = 0; libname_fmt[i].format; i++)
      {
! #ifdef DLL_SUPPORT 
!       if (libname_fmt[i].use_prefix)
  	{
! 	  if (!pe_dll_search_prefix)
! 	    continue;
! 	  sprintf (base_string, libname_fmt[i].format, pe_dll_search_prefix, filename);
  	}
+       else
+ #endif
+ 	sprintf (base_string, libname_fmt[i].format, filename);
+       if (ldfile_try_open_bfd (full_string, entry))
+ 	break;
+     }
+ 
+   if (!libname_fmt[i].format)
+     {
+       free (full_string);
+       return FALSE;
      }
  
!   entry->filename = full_string;
  
    return TRUE;
  }
Index: ld.texinfo
===================================================================
RCS file: /cvs/src/src/ld/ld.texinfo,v
retrieving revision 1.164
diff -c -3 -p -r1.164 ld.texinfo
*** ld.texinfo	14 Jun 2006 02:43:57 -0000	1.164
--- ld.texinfo	19 Jun 2006 00:46:55 -0000
*************** to find, in the first directory of its s
*** 5986,5992 ****
  @example
  libxxx.dll.a 
  xxx.dll.a 
! libxxx.a 
  cygxxx.dll (*)
  libxxx.dll 
  xxx.dll 
--- 5986,5993 ----
  @example
  libxxx.dll.a 
  xxx.dll.a 
! libxxx.a
! xxx.lib
  cygxxx.dll (*)
  libxxx.dll 
  xxx.dll 
*************** even when auto-import features are exerc
*** 6061,6067 ****
  @samp{--enable-runtime-pseudo-relocs} is used.
  
  Given the improvements in speed and memory usage, one might justifiably
! wonder why import libraries are used at all.  There are two reasons:
  
  1. Until recently, the link-directly-to-dll functionality did @emph{not}
  work with auto-imported data.
--- 6062,6068 ----
  @samp{--enable-runtime-pseudo-relocs} is used.
  
  Given the improvements in speed and memory usage, one might justifiably
! wonder why import libraries are used at all.  There are three reasons:
  
  1. Until recently, the link-directly-to-dll functionality did @emph{not}
  work with auto-imported data.
*************** symbols that point to the exports of a d
*** 6072,6080 ****
  for the cygwin kernel makes use of this ability, and it is not
  possible to do this without an import lib.
  
  So, import libs are not going away.  But the ability to replace
  true import libs with a simple symbolic link to (or a copy of) 
! a dll, in most cases, is a useful addition to the suite of tools 
  binutils makes available to the win32 developer.  Given the 
  massive improvements in memory requirements during linking, storage
  requirements, and linking speed, we expect that many developers
--- 6073,6086 ----
  for the cygwin kernel makes use of this ability, and it is not
  possible to do this without an import lib.
  
+ 3. Symbol aliases can only be resolved using an import lib.  This is
+ critical when linking against OS-supplied dll's (eg, the win32 API)
+ in which symbols are usually exported as undecorated aliases of their
+ stdcall-decorated assembly names.
+ 
  So, import libs are not going away.  But the ability to replace
  true import libs with a simple symbolic link to (or a copy of) 
! a dll, in many cases, is a useful addition to the suite of tools 
  binutils makes available to the win32 developer.  Given the 
  massive improvements in memory requirements during linking, storage
  requirements, and linking speed, we expect that many developers
