简体   繁体   English

从静态库(.a)中删除方法调用而不重新编译

[英]Removing a method call from inside a static lib(.a) without recompiling

I'm using a static lib thats giving me a warning when uploading my binary for review by apple. 我正在使用一个静态库,在上传我的二进制文件时会给我一个警告,供苹果查看。

The method in the static lib that causes the warning(non-public selectors) is never called by me, its corresponding .h is deleted from my proj, but warning still persists. 导致警告的静态库中的方法(非公共选择器)从未被我调用,其相应的.h从我的项目中删除,但警告仍然存在。

Given that I know the method name causing the problem, is there a way for me to open/edit this .a and comment/delete the offending piece of code and then use the modified .a in my project. 鉴于我知道导致问题的方法名称,有没有办法让我打开/编辑这个.a并注释/删除有问题的代码,然后在我的项目中使用修改后的.a。

I don't have access to the .a source to recompile it, and its very old and the creator of it has no contact details for me to track down. 我没有访问.a源代码来重新编译它,它的旧版本和它的创建者没有联系方式供我追踪。

Many Thanks, -Cake 非常感谢,-Cake

Quick and dirty solution: Open the .a file in a hex editor and change all instances of the name. 快速而肮脏的解决方案:在十六进制编辑器中打开.a文件并更改名称的所有实例。 Leave the function name the same length so that offsets in the file don't change, just change a letter or something like that. 保留函数名称的长度相同,以便文件中的偏移不会改变,只需更改字母或类似的东西即可。 I did a quick test, adding a dummy function to a subproject we're building as a static library then tweaking the function name in the .a file (there were five instances, for what that's worth) and everything built okay. 我做了一个快速测试,在我们构建为静态库的子项目中添加了一个虚函数,然后调整.a文件中的函数名称(有五个实例,这是值得的),一切都构建好了。 I don't see any reason it wouldn't pass the App Store check after that. 我认为没有任何理由在此之后它不会通过App Store检查。

I'm really surprised the function was still there in the final build, though—I thought Dead Code Stripping was supposed to clean out any unused code. 我真的很惊讶函数在最终构建中仍然存在,但我认为死代码剥离应该清除任何未使用的代码。 Huh. 呵呵。

http://opensource.apple.com/source/cctools/cctools-809/ http://opensource.apple.com/source/cctools/cctools-809/

I don't presume to get your bounty, because I haven't provided an easy solution. 我不认为得到你的赏金,因为我没有提供一个简单的解决方案。 But yes, it in theory is possible. 但是,理论上它是可能的。 You have your work cut out for you. 你的工作已经完成了。

No need to hack the binary files. 无需破解二进制文件。 Just turn off the compiler's "unused selectors" warning: -fno-unused-selectors. 只需关闭编译器的“未使用的选择器”警告:-fno-unused-selectors。

There are several solutions, depending on your lib and project. 有几种解决方案,具体取决于您的lib和项目。

In your build settings : 在您的构建设置中:

  1. Enable " dead code stripping " if possible : If the method is never used (even internally), the symbol will be deleted. 如果可能,启用“ 死代码剥离 ”:如果从不使用该方法(甚至是内部),则将删除该符号。

  2. Use " Unexported symbol file " : Simply add the symbol into a file and it will be removed from the binary. 使用“ Unexported symbol file ”:只需将符号添加到文件中,它就会从二进制文件中删除。 This will work even if the symbol is used internally. 即使在内部使用符号,这也可以工作。

  3. Enable " Deployment Postprocessing " and " Strip Linked Product " with " Strip Style " set to " All symbol " 启用“ 部署后处理 ”和“ 剥离链接产品 ”,并将“ 条带样式 ”设置为“ 所有符号

  4. (Not sure) Use " Symbols Hidden by Default ". (不确定)使用“ 默认隐藏的符号 ”。 This is related to the code generation and should not affect linking, but just in case everything above failed... 这与代码生成有关,不应影响链接,但以防上述所有内容都失败...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM