简体   繁体   English

如何在armv7应用程序中使用armv6第三方库?

[英]How to use armv6 third party libraries in an armv7 app?

I have two 3rd party libraries. 我有两个第三方图书馆。 One just has a build for armv6 and the other just has a build for armv7. 一个仅具有针对armv6的构建,而另一个仅具有针对armv7的构建。 I need to use both of them in my iOS enterprise application. 我需要在我的iOS企业应用程序中同时使用它们。 I've asked the armv6 library vendors to supply a armv7 version, but they haven't been able to do so. 我已经要求armv6库供应商提供armv7版本,但他们还没有提供。 (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.) (注意:我已经有了答案,并将提供答案。其他人在评论中提出了这个问题,没有足够的答案空间,因此我创建了自己的问题,并将提供我的答案。)

The answer is to hack the armv6 library into thinking it's an armv7 library. 答案是破解armv6库,使其认为它是armv7库。 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. 因此,如果armv6库告诉链接器它是armv7,则处理器仍应能够运行代码。 Of course, you can't go the other way. 当然,您不能选择其他方式。 Use otool -h on both libraries to see the cputype and cpusubtype. 在两个库上都使用otool -h可以查看cputype和cpusubtype。 On my libraries it was 12 for both cputypes, and 6 and 9 for the subtypes, indicating armv6 and armv7. 在我的库中,两个cputype均为12,亚型为6和9,分别表示armv6和armv7。 Using a hex editor, look for the hex string 0xcefaedfe which is the marker MH_MAGIC (0xfeedface) reversed due to big/little endian. 使用十六进制编辑器,查找十六进制字符串0xcefaedfe,这是由于尾序大/小而反转的标记MH_MAGIC(0xfeedface)。

Following that, there's a whole word with just 0xC. 然后,整个单词只有0xC。 That's the 12 for the cputype. 这是cputype的12。 Next is a word for 0x6. 接下来是0x6的字。 Change that to 0x9 for all cases. 在所有情况下都将其更改为0x9。 Now ld will think your library is an armv7, and act accordingly. 现在ld会认为您的库是armv7,并采取相应的措施。

You're probably not done, because the armv6 may have linked in some thumbs library routines. 您可能还没有完成,因为armv6可能已在某些Thumbs库例程中链接。 If you get link errors (I got some for switch8 and switch16), you need to find the Darwin code that has them. 如果您遇到链接错误(我在switch8和switch16上遇到了一些错误),则需要找到包含它们的达尔文代码。 Look for the file lib1funcs.asm on the web. 在网上查找文件lib1funcs.asm This will probably have your missing functions. 这可能会缺少您的功能。 They're probably conditionaled out, so adjust the #ifdefs and make sure they're being compiled. 它们可能是有条件的,因此请调整#ifdefs并确保它们已被编译。 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. 该文件尝试在末尾打开一些包含,但是由于它们在末尾,因此它们不会影响任何内容,因此只需将它们注释掉即可。

Yes, it is a tremendous hack, but it gets you up and running. 是的,这是一个巨大的hack,但是它可以使您正常运行。 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. 如果它适合您,则您仍在使用Apple的代码,如果仅使用armv6,它将与您正在运行的代码相同。

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

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