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);