Mach-O 共享库(`.dylib`s)支持符号版本控制吗?

发布于 2025-01-09 06:08:31 字数 151 浏览 3 评论 0原文

我遇到了一些段错误,这些错误似乎可以通过

例如,我知道在 Linux 上我可以执行 readelf -s libsomething.so ,它会输出版本信息以及符号。但是 readelf.dylib 文件上卡住了。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆伤 2025-01-16 06:08:32

不是真的,但你可以自己动手。

举个例子,Apple 实际上已经对 stat() 系列函数进行了某种符号版本控制。根据宏定义,stat 的声明将扩展为这样:

int stat(const char *, struct stat *) __asm("_stat");

或这样:

int stat(const char *, struct stat *) __asm("_stat$INODE64");

这就是库导出的样子:(

% 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

请注意,您必须使用x86_64 版本,因为 arm64 版本从来没有旧的实现,所以 _stat 已经有了新版本。)

但是如果你只是一个库的用户,那么除非你头文件损坏,结构和功能不匹配定义,那么这不会解决您的段错误问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文