Mercurial > pub > dyncall > dyncall
diff dynload/dynload_syms_mach-o.c @ 382:dd5d03483314
- dynload changes to support macos >= 11.0.1 "built-in dynamic linker cache of all system-provided libraries" (those dylibs are no longer present on the fs)"
* dynload_plain test code changes to reflect this
* note in doc
- changed dynload_plain to not do inode-based tests on windows
author | Tassilo Philipp |
---|---|
date | Wed, 20 Jan 2021 13:49:43 +0100 |
parents | 7ed642a9c3e9 |
children | 2144287113df |
line wrap: on
line diff
--- a/dynload/dynload_syms_mach-o.c Tue Dec 29 13:30:59 2020 +0100 +++ b/dynload/dynload_syms_mach-o.c Wed Jan 20 13:49:43 2021 +0100 @@ -39,7 +39,6 @@ #include <mach-o/dyld.h> #include <mach-o/nlist.h> -#include <sys/stat.h> #include <dlfcn.h> #include <string.h> @@ -73,13 +72,9 @@ DLLib* pLib; DLSyms* pSyms = NULL; uint32_t i, n; - struct stat st0; const struct MACH_HEADER_TYPE* pHeader = NULL; const struct dysymtab_command* dysymtab_cmd = NULL; - if(stat(libPath, &st0) == -1) - return NULL; - pLib = dlLoadLibrary(libPath); if(!pLib) return NULL; @@ -87,18 +82,26 @@ /* Loop over all dynamically linked images to find ours. */ for(i = 0, n = _dyld_image_count(); i < n; ++i) { - struct stat st1; const char* name = _dyld_get_image_name(i); - if(name && (stat(name, &st1) != -1)) + if(name) { /* Don't rely on name comparison alone, as libPath might be relative, symlink, differently */ - /* cased, etc., but compare inode number with the one of the mapped dyld image. */ - if(st0.st_ino == st1.st_ino/*!strcmp(name, libPath)*/) + /* cased, use weird osx path placeholders, etc., but compare inode number with the one of the mapped dyld image. */ + + /* reload already loaded lib to get handle to compare with, should be lightweight and only increase ref count */ + DLLib* pLib_ = dlLoadLibrary(name); + if(pLib_) { - pHeader = (const struct MACH_HEADER_TYPE*) _dyld_get_image_header(i); + /* free / refcount-- */ + dlFreeLibrary(pLib_); + + if(pLib == pLib_) + { + pHeader = (const struct MACH_HEADER_TYPE*) _dyld_get_image_header(i); //@@@ slide = _dyld_get_image_vmaddr_slide(i); - break; /* found header */ + break; /* found header */ + } } } }