Skip to contentSkip to conversation

mingw: fix build on Fedora 22

PATCH In review Michael S. Tsirkin 3 participants 5 messages Sep 22, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mingw: fix build on Fedora 22

mingw on Fedora 22 replaces localtime_r and gmtime_r macros with posix compliant functions in time.h.

These conflict with QEMU supplied ones.

Detect this and avoid overriding them.

We also need to define POSIX_C_SOURCE before including time.h for the first time, to make sure these are available to all users.

---
 include/qemu/osdep.h      | 1 +
 include/sysemu/os-win32.h | 6 ++++++
 util/oslib-win32.c        | 4 ++++
 3 files changed, 11 insertions(+)
include/qemu/osdep.h +1 -0
index ab3c876..9920ac3 100644
@@ -25,6 +25,7 @@
 #ifndef QEMU_OSDEP_H
 #define QEMU_OSDEP_H
 
+#define _POSIX_C_SOURCE 200809L
 #include "config-host.h"
 #include "qemu/compiler.h"
 #include <stdarg.h>
include/sysemu/os-win32.h +6 -0
index 706d85a..74230e7 100644
@@ -72,11 +72,17 @@
 #define sigsetjmp(env, savemask) setjmp(env)
 #define siglongjmp(env, val) longjmp(env, val)
 
+#ifdef gmtime_r
 /* Missing POSIX functions. Don't use MinGW-w64 macros. */
 #undef gmtime_r
+#define QEMU_NEED_GMTIME_R
 struct tm *gmtime_r(const time_t *timep, struct tm *result);
+#endif
+#ifdef localtime_r
 #undef localtime_r
+#define QEMU_NEED_LOCALTIME_R
 struct tm *localtime_r(const time_t *timep, struct tm *result);
+#endif
 
 
 static inline void os_setup_signal_handling(void) {}
util/oslib-win32.c +4 -0
index 730a670..abd710a 100644
@@ -95,6 +95,7 @@ void qemu_anon_ram_free(void *ptr, size_t size)
     }
 }
 
+#ifdef QEMU_NEED_GMTIME_R
 /* FIXME: add proper locking */
 struct tm *gmtime_r(const time_t *timep, struct tm *result)
 {
@@ -106,7 +107,9 @@ struct tm *gmtime_r(const time_t *timep, struct tm *result)
     }
     return p;
 }
+#endif
 
+#ifdef QEMU_NEED_LOCALTIME_R
 /* FIXME: add proper locking */
 struct tm *localtime_r(const time_t *timep, struct tm *result)
 {
@@ -118,6 +121,7 @@ struct tm *localtime_r(const time_t *timep, struct tm *result)
     }
     return p;
 }
+#endif
 
 void qemu_set_block(int fd)
 {
Signature · 1 line
MST
#1 lore raw
Quoted 37 lines · Michael S. Tsirkin

mingw on Fedora 22 replaces localtime_r and gmtime_r macros with posix compliant functions in time.h.

These conflict with QEMU supplied ones.

Detect this and avoid overriding them.

We also need to define POSIX_C_SOURCE before including time.h for the first time, to make sure these are available to all users.

---
 include/qemu/osdep.h      | 1 +
 include/sysemu/os-win32.h | 6 ++++++
 util/oslib-win32.c        | 4 ++++
 3 files changed, 11 insertions(+)
include/qemu/osdep.h +1 -0
index ab3c876..9920ac3 100644
@@ -25,6 +25,7 @@
 #ifndef QEMU_OSDEP_H
 #define QEMU_OSDEP_H
 
+#define _POSIX_C_SOURCE 200809L
 #include "config-host.h"
 #include "qemu/compiler.h"
 #include <stdarg.h>
include/sysemu/os-win32.h +0 -0
index 706d85a..74230e7 100644

include/sysemu/os-win32.h line 80

Quoted 9 lines
include/sysemu/os-win32.h +3 -0
@@ -72,11 +72,17 @@
 #define sigsetjmp(env, savemask) setjmp(env)
 #define siglongjmp(env, val) longjmp(env, val)
 
+#ifdef gmtime_r
 /* Missing POSIX functions. Don't use MinGW-w64 macros. */
 #undef gmtime_r
+#define QEMU_NEED_GMTIME_R
 struct tm *gmtime_r(const time_t *timep, struct tm *result);
+#endif

I don't think this is right. There are three possibilities with mingw

- No gmtime_r at all - need replacement
- gmtime_r defined as a macro - need replacement
- gmtime_r defined as a function - nothing needed

With this change of yours, if gmtime_r is defined as a macro QEMU will provide its own replacement. If gmtime_r is not defined at all, then QEMU doesn't provide its replacement which is wrong. I believe the change I previously proposed works in all three cases

https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg01926.html

Regards,
Daniel

Signature · 4 lines
|: 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 :|
#2 lore raw
Quoted 61 lines · Daniel P. Berrange
Quoted 37 lines · Michael S. Tsirkin

mingw on Fedora 22 replaces localtime_r and gmtime_r macros with posix compliant functions in time.h.

These conflict with QEMU supplied ones.

Detect this and avoid overriding them.

We also need to define POSIX_C_SOURCE before including time.h for the first time, to make sure these are available to all users.

---
 include/qemu/osdep.h      | 1 +
 include/sysemu/os-win32.h | 6 ++++++
 util/oslib-win32.c        | 4 ++++
 3 files changed, 11 insertions(+)
include/qemu/osdep.h +1 -0
index ab3c876..9920ac3 100644
@@ -25,6 +25,7 @@
 #ifndef QEMU_OSDEP_H
 #define QEMU_OSDEP_H
 
+#define _POSIX_C_SOURCE 200809L
 #include "config-host.h"
 #include "qemu/compiler.h"
 #include <stdarg.h>
include/sysemu/os-win32.h +0 -0
index 706d85a..74230e7 100644

include/sysemu/os-win32.h line 80

Quoted 9 lines
include/sysemu/os-win32.h +3 -0
@@ -72,11 +72,17 @@
 #define sigsetjmp(env, savemask) setjmp(env)
 #define siglongjmp(env, val) longjmp(env, val)
 
+#ifdef gmtime_r
 /* Missing POSIX functions. Don't use MinGW-w64 macros. */
 #undef gmtime_r
+#define QEMU_NEED_GMTIME_R
 struct tm *gmtime_r(const time_t *timep, struct tm *result);
+#endif

I don't think this is right. There are three possibilities with mingw

- No gmtime_r at all - need replacement
- gmtime_r defined as a macro - need replacement
- gmtime_r defined as a function - nothing needed

With this change of yours, if gmtime_r is defined as a macro QEMU will provide its own replacement. If gmtime_r is not defined at all, then QEMU doesn't provide its replacement which is wrong. I believe the change I previously proposed works in all three cases

Quoted 4 lines

https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg01926.html

Regards,
Daniel

Good point.
Can you bounce me your patch pls?

Quoted 5 lines
Signature · 4 lines
|: 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 :|
#3 lore raw
Quoted 15 lines · Michael S. Tsirkin
Quoted 14 lines · Daniel P. Berrange

I don't think this is right. There are three possibilities with mingw

- No gmtime_r at all - need replacement
- gmtime_r defined as a macro - need replacement
- gmtime_r defined as a function - nothing needed

With this change of yours, if gmtime_r is defined as a macro QEMU will provide its own replacement. If gmtime_r is not defined at all, then QEMU doesn't provide its replacement which is wrong. I believe the change I previously proposed works in all three cases

Quoted 4 lines
Quoted 2 lines

https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg01926.html

Good point.
Can you bounce me your patch pls?

I just sent it as a REPOST, with everyone on this thread CC'd.

Regards,
Daniel

Signature · 4 lines
|: 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 :|
#4 lore raw
In reply to Daniel P. Berrange
Quoted 54 lines · Daniel P. Berrange
Quoted 37 lines · Michael S. Tsirkin

mingw on Fedora 22 replaces localtime_r and gmtime_r macros with posix compliant functions in time.h.

These conflict with QEMU supplied ones.

Detect this and avoid overriding them.

We also need to define POSIX_C_SOURCE before including time.h for the first time, to make sure these are available to all users.

---
  include/qemu/osdep.h      | 1 +
  include/sysemu/os-win32.h | 6 ++++++
  util/oslib-win32.c        | 4 ++++
  3 files changed, 11 insertions(+)
include/qemu/osdep.h +1 -0
index ab3c876..9920ac3 100644
@@ -25,6 +25,7 @@
  #ifndef QEMU_OSDEP_H
  #define QEMU_OSDEP_H
 
+#define _POSIX_C_SOURCE 200809L
  #include "config-host.h"
  #include "qemu/compiler.h"
  #include <stdarg.h>
include/sysemu/os-win32.h +0 -0
index 706d85a..74230e7 100644

include/sysemu/os-win32.h line 80

Quoted 9 lines
include/sysemu/os-win32.h +3 -0
@@ -72,11 +72,17 @@
  #define sigsetjmp(env, savemask) setjmp(env)
  #define siglongjmp(env, val) longjmp(env, val)
 
+#ifdef gmtime_r
  /* Missing POSIX functions. Don't use MinGW-w64 macros. */
  #undef gmtime_r
+#define QEMU_NEED_GMTIME_R
  struct tm *gmtime_r(const time_t *timep, struct tm *result);
+#endif

I don't think this is right. There are three possibilities with mingw

- No gmtime_r at all - need replacement
- gmtime_r defined as a macro - need replacement
- gmtime_r defined as a function - nothing needed

Quoted 7 lines

With this change of yours, if gmtime_r is defined as a macro QEMU will provide its own replacement. If gmtime_r is not defined at all, then QEMU doesn't provide its replacement which is wrong. I believe the change I previously proposed works in all three cases

https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg01926.html

indeed, this looks better to me.

Den