build(android): add opt-in flag to disable SVE dispatch on Apple Silicon emulators - #719
Merged
Merged
Conversation
…con emulators Android emulators on Apple Silicon advertise SVE, SVE2 and friends in HWCAP although the host CPU implements none of them. KleidiCV, OpenCV's arm64 HAL, reads HWCAP in its static initializers and selects its SVE2 kernels, so the first SVE instruction (addvl) raises SIGILL and the app dies in `nativeCrop` as soon as a scan is cropped. Add a `getauxval` interposition that hides the SVE bits, compiled in only when building with `--gradleArgs=-PdisableSVE`, so KleidiCV falls back to NEON. The flag value is always passed to CMake so it cannot linger in the cache and reach a release build. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Android emulators running on Apple Silicon advertise SVE, SVE2 and friends in HWCAP even though the host CPU implements none of them. KleidiCV, OpenCV's arm64 HAL, reads HWCAP in its static initializers and selects its SVE2 kernels, so the first SVE instruction executed raises
SIGILLand the app dies innativeCropas soon as a scan is cropped:hwcap_sve.cpp, agetauxvalinterposition that hides the SVE bits so KleidiCV falls back to its NEON implementations. It is compiled in only when building with--gradleArgs=-PdisableSVE, and is a development aid — enabling it for a release would give up KleidiCV's SVE2 code paths on the devices that really support them.Nothing changes for a normal build.
Testing
Both directions checked with real plugin rebuilds on an arm64 emulator (API 36, Apple Silicon host):
getauxvalns build androidDISABLE_SVE:BOOL=0--gradleArgs=-PdisableSVEDISABLE_SVE:BOOL=1Note that the CLI reuses the prebuilt plugin aar, so toggling the flag alone rebuilds nothing until a plugin source changes.