x/mobile: gomobile's JNI crashes under android x86 with ARM translation #15986
Comments
Can you include the crash stack trace, and the output of 'gomobile bind -x -v'? Is the problem present with go1.7 (or tip) as well? |
Attached files are about the bind command and the panic stack trace. gomobile-bind.txt.zip 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. |
cc @crawshaw @wxiaoguang do you see the same problem when running it on real arm devices? |
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:
|
go version
)?go version go1.6.2 darwin/amd64
go env
)?Host: x86_64
Target:
genymotion android 4.2/4.3(x86) with arm translation 1.1
https://play.golang.org/p/zUeejSnLmO
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.
The crash only occurs under x86 with arm translation.
The code under armeabi-v7a and x86_64 with arm translation works correctly.
I made a very dirty hack to make the code work:
The text was updated successfully, but these errors were encountered: