[RFC] BFD MinGW/Cygwin build error in bfd/peiXXgen.c

"Pierre Muller" <[email protected]>
Newsgroups gmane.comp.gdb.devel,gmane.comp.gnu.binutils
Message-ID <[email protected]>
  Cygwin also fails to compile bfd/peigen.c, itself gebnerated
from source bfd/peXXigen.c.

  The patch below allows to compile both for mingw32 and cygwin hosts.
To fix the unknown wcsncasecmp function for mingw32 hosts,
I added this code:

+#ifdef __MINGW32__
+#define wcsncasecmp wcsnicmp
+#endif
  I think that using the Windows API function wcsnicmp
here is OK, but I don't know if the code should be somehow modified to
accept wcsncasecmp function if it is added later to mingw hosts...

Pierre Muller


bfd/ChangeLog entry:

2013-12-18  Pierre Muller  <[email protected]>

	peXXigen.c (u16_mbtouc): Avoid unused function warning by exculding if
	__CYGWIN__ or __MINGW32__ macro is defined.
	(rsrc_cmp): Fix short Windows OS version. Also use this code
	for mingw32 systems.
	[__MINGW32__]: Alias wcsncasecmp function to Windows API wcsnicmp function.

diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c
index 5e2a876..05c7d8b 100644
--- a/bfd/peXXigen.c
+++ b/bfd/peXXigen.c
@@ -2930,7 +2930,7 @@ rsrc_write_directory (rsrc_write_data * data,
   BFD_ASSERT (nt == 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.  */

@@ -2979,9 +2979,16 @@ rsrc_cmp (bfd_boolean is_name, rsrc_entry * a, rsrc_entry * b)
   /* We have to perform a case insenstive, unicode string comparison...  */
   int res;

-#ifdef __CYGWIN__
+#if defined  __CYGWIN__ || defined __MINGW32__
+#ifdef __MINGW32__
+#define wcsncasecmp wcsnicmp
+#endif
   /* Under Cygwin unicode == UTF-16 == wchar_t.
      FIXME: The same is true for MingGW - we should test for that too.  */
+  bfd_byte *    astring = a->name_id.name.string;
+  unsigned int  alen    = a->name_id.name.len;
+  bfd_byte *    bstring = b->name_id.name.string;
+  unsigned int  blen    = b->name_id.name.len;
   res = wcsncasecmp ((const wchar_t *) astring + 2, (const wchar_t *) bstring + 2, min (alen, blen));
 #elif defined HAVE_WCHAR_H
   unsigned int  i;



> -----Message d'origine-----
> De : [email protected] [mailto:binutils-
> [email protected]] De la part de Pedro Alves
> Envoyé : mercredi 18 décembre 2013 11:06
> À : asmwarrior
> Cc : GDB Development; Binutils Development
> Objet : Re: BFD MinGW build error: implicit declaration of function
> 'wcsncasecmp'
> 
> Hi there,
> 
> Adding the binutils folks.  (bfd is maintained by binutils.)
> 
> Looks like fallout from the .rsrc merge support.
> 
> On 12/18/2013 09:53 AM, asmwarrior wrote:
> > I see the build error when I build GDB(git head) under MSYS+MinGW,
> here the is build log
> >
> > mv -f .deps/pe-i386.Tpo .deps/pe-i386.Plo
> > rm -f peigen.c
> > sed -e s/XX/pe/g < ../../binutils-gdb/bfd/peXXigen.c > peigen.new
> > mv -f peigen.new peigen.c
> > /bin/sh ./libtool --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -
> I../../binutils-gdb/bfd -D__USE_MINGW_FSEEK    -I. -I../../binutils-
> gdb/bfd -I../../binutils-gdb/bfd/../include  -DHAVE_i386pe_vec -
> DHAVE_i386pei_vec -DHAVE_bfd_elf32_i386_vec -
> DHAVE_bfd_elf32_little_generic_vec -DHAVE_bfd_elf32_big_generic_vec  -
> DBINDIR='"/mingw/bin"'  -W -Wall -Wstrict-prototypes -Wmissing-
> prototypes -Wshadow -Wno-format -Werror -O0 -g -D__USE_MINGW_ACCESS -MT
> peigen.lo -MD -MP -MF .deps/peigen.Tpo -c -o peigen.lo peigen.c
> > libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I../../binutils-gdb/bfd -
> D__USE_MINGW_FSEEK -I. -I../../binutils-gdb/bfd -I../../binutils-
> gdb/bfd/../include -DHAVE_i386pe_vec -DHAVE_i386pei_vec -
> DHAVE_bfd_elf32_i386_vec -DHAVE_bfd_elf32_little_generic_vec -
> DHAVE_bfd_elf32_big_generic_vec -DBINDIR=\"/mingw/bin\" -W -Wall -
> Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wno-format -Werror -
> O0 -g -D__USE_MINGW_ACCESS -MT peigen.lo -MD -MP -MF .deps/peigen.Tpo -
> c peigen.c -o peigen.o
> > peigen.c: In function 'rsrc_cmp':
> > peigen.c:3006:7: error: implicit declaration of function
> 'wcsncasecmp' [-Werror=implicit-function-declaration]
> >        res = wcsncasecmp (& awc, & bwc, 1);
> >        ^
> > cc1.exe: all warnings being treated as errors
> > make[4]: *** [peigen.lo] Error 1
> > make[4]: Leaving directory `/f/build_gdb/mybuild/bfd'
> > make[3]: *** [all-recursive] Error 1
> > make[3]: Leaving directory `/f/build_gdb/mybuild/bfd'
> > make[2]: *** [all] Error 2
> >
> > I just see this is related to the change of this commit:
> >
> > Revision: 5879bb8fc592e4aea85bdc2a84381d89850e5770
> > Author: Nick Clifton <[email protected]>
> > Date: 2013-12-17 23:39:13
> > Message:
> > * peXXigen.c: Include wchar.h if available.
> >
> > Include safe-ctype.h.
> >     (HighBitSet, SetHighBit, WithoutHighBit): New macros.
> >     (pe_print_resource_entries): Rename to
> >     rsrc_print_resource_entries.  Handle names that are not RVAs.
> >     (pe_print_resource_directory): Rename to
> >     rsrc_print_resource_directory.
> >     (pe_print_rsrc): Rename to rsrc_print_section.  Corrupt
> >     computation of RVA bias.
> >     (rsrc_count_entries): New function.
> >     (rsrc_count_directory): New function.
> >     (rsrc_parse_entry): New function.
> >     (rsrc_parse_entries): New function.
> >     (rsrc_parse_directory): New function.
> >     (rsrc_write_string): New function.
> >     (rsrc_compute_rva): New function.
> >     (rsrc_write_leaf): New function.
> >     (rsrc_write_entry): New function.
> >     (rsrc_write_directory): New function.
> >     (u16_mbtouc): New function.
> >     (rsrc_cmp): New function.
> >     (rsrc_print_name): New function.
> >     (rsrc_resource_name): New function.
> >     (rsrc_merge_string_entries): New function.
> >     (rsrc_sort_entries): New function.
> >     (rsrc_attach_chain): New function.
> >     (rsrc_merge): New function.
> >     (rsrc_process_section): New function - merges the contents of a
> >     .rsrc section.
> >     (_bfd_XXi_final_link_postscript): Call rsrc_process_section.
> >     * configure.in (AC_CHECK_HEADERS): Add wchar.h
> >     * config.in: Regenerate.
> >     * configure: Regenerate.
> > ----
> > Modified: bfd/ChangeLog
> > Modified: bfd/config.in
> > Modified: bfd/configure
> > Modified: bfd/configure.in
> > Modified: bfd/peXXigen.c
> >
> > In my ststem, wchar.h exists, but I see there is no
> functionwcsncasecmp() here.
> >
> > Thanks
> >
> > Yuanhui Zhang
> >
> 
> 
> --
> Pedro Alves
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.