Bug #1455
closedPython 3.5 does not initialize on release builds
100%
Description
The python3.5 distribution from crystax ndk works fine in debug mode but fails in release mode. The crash happens when I call Py_Initialize() after I correctly set the location of the stdlib.zip file with Py_SetPath().
Here's the logcat for the event:
07-22 22:18:50.248 24633-24633/? I/pybridge: Initializing the Python interpreter
07-22 22:18:50.275 24633-24633/? A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 24633 (latangle.charts)
07-22 22:18:50.378 2793-2793/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
07-22 22:18:50.378 2793-2793/? A/DEBUG: Build fingerprint: 'motorola/titan_retaildsds/titan_umtsds:6.0/MPB24.65-34/31:user/release-keys'
07-22 22:18:50.378 2793-2793/? A/DEBUG: Revision: 'p400'
07-22 22:18:50.378 2793-2793/? A/DEBUG: ABI: 'arm'
07-22 22:18:50.378 2793-2793/? A/DEBUG: pid: 24633, tid: 24633, name: latangle.charts >>> com.flatangle.charts <<<
07-22 22:18:50.378 2793-2793/? A/DEBUG: signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
07-22 22:18:50.401 2793-2793/? A/DEBUG: r0 00000000 r1 00006039 r2 00000006 r3 b6feeb7c
07-22 22:18:50.401 2793-2793/? A/DEBUG: r4 b6feeb84 r5 b6feeb34 r6 0000000d r7 0000010c
07-22 22:18:50.401 2793-2793/? A/DEBUG: r8 b6d96e50 r9 ffffffff sl be92a4ac fp a4026b3c
07-22 22:18:50.401 2793-2793/? A/DEBUG: ip 00000006 sp be92a458 lr b6d74d89 pc b6d76cc0 cpsr 40070010
07-22 22:18:50.408 2793-2793/? A/DEBUG: backtrace:
07-22 22:18:50.408 2793-2793/? A/DEBUG: #00 pc 00043cc0 /system/lib/libc.so (tgkill+12)
07-22 22:18:50.408 2793-2793/? A/DEBUG: #01 pc 00041d85 /system/lib/libc.so (pthread_kill+32)
07-22 22:18:50.408 2793-2793/? A/DEBUG: #02 pc 0001b8e7 /system/lib/libc.so (raise+10)
07-22 22:18:50.408 2793-2793/? A/DEBUG: #03 pc 0001c683 /data/app/com.flatangle.charts-2/lib/arm/libcrystax.so (abort+26)
I've made a minimal example at https://github.com/joaoventura/pyapp that shows the failing behavior.
Updated by Dmitry M. over 8 years ago
- Category set to python
- Status changed from Open to In Progress
- Assignee set to Dmitry M.
- Priority changed from Normal to High
Updated by João V. over 8 years ago
I could confirm that the same error occurs in Android 5.1.
Updated by Dmitry M. over 8 years ago
João Ventura wrote:
I could confirm that the same error occurs in Android 5.1.
Yes, this happens on Android 5.x too. The most interesting thing here is that it has nothing to Python itself - even if we just compile simplest native module (with no dependencies at all), it is not getting loaded by unknown reason. And this happens only when debuggable is set to false. This looks like some security feature of latest Android versions, when it looks for some functionality in native module (for example, with dlsym) but can't find it... Of course, this is just an assumption, not assertion. This issue is really critical, so I'm debugging it further, making it the highest priority amongst other tasks.
Updated by Dmitry M. over 8 years ago
So after long debug I have finally figured out root cause of this crash. Shortly speaking, it's a problem with reading /proc/<uid>/auxv
pseudo-file, which doesn't work for applications having android:debuggable=false
in their manifests. In 10.3.1, getauxval()
function was implemented by reading /proc/<uid>/auxv
pseudo-file and, if for some reason it was not able to open it, call abort()
- and it was shown in call stack of crash. As I have found, calling Py_Initialize
cause subsequent call of getauxval
so this explains why app is got crashed. I have filed separated ticket for this issue - #1459, since really this crash has nothing to Python itself, this is just a bug in libcrystax. Now, when problem become clear, I'm going to fix it and provide new build.
Updated by Dmitry M. over 8 years ago
- Status changed from In Progress to Completed
- % Done changed from 0 to 100
So bug is closed by this fix.
I have initiated build of CrystaX NDK 10.3.2, which will take several days for build, packaging and testing. In the meantime, you can just download fixed libcrystax and unpack it to your existing 10.3.1 folder - this will be exactly how 10.3.2 differs from 10.3.1. When it's done, just rebuild your app again – the problem with Python crash should be gone.
Updated by João V. over 8 years ago
I can confirm that the fixed version is working fine in my Android 6.0 phone!
Updated by Dmitry M. over 8 years ago
- Target version changed from 11.0.0 to 10.3.2
Updated by Malcolm S. over 6 years ago
Unfortunately this workaround doesn't work on all devices. I've been receiving Google Play crash reports exactly like this for my Python-based apps built with Crystax 10.3.2. After obtaining a device of the same model and redirecting stderr to a file, I saw this message:
CRYSTAX_PANI: Can't set RLIMIT_CORE: Operation not permitted
Like the original problem, this only happens with release builds.
The device I reproduced this on was a Samsung Galaxy J2 J200H (Build.DEVICE "j23g"). Here's the full list of device IDs I've received identical crash reports from so far:
ADVAN_5059
ADVAN_5060
c177_gal_241
grandprimeve3g
hwp7
j1acevelte
j1mini3g
j1minive3g
j23g
j2xlte
j3xlte
S02
Vegas
More than half of these (all the ones beginning with "j", plus "grandprimeve3g") are Samsung devices running API level 22 or 23. These are quite common devices: over the last 30 days, the ratio of crashing devices to new installs was 2% for one of my apps and 7% for the other.
Updated by Malcolm S. over 6 years ago
I'll have to try modifying libcrystax to deal with this, but can anyone tell me exactly how or why getauxval
is being called during Py_Initialize
, so I know what changes would be safe?