如何在armv7应用程序中使用armv6第三方库? [英] How to use armv6 third party libraries in an armv7 app?

查看:533
本文介绍了如何在armv7应用程序中使用armv6第三方库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个第三方库。一个只有armv6的构建,另一个只有armv7的构建。我需要在我的iOS企业应用程序中使用它们。我已经要求armv6库供应商提供armv7版本,但他们无法做到这一点。 (注意:我已经得到了答案,并且会提供答案。有人在评论中提出这个问题并且没有足够的空间回答,所以我已经创建了自己的问题,并将提供我的答案。)

I have two 3rd party libraries. One just has a build for armv6 and the other just has a build for armv7. I need to use both of them in my iOS enterprise application. I've asked the armv6 library vendors to supply a armv7 version, but they haven't been able to do so. (Note: I've already got the answer and will provide it. Someone else asked this in a comment and there wasn't enough room to answer, so I've created its own question, and will provide my answer.)

推荐答案

答案是破解armv6库,认为它是一个armv7库。这将使您运行,直到供应商提供库。这样做的原因是因为arm规范要求所有arm架构都能够运行以前架构生成的代码。因此,如果armv6库告诉链接器它是armv7,处理器应该仍然能够运行代码。当然,你不能走另一条路。在两个库上使用otool -h来查看cputype和cpusubtype。在我的库中,两种cputypes都是12,而子类型是6和9,表明armv6和armv7。
使用十六进制编辑器,查找十六进制字符串0xcefaedfe,它是由于大/小端而反转的标记MH_MAGIC(0xfeedface)。

The answer is to hack the armv6 library into thinking it's an armv7 library. This will get you running until the vendor supplies the library. The reason this works is because the arm spec requires all arm architectures to be able to run code generated by previous architectures. So if an armv6 library told the linker it's an armv7, the processor should still be able to run the code. Of course, you can't go the other way. Use otool -h on both libraries to see the cputype and cpusubtype. On my libraries it was 12 for both cputypes, and 6 and 9 for the subtypes, indicating armv6 and armv7. Using a hex editor, look for the hex string 0xcefaedfe which is the marker MH_MAGIC (0xfeedface) reversed due to big/little endian.

之后,有只有0xC的整个单词。那是cputype的12。接下来是0x6的单词。对于所有情况,将其更改为0x9。
现在ld会认为你的库是一个armv7,并采取相应的行动。

Following that, there's a whole word with just 0xC. That's the 12 for the cputype. Next is a word for 0x6. Change that to 0x9 for all cases. Now ld will think your library is an armv7, and act accordingly.

你可能没有完成,因为armv6可能已链接到一些拇指库例程。如果你得到链接错误(我得到了一些switch8和switch16),你需要找到包含它们的Darwin代码。查找文件 lib1funcs.asm 在网上。这可能会让你缺少功能。它们可能已经过调整,因此请调整#ifdef并确保它们正在编译中。这个文件试图在最后打开一些包含,但由于它们在最后,它们不会影响任何东西,所以只需将它们注释掉。

You're probably not done, because the armv6 may have linked in some thumbs library routines. If you get link errors (I got some for switch8 and switch16), you need to find the Darwin code that has them. Look for the file lib1funcs.asm on the web. This will probably have your missing functions. They're probably conditionaled out, so adjust the #ifdefs and make sure they're being compiled. This file tries to open some includes at the end, but since they're at the end, they don't affect anything, so just comment them out.

是的,这是一个巨大的黑客攻击,但它会让你开始运行。如果您获得了修改后的库,则只需将其删除即可。无需更改代码。如果它适用于您,您仍然使用Apple的代码,如果您只使用armv6,它将与您运行的代码相同。

Yes, it is a tremendous hack, but it gets you up and running. If you get your revised library, you just have to drop it in. No code change required. If it works for you, you're still using Apple's code, and it would be the same code you'd be running if you were armv6 only.

这篇关于如何在armv7应用程序中使用armv6第三方库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆