public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Re: [Patch/pe-coff] : Add native spelling of import lib names to  dynamic lib search
@ 2006-06-20  8:51 Danny Smith
  0 siblings, 0 replies; 8+ messages in thread
From: Danny Smith @ 2006-06-20  8:51 UTC (permalink / raw)
  To: Binutils


At
<http://sourceware.org/ml/binutils/2006-06/msg00294.html>
Ross Ridge wrote

> Danny Smith wrote:
> >However, the native naming convention for these import libs is
"foo.lib"
> >and gld_i386pe_open_dynamic_archive does not currently recognize this
> >name format. This means that doing something like -L/path/to/sdk
-lfoo32
> >could link directly to "foo32.dll", rather than find the import lib
> >"foo32.lib". 
> 
> Umm... doing something like -L/path/to/sdk -lfoo32 already works for
> me with ld.  Am I missing something here?
>

It finds foo32.lib after unsuccesfully going through the dynamic lib
search list, then trying to find a static lib name libfoo32.a  and
finally trying the .lib spelling in
gld_${EMULATION_NAME}_find_potential_libraries

If 'foo32.dll' is found before the import lib, 'foo32.lib', ld will
attempt direct linking to foo32.dll. This will fail if, as in platform
sdk, the symbols are exported only by aliased name.

Now  I  realize that putting a DLL in a library search path is not the
best thing to do, but it happens.

It often happens when building/testing a project and the makefile puts
the new dll and the import lib in the same  directory.

See this:
http://cygwin.com/ml/cygwin/2006-06/msg00187.html

I didn't like the answer given by the cygwin respondents.  The patch was
an alternative answer.

Danny

> 					Ross Ridge
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: [Patch/pe-coff] : Add native spelling of import lib names to dynamic lib search
@ 2006-06-20  7:39 Ross Ridge
  0 siblings, 0 replies; 8+ messages in thread
From: Ross Ridge @ 2006-06-20  7:39 UTC (permalink / raw)
  To: binutils

Danny Smith wrote:
>However, the native naming convention for these import libs is "foo.lib"
>and gld_i386pe_open_dynamic_archive does not currently recognize this
>name format. This means that doing something like -L/path/to/sdk -lfoo32
>could link directly to "foo32.dll", rather than find the import lib
>"foo32.lib". 

Umm... doing something like -L/path/to/sdk -lfoo32 already works for
me with ld.  Am I missing something here?

					Ross Ridge

^ permalink raw reply	[flat|nested] 8+ messages in thread
* [Patch/pe-coff] : Add native spelling of import lib names to dynamic  lib search
@ 2006-06-19  9:35 Danny Smith
  2006-06-22 13:52 ` Nick Clifton
  0 siblings, 1 reply; 8+ messages in thread
From: Danny Smith @ 2006-06-19  9:35 UTC (permalink / raw)
  To: Binutils; +Cc: Christopher Faylor

[-- Attachment #1: Type: text/plain, Size: 1609 bytes --]

Hello, 

Current ld is able to handle the short import lib format (ILF)
used by windows32 native compiler. This means that mingw32 and cygwin
projects can link against system dlls using the import libs provided by
the  OS vendor (ie, the platform software and driver development kits
distributed by MS).

However, the native naming convention for these import libs is "foo.lib"
and gld_i386pe_open_dynamic_archive does not currently recognize this
name format. This means that doing something like -L/path/to/sdk -lfoo32
could link directly to "foo32.dll", rather than find the import lib
"foo32.lib". In the case of windows systems libs, this direct linking to
dll does _not_ work because of aliasing of the names in the symbol
export table. An import lib is necessary and the developer has to either
rename foo.lib to lib.foo.a or forego the -L/path/to/sdk -lfoo32 -lbar32
syntax and specify the full pathname of each import lib on the command
line. Recognition of "foo.lib" as an import lib would also mean that the
testing of dll's that are intended to work with native as well as GNU
development tools could bypass the current necessity of copying
lib.foo.a to foo.lib, 

The attached patch adds this feature. I have also added a note on symbol
aliasing and import libs to ld.texinfo.


ChangeLog

2006-06-19  Danny Smith  <dannysmith@users.sourceforge.net>

	* emultempl/pe.em (gld_${EMULATION_NAME}_open_dynamic_archive): 
	Restructure.  Add native "%s.lib" format to search list
	* ld.texinfo (node WIN32): Update documentation on dynamic lib
	search order. Add another reason for using import libs.	

[-- Attachment #2: open_dynamic.patch --]
[-- Type: application/octet-stream, Size: 8329 bytes --]

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2006-06-27 11:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-20  8:51 [Patch/pe-coff] : Add native spelling of import lib names to dynamic lib search Danny Smith
  -- strict thread matches above, loose matches on Subject: below --
2006-06-20  7:39 Ross Ridge
2006-06-19  9:35 Danny Smith
2006-06-22 13:52 ` Nick Clifton
2006-06-24 17:32   ` Pedro Alves
2006-06-25 13:50     ` Pedro Alves
2006-06-26 12:32       ` Pedro Alves
2006-06-27 14:57         ` Nick Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).