kivy / python-for-android

Turn your Python application into an Android APK
https://python-for-android.readthedocs.io
MIT License
8.33k stars 1.85k forks source link

dlopen fail on android 4.3 #141

Closed tshirtman closed 11 years ago

tshirtman commented 11 years ago

when my import import sleekxmpp in my service, i get a dlopen error

I/python  ( 3368):   File "/home/gaby/lcs/kitch/.buildozer/android/app/_applibs/sleekxmpp/__init__.py", line 9, in <module>
I/python  ( 3368):   File "/home/gaby/lcs/kitch/.buildozer/android/app/_applibs/sleekxmpp/basexmpp.py", line 22, in <module>
I/python  ( 3368):   File "/home/gaby/lcs/kitch/.buildozer/android/app/_applibs/sleekxmpp/roster/__init__.py", line 9, in <module>
I/python  ( 3368):   File "/home/gaby/lcs/kitch/.buildozer/android/app/_applibs/sleekxmpp/xmlstream/__init__.py", line 9, in <module>
I/python  ( 3368):   File "/home/gaby/lcs/kitch/.buildozer/android/app/_applibs/sleekxmpp/jid.py", line 18, in <module>
I/python  ( 3368):   File "/home/gaby/lcs/kitch/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/stringprep.py", line 8, in <module>
I/python  ( 3368): ImportError: dlopen failed: invalid flags to dlopen: 102

this was working just last week, and there was no major change in my code, so i though it could come from my android upgrade to 4.3… and bingo, there is indeed a change about this: http://www.funkyandroid.com/aosp-JDQ39-JWR66V.html "e66190d : Check for unknown flags passed to dlopen(3)."

tito commented 11 years ago

fuck :(

tshirtman commented 11 years ago

yeah, i've been trying to look into it, but it's very hard to find which call causes this, i was thinking about building a debug distro to use with gdb-remote, but not much time today for this.

tito commented 11 years ago

Means... any current modules loaded with dlopen failed right now? That's a big issue. So not the one with libpymodules i guess, but the one outside it? Do you have a full log (from the first install / decompression?)

tshirtman commented 11 years ago

what's weird is that only my service crash, my interface works perfectly, so i think it's not all dlopen. I'll post a more complete log.

brousch commented 11 years ago

Is this a problem only when compiling with with API 18, or for people running Android 4.3?

On Mon, Jul 29, 2013 at 8:19 AM, Mathieu Virbel notifications@github.comwrote:

Means... any current modules loaded with dlopen failed right now? That's a big issue. So not the one with libpymodules i guess, but the one outside it? Do you have a full log (from the first install / decompression?)

— Reply to this email directly or view it on GitHubhttps://github.com/kivy/python-for-android/issues/141#issuecomment-21715930 .

Ben Rousch brousch@gmail.com http://clusterbleep.net/

tito commented 11 years ago

I guess people who run android 4.3.

tito commented 11 years ago

My current analysis is: stringprep.py line 8 refers to from unicodedata import ucd_3_2_0 as unicodedata. unicodedata.so is imported via _PyImport_GetDynLoadFunc. So it will rely on the call:

handle = dlopen(pathname, dlopenflags);

The dlopenflags is initialized to 0, and set to:

dlopenflags = PyThreadState_GET()->interp->dlopenflags;

Which is set by default to:

build/hostpython/Python-2.7.2/Python/pystate.c:80:        interp->dlopenflags = RTLD_NOW;
build/hostpython/Python-2.7.2/Python/pystate.c:82:        interp->dlopenflags = RTLD_LAZY;

OR, set manually by sys.setdlopenflags().

The flags accepted by Android 4.3 are checked from this commit: https://android.googlesource.com/platform/bionic/+/e66190d%5E%21/#F1 | relevant part:

+  if ((flags & ~(RTLD_NOW|RTLD_LAZY|RTLD_LOCAL|RTLD_GLOBAL)) != 0) {
+    DL_ERR("invalid flags to dlopen: %x", flags);
+    return NULL;
+  }

Somewhere, somebody changed the flags, and set a wrong value?

tshirtman commented 11 years ago

my full log from uninstall/reinstall to crash http://paste.ubuntu.com/5925088/

and yeah, i found about as much, though was not sure who loaded the .so (__PyImport_GetDynLoadFunc ok), maybe the values of the declarations changed, because the constants seems to be the same.

tito commented 11 years ago

I really hope it's not that... because it would be ÜBER SILLY

tito commented 11 years ago

On linux:

#define RTLD_LAZY   0x00001 /* Lazy function call binding.  */
#define RTLD_NOW    0x00002 /* Immediate function call binding.  */
#define RTLD_BINDING_MASK   0x3 /* Mask of binding time value.  */
#define RTLD_NOLOAD 0x00004 /* Do not load the object.  */
#define RTLD_DEEPBIND   0x00008 /* Use deep binding.  */
#define RTLD_GLOBAL 0x00100
#define RTLD_LOCAL  0
#define RTLD_NODELETE   0x01000

On android:

enum {
  RTLD_NOW  = 0,
  RTLD_LAZY = 1,
  RTLD_LOCAL  = 0,
  RTLD_GLOBAL = 2,
};

Still, during compilation, the flags should be set to the right value.....

tito commented 11 years ago

invalid flags to dlopen: 102 -> the value is hex, so for the linux way, it should mean:RTLD_GLOBAL | RTLD_NOW.

Values are set manually somewhere.

tito commented 11 years ago

e9875e4 - fixed.