libretro / gpsp

gpSP for libretro.
GNU General Public License v2.0
55 stars 53 forks source link

Gpsp core fails to load on Android ('has text relocations') #41

Closed wgrthoen closed 3 years ago

wgrthoen commented 6 years ago

This issue was first reported here: https://github.com/libretro/libretro-super/issues/466 and is a verbatim copy. Retroarch 1.6.9 with the latest core from the app repo still exhibits the same behaviour.

After the Retroarch upgrade to 1.6.0, the Gpsp core fails to load.

The relevant error in the logcat is as follows:

06-09 11:54:50.620  9369  9385 E RetroArch: Failed to open libretro core: "/data/data/com.retroarch/cores/gpsp_libretro_android.so"
06-09 11:54:50.620  9369  9385 E RetroArch: Error(s): dlopen failed: /data/data/com.retroarch/cores/gpsp_libretro_android.so: has text relocations

Thinking the core and info file were outdated I manually pushed the core from: https://bot.libretro.com/nightly/android/latest/armeabi/ to my phone. It sadly gives me the exact same error:

06-09 12:05:45.701  9369  9385 E RetroArch: Failed to open libretro core: "/data/data/com.retroarch/cores/gpsp_libretro_android.so"
06-09 12:05:45.702  9369  9385 E RetroArch: Error(s): dlopen failed: /data/data/com.retroarch/cores/gpsp_libretro_android.so: has text relocations

If I look up whats this means I come up with this: https://android.googlesource.com/platform/bionic/+/master/android-changes-for-ndk-developers.md#Text-Relocations-Enforced-for-API-level-23. Which in short tells us that text relocations in .so files will not be allowed for API level 23 and above.

I Assume the API level was pushed to 23 with the RetroArch 1.6.0 release.

The reason I would still like to use the Gpsp core is that it gives me significantly better performance and battery life in comparison to the Mgba core on my Android phone.

Now I am not sure what the best way would be to go about and solving this, if possible at all. The possibilities I see now are:

  1. If the assembly is part of Gpsp itself it might be hard to rewrite this to conform to the needed PIC standard: https://wiki.gentoo.org/wiki/Hardened/Textrels_Guide#How_to_write_PIC_.28in_theory.29. Re- writing assembly is beyond my programmaing skills :(
  2. Bring down the API level of the RetroArch Android build to 22 to prevent android from denying the dload() of the .so file. This doesn't seem like a real long term solution.
  3. There have also been some old issues mentioned 'around the interwebs' with the NDK generating .so files with TEXTREL sections. If the android builds are done with one of these older versions simply upgrading the build NDK version could possibly solve it.
  4. Downgrade RetroArch on my mobile to 1.50 and use that for now, but that is not a sustainable solution and wouldn't help other users.
  5. Maybe other options/info I missed?

If I missed anything or could provide more feedback to help this issue along please let me know.

hamid-elaosta commented 6 years ago

Has this still not been fixed? Is gpsp dead?

blackman91 commented 6 years ago

The core fails to load on latest RetroArch nightly on Android 7 too, loading core and selecting it does nothing.

andres-asm commented 5 years ago

well, @notaz hasn't been too active and the emulator hasn[t got upstream updates since 2013. So yeah I guess

Notaz did fix picodrive and pcsx back then but I don't know if the fix would translate itself to the dynarec here.

https://github.com/libretro/pcsx_rearmed/commit/0e4ad31902f206e2c6945632bb1f558eae941ff1

notaz commented 5 years ago

IIRC there was something that demotivated me, probably too many unnecessary changes in this fork, and removal of standalone build required to do such work without too much pain.

davidgfnet commented 3 years ago

Is this still an issue? Unfortunately I do not test on Android regularly ^^' BTW @notaz, you can use heuripedes/nanoarch or my davidgfnet/miniretro frontends for testing! They allow uncomplicated testing (either manual or fully automated) and regression testing.

Devs21X commented 3 years ago

Hello everyone, i have been trying to get this core to work on my Retroid Pocket 2 but it doesn't work, i don't know if it's related to this problem but here's what the log says:

Failed to open libretro core: "/data/user/0/com.retroarch/cores/gpsp_libretro_android.so" Error(s): dlopen failed: "/data/data/com.retroarch/cores/gpsp_libretro_android.so": W + E load segments are not allowed

I tested the core on my phone with Android 10 and it works fine there, my Retroid Pocket 2 has Android 8.1 and RetroArch 1.9.5 installed.

matheuswillder commented 3 years ago

I tested today the latest build and I have the same problem, the core fails to load on Android but on Windows it loads correctly. Device with Android 11, armeabi-v7a architecture and RetroArch with default settings. I don't know if I can debug on Android but if need any more information I can try to help.

davidgfnet commented 3 years ago

You are absolutely right! Seems that, since Android 6 or so, text relocs have been disabled in Android: https://android.googlesource.com/platform/bionic/+/master/android-changes-for-ndk-developers.md#text-relocations-enforced-for-api-level-23

I'm working on fixing this, should have a fix in the coming days. Thanks!

matheuswillder commented 3 years ago

Great to hear! When it is fixed and there some new compilation in the buildbot I will test it again, thanks for the development!

davidgfnet commented 3 years ago

This is fixed as of today. Please check out the new builds and let me know if there's any issue with them!

matheuswillder commented 3 years ago

@davidgfnet The core already seems to have been updated in buildbot but it still doesn't load on my Android. I saved the event log (sorry I didn't do it before because I didn't know it's so simple to do, I figured I would need ADB and I have some limitations for doing this). See below:

Falha em abrir o núcleo Libretro: "/data/user/0/com.retroarch/cores/gpsp_libretro_android.so" Error(s): dlopen failed: "/data/user/0/com.retroarch/cores/gpsp_libretro_android.so": W+E load segments are not allowed [CORE]: Using content: /storage/emulated/0/Download/Super Mario Advance 2 - Super Mario World.gba. [Core]: Content ran for a total of: 00 hours, 00 minutes, 00 seconds. [Core]: Unloading core.. [Core]: Unloading core symbols.. Threaded video stats: Frames pushed: 3772, Frames dropped: 0. RetroArch 1.9.7 (Git 5c2f79a) === Build ======================================= Capacidades: NEON VFPv3 VFPv4 [INFO] Built: Jul 25 2021 [INFO] Version: 1.9.7 [INFO] Git: 5c2f79a [INFO] ================================================= jni_thread_destruct() [Input]: Found input driver: "android". [Core]: Loading dynamic libretro core from: "/data/user/0/com.retroarch/cores/gpsp_libretro_android.so" Falha em abrir o núcleo Libretro: "/data/user/0/com.retroarch/cores/gpsp_libretro_android.so" Error(s): dlopen failed: "/data/user/0/com.retroarch/cores/gpsp_libretro_android.so": W+E load segments are not allowed [Environ]: SET_PIXEL_FORMAT: RGB565. Versão da API libretro: 1 [INFO] Compilado contra a API: 1 [Audio]: Set audio input rate to: 48000.00 Hz. [Video]: Video @ 960x720 [Video]: Starting threaded video driver ... Android EGL: GLES version = 2. [EGL] Falling back to eglGetDisplay [EGL]: EGL version: 1.5 [GL]: Found GL context: egl_android [GL]: Detecting screen resolution 0x0. [EGL]: Current context: 0xd1ea1a40. [GL]: Vendor: Qualcomm, Renderer: Adreno (TM) 505. [GL]: Version: OpenGL ES 3.2 V@0502.0 (GIT@8fc5070, I2b41315a24, 1611347907) (Date:01/22/21). [GL]: Using resolution 720x1461 [GL]: Default shader backend found: glsl. [Shader driver]: Using GLSL shader backend. [GL]: Stock GLSL shaders will be used. [GLSL]: Found GLSL vertex shader. [GLSL]: Found GLSL fragment shader. [GLSL]: Linking GLSL program. [GLSL]: Found GLSL vertex shader. [GLSL]: Found GLSL fragment shader. [GLSL]: Linking GLSL program. [GLSL]: Found GLSL vertex shader. [GLSL]: Found GLSL fragment shader. [GLSL]: Linking GLSL program. [GL]: Using 4 textures. [GL]: Loaded 1 program(s). [Joypad]: Found joypad driver: "android". [Font]: Using font rendering backend: stb-unicode. [Video]: Found display server: android [OpenSL]: Requested audio latency: 128 ms.[OpenSL]: Setting audio latency: Block size = 768, Blocks = 32, Total = 24576 ... [Display]: Found display driver: "gl". [Font]: Using font rendering backend: stb-unicode. [Font]: Using font rendering backend: stb-unicode. [Font]: Using font rendering backend: stb-unicode. Falha em abrir o núcleo Libretro: "/data/user/0/com.retroarch/cores/gpsp_libretro_android.so" Error(s): dlopen failed: "/data/user/0/com.retroarch/cores/gpsp_libretro_android.so": W+E load segments are not allowed [Font]: Using font rendering backend: stb-unicode. [Font]: Using font rendering backend: stb-unicode. [Font]: Using font rendering backend: stb-unicode. [SRAM]: SRAM não será salva. [Playlist]: Written to playlist file: /storage/emulated/0/Android/data/com.retroarch/files/content_history.lpl [Playlist]: Written to playlist file: /storage/emulated/0/Android/data/com.retroarch/files/content_music_history.lpl [Playlist]: Written to playlist file: /storage/emulated/0/Android/data/com.retroarch/files/content_image_history.lpl [Playlist]: Carregando arquivo de histórico: [/storage/emulated/0/Android/data/com.retroarch/files/content_history.lpl]. [Playlist]: Carregando arquivo de histórico: [/storage/emulated/0/Android/data/com.retroarch/files/content_music_history.lpl]. [Playlist]: Carregando arquivo de histórico: [/storage/emulated/0/Android/data/com.retroarch/files/content_image_history.lpl]. [Playlist]: Carregando o arquivo de favoritos: [/storage/emulated/0/Android/data/com.retroarch/files/content_favorites.lpl]. [Config]: Nova configuração salva em "/storage/emulated/0/Android/data/com.retroarch/files/retroarch.cfg". [Core]: Content ran for a total of: 00 hours, 00 minutes, 00 seconds. [Core]: Unloading core.. [Core]: Unloading core symbols.. Threaded video stats: Frames pushed: 286, Frames dropped: 0.

Should I open a new issue?

davidgfnet commented 3 years ago

Oh lol thanks for the report. More work for me :D Let's just reuse this bug then to track this. Will fix it soon :)

matheuswillder commented 3 years ago

Thank you so much for your work and dedication, I saw the results of this on the libretro profile on Twitter and looks amazing. Let me know if you need more information, I will do my best to try to help.

davidgfnet commented 3 years ago

I added some fixes, could you check in a couple days and see whether they work? Dont have an old Android device sorry!

afjara commented 3 years ago

I added some fixes, could you check in a couple days and see whether they work? Dont have an old Android device sorry!

Now gpSP core updated from the libretro buildbot is working correctly in RetroArch 1.9.11 with my Retroid Pocket 2 (Flashed with LineageOS Android 8.1)

Thank you!

matheuswillder commented 3 years ago

Sorry for the delay, I've been a little busy these past few days and ended up missing your notification.

The core now works perfectly (and incredibly fast) on my Android 11! Here is a screenshot: Screenshot_20211103-235444_RetroArch

I don't understand why you talked about not have an old device to test, I think this issue only applied to newer Android versions, or did I get it wrong? Even before the fixes I was able to use this core on an old device with Android 4.1, here's a screenshot: Screenshot_2021-11-04-00-03-09

Anyway, thanks again for your work developing this project and also for your work on your other projects. Looking at your GitHub profile I saw that you were the developer of whatsapp-purple, which I perfectly remember using a few years ago. Thank you very much!

davidgfnet commented 3 years ago

Sure! Glad it works. The main issue was with gpsp for armv7 targets (32 bit android builds), 64 bit version should always work just fine (since it did not use the dyanrec). Anyway, closing this if nobody else complains :) Feel free to reopen of course if something new is found!