[libvirt] Libvirt / GNULIB failures using Mingw64 toolchain

With current Libvirt master + GNULIB (77cef20) I can successfully compile using the Mingw32 toolchain. If attempting to use the alternative Mingw64 toolchain, however, I get a number of errors. On both x86_64-w64-mingw32 and i686-w64-mingw32 I see the following: CC fstat.lo ../../../gnulib/lib/fstat.c:27:0: warning: "stat" redefined [enabled by default] In file included from ./sys/stat.h:32:0, from ../../../gnulib/lib/fstat.c:25: /usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/stat.h:258:0: note: this is the location of the previous definition ../../../gnulib/lib/fstat.c:28:0: warning: "fstat" redefined [enabled by default] In file included from ./sys/stat.h:32:0, from ../../../gnulib/lib/fstat.c:25: /usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/stat.h:259:0: note: this is the location of the previous definition CC stat.lo ../../../gnulib/lib/stat.c:32:0: warning: "stat" redefined [enabled by default] In file included from ./sys/stat.h:32:0, from ../../../gnulib/lib/stat.c:27: /usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/stat.h:258:0: note: this is the location of the previous definition CC stdio-read.lo ../../../gnulib/lib/stdio-read.c:102:1: error: redefinition of 'vscanf' In file included from ./stdio.h:43:0, from ../../../gnulib/lib/stdio-read.c:21: /usr/x86_64-w64-mingw32/sys-root/mingw/include/stdio.h:397:7: note: previous definition of 'vscanf' was here ../../../gnulib/lib/stdio-read.c:108:1: error: redefinition of 'vfscanf' In file included from ./stdio.h:43:0, from ../../../gnulib/lib/stdio-read.c:21: /usr/x86_64-w64-mingw32/sys-root/mingw/include/stdio.h:384:7: note: previous definition of 'vfscanf' was here make[3]: *** [stdio-read.lo] Error 1 make[3]: Leaving directory `/home/berrange/src/virt/libvirt/build/gnulib/lib' While on x86_64-w64-mingw32 only I see: In file included from ../../../gnulib/lib/regex.c:69:0: ../../../gnulib/lib/regcomp.c: In function 'parse_dup_op': ../../../gnulib/lib/regcomp.c:2624:39: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] ../../../gnulib/lib/regcomp.c: In function 'mark_opt_subexp': ../../../gnulib/lib/regcomp.c:3859:19: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Hi Paul, Daniel P. Berrange wrote:
While on x86_64-w64-mingw32 only I see:
In file included from ../../../gnulib/lib/regex.c:69:0: ../../../gnulib/lib/regcomp.c: In function 'parse_dup_op': ../../../gnulib/lib/regcomp.c:2624:39: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] ../../../gnulib/lib/regcomp.c: In function 'mark_opt_subexp': ../../../gnulib/lib/regcomp.c:3859:19: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
Obviously, the code assumes that 'long' has the same width as 'void*'. For portability the cast to 'long' should better be replaced with a cast to 'intptr_t'. This type is guaranteed to be defined by virtue of the #include <stdint.h> in regex_internal.h. Bruno

On 06/17/2012 07:00 AM, Bruno Haible wrote:
For portability the cast to 'long' should better be replaced with a cast to 'intptr_t'.
Thanks, I did that, except I used uintptr_t since the value in question is a size_t value. regex: avoid warning when pointers are not long * lib/regcomp.c (parse_dup_op, mark_opt_subexp): Cast between void * and uintptr_t, not long, for portability to hosts where pointers and long have different sizes. Issue noted by Daniel P. Berrange in <http://lists.gnu.org/archive/html/bug-gnulib/2012-06/msg00122.html> and fix suggested by Bruno Haible in <http://lists.gnu.org/archive/html/bug-gnulib/2012-06/msg00128.html>. diff --git a/lib/regcomp.c b/lib/regcomp.c index 7996dc0..7eb003b 100644 --- a/lib/regcomp.c +++ b/lib/regcomp.c @@ -2621,7 +2621,10 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa, old_tree = NULL; if (elem->token.type == SUBEXP) - postorder (elem, mark_opt_subexp, (void *) (long) elem->token.opr.idx); + { + uintptr_t subidx = elem->token.opr.idx; + postorder (elem, mark_opt_subexp, (void *) subidx); + } tree = create_tree (dfa, elem, NULL, (end == REG_MISSING ? OP_DUP_ASTERISK : OP_ALT)); @@ -3856,7 +3859,7 @@ create_token_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right, static reg_errcode_t mark_opt_subexp (void *extra, bin_tree_t *node) { - Idx idx = (Idx) (long) extra; + Idx idx = (uintptr_t) extra; if (node->token.type == SUBEXP && node->token.opr.idx == idx) node->token.opt_subexp = 1;

Hello Daniel,
CC fstat.lo ../../../gnulib/lib/fstat.c:27:0: warning: "stat" redefined [enabled by default] In file included from ./sys/stat.h:32:0, from ../../../gnulib/lib/fstat.c:25: /usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/stat.h:258:0: note: this is the location of the previous definition ../../../gnulib/lib/fstat.c:28:0: warning: "fstat" redefined [enabled by default] In file included from ./sys/stat.h:32:0, from ../../../gnulib/lib/fstat.c:25: /usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/stat.h:259:0: note: this is the location of the previous definition
In the copy of mingw64 that I have, <sys/stat.h> does not have a "#define stat ..." or "#define fstat ...". Can you please point us, where to find the <sys/stat.h> that you are using?
CC stdio-read.lo ../../../gnulib/lib/stdio-read.c:102:1: error: redefinition of 'vscanf' In file included from ./stdio.h:43:0, from ../../../gnulib/lib/stdio-read.c:21: /usr/x86_64-w64-mingw32/sys-root/mingw/include/stdio.h:397:7: note: previous definition of 'vscanf' was here
Likewise for <stdio.h>. The mingw64 <stdio.h> that I have contains a declaration, not a definition, of vscanf. Yours must be different. Can you please show it? Bruno

On Sun, Jun 17, 2012 at 04:28:02PM +0200, Bruno Haible wrote:
Hello Daniel,
CC fstat.lo ../../../gnulib/lib/fstat.c:27:0: warning: "stat" redefined [enabled by default] In file included from ./sys/stat.h:32:0, from ../../../gnulib/lib/fstat.c:25: /usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/stat.h:258:0: note: this is the location of the previous definition ../../../gnulib/lib/fstat.c:28:0: warning: "fstat" redefined [enabled by default] In file included from ./sys/stat.h:32:0, from ../../../gnulib/lib/fstat.c:25: /usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/stat.h:259:0: note: this is the location of the previous definition
In the copy of mingw64 that I have, <sys/stat.h> does not have a "#define stat ..." or "#define fstat ...". Can you please point us, where to find the <sys/stat.h> that you are using?
CC stdio-read.lo ../../../gnulib/lib/stdio-read.c:102:1: error: redefinition of 'vscanf' In file included from ./stdio.h:43:0, from ../../../gnulib/lib/stdio-read.c:21: /usr/x86_64-w64-mingw32/sys-root/mingw/include/stdio.h:397:7: note: previous definition of 'vscanf' was here
Likewise for <stdio.h>. The mingw64 <stdio.h> that I have contains a declaration, not a definition, of vscanf. Yours must be different. Can you please show it?
Looks like the Fedora 17 version might be taken from the Mingw64 upstream GIT master, rather than an official release: mingw32-headers-2.0.999-0.5.trunk.20120224.fc17.noarch Attaching the stdio.h & sys/stat.h that I have Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Daniel P. Berrange wrote:
Attaching the stdio.h & sys/stat.h that I have
Thanks.
CC fstat.lo ../../../gnulib/lib/fstat.c:27:0: warning: "stat" redefined [enabled by default] In file included from ./sys/stat.h:32:0, from ../../../gnulib/lib/fstat.c:25: /usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/stat.h:258:0: note: this is the location of the previous definition ../../../gnulib/lib/fstat.c:28:0: warning: "fstat" redefined [enabled by default] In file included from ./sys/stat.h:32:0, from ../../../gnulib/lib/fstat.c:25: /usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/stat.h:259:0: note: this is the location of the previous definition
mingw64's <sys/stat.h> and <_mingw_stat64.h> do #if defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64) #ifdef _USE_32BIT_TIME_T #define stat _stat32i64 = _stati64 #define fstat _fstat32i64 = _fstati64 #else #define stat _stat64 = _stati64 #define fstat _fstat64 = _fstati64 #endif #endif therefore what gnulib does in stat.c and fstat.c is equivalent to it. We lose nothing by silencing the warning. I'm applying this: 2012-06-19 Bruno Haible <bruno@clisp.org> stat, fstat: Avoid warnings on mingw64. * lib/stat.c (stat) [_GL_WINDOWS_64_BIT_ST_SIZE]: Undefine before redefining. * lib/fstat.c (stat, fstat) [_GL_WINDOWS_64_BIT_ST_SIZE]: Likewise. Reported by Daniel P. Berrange <berrange@redhat.com>. --- lib/fstat.c.orig Wed Jun 20 01:58:30 2012 +++ lib/fstat.c Wed Jun 20 01:58:17 2012 @@ -24,7 +24,9 @@ #include <sys/types.h> #include <sys/stat.h> #if _GL_WINDOWS_64_BIT_ST_SIZE +# undef stat /* avoid warning on mingw64 with _FILE_OFFSET_BITS=64 */ # define stat _stati64 +# undef fstat /* avoid warning on mingw64 with _FILE_OFFSET_BITS=64 */ # define fstat _fstati64 #endif #undef __need_system_sys_stat_h --- lib/stat.c.orig Wed Jun 20 01:58:30 2012 +++ lib/stat.c Wed Jun 20 01:58:16 2012 @@ -29,6 +29,7 @@ #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ # if _GL_WINDOWS_64_BIT_ST_SIZE +# undef stat /* avoid warning on mingw64 with _FILE_OFFSET_BITS=64 */ # define stat _stati64 # define REPLACE_FUNC_STAT_DIR 1 # undef REPLACE_FUNC_STAT_FILE
CC stdio-read.lo ../../../gnulib/lib/stdio-read.c:102:1: error: redefinition of 'vscanf' In file included from ./stdio.h:43:0, from ../../../gnulib/lib/stdio-read.c:21: /usr/x86_64-w64-mingw32/sys-root/mingw/include/stdio.h:397:7: note: previous definition of 'vscanf' was here
Their <stdio.h> file now *defines* many functions: sscanf scanf fscanf vsscanf vscanf vfscanf fprintf printf sprintf vfprintf vprintf vsprintf asprintf vasprintf snprintf vsnprintf swscanf wscanf fwscanf vswscanf vwscanf vfwscanf fwprintf wprintf swprintf vfwprintf vwprintf vswprintf snwprintf vsnwprintf But the situation is not clear to me. What are the results of $ grep -i vscanf config.status $ grep STDIO config.status ? Bruno

On Wed, Jun 20, 2012 at 02:11:32AM +0200, Bruno Haible wrote:
Daniel P. Berrange wrote:
CC stdio-read.lo ../../../gnulib/lib/stdio-read.c:102:1: error: redefinition of 'vscanf' In file included from ./stdio.h:43:0, from ../../../gnulib/lib/stdio-read.c:21: /usr/x86_64-w64-mingw32/sys-root/mingw/include/stdio.h:397:7: note: previous definition of 'vscanf' was here
Their <stdio.h> file now *defines* many functions: sscanf scanf fscanf vsscanf vscanf vfscanf fprintf printf sprintf vfprintf vprintf vsprintf asprintf vasprintf snprintf vsnprintf swscanf wscanf fwscanf vswscanf vwscanf vfwscanf fwprintf wprintf swprintf vfwprintf vwprintf vswprintf snwprintf vsnwprintf
But the situation is not clear to me. What are the results of $ grep -i vscanf config.status $ grep STDIO config.status ?
Here's what i see in config.status for my libvirt build: $ grep -i vscanf config.status S["GNULIB_VSCANF"]="0" $ grep STDIO config.status S["NEXT_AS_FIRST_DIRECTIVE_STDIO_H"]="<stdio.h>" S["NEXT_STDIO_H"]="<stdio.h>" S["REPLACE_STDIO_WRITE_FUNCS"]="1" S["REPLACE_STDIO_READ_FUNCS"]="1" S["GNULIB_STDIO_H_SIGPIPE"]="1" S["GNULIB_STDIO_H_NONBLOCKING"]="1" Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Daniel P. Berrange wrote:
Here's what i see in config.status for my libvirt build:
$ grep -i vscanf config.status S["GNULIB_VSCANF"]="0"
$ grep STDIO config.status S["NEXT_AS_FIRST_DIRECTIVE_STDIO_H"]="<stdio.h>" S["NEXT_STDIO_H"]="<stdio.h>" S["REPLACE_STDIO_WRITE_FUNCS"]="1" S["REPLACE_STDIO_READ_FUNCS"]="1" S["GNULIB_STDIO_H_SIGPIPE"]="1" S["GNULIB_STDIO_H_NONBLOCKING"]="1"
Thanks for these details. The attached patch looks like it should fix the compilation error. I'm committing it. Can you please try it (you need to re-bootstrap libvirt to this effect, I guess)? 2012-06-21 Bruno Haible <bruno@clisp.org> nonblocking: Avoid compilation error on mingw64. * m4/stdio_h.m4 (gl_STDIO_H): Invoke gl_MODULE_INDICATOR for scanf, fscanf. * modules/vscanf (configure.ac): Invoke gl_MODULE_INDICATOR. * modules/vfscanf (configure.ac): Likewise. * lib/stdio-read.c (scanf, fscanf, vscanf, vfscanf): Enable function definition only if stdio.h has prepared it. Reported by Daniel P. Berrange <berrange@redhat.com>. --- lib/stdio-read.c.orig Thu Jun 21 12:35:50 2012 +++ lib/stdio-read.c Thu Jun 21 12:35:21 2012 @@ -72,6 +72,9 @@ return ret; \ } +/* Enable this function definition only of gnulib's <stdio.h> has prepared it. + Otherwise we get a function definition conflict with mingw64's <stdio.h>. */ +# if GNULIB_SCANF int scanf (const char *format, ...) { @@ -84,7 +87,11 @@ return retval; } +# endif +/* Enable this function definition only of gnulib's <stdio.h> has prepared it. + Otherwise we get a function definition conflict with mingw64's <stdio.h>. */ +# if GNULIB_FSCANF int fscanf (FILE *stream, const char *format, ...) { @@ -97,19 +104,28 @@ return retval; } +# endif +/* Enable this function definition only of gnulib's <stdio.h> has prepared it. + Otherwise we get a function definition conflict with mingw64's <stdio.h>. */ +# if GNULIB_VSCANF int vscanf (const char *format, va_list args) { return vfscanf (stdin, format, args); } +# endif +/* Enable this function definition only of gnulib's <stdio.h> has prepared it. + Otherwise we get a function definition conflict with mingw64's <stdio.h>. */ +# if GNULIB_VFSCANF int vfscanf (FILE *stream, const char *format, va_list args) #undef vfscanf { CALL_WITH_ERRNO_FIX (int, vfscanf (stream, format, args), ret == EOF) } +# endif int getchar (void) --- m4/stdio_h.m4.orig Thu Jun 21 12:35:50 2012 +++ m4/stdio_h.m4 Thu Jun 21 12:30:28 2012 @@ -1,4 +1,4 @@ -# stdio_h.m4 serial 41 +# stdio_h.m4 serial 42 dnl Copyright (C) 2007-2012 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -13,7 +13,9 @@ dnl No need to create extra modules for these functions. Everyone who uses dnl <stdio.h> likely needs them. GNULIB_FSCANF=1 + gl_MODULE_INDICATOR([fscanf]) GNULIB_SCANF=1 + gl_MODULE_INDICATOR([scanf]) GNULIB_FGETC=1 GNULIB_GETC=1 GNULIB_GETCHAR=1 --- modules/vfscanf.orig Thu Jun 21 12:35:50 2012 +++ modules/vfscanf Thu Jun 21 12:30:24 2012 @@ -8,6 +8,7 @@ configure.ac: gl_STDIO_MODULE_INDICATOR([vfscanf]) +gl_MODULE_INDICATOR([vfscanf]) Makefile.am: --- modules/vscanf.orig Thu Jun 21 12:35:50 2012 +++ modules/vscanf Thu Jun 21 12:30:24 2012 @@ -8,6 +8,7 @@ configure.ac: gl_STDIO_MODULE_INDICATOR([vscanf]) +gl_MODULE_INDICATOR([vscanf]) Makefile.am:

On Thu, Jun 21, 2012 at 12:42:17PM +0200, Bruno Haible wrote:
Daniel P. Berrange wrote:
Here's what i see in config.status for my libvirt build:
$ grep -i vscanf config.status S["GNULIB_VSCANF"]="0"
$ grep STDIO config.status S["NEXT_AS_FIRST_DIRECTIVE_STDIO_H"]="<stdio.h>" S["NEXT_STDIO_H"]="<stdio.h>" S["REPLACE_STDIO_WRITE_FUNCS"]="1" S["REPLACE_STDIO_READ_FUNCS"]="1" S["GNULIB_STDIO_H_SIGPIPE"]="1" S["GNULIB_STDIO_H_NONBLOCKING"]="1"
Thanks for these details. The attached patch looks like it should fix the compilation error. I'm committing it. Can you please try it (you need to re-bootstrap libvirt to this effect, I guess)?
2012-06-21 Bruno Haible <bruno@clisp.org>
nonblocking: Avoid compilation error on mingw64. * m4/stdio_h.m4 (gl_STDIO_H): Invoke gl_MODULE_INDICATOR for scanf, fscanf. * modules/vscanf (configure.ac): Invoke gl_MODULE_INDICATOR. * modules/vfscanf (configure.ac): Likewise. * lib/stdio-read.c (scanf, fscanf, vscanf, vfscanf): Enable function definition only if stdio.h has prepared it. Reported by Daniel P. Berrange <berrange@redhat.com>.
Thanks Bruno. I have confirmed that this patch plus the other 2 previously committed allow libvirt/gnulib to compile warning/error free with Mingw64. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (3)
-
Bruno Haible
-
Daniel P. Berrange
-
Paul Eggert