summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian@centricular.com>2017-02-08 16:27:34 +0200
committerSebastian Dröge <sebastian@centricular.com>2017-05-09 15:58:15 +0200
commit0d81bb4e318b97780c70a55605cacf7e5b3fcaf7 (patch)
tree5feb3e0217b3457e66cd2061c415e42e05ffe5cf
parentcc5e9f2362e2f0088766d150f3149afac29f0d95 (diff)
downloadglib-0d81bb4e318b97780c70a55605cacf7e5b3fcaf7.tar.gz
gmodule – Don't use RTLD_DEFAULT on Android for g_module_self() on Android 64 bit
On 64 bit Android this is #defined to 0, which is considered an invalid library handle in all other cases. RTLD_DEFAULT is only supposed to be used with dlsym() it seems, and the usage here was just an "optimization" before. By dlopen'ing NULL, we get the same on all 64 bit Android variants and it actually works instead of erroring out. On 32 bit Android, dlopen() of NULL unfortunately usually gives us something useless that finds no symbols whatsoever. https://bugzilla.gnome.org/show_bug.cgi?id=776876
-rw-r--r--gmodule/gmodule-dl.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/gmodule/gmodule-dl.c b/gmodule/gmodule-dl.c
index e452e3495..80ef80ceb 100644
--- a/gmodule/gmodule-dl.c
+++ b/gmodule/gmodule-dl.c
@@ -111,8 +111,14 @@ _g_module_self (void)
/* to query symbols from the program itself, special link options
* are required on some systems.
*/
-
-#ifdef __BIONIC__
+
+ /* On Android 32 bit (i.e. not __LP64__), dlopen(NULL)
+ * does not work reliable and generally no symbols are found
+ * at all. RTLD_DEFAULT works though.
+ * On Android 64 bit, dlopen(NULL) seems to work but RTLD_DEFAULT
+ * is NULL, which is considered an invalid module.
+ */
+#if defined(__BIONIC__) && !defined(__LP64__)
handle = RTLD_DEFAULT;
#else
handle = dlopen (NULL, RTLD_GLOBAL | RTLD_LAZY);
@@ -129,9 +135,15 @@ _g_module_close (gpointer handle,
{
/* are there any systems out there that have dlopen()/dlclose()
* without a reference count implementation?
+ *
+ * See above for the Android special case
*/
+#if defined(__BIONIC__) && !defined(__LP64__)
+ is_unref = (handle != RTLD_DEFAULT);
+#else
is_unref |= 1;
-
+#endif
+
if (is_unref)
{
if (dlclose (handle) != 0)