You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

macOS中'restricted process'定义及dlopen版本搜索差异咨询

macOS中'restricted/unrestricted process'含义及dyld搜索路径差异问题

我一直想弄清楚macOS手册中**'restricted/unrestricted process'**的含义。以下是dlopen手册页中的片段:

Lastly, for old binaries, dyld will try some fallbacks. If $DYLD_FALLBACK_LIBRARY_PATH was set at launch, dyld will search in those directories, otherwise, dyld will look in /usr/local/lib/ (if the process is unrestricted), and then in /usr/lib/.

我编写了示例程序来测试三台Mac机器上的不同行为:

#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>

#define LIBM_SO "libcool.so"

int
main(int argc, char **argv)
{
    void *handle;
    double (*sine)(double);
    char *error;

    handle = dlopen(LIBM_SO, RTLD_LAZY);
    if (!handle) {
        fprintf(stderr, "%s\n", dlerror());
        exit(EXIT_FAILURE);
    }
    dlerror();

    *(void **) (&sine) = dlsym(handle, "sin");

    if ((error = dlerror()) != NULL)  {
        fprintf(stderr, "%s\n", error);
        exit(EXIT_FAILURE);
    }

    printf("%f\n", (*sine)(4.0));
    dlclose(handle);
    exit(EXIT_SUCCESS);
}

该程序在Mac 13.4上的输出如下:

./dlopen_example
 dlopen(libcool.so, 0x0001): tried: 'libcool.so' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibcool.so' (no such file), '/usr/lib/libcool.so' (no such file, not in dyld cache), 'libcool.so' (no such file), '/usr/local/lib/libcool.so' (no such file), '/usr/lib/libcool.so' (no such file, not in dyld cache)

在Mac 13.5上的输出如下:

./dlopen_example
 dlopen(libcool.so, 0x0001): tried: 'libcool.so' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibcool.so' (no such file), '/usr/lib/libcool.so' (no such file, not in dyld cache), 'libcool.so' (no such file)

可见Mac 13.5中的dlopen未搜索/usr/local/lib,我认为这与手册中提到的**'unrestricted process'**有关,但不清楚其含义。我已尽量保持两台机器环境一致:均开启SIP,用户均属wheel组,尝试sudo执行也无变化。我查阅了相关资料但无法得出结论,想知道这是否是Mac 13.4的特有现象?我的两台13.4版本机器都会检查/usr/local/lib,恳请技术帮助。


内容的提问来源于stack exchange,提问作者viral_mutant

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 23:10:15