From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12779 invoked by alias); 24 Jun 2006 13:03:02 -0000 Received: (qmail 12676 invoked from network); 24 Jun 2006 13:02:53 -0000 Received: from unknown (195.23.133.212) by sourceware.org with QMTP; 24 Jun 2006 13:02:53 -0000 Received: (qmail 23973 invoked from network); 24 Jun 2006 13:02:51 -0000 Received: from unknown (HELO mailfrt10.isp.novis.pt) ([195.23.133.202]) (envelope-sender ) by mailrly02.isp.novis.pt with compressed SMTP; 24 Jun 2006 13:02:51 -0000 Received: (qmail 32542 invoked from network); 24 Jun 2006 13:02:42 -0000 Received: from unknown (HELO mamas-laptop) ([195.23.225.213]) (envelope-sender ) by mailfrt10.isp.novis.pt with SMTP; 24 Jun 2006 13:02:42 -0000 Received: from localhost ([127.0.0.1]) by mamas-laptop with esmtp (Exim 4.62) (envelope-from ) id J1D88F-0000Z4-2L; Sat, 24 Jun 2006 14:02:39 +0100 Message-ID: <449D37EB.3030407@portugalmail.pt> Date: Sat, 24 Jun 2006 17:32:00 -0000 From: Pedro Alves User-Agent: Thunderbird 1.5.0.4 (Windows/20060516) MIME-Version: 1.0 To: Binutils CC: Danny Smith , Nick Clifton , Christopher Faylor Subject: Re: [Patch/pe-coff] : Add native spelling of import lib names to dynamic lib search References: <000401c6933b$4e261530$984861cb@anykey> <449A9F15.500@redhat.com> In-Reply-To: <449A9F15.500@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 0625-7, 23-06-2006), Outbound message X-Antivirus-Status: Clean X-IsSubscribed: yes 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/msg00374.txt.bz2 Hi all, Nick Clifton wrote: > Hi Danny, > >> 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. > > Approved and applied. > > Note - I slightly changed the construction of the size passed to the > xmalloc() function, so that instead of using sizeof on a separate > string, it accesses the libname_fmt structure and pulls a string out > of there. I felt that this made it more obvious as to why the value > was being included in the computation of the amount of memory > required. I also added a comment into the declaration of the > libname_fmt structure to remind future coders to check and update the > length if necessary. This doesn't work correctly. The sizeof (libname_fmt.format) is sizeof (const char*), not the sizeof the string. Fixed with the following patch. Other possibilities would be to s/sizeof/strlen/ or sizeof(*libname_fmt.format), by I think this way makes the code clearer, and less surprising. Cheers, Pedro Alves ---- 2006-06-24 Pedro Alves pedro_alves@portugalmail.pt PR ld/2537 * emultempl/pe.em (gld_${EMULATION_NAME}_open_dynamic_archive): New member fixed_len in libname_fmt, representing the length of the format string minus the length of the formatters. Adjust xmalloc call to use the longest of the lengths. --- pe.em.org 2006-06-24 13:18:22.000000000 +0100 +++ pe.em 2006-06-24 13:54:16.000000000 +0100 @@ -1697,52 +1697,60 @@ gld_${EMULATION_NAME}_open_dynamic_archi static const struct { const char * format; + int fixed_len; bfd_boolean use_prefix; } libname_fmt [] = { /* Preferred explicit import library for dll's. */ - { "lib%s.dll.a", FALSE }, + { "lib%s.dll.a", 9, FALSE }, /* Alternate explicit import library for dll's. */ - { "%s.dll.a", FALSE }, + { "%s.dll.a", 6, 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 }, + { "lib%s.a", 5, FALSE }, /* The 'native' spelling of an import lib name is "foo.lib". */ - { "%s.lib", FALSE }, + { "%s.lib", 4, FALSE }, #ifdef DLL_SUPPORT /* Try "foo.dll" (preferred dll name, if specified). */ - { "%s%s.dll", TRUE }, + { "%s%s.dll", 4, TRUE }, #endif /* Try "libfoo.dll" (default preferred dll name). */ - { "lib%s.dll", FALSE }, + { "lib%s.dll", 7, 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 } + { "%s.dll", 4, FALSE }, + { NULL, 0, FALSE } }; const char * filename; char * full_string; char * base_string; unsigned int i; - + static int fixed_format_max_len = -1; if (! entry->is_archive) return FALSE; + if (fixed_format_max_len < 0) + { + fixed_format_max_len = 0; + for (i = 0; libname_fmt[i].format; i++) + { + if (fixed_format_max_len < libname_fmt[i].fixed_len) + fixed_format_max_len = libname_fmt[i].fixed_len; + } + } + filename = entry->filename; full_string = xmalloc (strlen (search->name) + strlen (filename) - /* Allow space for the characters in the format - string. Also allow for the path separator that - is appended after the search name. We actually - allow 1 more byte than is strictly necessary, - but this will not hurt. */ - + sizeof libname_fmt[0].format + /* Allow space for the fixed characters in the format + string. */ + + fixed_format_max_len + /* Also allow for the path separator that + is appended after the search name. */ + + sizeof ("/") - 1 #ifdef DLL_SUPPORT + (pe_dll_search_prefix ? strlen (pe_dll_search_prefix) : 0)