From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27697 invoked by alias); 19 Jun 2006 00:57:20 -0000 Received: (qmail 27688 invoked by uid 22791); 19 Jun 2006 00:57:18 -0000 X-Spam-Check-By: sourceware.org Received: from smtp1.clear.net.nz (HELO smtp1.clear.net.nz) (203.97.33.27) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 19 Jun 2006 00:57:15 +0000 Received: from anykey (t001-m001-u152.acld.clear.net.nz [203.97.72.152]) by smtp1.clear.net.nz (CLEAR Net Mail) with ESMTP id <0J13000SD1B9Q4@smtp1.clear.net.nz> for binutils@sourceware.org; Mon, 19 Jun 2006 12:57:12 +1200 (NZST) Date: Mon, 19 Jun 2006 09:35:00 -0000 From: Danny Smith Subject: [Patch/pe-coff] : Add native spelling of import lib names to dynamic lib search To: Binutils Cc: Christopher Faylor Message-id: <000401c6933b$4e261530$984861cb@anykey> MIME-version: 1.0 X-Mailer: Microsoft Outlook, Build 10.0.2627 Content-type: multipart/mixed; boundary="----=_NextPart_000_0005_01C6939F.E35D6630" Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2006-06/txt/msg00281.txt.bz2 This is a multi-part message in MIME format. ------=_NextPart_000_0005_01C6939F.E35D6630 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-length: 1609 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 * 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. ------=_NextPart_000_0005_01C6939F.E35D6630 Content-Type: application/octet-stream; name="open_dynamic.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="open_dynamic.patch" Content-length: 9516 Index: emultempl/pe.em=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvs/src/src/ld/emultempl/pe.em,v=0A= retrieving revision 1.114=0A= diff -c -3 -p -r1.114 pe.em=0A= *** emultempl/pe.em 11 May 2006 08:48:58 -0000 1.114=0A= --- emultempl/pe.em 19 Jun 2006 00:46:33 -0000=0A= *************** gld_${EMULATION_NAME}_open_dynamic_archi=0A= *** 1695,1780 ****=0A= lang_input_statement_type *entry)=0A= {=0A= const char * filename;=0A= ! char * string;=0A= =20=20=0A= if (! entry->is_archive)=0A= return FALSE;=0A= =20=20=0A= filename =3D entry->filename;=0A= =20=20=0A= ! string =3D (char *) xmalloc (strlen (search->name)=0A= ! + strlen (filename)=0A= ! + sizeof "/lib.a.dll"=0A= #ifdef DLL_SUPPORT=0A= ! + (pe_dll_search_prefix ? strlen (pe_dll_search_prefix) : 0)=0A= #endif=0A= ! + 1);=0A= =20=20=0A= ! /* Try "libfoo.dll.a" first (preferred explicit import library for dll'= s. */=0A= ! sprintf (string, "%s/lib%s.dll.a", search->name, filename);=0A= !=20=0A= ! if (! ldfile_try_open_bfd (string, entry))=0A= {=0A= ! /* Try "foo.dll.a" next (alternate explicit import library for dll'= s. */=0A= ! sprintf (string, "%s/%s.dll.a", search->name, filename);=0A= ! if (! ldfile_try_open_bfd (string, entry))=0A= {=0A= ! /* Try libfoo.a next. Normally, this would be interpreted as a static= =0A= ! library, but it *could* be an import library. For backwards compati= bility,=0A= ! libfoo.a needs to =3D=3Dprecede=3D=3D libfoo.dll and foo.dll in the= search,=0A= ! or sometimes errors occur when building legacy packages.=0A= !=20=0A= ! Putting libfoo.a here means that in a failure case (i.e. the librar= y=0A= ! -lfoo is not found) we will search for libfoo.a twice before=0A= ! giving up -- once here, and once when searching for a "static" lib.= =0A= ! for a "static" lib. */=0A= ! /* Try "libfoo.a" (import lib, or static lib, but must=0A= ! take precedence over dll's). */=0A= ! sprintf (string, "%s/lib%s.a", search->name, filename);=0A= ! if (! ldfile_try_open_bfd (string, entry))=0A= ! {=0A= ! #ifdef DLL_SUPPORT=0A= ! if (pe_dll_search_prefix)=0A= ! {=0A= ! /* Try "foo.dll" (preferred dll name, if specified). */=0A= ! sprintf (string, "%s/%s%s.dll", search->name, pe_dll_search_prefix, f= ilename);=0A= ! if (! ldfile_try_open_bfd (string, entry))=0A= ! {=0A= ! /* Try "libfoo.dll" (default preferred dll name). */=0A= ! sprintf (string, "%s/lib%s.dll", search->name, filename);=0A= ! if (! ldfile_try_open_bfd (string, entry))=0A= ! {=0A= ! /* Finally, try "foo.dll" (alternate dll name). */=0A= ! sprintf (string, "%s/%s.dll", search->name, filename);=0A= ! if (! ldfile_try_open_bfd (string, entry))=0A= ! {=0A= ! free (string);=0A= ! return FALSE;=0A= ! }=0A= ! }=0A= ! }=0A= ! }=0A= ! else /* pe_dll_search_prefix not specified. */=0A= ! #endif=0A= ! {=0A= ! /* Try "libfoo.dll" (preferred dll name). */=0A= ! sprintf (string, "%s/lib%s.dll", search->name, filename);=0A= ! if (! ldfile_try_open_bfd (string, entry))=0A= ! {=0A= ! /* Finally, try "foo.dll" (alternate dll name). */=0A= ! sprintf (string, "%s/%s.dll", search->name, filename);=0A= ! if (! ldfile_try_open_bfd (string, entry))=0A= ! {=0A= ! free (string);=0A= ! return FALSE;=0A= ! }=0A= ! }=0A= ! }=0A= ! }=0A= }=0A= }=0A= =20=20=0A= ! entry->filename =3D string;=0A= =20=20=0A= return TRUE;=0A= }=0A= --- 1695,1773 ----=0A= lang_input_statement_type *entry)=0A= {=0A= const char * filename;=0A= ! char * full_string, * base_string;=0A= !=20=0A= ! static const struct=0A= ! {=0A= ! const char *format;=0A= ! bfd_boolean use_prefix;=0A= ! }=0A= ! libname_fmt [] =3D=0A= ! {=0A= ! /* Preferred explicit import library for dll's. */=0A= ! { "lib%s.dll.a", FALSE },=0A= ! /* Alternate explicit import library for dll's. */=0A= ! { "%s.dll.a", FALSE },=0A= ! /* "libfoo.a" could be either an import lib or a static lib.=0A= ! For backwards compatibility, libfoo.a needs to precede=0A= ! "libfoo.dll" and "foo.dll" in the search, */=0A= ! { "lib%s.a" , FALSE },=0A= ! /* The 'native' spelling of an import lib name is "foo.lib". */=20= =20=09=0A= ! { "%s.lib", FALSE },=0A= ! #ifdef DLL_SUPPORT=0A= ! /* Try "foo.dll" (preferred dll name, if specified). */=0A= ! { "%s%s.dll", TRUE },=0A= ! #endif=0A= ! /* Try "libfoo.dll" (default preferred dll name). */=0A= ! { "lib%s.dll", FALSE },=0A= ! /* Finally try 'native' dll name "foo.dll". */=0A= ! { "%s.dll", FALSE },=0A= ! { NULL, FALSE }=0A= ! };=0A= !=20=0A= ! int i;=0A= =20=20=0A= if (! entry->is_archive)=0A= return FALSE;=0A= =20=20=0A= filename =3D entry->filename;=0A= =20=20=0A= ! full_string =3D (char *) xmalloc (strlen (search->name)=0A= ! + strlen (filename)=0A= ! + sizeof "/lib.a.dll"=0A= #ifdef DLL_SUPPORT=0A= ! + (pe_dll_search_prefix=0A= ! ? strlen (pe_dll_search_prefix)=0A= ! : 0)=0A= #endif=0A= ! + 1);=0A= =20=20=0A= ! sprintf (full_string, "%s/", search->name);=0A= ! base_string =3D full_string + strlen (full_string);=0A= !=20=20=20=0A= ! for (i =3D 0; libname_fmt[i].format; i++)=0A= {=0A= ! #ifdef DLL_SUPPORT=20=0A= ! if (libname_fmt[i].use_prefix)=0A= {=0A= ! if (!pe_dll_search_prefix)=0A= ! continue;=0A= ! sprintf (base_string, libname_fmt[i].format, pe_dll_search_prefix, fil= ename);=0A= }=0A= + else=0A= + #endif=0A= + sprintf (base_string, libname_fmt[i].format, filename);=0A= + if (ldfile_try_open_bfd (full_string, entry))=0A= + break;=0A= + }=0A= +=20=0A= + if (!libname_fmt[i].format)=0A= + {=0A= + free (full_string);=0A= + return FALSE;=0A= }=0A= =20=20=0A= ! entry->filename =3D full_string;=0A= =20=20=0A= return TRUE;=0A= }=0A= Index: ld.texinfo=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvs/src/src/ld/ld.texinfo,v=0A= retrieving revision 1.164=0A= diff -c -3 -p -r1.164 ld.texinfo=0A= *** ld.texinfo 14 Jun 2006 02:43:57 -0000 1.164=0A= --- ld.texinfo 19 Jun 2006 00:46:55 -0000=0A= *************** to find, in the first directory of its s=0A= *** 5986,5992 ****=0A= @example=0A= libxxx.dll.a=20=0A= xxx.dll.a=20=0A= ! libxxx.a=20=0A= cygxxx.dll (*)=0A= libxxx.dll=20=0A= xxx.dll=20=0A= --- 5986,5993 ----=0A= @example=0A= libxxx.dll.a=20=0A= xxx.dll.a=20=0A= ! libxxx.a=0A= ! xxx.lib=0A= cygxxx.dll (*)=0A= libxxx.dll=20=0A= xxx.dll=20=0A= *************** even when auto-import features are exerc=0A= *** 6061,6067 ****=0A= @samp{--enable-runtime-pseudo-relocs} is used.=0A= =20=20=0A= Given the improvements in speed and memory usage, one might justifiably= =0A= ! wonder why import libraries are used at all. There are two reasons:=0A= =20=20=0A= 1. Until recently, the link-directly-to-dll functionality did @emph{not}= =0A= work with auto-imported data.=0A= --- 6062,6068 ----=0A= @samp{--enable-runtime-pseudo-relocs} is used.=0A= =20=20=0A= Given the improvements in speed and memory usage, one might justifiably= =0A= ! wonder why import libraries are used at all. There are three reasons:=0A= =20=20=0A= 1. Until recently, the link-directly-to-dll functionality did @emph{not}= =0A= work with auto-imported data.=0A= *************** symbols that point to the exports of a d=0A= *** 6072,6080 ****=0A= for the cygwin kernel makes use of this ability, and it is not=0A= possible to do this without an import lib.=0A= =20=20=0A= So, import libs are not going away. But the ability to replace=0A= true import libs with a simple symbolic link to (or a copy of)=20=0A= ! a dll, in most cases, is a useful addition to the suite of tools=20=0A= binutils makes available to the win32 developer. Given the=20=0A= massive improvements in memory requirements during linking, storage=0A= requirements, and linking speed, we expect that many developers=0A= --- 6073,6086 ----=0A= for the cygwin kernel makes use of this ability, and it is not=0A= possible to do this without an import lib.=0A= =20=20=0A= + 3. Symbol aliases can only be resolved using an import lib. This is=0A= + critical when linking against OS-supplied dll's (eg, the win32 API)=0A= + in which symbols are usually exported as undecorated aliases of their=0A= + stdcall-decorated assembly names.=0A= +=20=0A= So, import libs are not going away. But the ability to replace=0A= true import libs with a simple symbolic link to (or a copy of)=20=0A= ! a dll, in many cases, is a useful addition to the suite of tools=20=0A= binutils makes available to the win32 developer. Given the=20=0A= massive improvements in memory requirements during linking, storage=0A= requirements, and linking speed, we expect that many developers=0A= ------=_NextPart_000_0005_01C6939F.E35D6630--