# HG changeset patch # User Tassilo Philipp # Date 1493933910 -7200 # Node ID 06a354b2e1205d39a774dd04cb3de41445d5dc1c # Parent 0ba6189a51dd1b1bb491e393505d57234998f0df changes for dynload for macOS and OpenBSD: - reverted last commit, b/c of brainfat (wrongly assuming all libs iterated over are opened by dynload) - make use of RTLD_NOLOAD, though, when re-dlopen-ing to get path, for performance (where available) diff -r 0ba6189a51dd -r 06a354b2e120 dynload/dynload_unix.c --- a/dynload/dynload_unix.c Thu May 04 15:11:46 2017 +0200 +++ b/dynload/dynload_unix.c Thu May 04 23:38:30 2017 +0200 @@ -68,6 +68,14 @@ } +/* prefer RTLD_NOLOAD for code below that merely checks lib names */ +#if defined(RTLD_NOLOAD) +# define RTLD_LIGHTEST RTLD_NOLOAD +#else +# define RTLD_LIGHTEST RTLD_LAZY +#endif + + /* code for dlGetLibraryPath differs on Darwin */ #if defined(OS_Darwin) @@ -89,10 +97,12 @@ for(i=_dyld_image_count(); i>0;) /* iterate libs from end, more likely ours */ { const char* libPath = _dyld_get_image_name(--i); - DLLib* lib = dlLoadLibrary(libPath); /* re-open same way for same handle */ + void* lib = dlopen(libPath, RTLD_LIGHTEST); if(lib) { - dlFreeLibrary(lib); - if(pLib == lib) { + dlclose(lib); + /* compare handle pointers' high bits (in low 2 bits some flags might */ + /* be stored - should be safe b/c address needs alignment, anywas) */ + if(((intptr_t)pLib ^ (intptr_t)lib) < 4) { l = strlen(libPath); if(l < bufSize) /* l+'\0' <= bufSize */ strcpy(sOut, libPath); @@ -126,10 +136,10 @@ /* unable to relate info->dlpi_addr directly to our dlopen handle, let's */ /* do what we do on macOS above, re-dlopen the already loaded lib (just */ /* increases ref count) and compare handles. */ - DLLib* lib = dlLoadLibrary(info->dlpi_name); /* re-open same way for same handle */ + void* lib = dlopen(info->dlpi_name, RTLD_LIGHTEST); if(lib) { - dlFreeLibrary(lib); - if(lib == d->pLib) { + dlclose(lib); + if(lib == (void*)d->pLib) { l = strlen(info->dlpi_name); if(l < d->bufSize) /* l+'\0' <= bufSize */ strcpy(d->sOut, info->dlpi_name);