From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6454 invoked by alias); 19 Dec 2013 11:45:09 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 6434 invoked by uid 89); 19 Dec 2013 11:45:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.0 required=5.0 tests=AWL,BAYES_00,MSGID_MULTIPLE_AT autolearn=no version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mailhost.u-strasbg.fr Received: from mailhost.u-strasbg.fr (HELO mailhost.u-strasbg.fr) (130.79.222.213) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 19 Dec 2013 11:45:07 +0000 Received: from mailhost.u-strasbg.fr (localhost [127.0.0.1]) by antispam (Postfix) with ESMTP id 6F620C059D; Thu, 19 Dec 2013 12:45:04 +0100 (CET) Received: from mailhost.u-strasbg.fr (localhost [127.0.0.1]) by antivirus (Postfix) with ESMTP id 5E9B3C05A0; Thu, 19 Dec 2013 12:45:04 +0100 (CET) Received: from md16.u-strasbg.fr (md16.u-strasbg.fr [130.79.200.206]) by mr3.u-strasbg.fr (Postfix) with ESMTP id CAEDCC059D; Thu, 19 Dec 2013 12:44:58 +0100 (CET) Received: from ms16.u-strasbg.fr (ms16.u-strasbg.fr [130.79.204.116]) by md16.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id rBJBiwLo025336 ; Thu, 19 Dec 2013 12:44:58 +0100 (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from E6510Muller (gw-ics.u-strasbg.fr [130.79.210.225]) (Authenticated sender: mullerp) by ms16.u-strasbg.fr (Postfix) with ESMTPSA id D19681FD8E; Thu, 19 Dec 2013 12:44:53 +0100 (CET) From: "Pierre Muller" To: "'nick clifton'" , "'Pedro Alves'" , "'asmwarrior'" Cc: "'GDB Development'" , "'Binutils Development'" References: <52B17083.7040404@gmail.com> <52B1738D.4010409@redhat.com> <002101cefbf1$7554b9a0$5ffe2ce0$@muller@ics-cnrs.unistra.fr> <52B1E03E.9010002@redhat.com> In-Reply-To: <52B1E03E.9010002@redhat.com> Subject: [RFC-v2] BFD MinGW/Cygwin build error in bfd/peiXXgen.c Date: Thu, 19 Dec 2013 11:45:00 -0000 Message-ID: <006c01cefcaf$bec215b0$3c464110$@muller@ics-cnrs.unistra.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-SW-Source: 2013-12/txt/msg00061.txt.bz2 Hi Nick, After looking at the code a little longer, I think that there were still other issues in that part of the code. 1) The astring and bstring were still not declared for the last macro case (hosts having no wchar header). I solved this issue by placing the declarations at the start of the function. 2) In GDB coding rules, we are not allowed to mix code and declaration. The declaration of res after handling the ! is_name part does not follow this rule. Isn't that rule also used for Binutils project? I moved the declaration of astring, alen, bstring and blen to the start of the function. It does introduce a penalty, in the sense that those variables are set even though this is not useful if is_name is false. Otherwise adding an extra brace level might be the proper solution. Another silly coding style question: Should there by a space between the address operator "&" and the variable or expression following? 3) I was wondering why the Windows case started at astring + 2, but I couldn't find any valid reason, so that I changed it to compare the strings from the first position.=20 4) I did the same for the code if wchar is missing. 5) To have a symmetric code for cygwin versus mingw, I introduced a macro called rscpcmp for both cases. Finally, I also have a question regarding the codepage field. According to Windows PE resources can use any codepage. Is the new code restricted to UNICODE only? If not, shouldn't the rsrc_cmp code also depend on whether=20 16-bit Windows UNICODE is used or any other page code? The main problem is that I have no source code to test this code on... Pierre Muller PS: I removed the fixme as suggested by Pedro. 2013-12-19 Pierre Muller peXXigen.c (u16_mbtouc): Avoid unused function warning by excluding if __CYGWIN__ or __MINGW32__ macro is defined. (rsrc_cmp): Fix Windows host version and version without wchar header. [__CYGWIN__, __MINGW32__]: Introduce rsrccmp macro. diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c index 2a33a77..f5879f6 100644 --- a/bfd/peXXigen.c +++ b/bfd/peXXigen.c @@ -2930,7 +2930,7 @@ rsrc_write_directory (rsrc_write_data * data, BFD_ASSERT (nt =3D=3D next_entry); } -#ifdef HAVE_WCHAR_H +#if defined HAVE_WCHAR_H && ! defined __CYGWIN__ && ! defined __MINGW32__ /* Return the length (number of units) of the first character in S, putting its 'ucs4_t' representation in *PUC. */ @@ -2974,22 +2974,30 @@ static signed int rsrc_cmp (bfd_boolean is_name, rsrc_entry * a, rsrc_entry * b) { if (! is_name) - return a->name_id.id - b->name_id.id; + return a->name_id.id - b->name_id.id; /* We have to perform a case insenstive, unicode string comparison... */ int res; - -#ifdef __CYGWIN__ - /* Under Cygwin unicode =3D=3D UTF-16 =3D=3D wchar_t. - FIXME: The same is true for MingGW - we should test for that too. */ - res =3D wcsncasecmp ((const wchar_t *) astring + 2, (const wchar_t *) bs= tring + 2, min (alen, blen)); -#elif defined HAVE_WCHAR_H - unsigned int i; bfd_byte * astring =3D a->name_id.name.string; unsigned int alen =3D a->name_id.name.len; bfd_byte * bstring =3D b->name_id.name.string; unsigned int blen =3D b->name_id.name.len; +#if defined __CYGWIN__ || defined __MINGW32__ +#undef rscpcmp +#ifdef __CYGWIN__ +#define rscpcmp wcsncasecmp +#endif +#ifdef __MINGW32__ +#define rscpcmp wcsnicmp +#endif + /* Under Windows hosts (both cygwin and mingw types), + unicode =3D=3D UTF-16 =3D=3D wchar_t. */ + res =3D rscpcmp ((const wchar_t *) astring, (const wchar_t *) bstring, + min (alen, blen)); +#elif defined HAVE_WCHAR_H + unsigned int i; + res =3D 0; for (i =3D min (alen, blen); i--; astring +=3D 2, bstring +=3D 2) { @@ -3008,7 +3016,7 @@ rsrc_cmp (bfd_boolean is_name, rsrc_entry * a, rsrc_e= ntry * b) break; } #else - res =3D memcmp (astring + 2, bstring + 2, min (alen, blen) * 2); + res =3D memcmp (astring, bstring, min (alen, blen) * 2); #endif if (res =3D=3D 0)