Skip to content
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

Optimize extraction strategy #45

Closed

Conversation

codyi96
Copy link
Contributor

@codyi96 codyi96 commented Aug 20, 2019

fix bug.

Make extraction strategy of .so files smarter.
In past versions, SoLoader follows standard rule to extract .so files from zip. However, some phones customize application installer which doesn't follow standard rule. And then, may cause crash because .so files of different ABI is loaded in the application.
In this version, SoLoader will parse .so files in lib dir to determine which ABI of .so files should be extracted to lib-main dir. It can ensure that only one type of ABI will be loaded in the application so that SoLoader can be adapted for more models.

Copy link
Contributor

@oprisnik oprisnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good. I'll import this for internal testing / review.

PROJECT Outdated Show resolved Hide resolved
Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oprisnik has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link

@codyi96 has updated the pull request. Re-import the pull request

Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oprisnik has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@BurntBrunch BurntBrunch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for taking a look at this!

Let me see if I understand the problem correctly:
Oppo/Vivo devices are reporting 64-bit ABIs in Build.CPU_ABI/SUPPORTED_ABIS but instead extract the 32-bit libraries, presumably to improve RSS and general performance of the device. Correct?

The approach you're taking here (parsing already-extracted libraries) is correct but also a little excessive.
Assuming that these phones are not mixing up cpu families (x86 vs arm), the following logic is far simpler:

  1. Determine CPU family
  2. Determine process bitness
  3. Load correct ABI based on cpu+bitness

I assume family is correct in Build.CPU_ABI, so let's use that (libhoudini comes to mind but whatever, it's mostly a relic of the past). Bitness is also trivial to compute:

    // Check to see if we're actually running in 64-bit mode.
    try {
      return android.system.Os.readlink("/proc/self/exe").contains("64");
    } catch (android.system.ErrnoException e) {
      return false;
    }

This is not only easier to understand but also faster as you only need to resolve a symlink.

I don't have access to one of these devices to try it but I sincerely doubt Oppo messed with the app_process vs app_process64 naming.

So far I'm talking about the issue in the bug report this PR refers to (bitness being incorrect). I can however a see a slightly different issue as well - SoLoader should be falling back to system-extracted libraries automatically, it prepends ApplicationSoSource to its search list.

Is SoLoader not finding the system-extracted libs for some reason or are the react libs packaged in a way that is not system-installer-visible? (Sorry, don't know much about react native)

P.S. minor code style/organization things inline.

java/com/facebook/soloader/SysUtil.java Outdated Show resolved Hide resolved
java/com/facebook/soloader/SysUtil.java Outdated Show resolved Hide resolved
@facebook-github-bot
Copy link

@codyi96 has updated the pull request. Re-import the pull request

@codyi96 codyi96 force-pushed the bugfix/optimizeExtractionStrategy branch from 9a7ac10 to dc3025a Compare August 27, 2019 03:44
@facebook-github-bot
Copy link

@codyi96 has updated the pull request. Re-import the pull request

Copy link
Contributor

@BurntBrunch BurntBrunch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks @codyi96, this is really clean! 🥇

I imagine you retested this and it's still fine?

Left a couple of a minor comments inline. Do you mind addressing them, squashing into one commit and cleaning up the ELF code so we can land it cleanly?

java/com/facebook/soloader/SysUtil.java Outdated Show resolved Hide resolved
java/com/facebook/soloader/MinElf.java Outdated Show resolved Hide resolved
java/com/facebook/soloader/SysUtil.java Show resolved Hide resolved
@codyi96 codyi96 force-pushed the bugfix/optimizeExtractionStrategy branch from dc3025a to f09c8b6 Compare August 28, 2019 03:23
@facebook-github-bot
Copy link

@codyi96 has updated the pull request. Re-import the pull request

@codyi96 codyi96 force-pushed the bugfix/optimizeExtractionStrategy branch from f09c8b6 to 9553342 Compare August 28, 2019 03:28
@facebook-github-bot
Copy link

@codyi96 has updated the pull request. Re-import the pull request

Fixed: facebook/react-native#25490
Make extraction strategy of .so files smarter. In past versions,
SoLoader follows standard rule to extract .so files from zip.
However, some phones customize application installer which doesn't
follow standard rule. It may cause crash because .so files of
different ABIs are loaded in the application. In order to deal with
this problem, SoLoader will parse the path of current process to
determine which ABI should be extracted. It'll ensure that only
one type of ABI will be loaded in the application so that
SoLoader can be adapted for more models.
@codyi96 codyi96 force-pushed the bugfix/optimizeExtractionStrategy branch from 9553342 to 44956a2 Compare August 28, 2019 03:39
@facebook-github-bot
Copy link

@codyi96 has updated the pull request. Re-import the pull request

Copy link

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oprisnik has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@codyi96
Copy link
Contributor Author

codyi96 commented Sep 4, 2019

Is code being reviewed? @oprisnik

@oprisnik
Copy link
Contributor

oprisnik commented Sep 4, 2019

Yes, we're on it. Should be merged soon. Fingers crossed :)

@facebook-github-bot
Copy link

@oprisnik merged this pull request in b2555b8.

@mars-lan
Copy link

Still seeing incorrect version of lib being loaded and can reproduce it reliably on emulator: #55

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

App Crash on Android OS 5.1.1 Real Oppo R7s (32BIT) RN(0.60.0)
5 participants