-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Cross Compile for Android and issues with PyExc_OSError #111225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm not sure if this is useful, but I did find this in the Android NDK 26 notes Issue 360: thread_local variables with non-trivial destructors will cause segfaults if the containing library is dlcloseed. This was fixed in API 28, but code running on devices older than API 28 will need a workaround. The simplest fix is to stop calling dlclose. If you absolutely must continue calling dlclose, see the following table: |
That doesn't seem relevant, because you're not seeing a segfault. More likely, _socket.cpython-3.12.so has not been linked against libpython3.12.so. You can check this using |
@mhsmith, based on your comment, can we close this issue as not-planned? |
I've just remembered, I also encountered this problem when building Python 3.12 for Chaquopy. I was able to fix it with this patch, which I'll turn into a pull request in the near future. |
@mhsmith - Thanks for the update. I have tried your patch as is. Something is still different because it's looking for python3.12.so instead of libpython3.12.so. I'm playing with your patch file, I'm not an expert but looking at it and trying to figure out what my build needs for some of your changes. /android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android26-clang -shared -L/python3-android/src/Python-3.12.1/Android/sysroot/usr/lib -pie Modules/arraymodule.o -lpython3.12 -o Modules/array.cpython-312.so |
It doesn't say it's looking for python3.12.so, it says it's looking for The issue is probably that this file doesn't exist in any of the Lines 7500 to 7502 in 2305ca5
Are you sure you applied the whole patch? |
I am pretty confident that I applied the entire patch. What I'm not sure is how I can tell if ac_sys_system is being set right. Is there a log or anything I could put into the configure? I tried using an echo and a printf, but not having any luck. |
In looking at this more, and doing a before and after, I can see that it is trying to apply the patch, I don't see errors, but the configure patch is not being applied. I will look into this and make sure the patch is being applied. Sorry about that. |
I haven't looked at your build process, but maybe you're regenerating the configure script from the configure.ac file after applying the patch. |
You are correct. I didn't realize the script I was using was doing an auto reconfigure, and I was applying the patch before this. Once I applied the patch in the proper place, things worked as expected. I truly appreciate your help and time looking into this with me. |
That's great, but please reopen the issue, because the original bug still exists in an unpatched version of Python. |
Part of the work on PEP 738: Adding Android as a supported platform. * Rename the LIBPYTHON variable to MODULE_LDFLAGS, to more accurately reflect its purpose. * Edit makesetup to use MODULE_LDFLAGS when linking extension modules. * Edit the Makefile so that extension modules depend on libpython on Android and Cygwin. * Restore `-fPIC` on Android. It was removed several years ago with a note that the toolchain used it automatically, but this is no longer the case. Omitting it causes all linker commands to fail with an error like `relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol '_Py_FalseStruct'; recompile with -fPIC`.
…ython#115780) Part of the work on PEP 738: Adding Android as a supported platform. * Rename the LIBPYTHON variable to MODULE_LDFLAGS, to more accurately reflect its purpose. * Edit makesetup to use MODULE_LDFLAGS when linking extension modules. * Edit the Makefile so that extension modules depend on libpython on Android and Cygwin. * Restore `-fPIC` on Android. It was removed several years ago with a note that the toolchain used it automatically, but this is no longer the case. Omitting it causes all linker commands to fail with an error like `relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol '_Py_FalseStruct'; recompile with -fPIC`.
…ython#115780) Part of the work on PEP 738: Adding Android as a supported platform. * Rename the LIBPYTHON variable to MODULE_LDFLAGS, to more accurately reflect its purpose. * Edit makesetup to use MODULE_LDFLAGS when linking extension modules. * Edit the Makefile so that extension modules depend on libpython on Android and Cygwin. * Restore `-fPIC` on Android. It was removed several years ago with a note that the toolchain used it automatically, but this is no longer the case. Omitting it causes all linker commands to fail with an error like `relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol '_Py_FalseStruct'; recompile with -fPIC`.
It's been a while, trying to build against 3.12.4, is this patch still needed? |
It's still needed on Python 3.12 and older, but it won't be needed in Python 3.13. |
Perfect, I figured as much but wanted to be sure. I appreciate it. |
…ython#115780) Part of the work on PEP 738: Adding Android as a supported platform. * Rename the LIBPYTHON variable to MODULE_LDFLAGS, to more accurately reflect its purpose. * Edit makesetup to use MODULE_LDFLAGS when linking extension modules. * Edit the Makefile so that extension modules depend on libpython on Android and Cygwin. * Restore `-fPIC` on Android. It was removed several years ago with a note that the toolchain used it automatically, but this is no longer the case. Omitting it causes all linker commands to fail with an error like `relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol '_Py_FalseStruct'; recompile with -fPIC`.
Bug report
Bug description:
In trying to run Python 3.12 on Android. I have been cross-compiling Python for a number of years. Having built a 64bit version I am getting the following error when I try to run
I get the following error at runtime.
ImportError('dlopen failed: cannot locate symbol "PyExc_OSError" referenced by "/data/data/com.myapp/files/Python64/lib-dynload/_socket.cpython-312.so"...')
I have verified that the _socket.cpython-3.12.so exists. I'm not really sure what other info would be beneficial for people to help me understand this error so I will start with this and happily add more details if requested.
CPython versions tested on:
3.12
Operating systems tested on:
Other
Linked PRs
The text was updated successfully, but these errors were encountered: