How to use armv6 third party libraries in an armv7 app?
Asked Answered
T

1

0

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.)

Thickset answered 16/5, 2012 at 19:21 Comment(0)
T
4

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.

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.

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.

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.

Thickset answered 16/5, 2012 at 19:39 Comment(3)
UPDATE: Xcode 4.4 changes the way assembler is done, and won't compile the lib1funcs.asm file out of the box. To use the old assembler, add -no-integrated-as to the "Other C Flags" section of the project build settings for each of your targets that use the assembler.Thickset
Now that armv6 is removed from Xcode 4.5, those of you stuck with armv6 libraries may have to resort to the above.Thickset
Rather than using lib1funcs.asm, it was suggested by someone at Apple to use the versions of switch8 and switch16 at compiler-rt instead. compiler-rt/lib/arm/switch8.S and compiler-rt/lib/arm/switch16.S. llvm.org/svn/llvm-project/compiler-rt/trunk/lib/armThickset

© 2022 - 2024 — McMap. All rights reserved.