Mercurial > pub > dyncall > dyncall
comparison test/dynload_plain/dynload_plain.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 | 3124f4c4f293 |
children | 7608e34098b0 |
comparison
equal
deleted
inserted
replaced
381:fccbb45a2dae | 382:dd5d03483314 |
---|---|
65 int r = 0, i; | 65 int r = 0, i; |
66 void* p; | 66 void* p; |
67 DLLib* pLib; | 67 DLLib* pLib; |
68 DLSyms* pSyms; | 68 DLSyms* pSyms; |
69 const char* path = NULL; | 69 const char* path = NULL; |
70 int cmp_inode = 1; | |
71 | |
70 /* hacky/lazy list of some clib paths per platform - more/others, like version-suffixed ones */ | 72 /* hacky/lazy list of some clib paths per platform - more/others, like version-suffixed ones */ |
71 /* can be specified in Makefile; this avoids trying to write portable directory traversal stuff */ | 73 /* can be specified in Makefile; this avoids trying to write portable directory traversal stuff */ |
72 const char* clibs[] = { | 74 const char* clibs[] = { |
73 #if defined(DEF_C_DYLIB) | 75 #if defined(DEF_C_DYLIB) |
74 DEF_C_DYLIB, | 76 DEF_C_DYLIB, |
76 /* fallback guessing if not provided by Makefile */ | 78 /* fallback guessing if not provided by Makefile */ |
77 "/lib/libc.so", | 79 "/lib/libc.so", |
78 "/lib32/libc.so", | 80 "/lib32/libc.so", |
79 "/lib64/libc.so", | 81 "/lib64/libc.so", |
80 "/usr/lib/libc.so", | 82 "/usr/lib/libc.so", |
81 "/usr/lib/system/libsystem_c.dylib", /* macos */ | 83 "/usr/lib/system/libsystem_c.dylib", /* macos - note: not on fs w/ macos >= 11.0.1 */ |
82 "/usr/lib/libc.dylib", | 84 "/usr/lib/libc.dylib", |
83 "/boot/system/lib/libroot.so", /* Haiku */ | 85 "/boot/system/lib/libroot.so", /* Haiku */ |
84 "\\ReactOS\\system32\\msvcrt.dll", /* ReactOS */ | 86 "\\ReactOS\\system32\\msvcrt.dll", /* ReactOS */ |
85 "C:\\ReactOS\\system32\\msvcrt.dll", | 87 "C:\\ReactOS\\system32\\msvcrt.dll", |
86 "\\Windows\\system32\\msvcrt.dll", /* Windows */ | 88 "\\Windows\\system32\\msvcrt.dll", /* Windows */ |
91 for(i=0; i<(sizeof(clibs)/sizeof(const char*)); ++i) { | 93 for(i=0; i<(sizeof(clibs)/sizeof(const char*)); ++i) { |
92 if(access(clibs[i], F_OK) != -1) { | 94 if(access(clibs[i], F_OK) != -1) { |
93 path = clibs[i]; | 95 path = clibs[i]; |
94 break; | 96 break; |
95 } | 97 } |
98 #if defined(DC__OS_Darwin) | |
99 /* macos >= 11.0.1 (Big Sur) dylibs might not be on disk but in a sys cache, so dlopen works but not fs checks */ | |
100 else if((pLib = dlLoadLibrary(clibs[i]))) { | |
101 cmp_inode = 0; /* not dealing with files but dylib sys cache */ | |
102 dlFreeLibrary(pLib); | |
103 path = clibs[i]; | |
104 break; | |
105 } | |
106 #endif | |
96 } | 107 } |
97 | 108 |
98 if(path) { | 109 if(path) { |
99 printf("using clib to test at: %s\n", path); | 110 printf("using clib to test at: %s\n", path); |
100 ++r; | 111 ++r; |
113 printf("printf at: %p\n", p); | 124 printf("printf at: %p\n", p); |
114 r += (p != NULL); | 125 r += (p != NULL); |
115 | 126 |
116 bs = dlGetLibraryPath(pLib, queriedPath, 200); | 127 bs = dlGetLibraryPath(pLib, queriedPath, 200); |
117 if(bs && bs <= 200) { | 128 if(bs && bs <= 200) { |
118 struct stat st0, st1; /* to check if same file */ | |
119 int b, bs_; | 129 int b, bs_; |
120 printf("path of lib looked up via handle: %s\n", queriedPath); | 130 printf("path of lib looked up via handle: %s\n", queriedPath); |
121 b = (stat(path, &st0) != -1) && (stat(queriedPath, &st1) != -1); | 131 |
122 printf("lib (inode:%d) and looked up lib (inode:%d) are same: %d\n", b?st0.st_ino:-1, b?st1.st_ino:-1, b && (st0.st_ino == st1.st_ino)); //@@@ on windows, inode numbers returned here are always 0 | |
123 r += b && (st0.st_ino == st1.st_ino); /* compare if same lib using inode */ | |
124 /*@@@ check if resolved path is absolute*/ | 132 /*@@@ check if resolved path is absolute*/ |
133 | |
134 #if defined(DC_WINDOWS) | |
135 /* on windows, inode numbers returned by stat(2) tests below are always 0, so don't use those */ | |
136 cmp_inode = 0; | |
137 #endif | |
138 | |
139 /* path based check if same lib */ | |
140 if(cmp_inode) | |
141 { | |
142 struct stat st0, st1; /* to check if same file */ | |
143 b = (stat(path, &st0) != -1) && (stat(queriedPath, &st1) != -1); | |
144 printf("lib (inode:%d) and looked up lib (inode:%d) are same: %d\n", b?(int)st0.st_ino:-1, b?(int)st1.st_ino:-1, b && (st0.st_ino == st1.st_ino)); | |
145 r += b && (st0.st_ino == st1.st_ino); /* compare if same lib using inode */ | |
146 } | |
147 else | |
148 printf("-- skipping inode based check (doesn't apply to this platform or we are dealing with macos dylib that isn't on fs) --\n"); | |
149 | |
150 /* just load lib with queried path and compare handle */ | |
151 { | |
152 DLLib* pLib_ = dlLoadLibrary(queriedPath); | |
153 b = (pLib == pLib_); /* pLib guaranteed to not be NULL, here, so no explicit !pLib_ check */ | |
154 printf("lib (handle:%p) and looked up lib (handle:%p) are same: %d\n", pLib, pLib_, b); | |
155 r += b; | |
156 dlFreeLibrary(pLib_); /* dec ref count */ | |
157 } | |
125 | 158 |
126 /* check correct bufsize retval */ | 159 /* check correct bufsize retval */ |
127 b = (bs == strlen(queriedPath) + 1); | 160 b = (bs == strlen(queriedPath) + 1); |
128 printf("looked up path's needed buffer size (%d) computed correctly 1/2: %d\n", bs, b); | 161 printf("looked up path's needed buffer size (%d) computed correctly 1/2: %d\n", bs, b); |
129 r += b; | 162 r += b; |
243 else | 276 else |
244 printf("dlSymsInit failed\n"); | 277 printf("dlSymsInit failed\n"); |
245 } | 278 } |
246 | 279 |
247 /* Check final score of right ones to see if all worked */ | 280 /* Check final score of right ones to see if all worked */ |
248 r = (r == 16); | 281 r = (r == 16 + cmp_inode); |
249 printf("result: dynload_plain: %d\n", r); | 282 printf("result: dynload_plain: %d\n", r); |
250 return !r; | 283 return !r; |
251 } | 284 } |
252 | 285 |