* [Qemu-devel] [PATCH v3] configure: sanity check the glib library that pkg-config finds
@ 2016-01-27 9:00 Daniel P. Berrange
2016-01-27 10:55 ` Paolo Bonzini
0 siblings, 1 reply; 2+ messages in thread
From: Daniel P. Berrange @ 2016-01-27 9:00 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Dr. David Alan Gilbert, Paolo Bonzini
Developers on 64-bit machines will often try to perform a
32-bit build of QEMU by running
./configure --extra-cflags="-m32"
Unfortunately if PKG_CONFIG_LIBDIR is not set to point to
the location of the 32-bit pkg-config files, then configure
will silently pick up the 64-bit pkg-config files and still
succeed.
This causes a problem for glib because it means QEMU will
be pulling in /usr/lib64/glib-2.0/include/glibconfig.h
instead of /usr/lib/glib-2.0/include/glibconfig.h
This causes problems because the 'gsize' type (defined as
'unsigned long') will no longer be fully compatible with
the 'size_t' type (defined as 'unsigned int'). Although
both are the same size, the compiler refuses to allow
casts from 'unsigned long *' to 'unsigned int *' as they
are different pointer types. This results in non-obvious
compiler errors when building QEMU eg
qga/commands-posix.c: In function ‘qmp_guest_set_user_password’:
qga/commands-posix.c:1912:55: error: passing argument 2 of ‘g_base64_decode’ from incompatible pointer type [-Werror=incompatible-pointer-types]
rawpasswddata = (char *)g_base64_decode(password, &rawpasswdlen);
^
In file included from /usr/include/glib-2.0/glib.h:35:0,
from qga/commands-posix.c:14:
/usr/include/glib-2.0/glib/gbase64.h:52:9: note: expected ‘gsize * {aka long unsigned int *}’ but argument is of type ‘size_t * {aka unsigned int *}’
guchar *g_base64_decode (const gchar *text,
^
cc1: all warnings being treated as errors
To detect this problem, add a check to configure that
verifies that GLIB_SIZEOF_SIZE_T matches sizeof(size_t).
If this fails print a warning suggesting that the dev
probably needs to set PKG_CONFIG_LIBDIR.
On Fedora x86_64 it passes with any of:
# ./configure
# PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig ./configure --extra-cflags="-m32"
# PKG_CONFIG_LIBDIR=/usr/lib64/pkgconfig ./configure --extra-cflags="-m64"
And fails with a mis-match
# PKG_CONFIG_LIBDIR=/usr/lib64/pkgconfig ./configure --extra-cflags="-m32"
# PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig ./configure --extra-cflags="-m64"
ERROR: sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T.
You probably need to set PKG_CONFIG_LIBDIR
to point to the right pkg-config files for your
build target
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
Changed in v3:
- Removed use of G_STATIC_ASSERT in favour of simplified
version of QEMU_BUILD_BUG_ON to avoid unused typedef
warning
configure | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/configure b/configure
index 44ac9ab..fbd2482 100755
--- a/configure
+++ b/configure
@@ -2997,6 +2997,30 @@ for i in $glib_modules; do
fi
done
+# Sanity check that the current size_t matches the
+# size that glib thinks it should be. This catches
+# problems on multi-arch where people try to build
+# 32-bit QEMU while pointing at 64-bit glib headers
+cat > $TMPC <<EOF
+#include <glib.h>
+#include <unistd.h>
+
+#define QEMU_BUILD_BUG_ON(x) \
+ typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused));
+
+int main(void) {
+ QEMU_BUILD_BUG_ON(sizeof(size_t) != GLIB_SIZEOF_SIZE_T);
+ return 0;
+}
+EOF
+
+if ! compile_prog "-Werror $CFLAGS" "$LIBS" ; then
+ error_exit "sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T."\
+ "You probably need to set PKG_CONFIG_LIBDIR"\
+ "to point to the right pkg-config files for your"\
+ "build target"
+fi
+
# g_test_trap_subprocess added in 2.38. Used by some tests.
glib_subprocess=yes
if ! $pkg_config --atleast-version=2.38 glib-2.0; then
--
2.5.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH v3] configure: sanity check the glib library that pkg-config finds
2016-01-27 9:00 [Qemu-devel] [PATCH v3] configure: sanity check the glib library that pkg-config finds Daniel P. Berrange
@ 2016-01-27 10:55 ` Paolo Bonzini
0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2016-01-27 10:55 UTC (permalink / raw)
To: Daniel P. Berrange, qemu-devel; +Cc: Peter Maydell, Dr. David Alan Gilbert
On 27/01/2016 10:00, Daniel P. Berrange wrote:
> Developers on 64-bit machines will often try to perform a
> 32-bit build of QEMU by running
>
> ./configure --extra-cflags="-m32"
>
> Unfortunately if PKG_CONFIG_LIBDIR is not set to point to
> the location of the 32-bit pkg-config files, then configure
> will silently pick up the 64-bit pkg-config files and still
> succeed.
>
> This causes a problem for glib because it means QEMU will
> be pulling in /usr/lib64/glib-2.0/include/glibconfig.h
> instead of /usr/lib/glib-2.0/include/glibconfig.h
>
> This causes problems because the 'gsize' type (defined as
> 'unsigned long') will no longer be fully compatible with
> the 'size_t' type (defined as 'unsigned int'). Although
> both are the same size, the compiler refuses to allow
> casts from 'unsigned long *' to 'unsigned int *' as they
> are different pointer types. This results in non-obvious
> compiler errors when building QEMU eg
>
> qga/commands-posix.c: In function ‘qmp_guest_set_user_password’:
> qga/commands-posix.c:1912:55: error: passing argument 2 of ‘g_base64_decode’ from incompatible pointer type [-Werror=incompatible-pointer-types]
> rawpasswddata = (char *)g_base64_decode(password, &rawpasswdlen);
> ^
> In file included from /usr/include/glib-2.0/glib.h:35:0,
> from qga/commands-posix.c:14:
> /usr/include/glib-2.0/glib/gbase64.h:52:9: note: expected ‘gsize * {aka long unsigned int *}’ but argument is of type ‘size_t * {aka unsigned int *}’
> guchar *g_base64_decode (const gchar *text,
> ^
> cc1: all warnings being treated as errors
>
> To detect this problem, add a check to configure that
> verifies that GLIB_SIZEOF_SIZE_T matches sizeof(size_t).
> If this fails print a warning suggesting that the dev
> probably needs to set PKG_CONFIG_LIBDIR.
>
> On Fedora x86_64 it passes with any of:
>
> # ./configure
> # PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig ./configure --extra-cflags="-m32"
> # PKG_CONFIG_LIBDIR=/usr/lib64/pkgconfig ./configure --extra-cflags="-m64"
>
> And fails with a mis-match
>
> # PKG_CONFIG_LIBDIR=/usr/lib64/pkgconfig ./configure --extra-cflags="-m32"
> # PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig ./configure --extra-cflags="-m64"
>
> ERROR: sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T.
> You probably need to set PKG_CONFIG_LIBDIR
> to point to the right pkg-config files for your
> build target
>
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> ---
>
> Changed in v3:
>
> - Removed use of G_STATIC_ASSERT in favour of simplified
> version of QEMU_BUILD_BUG_ON to avoid unused typedef
> warning
>
> configure | 24 ++++++++++++++++++++++++
> 1 file changed, 24 insertions(+)
>
> diff --git a/configure b/configure
> index 44ac9ab..fbd2482 100755
> --- a/configure
> +++ b/configure
> @@ -2997,6 +2997,30 @@ for i in $glib_modules; do
> fi
> done
>
> +# Sanity check that the current size_t matches the
> +# size that glib thinks it should be. This catches
> +# problems on multi-arch where people try to build
> +# 32-bit QEMU while pointing at 64-bit glib headers
> +cat > $TMPC <<EOF
> +#include <glib.h>
> +#include <unistd.h>
> +
> +#define QEMU_BUILD_BUG_ON(x) \
> + typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused));
> +
> +int main(void) {
> + QEMU_BUILD_BUG_ON(sizeof(size_t) != GLIB_SIZEOF_SIZE_T);
> + return 0;
> +}
> +EOF
> +
> +if ! compile_prog "-Werror $CFLAGS" "$LIBS" ; then
> + error_exit "sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T."\
> + "You probably need to set PKG_CONFIG_LIBDIR"\
> + "to point to the right pkg-config files for your"\
> + "build target"
> +fi
> +
> # g_test_trap_subprocess added in 2.38. Used by some tests.
> glib_subprocess=yes
> if ! $pkg_config --atleast-version=2.38 glib-2.0; then
>
Queued, thanks.
Paolo
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-01-27 10:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-27 9:00 [Qemu-devel] [PATCH v3] configure: sanity check the glib library that pkg-config finds Daniel P. Berrange
2016-01-27 10:55 ` Paolo Bonzini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.