Is there a compiler flag to indicate lack of armv7

2019-02-07 01:44发布

问题:

With the iPhone 5 and other armv7s devices now appearing, there are compatibility problems with existing (closed-source) 3rd-party frameworks such as Flurry which are built without this newer architecture.

One option is to wait until they release a new build, but I was hoping there might be a compiler flag or something I can use in my Xcode project that would let the linker know not to expect armv7s architecture from this framework, and use the armv7 instead. Does anything like this exist?

回答1:

It's not possible to load a framework which doesn't include the targeted architecture.

What you could do is only ship a armv7 app until the frameworks are updated. The app will still work on the iPhone 5, just don't use the latest performance optimizations it offers.

Or if you could live without the framework on the new architecture you could weak link it. But then you need to check in your code if it is loaded everywhere you use stuff from the framework.



回答2:

There used to be a linker flag in GCC, allow_sub_type_mismatches, which would let you mix and match ARM architecture versions in linked libraries, but they seem to have taken that away in recent versions of Xcode.

However, this can actually be hacked around in a different way; make a copy of the framework, view its contents, open up the actual code library file inside of it in a hex editor, and do the following replace all:

CEFAEDFE 0C000000 09000000

to

CEFAEDFE 0C000000 0B000000

What you're basically doing is changing the header inside of each code object to identify it as ARMv7s rather than an ARMv7 code - the instruction sets are backwards compatible (or seem to be, anyway), so it should run fine even with this hack, though I have to admit that we won't know that for certain until we actually get a chance to test it on an iPhone 5.

Anyway, once you've modified the framework, simply add both versions to your project and link to the appropriate one from each architecture. You might also be able to create a new single framework by using lipo to merge the modified and original libraries.