I have tried looking for my file
sudo find / -name libSystem.B.dylib
but not luck.
That’s expected, because, on modern systems, this dynamic library has been rolled into the dynamic linker shared cache. See this post for the specifics and An Apple Library Primer for more context.
The dynamic linker is supposed to find this library in its shared cache. Consider this:
% cat hello.c
#include <stdio.h>
int main(int argc, char **argv) {
printf("Hello Cruel World!\n");
}
% clang hello.c
% ./a.out
Hello Cruel World!
% DYLD_PRINT_SEARCHING=1 ./a.out
dyld[64879]: find path "/usr/lib/libSystem.B.dylib"
dyld[64879]: possible path(original path on disk): "/usr/lib/libSystem.B.dylib"
dyld[64879]: possible path(cryptex prefix): "/System/Volumes/Preboot/Cryptexes/OS/usr/lib/libSystem.B.dylib"
dyld[64879]: possible path(original path): "/usr/lib/libSystem.B.dylib"
dyld[64879]: found: dylib-from-cache: (0x00AB) "/usr/lib/libSystem.B.dylib"
Hello Cruel World!
When you set DYLD_PRINT_SEARCHING
the dynamic linker logs information about where it searched for libraries, and you can see that it found libSystem.B.dylib
in its shared cache.
So, the question here is why that’s not happening for your program? The syscall to map cache into shared region failed
message is obviously part of the problem. Some spelunking on the ’net pointed me back to DevForums, and specifically this thread. And if I add a huge static array to my test project:
% cat hello.c
#include <stdio.h>
char map[0x7fffffff];
int main(int argc, char **argv) {
printf("Hello Cruel World!\n");
}
I’m able to reproduce the problem:
% clang hello.c
% ./a.out
dyld[33592]: dyld cache '(null)' not loaded: syscall to map cache into shared region failed
dyld[33592]: Library not loaded: /usr/lib/libSystem.B.dylib
…
zsh: abort ./a.out
Does your program use huge static arrays? If you run size
against it, what do you see?
% size a.out
__TEXT __DATA …
16384 2147483648 …
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"