]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-bus-marshal: dlopen() glib and libdbus instead of linking directly
authorDaan De Meyer <daan@amutable.com>
Fri, 15 May 2026 18:24:11 +0000 (18:24 +0000)
committerDaan De Meyer <daan@amutable.com>
Mon, 18 May 2026 21:17:38 +0000 (21:17 +0000)
The test only uses 9 symbols (5 from glib, 4 from libdbus) for its
interop checks; dlopen them at runtime so the binary no longer carries a
hard link-time dependency on either library. Headers are still pulled in
through the *_cflags partial dependencies for the type declarations.

While we're at it, drop the compat glue for glib 2.36 which is long obsolete
at this point.

meson.build
src/libsystemd/meson.build
src/libsystemd/sd-bus/test-bus-marshal.c

index 92129bee7d77bc4fb456279fc1e56dc7d85a3a91..05739e517b27461ab5c68e7ac00fc9d285f0962e 100644 (file)
@@ -1319,11 +1319,15 @@ libgobject = dependency('gobject-2.0',
 libgio =     dependency('gio-2.0',
                         required : get_option('glib'))
 conf.set10('HAVE_GLIB', libglib.found() and libgobject.found() and libgio.found())
+libglib_cflags = libglib.partial_dependency(includes: true, compile_args: true)
+libgobject_cflags = libgobject.partial_dependency(includes: true, compile_args: true)
+libgio_cflags = libgio.partial_dependency(includes: true, compile_args: true)
 
 libdbus = dependency('dbus-1',
                      version : '>= 1.3.2',
                      required : get_option('dbus'))
 conf.set10('HAVE_DBUS', libdbus.found())
+libdbus_cflags = libdbus.partial_dependency(includes: true, compile_args: true)
 
 dbusdatadir = libdbus.get_variable(pkgconfig: 'datadir', default_value: datadir) / 'dbus-1'
 
index 2fab54719474ce2104ef5325910e80e12f6c48ae..2c86a231064a8fbfca1b04fe1b36624bb73e02d5 100644 (file)
@@ -221,10 +221,10 @@ libsystemd_tests += [
         {
                 'sources' : files('sd-bus/test-bus-marshal.c'),
                 'dependencies' : [
-                        libdbus,
-                        libgio,
-                        libglib,
-                        libgobject,
+                        libdbus_cflags,
+                        libgio_cflags,
+                        libglib_cflags,
+                        libgobject_cflags,
                         libm,
                         threads,
                 ],
index e26ca43344713ae6872f2a2ce98a55cb013f529f..8229eef54ab9f9ea0f6633ef10982d9e879f9e50 100644 (file)
@@ -23,6 +23,7 @@ REENABLE_WARNING
 #include "bus-label.h"
 #include "bus-message.h"
 #include "bus-util.h"
+#include "dlfcn-util.h"
 #include "escape.h"
 #include "fd-util.h"
 #include "log.h"
@@ -31,6 +32,40 @@ REENABLE_WARNING
 #include "stat-util.h"
 #include "tests.h"
 
+#if HAVE_GLIB
+static void *glib_dl = NULL;
+static DLSYM_PROTOTYPE(g_dbus_message_new_from_blob) = NULL;
+static DLSYM_PROTOTYPE(g_dbus_message_print)         = NULL;
+static DLSYM_PROTOTYPE(g_free)                       = NULL;
+static DLSYM_PROTOTYPE(g_object_unref)               = NULL;
+
+static int dlopen_glib(void) {
+        return dlopen_many_sym_or_warn(
+                        &glib_dl, "libgio-2.0.so.0", LOG_DEBUG,
+                        DLSYM_ARG(g_dbus_message_new_from_blob),
+                        DLSYM_ARG(g_dbus_message_print),
+                        DLSYM_ARG(g_free),
+                        DLSYM_ARG(g_object_unref));
+}
+#endif
+
+#if HAVE_DBUS
+static void *libdbus_dl = NULL;
+static DLSYM_PROTOTYPE(dbus_error_init)        = NULL;
+static DLSYM_PROTOTYPE(dbus_error_free)        = NULL;
+static DLSYM_PROTOTYPE(dbus_message_demarshal) = NULL;
+static DLSYM_PROTOTYPE(dbus_message_unref)     = NULL;
+
+static int dlopen_libdbus(void) {
+        return dlopen_many_sym_or_warn(
+                        &libdbus_dl, "libdbus-1.so.3", LOG_DEBUG,
+                        DLSYM_ARG(dbus_error_init),
+                        DLSYM_ARG(dbus_error_free),
+                        DLSYM_ARG(dbus_message_demarshal),
+                        DLSYM_ARG(dbus_message_unref));
+}
+#endif
+
 static void test_bus_path_encode_unique(void) {
         _cleanup_free_ char *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL;
 
@@ -322,39 +357,32 @@ int main(int argc, char *argv[]) {
         log_info("message size = %zu, contents =\n%s", sz, h);
 
 #if HAVE_GLIB
-        /* Work-around for asan bug. See c8d980a3e962aba2ea3a4cedf75fa94890a6d746. */
-#if !HAS_FEATURE_ADDRESS_SANITIZER
-        {
+        if (dlopen_glib() >= 0) {
                 GDBusMessage *g;
                 char *p;
 
-#if !defined(GLIB_VERSION_2_36)
-                g_type_init();
-#endif
-
-                g = g_dbus_message_new_from_blob(buffer, sz, 0, NULL);
-                p = g_dbus_message_print(g, 0);
+                g = sym_g_dbus_message_new_from_blob(buffer, sz, 0, NULL);
+                p = sym_g_dbus_message_print(g, 0);
                 log_info("%s", p);
-                g_free(p);
-                g_object_unref(g);
+                sym_g_free(p);
+                sym_g_object_unref(g);
         }
 #endif
-#endif
 
 #if HAVE_DBUS
-        {
+        if (dlopen_libdbus() >= 0) {
                 DBusMessage *w;
                 DBusError error;
 
-                dbus_error_init(&error);
+                sym_dbus_error_init(&error);
 
-                w = dbus_message_demarshal(buffer, sz, &error);
+                w = sym_dbus_message_demarshal(buffer, sz, &error);
                 if (!w)
                         log_error("%s", error.message);
                 else
-                        dbus_message_unref(w);
+                        sym_dbus_message_unref(w);
 
-                dbus_error_free(&error);
+                sym_dbus_error_free(&error);
         }
 #endif