Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
x/mobile: gomobile's JNI crashes under android x86 with ARM translation #15986
armeabi-v7a under android x86 with arm translation, the CompareAndSwapUint64 crashes like this:
I only want to build armeabi-v7a JNIs to reduce my APK's size.
I made a very dirty hack to make the code work:
Attached files are about the bind command and the panic stack trace.
The crash occurred in the net module, I debugged for a while and found that it was caused by CompareAndSwapUint64.
I am pretty sure that the problem is caused by using golang's linux-kernel atomic CAS64(__kuser_cmpxchg64) under a android x86 with ARM translation.
You can refer to my "dirty solution", I just removed the code for "__kuser_cmpxchg64" in /usr/local/go/src/sync/atomic/asm_linux_arm.s, and force golang to use "armCompareAndSwapUint64", then everything works.
I will try go 1.7 later, but I don't think it works if it still uses the same code for "__kuser_cmpxchg64".
Maybe this problem is not very serious, because seldom people do what I do: unpack the aar and remove everything(x86/x86_64) else besides armeabi-v7a to keep the APK as small as possible :)
I have some new thoughts about this problem.
Since gomobile only supports armeabi-v7a and above, can we make a special CompareAndSwapUint64 for armeabi-v7a and above? Then this special implementation can call armCompareAndSwapUint64 directly which is efficient enough. I read the source code about __kuser_cmpxchg64 and thought that it's not necessary to use it under an arm-v7a and above CPU.
Real arm devices works OK. This problem only occurs under x86(i386 only) with arm translation.
I have made a cleaner fix, just change the detection order: