I'm running into some segfaults that seem to be resolved on linux platforms by symbol versioning inside the ELF dynamic libraries. But I'm still getting segfaults on macOS. Is there a comparable feature in Mach-O shared libraries? And if so, how can I see the version information in the file?
For example, I know that on linux I can do readelf -s libsomething.so
, and it will output the version info along with the symbols. But readelf
chokes on .dylib
files.
Not really, but you can kinda roll your own.
To serve as an example, Apple has actually done some kind of symbol versioning to the stat()
family of functions. Depending on macro definitions, the declaration of stat
will expand to either this:
int stat(const char *, struct stat *) __asm("_stat");
Or this:
int stat(const char *, struct stat *) __asm("_stat$INODE64");
And this is what the library exports look like:
% nm -arch x86_64 /usr/lib//system/libsystem_kernel.dylib | fgrep ' _stat'
0000000000009650 T _stat
0000000000001fd8 T _stat$INODE64
0000000000001fd8 T _stat64
00000000000250dc T _statfs
0000000000002e4c T _statfs$INODE64
0000000000002e4c T _statfs64
(Note that you have to use the x86_64 version there, as the arm64 version never had the old implementation to begin with, and so _stat
there is already the new version.)
But if you're just a user of a library, then unless you have broken headers with mismatched struct and function definitions, then this is not going to solve your segfault issue.