From 10c611a3f1e2cb6c796a3eb1b3aaf77b69b3466b Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Fri, 13 Dec 2013 12:22:36 -0800 Subject: [PATCH] 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. --- src/dispatch_common.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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);