[libvirt] Linking fails on FreeBSD

Hi, Linking fails on FreeBSD: CCLD libvirt.la /usr/bin/ld: ./.libs/libvirt_util.a(libvirt_util_la-vircgroup.o): relocation R_X86_64_PC32 against `virCgroupPartitionEscape' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: Bad value Following the suggestion and re-compiling with -fPIC doesn't help. Anybody has an idea how to fix that? Roman Bogorodskiy

On Mon, Jul 29, 2013 at 10:30:15AM +0400, Roman Bogorodskiy wrote:
Hi,
Linking fails on FreeBSD:
CCLD libvirt.la /usr/bin/ld: ./.libs/libvirt_util.a(libvirt_util_la-vircgroup.o): relocation R_X86_64_PC32 against `virCgroupPartitionEscape' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: Bad value
Following the suggestion and re-compiling with -fPIC doesn't help. Anybody has an idea how to fix that?
using 1.1.1-rc1, rc2 or git ? Daniel -- Daniel Veillard | Open Source and Standards, Red Hat veillard@redhat.com | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | virtualization library http://libvirt.org/

On Sun, Jul 28, 2013 at 11:38 PM, Daniel Veillard <veillard@redhat.com>wrote:
On Mon, Jul 29, 2013 at 10:30:15AM +0400, Roman Bogorodskiy wrote:
Hi,
Linking fails on FreeBSD:
CCLD libvirt.la /usr/bin/ld: ./.libs/libvirt_util.a(libvirt_util_la-vircgroup.o): relocation R_X86_64_PC32 against `virCgroupPartitionEscape' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: Bad value
Following the suggestion and re-compiling with -fPIC doesn't help. Anybody has an idea how to fix that?
using 1.1.1-rc1, rc2 or git ?
rc2
http://meatwad.mouf.net/rubick/poudriere/logs/bulk/91amd64-default/2013-07-2... -jgh -- Jason Helfman | FreeBSD Committer jgh@FreeBSD.org | http://people.freebsd.org/~jgh | The Power to Serve

On Mon, Jul 29, 2013 at 12:12:29AM -0700, Jason Helfman wrote:
On Sun, Jul 28, 2013 at 11:38 PM, Daniel Veillard <veillard@redhat.com>wrote:
On Mon, Jul 29, 2013 at 10:30:15AM +0400, Roman Bogorodskiy wrote:
Hi,
Linking fails on FreeBSD:
CCLD libvirt.la /usr/bin/ld: ./.libs/libvirt_util.a(libvirt_util_la-vircgroup.o): relocation R_X86_64_PC32 against `virCgroupPartitionEscape' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: Bad value
Following the suggestion and re-compiling with -fPIC doesn't help. Anybody has an idea how to fix that?
using 1.1.1-rc1, rc2 or git ?
rc2
http://meatwad.mouf.net/rubick/poudriere/logs/bulk/91amd64-default/2013-07-2...
I see CC libvirt_util_la-virdbus.lo util/vircgroup.c:70: warning: 'virCgroupPartitionEscape' used but never defined I guess that's where the problem comes from, on line 70 I see: static int virCgroupPartitionEscape(char **path); it is then used in virCgroupValidateMachineGroup line 112 but defined in a block surrounded by #if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R because it uses virCgroupPartitionNeedsEscaping() which is in that block I smell that some reformating is needed to really get rid of this issue in 1.1.1 ... Daniel -- Daniel Veillard | Open Source and Standards, Red Hat veillard@redhat.com | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | virtualization library http://libvirt.org/

On Mon, Jul 29, 2013 at 10:30:15AM +0400, Roman Bogorodskiy wrote:
Hi,
Linking fails on FreeBSD:
CCLD libvirt.la /usr/bin/ld: ./.libs/libvirt_util.a(libvirt_util_la-vircgroup.o): relocation R_X86_64_PC32 against `virCgroupPartitionEscape' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: Bad value
Following the suggestion and re-compiling with -fPIC doesn't help. Anybody has an idea how to fix that?
Try building with thsi patch diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 68ec953..62b1b1e 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -95,6 +95,7 @@ bool virCgroupAvailable(void) return ret; } +#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R static bool virCgroupValidateMachineGroup(virCgroupPtr group, const char *name, @@ -149,7 +150,16 @@ virCgroupValidateMachineGroup(virCgroupPtr group, VIR_FREE(partname); return valid; } - +#else +static bool +virCgroupValidateMachineGroup(virCgroupPtr group ATTRIBUTE_UNUSED, + const char *name ATTRIBUTE_UNUSED, + const char *drivername ATTRIBUTE_UNUSED, + bool stripEmulatorSuffix ATTRIBUTE_UNUSED) +{ + return true; +} +#endif /** * virCgroupFree: 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:
On Mon, Jul 29, 2013 at 10:30:15AM +0400, Roman Bogorodskiy wrote:
Hi,
Linking fails on FreeBSD:
CCLD libvirt.la /usr/bin/ld: ./.libs/libvirt_util.a(libvirt_util_la-vircgroup.o): relocation R_X86_64_PC32 against `virCgroupPartitionEscape' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: Bad value
Following the suggestion and re-compiling with -fPIC doesn't help. Anybody has an idea how to fix that?
Try building with thsi patch
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 68ec953..62b1b1e 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -95,6 +95,7 @@ bool virCgroupAvailable(void) return ret; }
+#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R static bool virCgroupValidateMachineGroup(virCgroupPtr group, const char *name, @@ -149,7 +150,16 @@ virCgroupValidateMachineGroup(virCgroupPtr group, VIR_FREE(partname); return valid; } - +#else +static bool +virCgroupValidateMachineGroup(virCgroupPtr group ATTRIBUTE_UNUSED, + const char *name ATTRIBUTE_UNUSED, + const char *drivername ATTRIBUTE_UNUSED, + bool stripEmulatorSuffix ATTRIBUTE_UNUSED) +{ + return true; +} +#endif
/** * virCgroupFree:
Yes, it works, thanks! --
|: 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 :|
Roman Bogorodskiy

On Mon, Jul 29, 2013 at 05:23:40PM +0400, Roman Bogorodskiy wrote:
Daniel P. Berrange wrote:
On Mon, Jul 29, 2013 at 10:30:15AM +0400, Roman Bogorodskiy wrote:
Hi,
Linking fails on FreeBSD:
CCLD libvirt.la /usr/bin/ld: ./.libs/libvirt_util.a(libvirt_util_la-vircgroup.o): relocation R_X86_64_PC32 against `virCgroupPartitionEscape' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: Bad value
Following the suggestion and re-compiling with -fPIC doesn't help. Anybody has an idea how to fix that?
Try building with thsi patch
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 68ec953..62b1b1e 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -95,6 +95,7 @@ bool virCgroupAvailable(void) return ret; }
+#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R static bool virCgroupValidateMachineGroup(virCgroupPtr group, const char *name, @@ -149,7 +150,16 @@ virCgroupValidateMachineGroup(virCgroupPtr group, VIR_FREE(partname); return valid; } - +#else +static bool +virCgroupValidateMachineGroup(virCgroupPtr group ATTRIBUTE_UNUSED, + const char *name ATTRIBUTE_UNUSED, + const char *drivername ATTRIBUTE_UNUSED, + bool stripEmulatorSuffix ATTRIBUTE_UNUSED) +{ + return true; +} +#endif
/** * virCgroupFree:
Yes, it works, thanks!
Ok, I'll push this shortly. 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 :|

On 07/29/2013 04:32 AM, Daniel P. Berrange wrote:
On Mon, Jul 29, 2013 at 10:30:15AM +0400, Roman Bogorodskiy wrote:
Hi,
Linking fails on FreeBSD:
And on a cross-build to mingw as well.
Try building with thsi patch
Closer, but not there yet: CC libvirt_util_la-vircgroup.lo ../../src/util/vircgroup.c:70:12: error: 'virCgroupPartitionEscape' declared 'static' but never defined [-Werror=unused-function] static int virCgroupPartitionEscape(char **path); ^ And another mingw bug: ../../src/util/virdbus.c:1102:35: error: expected ';', ',' or ')' before 'struct' const char *interface, ^ 'interface' is poisoned by mingw headers. I'll be pushing fixes under the build-breaker rule. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org


This fixes the FreeBSD link error and several mingw errors, although I'm still chasing down some more failures in the testsuite (for example, we try and fail to build systemdmock on mingw, even though it makes no sense since systemd is Linux-only; and there are some uses of fprintf that need to be changed to virFilePrintf per commit a2619962). Daniel P. Berrange (1): build: yet another cgroup conditional compilation fix Eric Blake (3): build: fix virdbus build on mingw build: fix virthread build on mingw build: fix virutil build on mingw src/util/vircgroup.c | 17 ++++++++++++++--- src/util/virdbus.c | 10 +++++----- src/util/virthreadwin32.c | 2 ++ src/util/virutil.c | 9 +++++++++ 4 files changed, 30 insertions(+), 8 deletions(-) -- 1.8.3.1

From: "Daniel P. Berrange" <berrange@redhat.com> Linking fails on FreeBSD: CCLD libvirt.la /usr/bin/ld: ./.libs/libvirt_util.a(libvirt_util_la-vircgroup.o): relocation R_X86_64_PC32 against `virCgroupPartitionEscape' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: Bad value Signed-off-by: Eric Blake <eblake@redhat.com> --- src/util/vircgroup.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 68ec953..f9007e3 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -67,8 +67,6 @@ typedef enum { */ } virCgroupFlags; -static int virCgroupPartitionEscape(char **path); - bool virCgroupAvailable(void) { bool ret = false; @@ -95,6 +93,10 @@ bool virCgroupAvailable(void) return ret; } +#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R + +static int virCgroupPartitionEscape(char **path); + static bool virCgroupValidateMachineGroup(virCgroupPtr group, const char *name, @@ -149,7 +151,16 @@ virCgroupValidateMachineGroup(virCgroupPtr group, VIR_FREE(partname); return valid; } - +#else +static bool +virCgroupValidateMachineGroup(virCgroupPtr group ATTRIBUTE_UNUSED, + const char *name ATTRIBUTE_UNUSED, + const char *drivername ATTRIBUTE_UNUSED, + bool stripEmulatorSuffix ATTRIBUTE_UNUSED) +{ + return true; +} +#endif /** * virCgroupFree: -- 1.8.3.1

On Mon, Jul 29, 2013 at 08:53:35AM -0600, Eric Blake wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
Linking fails on FreeBSD: CCLD libvirt.la /usr/bin/ld: ./.libs/libvirt_util.a(libvirt_util_la-vircgroup.o): relocation R_X86_64_PC32 against `virCgroupPartitionEscape' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: Bad value
Signed-off-by: Eric Blake <eblake@redhat.com> --- src/util/vircgroup.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 68ec953..f9007e3 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -67,8 +67,6 @@ typedef enum { */ } virCgroupFlags;
-static int virCgroupPartitionEscape(char **path); - bool virCgroupAvailable(void) { bool ret = false; @@ -95,6 +93,10 @@ bool virCgroupAvailable(void) return ret; }
+#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R + +static int virCgroupPartitionEscape(char **path); + static bool virCgroupValidateMachineGroup(virCgroupPtr group, const char *name, @@ -149,7 +151,16 @@ virCgroupValidateMachineGroup(virCgroupPtr group, VIR_FREE(partname); return valid; } - +#else +static bool +virCgroupValidateMachineGroup(virCgroupPtr group ATTRIBUTE_UNUSED, + const char *name ATTRIBUTE_UNUSED, + const char *drivername ATTRIBUTE_UNUSED, + bool stripEmulatorSuffix ATTRIBUTE_UNUSED) +{ + return true; +} +#endif
/** * virCgroupFree:
This won't apply to master, since I pushed my previous version of the patch before you posted about the mingw32 problems 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 :|

On 07/29/2013 09:09 AM, Daniel P. Berrange wrote:
On Mon, Jul 29, 2013 at 08:53:35AM -0600, Eric Blake wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
-static int virCgroupPartitionEscape(char **path); - bool virCgroupAvailable(void) { bool ret = false; @@ -95,6 +93,10 @@ bool virCgroupAvailable(void) return ret; }
+#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R + +static int virCgroupPartitionEscape(char **path); +
This won't apply to master, since I pushed my previous version of the patch before you posted about the mingw32 problems
So I noticed. But all I did that yours didn't do was move the static declaration into the conditional, to shut up the compiler warning about an unused static forward declaration. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Mingw headers pollute the namespace. CC libvirt_util_la-virdbus.lo ../../src/util/virdbus.c:1102:35: error: expected ';', ',' or ')' before 'struct' const char *interface, ^ * src/util/virdbus.c (virDBusCallMethod): Avoid 'interface'. Signed-off-by: Eric Blake <eblake@redhat.com> --- src/util/virdbus.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/util/virdbus.c b/src/util/virdbus.c index 4ce6c46..8f724e9 100644 --- a/src/util/virdbus.c +++ b/src/util/virdbus.c @@ -982,13 +982,13 @@ int virDBusMessageDecode(DBusMessage* msg, * @replyout: pointer to receive reply message, or NULL * @destination: bus identifier of the target service * @path: object path of the target service - * @interface: the interface of the object + * @iface: the interface of the object * @member: the name of the method in the interface * @types: type signature for following method arguments * @...: method arguments * * This invokes a method on a remote service on the - * DBus bus @conn. The @destination, @path, @interface + * DBus bus @conn. The @destination, @path, @iface * and @member parameters identify the object method to * be invoked. The optional @replyout parameter will be * filled with any reply to the method call. The @@ -1099,7 +1099,7 @@ int virDBusCallMethod(DBusConnection *conn, DBusMessage **replyout, const char *destination, const char *path, - const char *interface, + const char *iface, const char *member, const char *types, ...) { @@ -1113,7 +1113,7 @@ int virDBusCallMethod(DBusConnection *conn, if (!(call = dbus_message_new_method_call(destination, path, - interface, + iface, member))) { virReportOOMError(); goto cleanup; @@ -1206,7 +1206,7 @@ int virDBusCallMethod(DBusConnection *conn ATTRIBUTE_UNUSED, DBusMessage **reply ATTRIBUTE_UNUSED, const char *destination ATTRIBUTE_UNUSED, const char *path ATTRIBUTE_UNUSED, - const char *interface ATTRIBUTE_UNUSED, + const char *iface ATTRIBUTE_UNUSED, const char *member ATTRIBUTE_UNUSED, const char *types ATTRIBUTE_UNUSED, ...) { -- 1.8.3.1

Our recent conversion to make VIR_ALLOC report oom wasn't tested on mingw: In file included from ../../src/util/virthread.c:29:0: ../../src/util/virthreadwin32.c: In function 'virCondWait': ../../src/util/virthreadwin32.c:166:81: error: 'VIR_FROM_THIS' undeclared (first use in this function) if (VIR_REALLOC_N(c->waiters, c->nwaiters + 1) < 0) { ^ * src/util/virthreadwin32.c (VIR_FROM_THIS): Define. Signed-off-by: Eric Blake <eblake@redhat.com> --- src/util/virthreadwin32.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util/virthreadwin32.c b/src/util/virthreadwin32.c index 8928414..5d6277f 100644 --- a/src/util/virthreadwin32.c +++ b/src/util/virthreadwin32.c @@ -25,6 +25,8 @@ #include "viralloc.h" +#define VIR_FROM_THIS VIR_FROM_NONE + struct virThreadLocalData { DWORD key; virThreadLocalCleanup cleanup; -- 1.8.3.1

On platforms without decent group support, the build failed: Cannot export virGetGroupList: symbol not defined ./.libs/libvirt_security_manager.a(libvirt_security_manager_la-security_dac.o): In function `virSecurityDACPreFork': /home/eblake/libvirt-tmp/build/src/../../src/security/security_dac.c:248: undefined reference to `virGetGroupList' collect2: error: ld returned 1 exit status * src/util/virutil.c (virGetGroupList): Provide dummy implementation. Signed-off-by: Eric Blake <eblake@redhat.com> --- src/util/virutil.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/util/virutil.c b/src/util/virutil.c index c6c817f..adcdb3c 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1036,6 +1036,14 @@ virSetUIDGID(uid_t uid, gid_t gid, gid_t *groups ATTRIBUTE_UNUSED, #else /* ! HAVE_GETPWUID_R */ +int +virGetGroupList(uid_t uid ATTRIBUTE_UNUSED, gid_t gid ATTRIBUTE_UNUSED, + gid_t **list) +{ + *list = NULL; + return 0; +} + # ifdef WIN32 /* These methods are adapted from GLib2 under terms of LGPLv2+ */ static int @@ -1166,6 +1174,7 @@ virGetUserRuntimeDirectory(void) { return virGetUserCacheDirectory(); } + # else /* !HAVE_GETPWUID_R && !WIN32 */ char * virGetUserDirectory(void) -- 1.8.3.1

On Mon, Jul 29, 2013 at 08:53:34AM -0600, Eric Blake wrote:
This fixes the FreeBSD link error and several mingw errors, although I'm still chasing down some more failures in the testsuite (for example, we try and fail to build systemdmock on mingw, even though it makes no sense since systemd is Linux-only; and there are some uses of fprintf that need to be changed to virFilePrintf per commit a2619962).
Daniel P. Berrange (1): build: yet another cgroup conditional compilation fix
Eric Blake (3): build: fix virdbus build on mingw build: fix virthread build on mingw build: fix virutil build on mingw
src/util/vircgroup.c | 17 ++++++++++++++--- src/util/virdbus.c | 10 +++++----- src/util/virthreadwin32.c | 2 ++ src/util/virutil.c | 9 +++++++++ 4 files changed, 30 insertions(+), 8 deletions(-)
ACK if you re-diff the first patch 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 :|

Depending on the set of mingw packages installed, it is possible that other .c files hit the mingw header pollution from the virdbus.h file. In file included from ../../src/rpc/virnetserver.c:39:0: ../../src/util/virdbus.h:41:35: error: expected ';', ',' or ')' before 'struct' const char *interface, ^ * src/util/virdbus.h (virDBusCallMethod): Match .c file change. Signed-off-by: Eric Blake <eblake@redhat.com> --- Another build-breaker push. src/util/virdbus.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/virdbus.h b/src/util/virdbus.h index c04fd10..39de479 100644 --- a/src/util/virdbus.h +++ b/src/util/virdbus.h @@ -38,7 +38,7 @@ int virDBusCallMethod(DBusConnection *conn, DBusMessage **reply, const char *destination, const char *path, - const char *interface, + const char *iface, const char *member, const char *types, ...); int virDBusMessageRead(DBusMessage *msg, -- 1.8.3.1

A cross-compile to mingw failed: CC virsystemdmock_la-virsystemdmock.lo ../../tests/virsystemdmock.c:29:6: error: 'dbus_connection_set_change_sigpipe' redeclared without dllimport attribute: previous dllimport ignored [-Werror=attributes] void dbus_connection_set_change_sigpipe(dbus_bool_t will_modify_sigpipe ATTRIBUTE_UNUSED) ^ But when you think about it, systemd is Linux-only, and even our use of LD_PRELOAD to provide mock syscalls is Linux-only. * tests/virsystemdmock.c: Avoid compilation outside Linux. Signed-off-by: Eric Blake <eblake@redhat.com> --- Another build-breaker push. tests/virsystemdmock.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/virsystemdmock.c b/tests/virsystemdmock.c index 1f4413c..b6c3695 100644 --- a/tests/virsystemdmock.c +++ b/tests/virsystemdmock.c @@ -20,11 +20,12 @@ #include <config.h> -#include "internal.h" +#ifdef __linux__ +# include "internal.h" -#include <stdlib.h> +# include <stdlib.h> -#include <dbus/dbus.h> +# include <dbus/dbus.h> void dbus_connection_set_change_sigpipe(dbus_bool_t will_modify_sigpipe ATTRIBUTE_UNUSED) { @@ -79,3 +80,7 @@ DBusMessage *dbus_connection_send_with_reply_and_block(DBusConnection *connectio return reply; } + +#else +/* Nothing to override on non-__linux__ platforms */ +#endif -- 1.8.3.1

Commit a2619962 introduced virFilePrintf to work around the fact that gnulib doesn't (yet) provide guarantees about fprintf() vs. %z, which in turn causes all sorts of mingw compilation errors: ../../tests/testutils.c: In function 'virtTestResult': ../../tests/testutils.c:101:9: error: unknown conversion type character 'z' in format [-Werror=format=] fprintf(stderr, "%3zu) %-60s ", testCounter, name); ^ Rather than s/fprintf/virFilePrintf/ (and reformatting loads of lines across multiple files), it's easier to just hack the entire testsuite to take advantage of our helper function. * tests/testutils.c: s/fprintf/virFilePrintf/ for mingw. Signed-off-by: Eric Blake <eblake@redhat.com> --- tests/testutils.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/testutils.h b/tests/testutils.h index bf5c701..73c5f88 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -31,6 +31,10 @@ # define EXIT_AM_SKIP 77 /* tell Automake we're skipping a test */ # define EXIT_AM_HARDFAIL 99 /* tell Automake that the framework is broken */ +/* Work around lack of gnulib support for fprintf %z */ +# undef fprintf +# define fprintf virFilePrintf + extern char *progname; extern char *abs_srcdir; -- 1.8.3.1

Mingw *printf is a moving target; newer mingw now provides a version of asprintf() that fails to understand %lld: CC event_test-event-test.o ../../../../examples/domain-events/events-c/event-test.c: In function 'myDomainEventRTCChangeCallback': ../../../../examples/domain-events/events-c/event-test.c:270:18: error: unknown conversion type character 'l' in format [-Werror=format=] virDomainGetID(dom), offset) < 0) ^ But since our examples already admitted that they were hacking around a mingw deficiency, it is easier to just use printf() directly, coupled with <inttypes.h> macros, for a more portable work-around. * examples/domain-events/events-c/event-test.c (myDomainEventRTCChangeCallback): Use PRIdMAX instead of asprintf. Signed-off-by: Eric Blake <eblake@redhat.com> --- Pushing under the build-breaker rule; and with this, I _finally_ completed a run of ./autobuild.sh with a mingw cross-compilation environment installed. examples/domain-events/events-c/event-test.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/examples/domain-events/events-c/event-test.c b/examples/domain-events/events-c/event-test.c index fe4eb56..52aa3d0 100644 --- a/examples/domain-events/events-c/event-test.c +++ b/examples/domain-events/events-c/event-test.c @@ -262,16 +262,9 @@ static int myDomainEventRTCChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED, long long offset, void *opaque ATTRIBUTE_UNUSED) { - char *str = NULL; - /* HACK: use asprintf since we have gnulib's wrapper for %lld on Win32 - * but don't have a printf() replacement with %lld */ - if (asprintf(&str, "%s EVENT: Domain %s(%d) rtc change %lld\n", - __func__, virDomainGetName(dom), - virDomainGetID(dom), offset) < 0) - return 0; - - printf("%s", str); - free(str); + printf("%s EVENT: Domain %s(%d) rtc change %" PRIdMAX "\n", + __func__, virDomainGetName(dom), virDomainGetID(dom), + (intmax_t)offset); return 0; } -- 1.8.3.1

Commit 93ec384 was tested on mingw, but broke the build on Linux: CCLD shunloadtest shunloadtest.o: In function `main': /home/eblake/libvirt/tests/shunloadtest.c:106: undefined reference to `virFilePrintf' ... ssh.o: In function `main': /home/eblake/libvirt/tests/ssh.c:43: undefined reference to `virFilePrintf' /home/eblake/libvirt/tests/ssh.c:49: undefined reference to `virFilePrintf' * tests/testutils.h (fprintf): Provide escape hatch. * tests/shunloadtest.c: Use it. * tests/ssh.c: Likewise. Signed-off-by: Eric Blake <eblake@redhat.com> --- I guess I should have tested my earlier patch a bit more thoroughly before pushing it under the build-breaker rule... This one is tested on both Linux and mingw. tests/shunloadtest.c | 3 ++- tests/ssh.c | 3 ++- tests/testutils.h | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/shunloadtest.c b/tests/shunloadtest.c index 8190e97..499b1be 100644 --- a/tests/shunloadtest.c +++ b/tests/shunloadtest.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 Red Hat, Inc. + * Copyright (C) 2011, 2013 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -40,6 +40,7 @@ #include <config.h> +#define NO_LIBVIRT /* This file intentionally does not link to libvirt */ #include "testutils.h" #ifdef linux diff --git a/tests/ssh.c b/tests/ssh.c index 76c60d3..31bd390 100644 --- a/tests/ssh.c +++ b/tests/ssh.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 Red Hat, Inc. + * Copyright (C) 2011, 2013 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -22,6 +22,7 @@ #include <stdio.h> #include "internal.h" +#define NO_LIBVIRT /* This file intentionally does not link to libvirt */ #include "testutils.h" #ifndef WIN32 diff --git a/tests/testutils.h b/tests/testutils.h index 73c5f88..27af5da 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -32,8 +32,10 @@ # define EXIT_AM_HARDFAIL 99 /* tell Automake that the framework is broken */ /* Work around lack of gnulib support for fprintf %z */ -# undef fprintf -# define fprintf virFilePrintf +# ifndef NO_LIBVIRT +# undef fprintf +# define fprintf virFilePrintf +# endif extern char *progname; extern char *abs_srcdir; -- 1.8.3.1
participants (5)
-
Daniel P. Berrange
-
Daniel Veillard
-
Eric Blake
-
Jason Helfman
-
Roman Bogorodskiy