build: link to glib library

Add the main glib.h to internal.h so that all common code can use it.

Historically glib allowed applications to register an alternative
memory allocator, so mixing g_malloc/g_free with malloc/free was not
safe.

This was feature was dropped in 2.46.0 with:

      commit 3be6ed60aa58095691bd697344765e715a327fc1
      Author: Alexander Larsson <alexl@redhat.com>
      Date:   Sat Jun 27 18:38:42 2015 +0200

        Deprecate and drop support for memory vtables

Applications are still encourged to match g_malloc/g_free, but it is no
longer a mandatory requirement for correctness, just stylistic. This is
explicitly clarified in

    commit 1f24b36607bf708f037396014b2cdbc08d67b275
    Author: Daniel P. Berrangé <berrange@redhat.com>
    Date:   Thu Sep 5 14:37:54 2019 +0100

        gmem: clarify that g_malloc always uses the system allocator

Applications can still use custom allocators in general, but they must
do this by linking to a library that replaces the core malloc/free
implemenentation entirely, instead of via a glib specific call.

This means that libvirt does not need to be concerned about use of
g_malloc/g_free causing an ABI change in the public libary, and can
avoid memory copying when talking to external libraries.

This patch probes for glib, which provides the foundation layer with
a collection of data structures, helper APIs, and platform portability
logic.

Later patches will introduce linkage to gobject which provides the
object type system, built on glib, and gio which providing objects
for various interesting tasks, most notably including DBus client
and server support and portable sockets APIs, but much more too.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2019-08-29 16:12:24 +01:00
parent 58e7c9bc05
commit cfbe9f1201
22 changed files with 83 additions and 5 deletions

View File

@ -989,6 +989,27 @@ BAD:
it points to, or it is aliased to another pointer that is.
</p>
<h2><a id="glib">Adoption of GLib APIs</a></h2>
<p>
Libvirt has adopted use of the
<a href="https://developer.gnome.org/glib/stable/">GLib library</a>.
Due to libvirt's long history of development, there are many APIs
in libvirt, for which GLib provides an alternative solution. The
general rule to follow is that the standard GLib solution will be
preferred over historical libvirt APIs. Existing code will be
ported over to use GLib APIs over time, but new code should use
the GLib APIs straight away where possible.
</p>
<p>
The following is a list of libvirt APIs that should no longer be
used in new code, and their suggested GLib replacements:
</p>
<dl>
</dl>
<h2><a id="memalloc">Low level memory management</a></h2>
<p>

View File

@ -34,6 +34,7 @@ AM_CPPFLAGS = -I../gnulib/lib \
WARN_CFLAGS += $(STRICT_FRAME_LIMIT_CFLAGS)
AM_CFLAGS = $(LIBXML_CFLAGS) \
$(GLIB_CFLAGS) \
$(WARN_CFLAGS) \
$(LOCK_CHECKING_CFLAGS) \
$(WIN32_EXTRA_CFLAGS) \
@ -558,6 +559,7 @@ libvirt_admin_la_LIBADD += \
$(YAJL_LIBS) \
$(DEVMAPPER_LIBS) \
$(LIBXML_LIBS) \
$(GLIB_LIBS) \
$(SSH2_LIBS) \
$(SASL_LIBS) \
$(GNUTLS_LIBS) \
@ -773,6 +775,7 @@ libvirt_iohelper_LDFLAGS = \
$(NULL)
libvirt_iohelper_LDADD = \
libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la
if WITH_DTRACE_PROBES
libvirt_iohelper_LDADD += libvirt_probes.lo

View File

@ -59,7 +59,9 @@ libvirt_driver_access_la_CFLAGS = \
$(AM_CFLAGS) \
$(NULL)
libvirt_driver_access_la_LDFLAGS = $(AM_LDFLAGS)
libvirt_driver_access_la_LIBADD =
libvirt_driver_access_la_LIBADD = \
$(GLIB_LIBS) \
$(NULL)
$(ACCESS_DRIVER_POLKIT_POLICY): $(srcdir)/access/viraccessperm.h \

View File

@ -34,6 +34,7 @@ libvirt_driver_bhyve_la_SOURCES =
libvirt_driver_bhyve_la_LIBADD = \
libvirt_driver_bhyve_impl.la \
libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
mod_LTLIBRARIES += libvirt_driver_bhyve.la

View File

@ -28,6 +28,7 @@ libvirt_driver_interface_la_CFLAGS = \
libvirt_driver_interface_la_LDFLAGS = $(AM_LDFLAGS_MOD_NOUNDEF)
libvirt_driver_interface_la_LIBADD = \
libvirt.la \
$(GLIB_LIBS) \
$(NULL)
libvirt_driver_interface_la_SOURCES = $(INTERFACE_DRIVER_SOURCES)
if WITH_NETCF

View File

@ -28,6 +28,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <glib.h>
#if STATIC_ANALYSIS
# undef NDEBUG /* Don't let a prior NDEBUG definition cause trouble. */

View File

@ -34,6 +34,7 @@ libvirt_driver_libxl_la_SOURCES =
libvirt_driver_libxl_la_LIBADD = \
libvirt_driver_libxl_impl.la \
libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
mod_LTLIBRARIES += libvirt_driver_libxl.la

View File

@ -103,6 +103,7 @@ lockd_la_CFLAGS = \
lockd_la_LDFLAGS = $(AM_LDFLAGS_MOD_NOUNDEF)
lockd_la_LIBADD = \
libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
augeas_DATA += locking/libvirt_lockd.aug
@ -145,6 +146,7 @@ virtlockd_LDFLAGS = \
virtlockd_LDADD = \
libvirt.la \
libvirt_driver_admin.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(CYGWIN_EXTRA_LIBADD) \
$(NULL)
@ -163,7 +165,12 @@ lockdriver_LTLIBRARIES += sanlock.la
sanlock_la_SOURCES = $(LOCK_DRIVER_SANLOCK_SOURCES)
sanlock_la_CFLAGS = -I$(srcdir)/conf $(AM_CFLAGS)
sanlock_la_LDFLAGS = $(AM_LDFLAGS_MOD_NOUNDEF)
sanlock_la_LIBADD = -lsanlock_client libvirt.la ../gnulib/lib/libgnu.la
sanlock_la_LIBADD = \
-lsanlock_client \
libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
augeas_DATA += locking/libvirt_sanlock.aug

View File

@ -82,6 +82,7 @@ virtlogd_LDFLAGS = \
virtlogd_LDADD = \
libvirt_driver_admin.la \
libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(CYGWIN_EXTRA_LIBADD) \
$(NULL)

View File

@ -83,6 +83,7 @@ libvirt_driver_lxc_la_SOURCES =
libvirt_driver_lxc_la_LIBADD = \
libvirt_driver_lxc_impl.la \
libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
mod_LTLIBRARIES += libvirt_driver_lxc.la
@ -184,10 +185,12 @@ libvirt_lxc_LDFLAGS = \
$(PIE_LDFLAGS) \
$(CAPNG_LIBS) \
$(LIBXML_LIBS) \
$(GLIB_LIBS) \
$(NULL)
libvirt_lxc_LDADD = \
libvirt.la \
$(FUSE_LIBS) \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
if WITH_DTRACE_PROBES
@ -200,6 +203,7 @@ libvirt_lxc_CFLAGS = \
$(PIE_CFLAGS) \
$(CAPNG_CFLAGS) \
$(LIBXML_CFLAGS) \
$(GLIB_CFLAGS) \
$(LIBNL_CFLAGS) \
$(FUSE_CFLAGS) \
$(DBUS_CFLAGS) \

View File

@ -32,6 +32,7 @@ libvirt_driver_network_la_SOURCES =
libvirt_driver_network_la_LIBADD = \
libvirt_driver_network_impl.la \
libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(LIBNL_LIBS) \
$(DBUS_LIBS) \
@ -121,6 +122,7 @@ libvirt_leaseshelper_LDFLAGS = \
$(NULL)
libvirt_leaseshelper_LDADD = \
libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la
if WITH_DTRACE_PROBES
libvirt_leaseshelper_LDADD += libvirt_probes.lo

View File

@ -44,7 +44,10 @@ libvirt_driver_nodedev_la_CFLAGS = \
$(LIBNL_CFLAGS) \
$(NULL)
libvirt_driver_nodedev_la_LDFLAGS = $(AM_LDFLAGS_MOD_NOUNDEF)
libvirt_driver_nodedev_la_LIBADD = libvirt.la
libvirt_driver_nodedev_la_LIBADD = \
libvirt.la \
$(GLIB_LIBS) \
$(NULL)
if WITH_HAL
libvirt_driver_nodedev_la_SOURCES += $(NODE_DEVICE_DRIVER_HAL_SOURCES)

View File

@ -46,6 +46,7 @@ libvirt_driver_nwfilter_impl_la_LIBADD = \
$(LIBPCAP_LIBS) \
$(LIBNL_LIBS) \
$(DBUS_LIBS) \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
libvirt_driver_nwfilter_impl_la_SOURCES = $(NWFILTER_DRIVER_SOURCES)

View File

@ -83,6 +83,7 @@ libvirt_driver_qemu_la_SOURCES =
libvirt_driver_qemu_la_LIBADD = \
libvirt_driver_qemu_impl.la \
libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
mod_LTLIBRARIES += libvirt_driver_qemu.la

View File

@ -38,6 +38,7 @@ REMOTE_DAEMON_SOURCES = \
REMOTE_DAEMON_CFLAGS = \
$(LIBXML_CFLAGS) \
$(GLIB_CFLAGS) \
$(GNUTLS_CFLAGS) \
$(SASL_CFLAGS) \
$(XDR_CFLAGS) \
@ -76,6 +77,7 @@ REMOTE_DAEMON_LD_ADD += ../src/libvirt_probes.lo
endif WITH_DTRACE_PROBES
REMOTE_DAEMON_LD_ADD += \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)

View File

@ -33,6 +33,7 @@ libvirt_driver_secret_la_CFLAGS = \
$(NULL)
libvirt_driver_secret_la_LIBADD = \
libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
libvirt_driver_secret_la_LDFLAGS = $(AM_LDFLAGS_MOD_NOUNDEF)

View File

@ -73,6 +73,7 @@ virt_aa_helper_LDFLAGS = \
virt_aa_helper_LDADD = \
libvirt.la \
libvirt_driver_storage_impl.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
if WITH_DTRACE_PROBES

View File

@ -136,6 +136,7 @@ libvirt_driver_storage_la_SOURCES =
libvirt_driver_storage_la_LIBADD = \
libvirt_driver_storage_impl.la \
libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
mod_LTLIBRARIES += libvirt_driver_storage.la
@ -217,6 +218,7 @@ storagebackend_LTLIBRARIES += libvirt_storage_backend_fs.la
libvirt_storage_backend_fs_la_LDFLAGS = $(AM_LDFLAGS_MOD)
libvirt_storage_backend_fs_la_LIBADD = \
libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
@ -230,6 +232,7 @@ storagefile_LTLIBRARIES += libvirt_storage_file_fs.la
libvirt_storage_file_fs_la_LDFLAGS = $(AM_LDFLAGS_MOD)
libvirt_storage_file_fs_la_LIBADD = \
libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
endif WITH_STORAGE
@ -245,6 +248,7 @@ storagebackend_LTLIBRARIES += libvirt_storage_backend_logical.la
libvirt_storage_backend_logical_la_LDFLAGS = $(AM_LDFLAGS_MOD)
libvirt_storage_backend_logical_la_LIBADD = \
libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
endif WITH_STORAGE_LVM
@ -261,6 +265,7 @@ storagebackend_LTLIBRARIES += libvirt_storage_backend_iscsi.la
libvirt_storage_backend_iscsi_la_LDFLAGS = $(AM_LDFLAGS_MOD)
libvirt_storage_backend_iscsi_la_LIBADD = \
libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
endif WITH_STORAGE_ISCSI
@ -279,6 +284,7 @@ storagebackend_LTLIBRARIES += libvirt_storage_backend_iscsi-direct.la
libvirt_storage_backend_iscsi_direct_la_LDFLAGS = $(AM_LDFLAGS_MOD)
libvirt_storage_backend_iscsi_direct_la_LIBADD = \
libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(LIBISCSI_LIBS) \
$(NULL)
@ -295,6 +301,7 @@ storagebackend_LTLIBRARIES += libvirt_storage_backend_scsi.la
libvirt_storage_backend_scsi_la_LDFLAGS = $(AM_LDFLAGS_MOD)
libvirt_storage_backend_scsi_la_LIBADD = \
libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
endif WITH_STORAGE_SCSI
@ -304,6 +311,7 @@ libvirt_storage_backend_mpath_la_SOURCES = $(STORAGE_DRIVER_MPATH_SOURCES)
libvirt_storage_backend_mpath_la_LIBADD = \
libvirt.la \
$(DEVMAPPER_LIBS) \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
libvirt_storage_backend_mpath_la_CFLAGS = \
@ -327,6 +335,7 @@ storagebackend_LTLIBRARIES += libvirt_storage_backend_disk.la
libvirt_storage_backend_disk_la_LDFLAGS = $(AM_LDFLAGS_MOD)
libvirt_storage_backend_disk_la_LIBADD = \
libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
endif WITH_STORAGE_DISK
@ -336,6 +345,7 @@ libvirt_storage_backend_rbd_la_SOURCES = $(STORAGE_DRIVER_RBD_SOURCES)
libvirt_storage_backend_rbd_la_LIBADD = \
libvirt.la \
$(LIBRBD_LIBS) \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
libvirt_storage_backend_rbd_la_CFLAGS = \
@ -368,6 +378,7 @@ storagebackend_LTLIBRARIES += libvirt_storage_backend_sheepdog.la
libvirt_storage_backend_sheepdog_la_LDFLAGS = $(AM_LDFLAGS_MOD)
libvirt_storage_backend_sheepdog_la_LIBADD = \
libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
endif WITH_STORAGE_SHEEPDOG
@ -378,6 +389,7 @@ libvirt_storage_backend_gluster_la_SOURCES = \
libvirt_storage_backend_gluster_la_LIBADD = \
libvirt.la \
$(GLUSTERFS_LIBS) \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
libvirt_storage_backend_gluster_la_CFLAGS = \
@ -395,6 +407,7 @@ libvirt_storage_file_gluster_la_SOURCES = \
libvirt_storage_file_gluster_la_LIBADD = \
libvirt.la \
$(GLUSTERFS_LIBS) \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
libvirt_storage_file_gluster_la_CFLAGS = \
@ -419,6 +432,7 @@ storagebackend_LTLIBRARIES += libvirt_storage_backend_zfs.la
libvirt_storage_backend_zfs_la_LDFLAGS = $(AM_LDFLAGS_MOD)
libvirt_storage_backend_zfs_la_LIBADD = \
libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
endif WITH_STORAGE_ZFS
@ -435,6 +449,7 @@ storagebackend_LTLIBRARIES += libvirt_storage_backend_vstorage.la
libvirt_storage_backend_vstorage_la_LDFLAGS = $(AM_LDFLAGS_MOD)
libvirt_storage_backend_vstorage_la_LIBADD = \
libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
endif WITH_STORAGE_VSTORAGE
@ -450,6 +465,7 @@ libvirt_parthelper_LDFLAGS = \
libvirt_parthelper_LDADD = \
$(LIBPARTED_LIBS) \
libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
if WITH_DTRACE_PROBES

View File

@ -46,6 +46,7 @@ libvirt_driver_vbox_la_SOURCES =
libvirt_driver_vbox_la_LIBADD = \
libvirt_driver_vbox_impl.la \
libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
mod_LTLIBRARIES += libvirt_driver_vbox.la

View File

@ -21,6 +21,7 @@ libvirt_driver_vz_la_SOURCES =
libvirt_driver_vz_la_LIBADD = \
libvirt_driver_vz_impl.la \
libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
mod_LTLIBRARIES += libvirt_driver_vz.la

View File

@ -35,6 +35,7 @@ AM_CFLAGS = \
-Dabs_srcdir="\"$(abs_srcdir)\"" \
-Dabs_top_srcdir="\"$(abs_top_srcdir)\"" \
$(LIBXML_CFLAGS) \
$(GLIB_CFLAGS) \
$(LIBNL_CFLAGS) \
$(GNUTLS_CFLAGS) \
$(SASL_CFLAGS) \
@ -72,7 +73,9 @@ LDADDS = \
$(NO_INDIRECT_LDFLAGS) \
$(PROBES_O) \
$(GNULIB_LIBS) \
../src/libvirt.la
../src/libvirt.la \
$(GLIB_LIBS) \
$(NULL)
MOCKLIBS_LIBS = \
$(GNULIB_LIBS) \
@ -522,7 +525,7 @@ libxlxml2domconfigtest_LDADD = $(libxl_LDADDS) $(LIBXML_LIBS)
libxlmock_la_SOURCES = \
libxlmock.c
libxlmock_la_CFLAGS = $(LIBXL_CFLAGS) $(LIBXML_CFLAGS)
libxlmock_la_CFLAGS = $(LIBXL_CFLAGS) $(LIBXML_CFLAGS) $(GLIB_CFLAGS)
libxlmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS)
libxlmock_la_LIBADD = $(MOCKLIBS_LIBS)

View File

@ -36,6 +36,7 @@ AM_CFLAGS = \
$(COVERAGE_CFLAGS) \
$(PIE_CFLAGS) \
$(LIBXML_CFLAGS) \
$(GLIB_CFLAGS) \
$(NULL)
AM_LDFLAGS = \
@ -150,6 +151,7 @@ libvirt_shell_la_LIBADD = \
../src/libvirt.la \
$(LIBXML_LIBS) \
$(READLINE_LIBS) \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
libvirt_shell_la_SOURCES = \
@ -195,6 +197,7 @@ virt_host_validate_LDFLAGS = \
virt_host_validate_LDADD = \
../src/libvirt.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
@ -221,6 +224,7 @@ virt_login_shell_helper_LDFLAGS = \
virt_login_shell_helper_LDADD = \
../src/libvirt.la \
../src/libvirt-lxc.la \
$(GLIB_LIBS) \
../gnulib/lib/libgnu.la
virt_login_shell_helper_CFLAGS = \