[Pkg-libvirt-commits] [libguestfs] 03/65: lib: Fix static linking by forcing launch-*.o objects to be always linked.
Hilko Bengen
bengen at moszumanska.debian.org
Tue Apr 21 12:10:42 UTC 2015
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to branch experimental
in repository libguestfs.
commit f1007fc26d58a62b3692f64a6d8219ad9221510f
Author: Richard W.M. Jones <rjones at redhat.com>
Date: Sat Mar 28 10:15:57 2015 +0000
lib: Fix static linking by forcing launch-*.o objects to be always linked.
Because the launch-*.o objects only contain statically scoped
declarations, the linker doesn't need to link them in. This causes a
problem when static linking as they will be left out of the final
binary, and so no backends will be available.
This is essentially the same problem as described here:
https://stackoverflow.com/questions/1202494/why-doesnt-attribute-constructor-work-in-a-static-library
---
src/guestfs-internal.h | 8 ++++++++
src/launch-direct.c | 5 ++---
src/launch-libvirt.c | 5 ++---
src/launch-uml.c | 5 ++---
src/launch-unix.c | 5 ++---
src/launch.c | 13 +++++++++++++
6 files changed, 29 insertions(+), 12 deletions(-)
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index 43cdd4d..414a634 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -883,6 +883,14 @@ extern void guestfs_int_cleanup_cmd_close (struct command **);
extern char *guestfs_int_drive_source_qemu_param (guestfs_h *g, const struct drive_source *src);
extern bool guestfs_int_discard_possible (guestfs_h *g, struct drive *drv, unsigned long qemu_version);
+/* launch-*.c constructors */
+void guestfs_int_init_direct_backend (void) __attribute__((constructor));
+#ifdef HAVE_LIBVIRT
+void guestfs_int_init_libvirt_backend (void) __attribute__((constructor));
+#endif
+void guestfs_int_init_uml_backend (void) __attribute__((constructor));
+void guestfs_int_init_unix_backend (void) __attribute__((constructor));
+
/* guid.c */
extern int guestfs_int_validate_guid (const char *);
diff --git a/src/launch-direct.c b/src/launch-direct.c
index 5753236..ea67ec9 100644
--- a/src/launch-direct.c
+++ b/src/launch-direct.c
@@ -1544,9 +1544,8 @@ static struct backend_ops backend_direct_ops = {
.max_disks = max_disks_direct,
};
-static void init_backend (void) __attribute__((constructor));
-static void
-init_backend (void)
+void
+guestfs_int_init_direct_backend (void)
{
guestfs_int_register_backend ("direct", &backend_direct_ops);
}
diff --git a/src/launch-libvirt.c b/src/launch-libvirt.c
index 45d0d76..f46782c 100644
--- a/src/launch-libvirt.c
+++ b/src/launch-libvirt.c
@@ -2262,9 +2262,8 @@ static struct backend_ops backend_libvirt_ops = {
.hot_remove_drive = hot_remove_drive_libvirt,
};
-static void init_backend (void) __attribute__((constructor));
-static void
-init_backend (void)
+void
+guestfs_int_init_libvirt_backend (void)
{
guestfs_int_register_backend ("libvirt", &backend_libvirt_ops);
}
diff --git a/src/launch-uml.c b/src/launch-uml.c
index 34e7068..785548c 100644
--- a/src/launch-uml.c
+++ b/src/launch-uml.c
@@ -609,9 +609,8 @@ static struct backend_ops backend_uml_ops = {
.max_disks = max_disks_uml,
};
-static void init_backend (void) __attribute__((constructor));
-static void
-init_backend (void)
+void
+guestfs_int_init_uml_backend (void)
{
guestfs_int_register_backend ("uml", &backend_uml_ops);
}
diff --git a/src/launch-unix.c b/src/launch-unix.c
index 99a6e80..dae4389 100644
--- a/src/launch-unix.c
+++ b/src/launch-unix.c
@@ -120,9 +120,8 @@ static struct backend_ops backend_unix_ops = {
.shutdown = shutdown_unix,
};
-static void init_backend (void) __attribute__((constructor));
-static void
-init_backend (void)
+void
+guestfs_int_init_unix_backend (void)
{
guestfs_int_register_backend ("unix", &backend_unix_ops);
}
diff --git a/src/launch.c b/src/launch.c
index cbaef28..fbe9246 100644
--- a/src/launch.c
+++ b/src/launch.c
@@ -527,3 +527,16 @@ guestfs_int_set_backend (guestfs_h *g, const char *method)
return 0;
}
+
+/* This hack is only required to make static linking work. See:
+ * https://stackoverflow.com/questions/1202494/why-doesnt-attribute-constructor-work-in-a-static-library
+ */
+void *
+guestfs_int_force_load_backends[] = {
+ guestfs_int_init_direct_backend,
+#ifdef HAVE_LIBVIRT
+ guestfs_int_init_libvirt_backend,
+#endif
+ guestfs_int_init_uml_backend,
+ guestfs_int_init_unix_backend,
+};
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git
More information about the Pkg-libvirt-commits
mailing list