diff mbox

MinGW build

Message ID 878u5foc1m.fsf@emacs.mitica
State New
Headers show

Commit Message

Juan Quintela Nov. 30, 2015, 1:24 p.m. UTC
Peter Maydell <peter.maydell@linaro.org> wrote:
> On 28 November 2014 at 07:14, Stefan Weil <sw@weilnetz.de> wrote:
>> The libvixl code is correct, but the C++ compiler would need to be
>> fixed. Here are some examples:
>>
>> disas/libvixl/a64/disasm-a64.cc:1340:57: warning: unknown conversion
>> type character ā€˜lā€™ in format [-Wformat]
>> disas/libvixl/a64/disasm-a64.cc:1340:57: warning: too many arguments for
>> format [-Wformat-extra-args]
>> disas/libvixl/a64/disasm-a64.cc:1492:42: warning: unknown conversion
>> type character ā€˜lā€™ in format [-Wformat]
>>
>> That code uses PRIx64, so the format specifier is %llx which is correct.
>> Obviously the C++ compiler ignores that QEMU uses ANSI format specifiers
>> (compiler option -D__USE_MINGW_ANSI_STDIO=1) instead of the MS specific
>> ones.
>
> I finally got around to looking at this (a year later!), and it turns out
> that the problem here is just that libvixl's code for marking functions
> as having format strings doesn't have the check that we do in
> include/qemu/compiler.h:
>
> #if defined __GNUC__
> # if !QEMU_GNUC_PREREQ(4, 4)
>    /* gcc versions before 4.4.x don't support gnu_printf, so use printf. */
> #  define GCC_FMT_ATTR(n, m) __attribute__((format(printf, n, m)))
> # else
>    /* Use gnu_printf when supported (qemu uses standard format strings). */
> #  define GCC_FMT_ATTR(n, m) __attribute__((format(gnu_printf, n, m)))
> #  if defined(_WIN32)
>     /* Map __printf__ to __gnu_printf__ because we want standard format strings
>      * even when MinGW or GLib include files use __printf__. */
> #   define __printf__ __gnu_printf__
> #  endif
> # endif
> #else
> #define GCC_FMT_ATTR(n, m)
> #endif
>
> ...which will effectively cause us to use 'gnu_printf' on this
> compiler, which works. The libvixl headers always use plain 'printf',
> which gets warnings. So I think we can fix this pretty simply in
> disas/libvixl/utils.h by making it also do "use gnu_printf for
> a compiler that's 4.4 or better".

Confirmed that following patch works for me (as I don't have a pre-4.4
compiler, I didn't care if doing the proper thing).

Comments

Stefan Weil Nov. 30, 2015, 1:29 p.m. UTC | #1
Am 30.11.2015 um 14:24 schrieb Juan Quintela:

[...]
> I lied, on win64, you also need the following one (notice that
> getpagesize on unix return int as far as I can see).  And this is the
> solution that was suggested on list.  Should I submit that one, or
> should we leave the warning?
>
> Thanks, Juan.
>
>
> diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
> index 13dcef6..400e098 100644
> --- a/include/sysemu/os-win32.h
> +++ b/include/sysemu/os-win32.h
> @@ -87,7 +87,7 @@ static inline void os_setup_post(void) {}
>  void os_set_line_buffering(void);
>  static inline void os_set_proc_name(const char *dummy) {}
>
> -size_t getpagesize(void);
> +int getpagesize(void);
>
>  #if !defined(EPROTONOSUPPORT)
>  # define EPROTONOSUPPORT EINVAL
> diff --git a/util/oslib-win32.c b/util/oslib-win32.c
> index 09f9e98..7aad185 100644
> --- a/util/oslib-win32.c
> +++ b/util/oslib-win32.c
> @@ -454,7 +454,7 @@ gint g_poll(GPollFD *fds, guint nfds, gint timeout)
>      return retval;
>  }
>
> -size_t getpagesize(void)
> +getpagesize(void)
>  {
>      SYSTEM_INFO system_info;
>
> @@ -465,7 +465,7 @@ size_t getpagesize(void)
>  void os_mem_prealloc(int fd, char *area, size_t memory)
>  {
>      int i;
> -    size_t pagesize = getpagesize();
> +    int pagesize = getpagesize();
>
>      memory = (memory + pagesize - 1) & -pagesize;
>      for (i = 0; i < memory / pagesize; i++) {


Something like this one: http://patchwork.ozlabs.org/patch/549870/ ? :-)

I'd be happy if you could review all three commits in that pull request,
because nobody did so far.

Regards,
Stefan
diff mbox

Patch

diff --git a/disas/libvixl/utils.h b/disas/libvixl/utils.h
index b440626..96ef4b0 100644
--- a/disas/libvixl/utils.h
+++ b/disas/libvixl/utils.h
@@ -36,7 +36,7 @@  namespace vixl {
 // Macros for compile-time format checking.
 #if defined(__GNUC__)
 #define PRINTF_CHECK(format_index, varargs_index) \
-  __attribute__((format(printf, format_index, varargs_index)))
+  __attribute__((format(gnu_printf, format_index, varargs_index)))
 #else
 #define PRINTF_CHECK(format_index, varargs_index)
 #endif

I lied, on win64, you also need the following one (notice that
getpagesize on unix return int as far as I can see).  And this is the
solution that was suggested on list.  Should I submit that one, or
should we leave the warning?

Thanks, Juan.


diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
index 13dcef6..400e098 100644
--- a/include/sysemu/os-win32.h
+++ b/include/sysemu/os-win32.h
@@ -87,7 +87,7 @@  static inline void os_setup_post(void) {}
 void os_set_line_buffering(void);
 static inline void os_set_proc_name(const char *dummy) {}

-size_t getpagesize(void);
+int getpagesize(void);

 #if !defined(EPROTONOSUPPORT)
 # define EPROTONOSUPPORT EINVAL
diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index 09f9e98..7aad185 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -454,7 +454,7 @@  gint g_poll(GPollFD *fds, guint nfds, gint timeout)
     return retval;
 }

-size_t getpagesize(void)
+getpagesize(void)
 {
     SYSTEM_INFO system_info;

@@ -465,7 +465,7 @@  size_t getpagesize(void)
 void os_mem_prealloc(int fd, char *area, size_t memory)
 {
     int i;
-    size_t pagesize = getpagesize();
+    int pagesize = getpagesize();

     memory = (memory + pagesize - 1) & -pagesize;
     for (i = 0; i < memory / pagesize; i++) {