如何安装 ld 未明确支持的 DYLD 加载器命令?
在 Mac OS X 上,DYLD 格式的二进制可执行文件包含“加载器命令”,指示库加载系统如何处理文件的内容。特别是,加载程序命令指示系统应在何处搜索依赖库等。
您可以通过运行“otool -l /path/to/your/app”来查看系统上任何二进制文件的加载程序命令的完整列表。
一般来说,这些加载器命令是在项目编译的链接阶段由“ld”工具设置的。
我的问题是,我需要做什么来为 ld (显然)不支持的公开类型添加加载程序命令?
特别是,我想利用 LC_DYLD_ENVIRONMENT 加载程序命令,该命令可用于指定二进制文件的加载程序命令表中的字符串,该字符串应作为可执行文件上下文中的环境变量设置进行加载和评估。
我没有看到任何 ld 的论据可以促进这一点。我想要的是类似“-sectcreate”但专门添加到加载器命令内容的东西。
我知道这是可能的,因为 Mac OS X 上至少有一个标准应用程序使用它:Safari。但我不知道他们是否通过某种二进制后链接按摩来实现这一点,如果他们使用知道如何构建和链接自定义加载程序命令的 ld 自定义版本,或者他们是否正在利用我无法弄清楚 ld 命令的通用功能。
On Mac OS X, binary executables in the DYLD format contain "loader commands" that instruct the library loading system how to handle the contents of the file. In particular, the loader command instruct the system where dependent libraries should be searched for, etc.
You can see the complete list of loader commands for any binary on your system by running "otool -l /path/to/your/app".
Generally speaking these loader commands are set by the "ld" tool during the link phase of a project's compilation.
My question is, what do I need to do to add loader commands for publicized types that are not supported (apparently) by ld?
In particular, I would like to take advantage of the LC_DYLD_ENVIRONMENT loader commmand, which can be used to specify a string in the loader commands table of a binary that should be loaded and evaluated as environment variable settings in the context of the executable.
I don't see any argument to ld that would facilitate this. Something like "-sectcreate" but for specifically adding to the content of the loader commands, is what I'm after.
I know this is possible because at least one standard app on Mac OS X uses it: Safari. But I don't know whether they achieve this by some kind of post-link massage of the binary, if they're using a custom version of ld that knows how to build and chain the custom loader command in, or if they are exploiting a general-purpopse feature of the ld command that I haven't been able to figure out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您可以使用 -dyld_env,如下所示:“-dyld_env DYLD_FRAMEWORK_PATH=/”。这没有在手册页中记录,但可以在 ld64 的 Options.cpp 中找到,并在 Changelog 文件中提到。如果您尝试从 Xcode 执行此操作,则可能必须这样做:“-Xlinker -dyld_env -Xlinker DYLD_FRAMEWORK_PATH=/”。
需要注意的一件事是:如果您查看 dyld 的 dyld.cpp,您会发现它只允许以 DYLD_ 开头并以 _PATH 结尾的环境变量。
It looks like you can use -dyld_env, like so: "-dyld_env DYLD_FRAMEWORK_PATH=/". This isn't documented in the man page, but can be found in ld64's Options.cpp and mentioned in the Changelog file. If you're trying to do it from Xcode, you'll probably have to do it like this: "-Xlinker -dyld_env -Xlinker DYLD_FRAMEWORK_PATH=/".
One thing to note: if you look at dyld's dyld.cpp, you'll see that it only allows environment variables that start with DYLD_ and ends with _PATH.
如果您的可执行文件是标准 OS X 应用程序包的一部分(即可以由用户启动的 .app),则指定应用程序特定环境变量的传统方法是通过其 plist 文件使用
LSEnvironment键。请参阅此处了解更多信息。
If your executable is structured as part of a standard OS X application bundle (i.e. a .app that can be launched by a user), the conventional way to specify application specific environment variables is through its plist file using the
LSEnvironment
key. See here for more information.