当 iOS 应用程序链接到静态库时,如何获取废弃符号的列表?
我正在构建一个 iOS 静态库供第三方使用。它是使用其他几个包含大量 C++ 的静态库构建的,从而产生了一个巨大的可交付库。
iOS 库的 API 非常简单,而且我知道它不会使用所有包含的代码。我想从各个库中删除不需要的模块,这样我就可以缩小最终的大小。
我有一个使用所有库 API 的示例应用程序,当它链接时,库中的大多数符号都会被丢弃。有没有办法获取这些符号的列表?
I'm building a iOS static library for third parties to use. It's built using several other static libraries containing a large amount of C++, resulting in a huge deliverable library.
The API to the iOS library is quite simple, and I know that it doesn't exercise all of the included code. I'd like to remove the unwanted modules from the various libraries so I can get the final size down.
I have an example app which uses all the library APIs, and when it's linked most of the symbols in the library are discarded. Is there a way of getting a list of those symbols?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个答案似乎表明你想要做的事情在 GCC 3.x 和 4.x 中是不可能的:
限制 Linux 静态库中的符号
This answer seems to indicate that what you want to do isn't possible in GCC 3.x and 4.x:
Restricting symbols in a Linux static library
我被告知对使用动态库的限制是由代码签名过程强制执行的,因此我认为这可能有效:
nm -uj
to list可执行文件中未定义的符号。由于该库已静态链接,因此唯一未定义的符号应该是标准 iOS 库定义的符号nm -uj 针对此可执行文件。未定义的符号是步骤 2 中列出的符号与可执行文件实际引用的库符号的并集
diff
步骤 2 和步骤 5 中的列表。这将为您提供以下符号列表仅库nm -js __TEXT __text
以获取每个目标文件导出的函数列表。可以自动化,并且可能需要改进以考虑函数以外的符号(例如全局变量)。
I’ve been told that the restriction upon using dynamic library is enforced by the code signing process so I think this might work:
nm -uj
to list the undefined symbols in the executable. Since the library has been linked statically, the only undefined symbols should be the ones defined by the standard iOS librariesnm -uj
against this executable. The undefined symbols are the union of the ones listed in step 2 with the library symbols that are actually referenced by the executablediff
the lists from step 2 and step 5. This will give you the list of symbols in the library onlynm -js __TEXT __text
on the object files to get a list of the functions exported by each object fileThis can be automated and probably needs to be improved to take into account symbols other than functions (e.g. global variables).