From 14bbc77bc465b42454112bc6a33264c2c3e013e5 Mon Sep 17 00:00:00 2001
From: Ross Burton <ross.burton@intel.com>
Date: Fri, 11 Mar 2016 15:35:55 +0000
Subject: [PATCH] glib-2.0: relocate the GIO module directory for native builds

Instead of hard-coding GIO_MODULE_PATH when glib is built, use dladdr() to
determine where libglib.so is and use that path to calculate GIO_MODULES_DIR.

This solves relocation problems with GIOModule for native builds of glib.

Upstream-Status: Inappropriate
Signed-off-by: Ross Burton <ross.burton@intel.com>

Port patch to 2.48
Signed-off-by: Jussi Kukkonen <jussi.kukkonen@intel.com>

Port patch to 2.88
Signed-off-by: Peter Marko <peter.marko@siemens.com>
---
 gio/giomodule.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/gio/giomodule.c b/gio/giomodule.c
index 38761e4..afa7878 100644
--- a/gio/giomodule.c
+++ b/gio/giomodule.c
@@ -1312,6 +1312,24 @@ get_gio_module_dir (void)
       module_dir = get_gio_module_dir_darwin ();
 #else
       module_dir = g_strdup (GIO_MODULE_DIR);
+#include <dlfcn.h>
+      {
+        g_autofree gchar *path = NULL;
+        g_autofree gchar *possible_dir = NULL;
+        Dl_info info;
+
+        if (dladdr (get_gio_module_dir, &info))
+          {
+            /* Gets path to the PREFIX/lib directory */
+            path = g_path_get_dirname (info.dli_fname);
+            possible_dir = g_build_filename (path, "gio", "modules", NULL);
+            if (g_file_test (possible_dir, G_FILE_TEST_IS_DIR))
+              {
+                g_free (module_dir);
+                module_dir = g_steal_pointer (&possible_dir);
+              }
+          }
+      }
 #endif
     }
 
