diff options
author | Nick Clifton <nickc@redhat.com> | 2006-06-22 13:43:04 +0000 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2006-06-22 13:43:04 +0000 |
commit | 45e948fe97db49546f4712992daae024fb822ec4 (patch) | |
tree | d3cdd769c076ab0ae7a52ed3e2729a8c9e5a94d5 /ld | |
parent | 47c7e8efbb04ec602c279f70c3ca930ad80c989a (diff) | |
download | gdb-45e948fe97db49546f4712992daae024fb822ec4.zip gdb-45e948fe97db49546f4712992daae024fb822ec4.tar.gz gdb-45e948fe97db49546f4712992daae024fb822ec4.tar.bz2 |
* 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.
Diffstat (limited to 'ld')
-rw-r--r-- | ld/ChangeLog | 7 | ||||
-rw-r--r-- | ld/emultempl/pe.em | 131 | ||||
-rw-r--r-- | ld/ld.texinfo | 26 |
3 files changed, 88 insertions, 76 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog index 684d34f..7f03312 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,10 @@ +2006-06-22 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. + 2006-06-21 Mark Shinwell <shinwell@codesourcery.com> * ldlang.c (lang_insert_orphan): Correctly handle the case where diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em index 33ac71e..646be98 100644 --- a/ld/emultempl/pe.em +++ b/ld/emultempl/pe.em @@ -11,7 +11,7 @@ rm -f e${EMULATION_NAME}.c cat >>e${EMULATION_NAME}.c <<EOF /* This file is part of GLD, the Gnu Linker. Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, - 2005 Free Software Foundation, Inc. + 2005, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1694,87 +1694,86 @@ gld_${EMULATION_NAME}_open_dynamic_archive (const char *arch ATTRIBUTE_UNUSED, search_dirs_type *search, lang_input_statement_type *entry) { + 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 }, + /* Note: If adding more formats to this table, make sure to check to + see if their length is longer than libname_fmt[0].format, and if + so, update the call to xmalloc() below. */ + { NULL, FALSE } + }; const char * filename; - char * string; + char * full_string; + char * base_string; + unsigned int i; + if (! entry->is_archive) return FALSE; filename = entry->filename; - string = (char *) xmalloc (strlen (search->name) - + strlen (filename) - + sizeof "/lib.a.dll" + full_string = xmalloc (strlen (search->name) + + strlen (filename) + /* Allow space for the characters in the format + string. We actually allow 2 more bytes than + necessary, but this will not hurt. */ + + sizeof libname_fmt[0].format #ifdef DLL_SUPPORT - + (pe_dll_search_prefix ? strlen (pe_dll_search_prefix) : 0) + + (pe_dll_search_prefix + ? strlen (pe_dll_search_prefix) : 0) #endif - + 1); + + 1); - /* Try "libfoo.dll.a" first (preferred explicit import library for dll's. */ - sprintf (string, "%s/lib%s.dll.a", search->name, filename); + sprintf (full_string, "%s/", search->name); + base_string = full_string + strlen (full_string); - if (! ldfile_try_open_bfd (string, entry)) + for (i = 0; libname_fmt[i].format; i++) { - /* 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)) +#ifdef DLL_SUPPORT + if (libname_fmt[i].use_prefix) { - /* 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; - } - } - } - } + 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 = string; + entry->filename = full_string; return TRUE; } diff --git a/ld/ld.texinfo b/ld/ld.texinfo index cfbe26e..1d5e5a5 100644 --- a/ld/ld.texinfo +++ b/ld/ld.texinfo @@ -1,7 +1,7 @@ \input texinfo @setfilename ld.info @c Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, -@c 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. +@c 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. @syncodeindex ky cp @c man begin INCLUDE @include configdoc.texi @@ -64,7 +64,7 @@ END-INFO-DIR-ENTRY This file documents the @sc{gnu} linker LD version @value{VERSION}. Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000, -2001, 2002, 2003, 2004 Free Software Foundation, Inc. +2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. @ignore @@ -109,7 +109,7 @@ notice identical to this one except for the removal of this paragraph @vskip 0pt plus 1filll @c man begin COPYRIGHT Copyright @copyright{} 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001, -2002, 2003, 2004 Free Software Foundation, Inc. +2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 @@ -5984,12 +5984,13 @@ For instance, when ld is called with the argument @samp{-lxxx} it will attempt to find, in the first directory of its search path, @example -libxxx.dll.a -xxx.dll.a -libxxx.a +libxxx.dll.a +xxx.dll.a +libxxx.a +xxx.lib cygxxx.dll (*) -libxxx.dll -xxx.dll +libxxx.dll +xxx.dll @end example before moving on to the next directory in the search path. @@ -6061,7 +6062,7 @@ even when auto-import features are exercised, and even when @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: +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. @@ -6072,9 +6073,14 @@ symbols that point to the exports of a dll). Again, the import lib 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 most cases, is a useful addition to the suite of tools +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 |