Skip to contentSkip to conversation

build: qga: add macro to force use of native mingw32 assert()

PATCH Superseded Michael Roth 2 participants 3 messages Nov 9, 2018 – Nov 11, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 build: qga: add macro to force use of native mingw32 assert()

When building qemu-ga for w32 with VSS support, some parts of qemu-ga are not linked against glib, specifically the C++ bits used to create the VSS provider DLL. With 3ebee3b191e, we now define assert() as g_assert() for all mingw32 builds via osdep.h, which results in the following build breakage:

x86_64-w64-mingw32-g++ -o qga/vss-win32/qga-vss.dll qga/vss-win32/requester.o qga/vss-win32/provider.o qga/vss-win32/install.o /home/mdroth/w/qemu4.git/qga/vss-win32/qga-vss.def -shared -Wl,--add-stdcall-alias,--enable-stdcall-fixup -lole32 -loleaut32 -lshlwapi -luuid -static qga/vss-win32/requester.o: In function `requester_freeze':
/home/mdroth/w/qemu4.git/qga/vss-win32/requester.cpp:284: undefined reference to `g_assertion_message_expr'
qga/vss-win32/requester.o: In function `requester_thaw':
/home/mdroth/w/qemu4.git/qga/vss-win32/requester.cpp:508: undefined reference to `g_assertion_message_expr'
/home/mdroth/w/qemu4.git/qga/vss-win32/requester.cpp:509: undefined reference to `g_assertion_message_expr'
collect2: error: ld returned 1 exit status
make: *** [/home/mdroth/w/qemu4.git/qga/vss-win32/Makefile.objs:10: qga/vss-win32/qga-vss.dll] Error 1
make: *** Waiting for unfinished jobs....

Fix this by introducing a USE_NATIVE_MINGW32_ASSERT macro that can be defined prior to inclusion of osdep.h in individual C/C++ files that don't link against glib.

Cc Richard Henderson <[email protected]>
---
 include/qemu/osdep.h        | 2 +-
 qga/vss-win32/install.cpp   | 2 +-
 qga/vss-win32/provider.cpp  | 2 +-
 qga/vss-win32/requester.cpp | 2 +-
 qga/vss-win32/vss-common.h  | 2 ++
 5 files changed, 6 insertions(+), 4 deletions(-)
include/qemu/osdep.h +1 -1
index 3bf48bcdec..59364bfeb0 100644
@@ -129,7 +129,7 @@ extern int daemon(int, int);
  * code that is unreachable when features are disabled.
  * All supported versions of Glib's g_assert() satisfy this requirement.
  */
-#ifdef __MINGW32__
+#if defined(__MINGW32__) && !defined(USE_NATIVE_MINGW32_ASSERT)
 #undef assert
 #define assert(x)  g_assert(x)
 #endif
qga/vss-win32/install.cpp +1 -1
index 6713e58670..6ed2d5930c 100644
@@ -10,9 +10,9 @@
  * See the COPYING file in the top-level directory.
  */
 
+#include "vss-common.h"
 #include "qemu/osdep.h"
 
-#include "vss-common.h"
 #include <inc/win2003/vscoordint.h>
 #include "install.h"
 #include <wbemidl.h>
qga/vss-win32/provider.cpp +1 -1
index 72d8b0e19d..d298af91b2 100644
@@ -10,8 +10,8 @@
  * See the COPYING file in the top-level directory.
  */
 
-#include "qemu/osdep.h"
 #include "vss-common.h"
+#include "qemu/osdep.h"
 #include <inc/win2003/vscoordint.h>
 #include <inc/win2003/vsprov.h>
 
qga/vss-win32/requester.cpp +1 -1
index 5378c55d23..d239bd9598 100644
@@ -10,8 +10,8 @@
  * See the COPYING file in the top-level directory.
  */
 
-#include "qemu/osdep.h"
 #include "vss-common.h"
+#include "qemu/osdep.h"
 #include "requester.h"
 #include "install.h"
 #include <inc/win2003/vswriter.h>
qga/vss-win32/vss-common.h +2 -0
index 61c170b52e..275cbb59c5 100644
@@ -13,6 +13,8 @@
 #ifndef VSS_COMMON_H
 #define VSS_COMMON_H
 
+#define USE_NATIVE_MINGW32_ASSERT
+
 #define __MIDL_user_allocate_free_DEFINED__
 #include <windows.h>
 #include <shlwapi.h>
Signature · 1 line
2.17.1
#1 lore raw

Hi Michael,

Quoted 35 lines · Michael Roth

When building qemu-ga for w32 with VSS support, some parts of qemu-ga are not linked against glib, specifically the C++ bits used to create the VSS provider DLL. With 3ebee3b191e, we now define assert() as g_assert() for all mingw32 builds via osdep.h, which results in the following build breakage:

x86_64-w64-mingw32-g++ -o qga/vss-win32/qga-vss.dll qga/vss-win32/requester.o qga/vss-win32/provider.o qga/vss-win32/install.o /home/mdroth/w/qemu4.git/qga/vss-win32/qga-vss.def -shared -Wl,--add-stdcall-alias,--enable-stdcall-fixup -lole32 -loleaut32 -lshlwapi -luuid -static qga/vss-win32/requester.o: In function `requester_freeze':
/home/mdroth/w/qemu4.git/qga/vss-win32/requester.cpp:284: undefined reference to `g_assertion_message_expr'
qga/vss-win32/requester.o: In function `requester_thaw':
/home/mdroth/w/qemu4.git/qga/vss-win32/requester.cpp:508: undefined reference to `g_assertion_message_expr'
/home/mdroth/w/qemu4.git/qga/vss-win32/requester.cpp:509: undefined reference to `g_assertion_message_expr'
collect2: error: ld returned 1 exit status
make: *** [/home/mdroth/w/qemu4.git/qga/vss-win32/Makefile.objs:10: qga/vss-win32/qga-vss.dll] Error 1
make: *** Waiting for unfinished jobs....

Fix this by introducing a USE_NATIVE_MINGW32_ASSERT macro that can be defined prior to inclusion of osdep.h in individual C/C++ files that don't link against glib.

Cc Richard Henderson <[email protected]>
---
 include/qemu/osdep.h        | 2 +-
 qga/vss-win32/install.cpp   | 2 +-
 qga/vss-win32/provider.cpp  | 2 +-
 qga/vss-win32/requester.cpp | 2 +-
 qga/vss-win32/vss-common.h  | 2 ++
 5 files changed, 6 insertions(+), 4 deletions(-)
include/qemu/osdep.h +0 -0
index 3bf48bcdec..59364bfeb0 100644

include/qemu/osdep.h extern int daemon(int, int); · line 135

Quoted 8 lines
include/qemu/osdep.h +1 -1
@@ -129,7 +129,7 @@ extern int daemon(int, int);
  * code that is unreachable when features are disabled.
  * All supported versions of Glib's g_assert() satisfy this requirement.
  */
-#ifdef __MINGW32__
+#if defined(__MINGW32__) && !defined(USE_NATIVE_MINGW32_ASSERT)
 #undef assert
 #define assert(x)  g_assert(x)
 #endif

OK.

qga/vss-win32/install.cpp line 14

Quoted 10 lines
qga/vss-win32/install.cpp +1 -0
index 6713e58670..6ed2d5930c 100644
@@ -10,9 +10,9 @@
  * See the COPYING file in the top-level directory.
  */
 
+#include "vss-common.h"
 #include "qemu/osdep.h"

I don't like breaking the rule and not using "qemu/osdep.h" first. (See below for suggestion).

Quoted 10 lines
qga/vss-win32/install.cpp +0 -1
-#include "vss-common.h"
 #include <inc/win2003/vscoordint.h>
 #include "install.h"
 #include <wbemidl.h>
qga/vss-win32/provider.cpp +0 -0
index 72d8b0e19d..d298af91b2 100644

qga/vss-win32/provider.cpp line 14

Quoted 6 lines
qga/vss-win32/provider.cpp +1 -1
@@ -10,8 +10,8 @@
  * See the COPYING file in the top-level directory.
  */
 
-#include "qemu/osdep.h"
 #include "vss-common.h"
+#include "qemu/osdep.h"

Ditto.

Quoted 8 lines
qga/vss-win32/provider.cpp +0 -0
 #include <inc/win2003/vscoordint.h>
 #include <inc/win2003/vsprov.h>
 
qga/vss-win32/requester.cpp +0 -0
index 5378c55d23..d239bd9598 100644

qga/vss-win32/requester.cpp line 14

Quoted 6 lines
qga/vss-win32/requester.cpp +1 -1
@@ -10,8 +10,8 @@
  * See the COPYING file in the top-level directory.
  */
 
-#include "qemu/osdep.h"
 #include "vss-common.h"
+#include "qemu/osdep.h"

Ditto.

qga/vss-win32/vss-common.h line 16

Quoted 12 lines
qga/vss-win32/requester.cpp +0 -0
 #include "requester.h"
 #include "install.h"
 #include <inc/win2003/vswriter.h>
qga/vss-win32/vss-common.h +1 -0
index 61c170b52e..275cbb59c5 100644
@@ -13,6 +13,8 @@
 #ifndef VSS_COMMON_H
 #define VSS_COMMON_H
 
+#define USE_NATIVE_MINGW32_ASSERT

I believe you can add this in the "VSS SDK" section of the ./configure script:

-- >8 --

configure +1 -1
@@ -4588,7 +4588,7 @@ int main(void) { return VSS_CTX_BACKUP; }
 EOF
   if compile_prog "$vss_win32_include" "" ; then
     guest_agent_with_vss="yes"
-    QEMU_CFLAGS="$QEMU_CFLAGS $vss_win32_include"
+    QEMU_CFLAGS="$QEMU_CFLAGS -DUSE_NATIVE_MINGW32_ASSERT

$vss_win32_include"

     libs_qga="-lole32 -loleaut32 -lshlwapi -lstdc++
-Wl,--enable-stdcall-fixup $libs_qga"
     qga_vss_provider="qga/vss-win32/qga-vss.dll qga/vss-win32/qga-vss.tlb"

else
---

What do you think?

Regards,

Phil.

Quoted 5 lines
qga/vss-win32/vss-common.h +1 -0
+
 #define __MIDL_user_allocate_free_DEFINED__
 #include <windows.h>
 #include <shlwapi.h>
#2 lore raw

Quoting Philippe Mathieu-Daudé (2018-11-10 13:34:25)

Quoted 57 lines

Hi Michael,

Quoted 35 lines · Michael Roth

When building qemu-ga for w32 with VSS support, some parts of qemu-ga are not linked against glib, specifically the C++ bits used to create the VSS provider DLL. With 3ebee3b191e, we now define assert() as g_assert() for all mingw32 builds via osdep.h, which results in the following build breakage:

x86_64-w64-mingw32-g++ -o qga/vss-win32/qga-vss.dll qga/vss-win32/requester.o qga/vss-win32/provider.o qga/vss-win32/install.o /home/mdroth/w/qemu4.git/qga/vss-win32/qga-vss.def -shared -Wl,--add-stdcall-alias,--enable-stdcall-fixup -lole32 -loleaut32 -lshlwapi -luuid -static qga/vss-win32/requester.o: In function `requester_freeze':
/home/mdroth/w/qemu4.git/qga/vss-win32/requester.cpp:284: undefined reference to `g_assertion_message_expr'
qga/vss-win32/requester.o: In function `requester_thaw':
/home/mdroth/w/qemu4.git/qga/vss-win32/requester.cpp:508: undefined reference to `g_assertion_message_expr'
/home/mdroth/w/qemu4.git/qga/vss-win32/requester.cpp:509: undefined reference to `g_assertion_message_expr'
collect2: error: ld returned 1 exit status
make: *** [/home/mdroth/w/qemu4.git/qga/vss-win32/Makefile.objs:10: qga/vss-win32/qga-vss.dll] Error 1
make: *** Waiting for unfinished jobs....

Fix this by introducing a USE_NATIVE_MINGW32_ASSERT macro that can be defined prior to inclusion of osdep.h in individual C/C++ files that don't link against glib.

Cc Richard Henderson <[email protected]>
---
 include/qemu/osdep.h        | 2 +-
 qga/vss-win32/install.cpp   | 2 +-
 qga/vss-win32/provider.cpp  | 2 +-
 qga/vss-win32/requester.cpp | 2 +-
 qga/vss-win32/vss-common.h  | 2 ++
 5 files changed, 6 insertions(+), 4 deletions(-)
include/qemu/osdep.h +0 -0
index 3bf48bcdec..59364bfeb0 100644

include/qemu/osdep.h extern int daemon(int, int); · line 135

Quoted 8 lines
include/qemu/osdep.h +1 -1
@@ -129,7 +129,7 @@ extern int daemon(int, int);
  * code that is unreachable when features are disabled.
  * All supported versions of Glib's g_assert() satisfy this requirement.
  */
-#ifdef __MINGW32__
+#if defined(__MINGW32__) && !defined(USE_NATIVE_MINGW32_ASSERT)
 #undef assert
 #define assert(x)  g_assert(x)
 #endif

OK.

Quoted 8 lines
qga/vss-win32/install.cpp +0 -0
index 6713e58670..6ed2d5930c 100644
@@ -10,9 +10,9 @@
  * See the COPYING file in the top-level directory.
  */
 
Quoted 5 lines

qga/vss-win32/install.cpp line 14

Quoted 2 lines
qga/vss-win32/install.cpp +1 -0
+#include "vss-common.h"
 #include "qemu/osdep.h"

I don't like breaking the rule and not using "qemu/osdep.h" first. (See below for suggestion).

Yah, if it can be easily avoided that's probably the better route.

Quoted 62 lines
Quoted 11 lines
qga/vss-win32/install.cpp +0 -1
-#include "vss-common.h"
 #include <inc/win2003/vscoordint.h>
 #include "install.h"
 #include <wbemidl.h>
qga/vss-win32/provider.cpp +0 -0
index 72d8b0e19d..d298af91b2 100644

qga/vss-win32/provider.cpp line 14

Quoted 6 lines
qga/vss-win32/provider.cpp +1 -1
@@ -10,8 +10,8 @@
  * See the COPYING file in the top-level directory.
  */
 
-#include "qemu/osdep.h"
 #include "vss-common.h"
+#include "qemu/osdep.h"

Ditto.

Quoted 8 lines
qga/vss-win32/provider.cpp +0 -0
 #include <inc/win2003/vscoordint.h>
 #include <inc/win2003/vsprov.h>
 
qga/vss-win32/requester.cpp +0 -0
index 5378c55d23..d239bd9598 100644

qga/vss-win32/requester.cpp line 14

Quoted 6 lines
qga/vss-win32/requester.cpp +1 -1
@@ -10,8 +10,8 @@
  * See the COPYING file in the top-level directory.
  */
 
-#include "qemu/osdep.h"
 #include "vss-common.h"
+#include "qemu/osdep.h"

Ditto.

qga/vss-win32/vss-common.h line 16

Quoted 12 lines
qga/vss-win32/requester.cpp +0 -0
 #include "requester.h"
 #include "install.h"
 #include <inc/win2003/vswriter.h>
qga/vss-win32/vss-common.h +1 -0
index 61c170b52e..275cbb59c5 100644
@@ -13,6 +13,8 @@
 #ifndef VSS_COMMON_H
 #define VSS_COMMON_H
 
+#define USE_NATIVE_MINGW32_ASSERT

I believe you can add this in the "VSS SDK" section of the ./configure script:

-- >8 --

configure +1 -1
@@ -4588,7 +4588,7 @@ int main(void) { return VSS_CTX_BACKUP; }
 EOF
   if compile_prog "$vss_win32_include" "" ; then
     guest_agent_with_vss="yes"
-    QEMU_CFLAGS="$QEMU_CFLAGS $vss_win32_include"
+    QEMU_CFLAGS="$QEMU_CFLAGS -DUSE_NATIVE_MINGW32_ASSERT

$vss_win32_include"

Quoted 7 lines
     libs_qga="-lole32 -loleaut32 -lshlwapi -lstdc++
-Wl,--enable-stdcall-fixup $libs_qga"
     qga_vss_provider="qga/vss-win32/qga-vss.dll qga/vss-win32/qga-vss.tlb"

else
---

What do you think?

This may pass it on to the qemu build itself, but something similar for just the VSS DLL target might do the trick. I'll give that a shot, thanks.

Quoted 11 lines

Regards,

Phil.

Quoted 5 lines
qga/vss-win32/vss-common.h +1 -0
+
 #define __MIDL_user_allocate_free_DEFINED__
 #include <windows.h>
 #include <shlwapi.h>