summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2013-12-13 12:22:36 -0800
committerEric Anholt <eric@anholt.net>2013-12-13 12:30:14 -0800
commit10c611a3f1e2cb6c796a3eb1b3aaf77b69b3466b (patch)
treea148119220925b21148f94ff7cc4ad6cc4874a59
parent03e9537331269442e0c2c3a59fe0b325cc4770a0 (diff)
Add a check that we've made it into the C runtime when doing dlopen().
This should give us a more informative failure mode than the one mentioned in the README.
-rw-r--r--src/dispatch_common.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/dispatch_common.c b/src/dispatch_common.c
index 8d7c1d1..03d08fc 100644
--- a/src/dispatch_common.c
+++ b/src/dispatch_common.c
@@ -157,12 +157,29 @@ static struct api api = {
};
#ifndef _WIN32
+static bool library_initialized;
+
+static void
+library_init(void) __attribute__((constructor));
+
+static void
+library_init(void)
+{
+ library_initialized = true;
+}
+
static void
get_dlopen_handle(void **handle, const char *lib_name, bool exit_on_fail)
{
if (*handle)
return;
+ if (!library_initialized) {
+ fprintf(stderr,
+ "Attempting to dlopen() while in the dynamic linker.\n");
+ abort();
+ }
+
pthread_mutex_lock(&api.mutex);
if (!*handle) {
*handle = dlopen(lib_name, RTLD_LAZY | RTLD_LOCAL);