We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3434 - LoadLibrary on X86 Android devices running ARM code
Summary: LoadLibrary on X86 Android devices running ARM code
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: 2.0.4
Hardware: x86 Android (All)
: P2 blocker
Assignee: Sylvain
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-25 10:51 UTC by Nix
Modified: 2018-12-30 13:28 UTC (History)
0 users

See Also:


Attachments
patch to load from static context (3.78 KB, patch)
2017-08-12 08:21 UTC, Sylvain
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nix 2016-09-25 10:51:48 UTC
With the move to 2.0.4 the java-wrapper for android project changes the location of the code that loads the shared-objects. Originally in the static {} constructor of SDLActivity it was moved to onCreate - On x86 devices that run emulated ARM this will crash. Moving the loadLibrary back to the static constructor fixed this.

[I can't compile x86 due to library restrictions)
Comment 1 Nix 2016-09-25 10:53:20 UTC
The bug will come in the form of unsupported e_machine: 40 bug while loading the shared-object.
Comment 2 Sam Lantinga 2017-08-11 20:54:45 UTC
Sylvain, this is a blocking bug, can you take a look at it?

Thanks!
Comment 3 Sylvain 2017-08-12 08:21:53 UTC
Created attachment 2827 [details]
patch to load from static context

Can you add more precisions to try this ? 

- I have no x86 android device. Can I use an android x86 emulator on my pc, that would run emulated ARM ? How to set this up ?
- Did you try various arm abis (arm vs arm-v7a), and lastest ndk (ndk-r13b, r15).
- Maybe, in the mean-times, you would have tested a newer version of your emulator ? (is this libhoudini ?)


Indeed java code that loads the shared objects has changed, with ticket #2759, to add a popup when shared libraries fail to load.
And also, it also allow users to customize the list of libraries to load from a subclass (https://hg.libsdl.org/SDL/rev/9a0ebeef4988).


We can revert the loading to make them from a static context, and still have a pop-up when they fail to load.
But we will lose the customisation of libraries. (Do we really need this ? shared libraries dependencies seems automatically pulled) 

According to https://developer.android.com/training/articles/perf-jni.html
"The preferred way to get at your native code is to Call System.loadLibrary from a static class initializer. "

Here's a patch for that.
Comment 4 Sam Lantinga 2017-08-12 22:11:17 UTC
Nix, can you confirm that Sylvain's patch fixes the bug for you?
Comment 5 Nix 2017-08-15 08:52:46 UTC
Hi,

At the time I tested on NDK 10e. Did not test on emulator. 

From what I can tell, the patch only moves the list of libraries to load to a member method rather than in-function variables. I don't see a reason this will fix the binary loading on x86 as its practically the same?
Comment 6 Sylvain 2017-08-23 13:37:02 UTC
Nix,

With the patch the libs are loaded from a static {} constructor.
As before : https://hg.libsdl.org/SDL/rev/8ebee8e28593 , as you remarked.

Can you also give more information about your testing device ?
Comment 7 Nix 2017-09-04 09:29:37 UTC
Hi,

Sorry didn't see the patch before.

I have no way of testing this now, how ever, moving it to the static constructor worked for me at the time.

My testing device was an x86 intel android device. I am not sure if all x86 will crash when not loading from static constructor.

The patch is the right solution
Comment 8 Sylvain 2017-09-05 11:04:40 UTC
Hi, and do you think you could have access to this mysterious android device again ?
Comment 9 Nix 2017-09-06 08:02:24 UTC
Sorry :/ don't have access to it anymore..

I did find the model though;
http://www.gsmarena.com/samsung_galaxy_tab_3_10_1_p5210-5478.php

Chipset	Intel Atom Z2560
CPU	Dual-core 1.6 GHz
Comment 11 Nix 2017-09-06 08:08:17 UTC
I have never tried running the emulator so I don't really know.. I figured its not that good with graphics/heavy real time
Comment 12 Sylvain 2017-09-06 11:16:42 UTC
I tried the x86 emulator, but I think it has no arm translation brige enabled.
When I run an ARM .apk, it does not find the shared libraries.
So it does not even try to translate and execute them.
Comment 13 Sylvain 2017-09-06 11:41:06 UTC
from this link https://software.intel.com/en-us/android/articles/intel-architecture-support-guide-for-android-middleware-providers

When having support for 3rd party plugins that can embed architecture-specific binaries, like Unity has, attention should be given to be sure these plugins are compatible with all the supported platforms. Before Android 5.0, it was possible to still load ARM libs from an x86 folder. But this isn’t possible anymore and leads to errors such has “dlopen failed: ‘libMyLib.so’ has unexpected e_machine: 40”. So plugins have to be upgraded to also include x86 binaries and the engine/service has to enforce that, in order to allow a smooth transition.

maybe you were also loading your arm library from the x86 folder ?
Comment 14 Nix 2017-09-06 12:17:30 UTC
Nope, our project only has ARM binaries, located in app\src\main\jniLibs\armeabi-v7a
Comment 15 Sylvain 2018-12-30 13:28:36 UTC
Closing it

- SDL2 is choosing to load libraries dynamically.

- SDL2 now support "relinker": 
  https://github.com/KeepSafe/ReLinker
  https://hg.libsdl.org/SDL/rev/f4dde3c6bae9