Commit 20eb5c54 authored by simonb's avatar simonb Committed by Commit bot

On library load failure, retry without shared RELRO.

https://codereview.chromium.org/443393003 introduced code for service
processes that turns off RELRO sharing and retries a library load in
the event of an address clash or other failure to load a library with
shared RELRO.

This change adds the same back off and retry strategy to the libraries
loaded in the main browser process, for cases where low memory devices
aggressively share RELRO as widely as possible.

BUG=411928
TBR=rmcilroy@chromium.org

Review URL: https://codereview.chromium.org/551373004

Cr-Commit-Position: refs/heads/master@{#294393}
parent 69909ccc
...@@ -148,19 +148,47 @@ public class LibraryLoader { ...@@ -148,19 +148,47 @@ public class LibraryLoader {
long startTime = SystemClock.uptimeMillis(); long startTime = SystemClock.uptimeMillis();
boolean useChromiumLinker = Linker.isUsed(); boolean useChromiumLinker = Linker.isUsed();
if (useChromiumLinker) Linker.prepareLibraryLoad(); if (useChromiumLinker) {
// Load libraries using the Chromium linker.
Linker.prepareLibraryLoad();
for (String library : NativeLibraries.LIBRARIES) { for (String library : NativeLibraries.LIBRARIES) {
if (useChromiumLinker) { String zipfile = null;
if (Linker.isInZipFile()) { if (Linker.isInZipFile()) {
String zipfile = context.getApplicationInfo().sourceDir; zipfile = context.getApplicationInfo().sourceDir;
Log.i(TAG, "Loading " + library + " from within " + zipfile); Log.i(TAG, "Loading " + library + " from within " + zipfile);
Linker.loadLibraryInZipFile(zipfile, library);
} else { } else {
Log.i(TAG, "Loading: " + library); Log.i(TAG, "Loading: " + library);
}
boolean isLoaded = false;
if (Linker.isUsingBrowserSharedRelros()) {
try {
if (zipfile != null) {
Linker.loadLibraryInZipFile(zipfile, library);
} else {
Linker.loadLibrary(library); Linker.loadLibrary(library);
} }
isLoaded = true;
} catch (UnsatisfiedLinkError e) {
Log.w(TAG, "Failed to load native library with shared RELRO, " +
"retrying without");
Linker.disableSharedRelros();
}
}
if (!isLoaded) {
if (zipfile != null) {
Linker.loadLibraryInZipFile(zipfile, library);
} else { } else {
Linker.loadLibrary(library);
}
}
}
Linker.finishLibraryLoad();
} else {
// Load libraries using the system linker.
for (String library : NativeLibraries.LIBRARIES) {
try { try {
System.loadLibrary(library); System.loadLibrary(library);
} catch (UnsatisfiedLinkError e) { } catch (UnsatisfiedLinkError e) {
...@@ -174,7 +202,6 @@ public class LibraryLoader { ...@@ -174,7 +202,6 @@ public class LibraryLoader {
} }
} }
} }
if (useChromiumLinker) Linker.finishLibraryLoad();
if (context != null if (context != null
&& shouldDeleteOldWorkaroundLibraries && shouldDeleteOldWorkaroundLibraries
......
...@@ -373,6 +373,17 @@ public class Linker { ...@@ -373,6 +373,17 @@ public class Linker {
} }
} }
/**
* Call this method to determine if the linker will try to use shared RELROs
* for the browser process.
*/
public static boolean isUsingBrowserSharedRelros() {
synchronized (Linker.class) {
ensureInitializedLocked();
return sBrowserUsesSharedRelro;
}
}
/** /**
* Call this method to determine if the chromium project must load * Call this method to determine if the chromium project must load
* the library directly from the zip file. * the library directly from the zip file.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment